tramway-admin 1.23.0.3 → 1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e829ed2d89e8d5fd1473c6e9ee5b62e0575f5c75d60a7093847c6528c7dfa380
4
- data.tar.gz: 0641cb8bb91d91f751d0aba568d0c31915ecf4832474889b0d791680bb4f9af4
3
+ metadata.gz: 011d456ac295086199431405fbb6d3531094e79c985918fa968a789ca1f02bed
4
+ data.tar.gz: 0a9d46e59b30f6b4fee4d83adcf1d69bffe184ec965931cbb3e318a5111b0fc0
5
5
  SHA512:
6
- metadata.gz: ee3bfebb363dcbad9d0beee9ff640d7dbecec7c6894bd462c084cf5c5e2b3505cd54c6dc56481d33855b50889abded2274471a94ab1c04daf0a156a52eba6896
7
- data.tar.gz: 6ff5398fd1251c97811667d05075d317f35ef668ed63a04a968c11c230ae7599957d17ba6213fcf81b1c6c975eb8efbcbb44b012317aead899418c5647ac79d5
6
+ metadata.gz: 0c11ce53229c6bb4e73d482a575d65e268d02b93cfff84545cb5385c7e4289c54e0607b01e5c77c2fe683235babd5fe134d6487c5213594d8c31765c299c7823
7
+ data.tar.gz: 6cf766da4f7d49f79908a097a155435e6646651599fa4d5c0df8e450a4ff33425cdc57a7e4a4cee4a519c2a8f0a588ea4364c522c635e4c2055be1f30879497a
@@ -13,5 +13,6 @@
13
13
  %td
14
14
  = link_to association_object.name, record_path(association_object.id, model: association.options[:class_name])
15
15
  %td
16
- = delete_button url: record_path(association_object.id, model: association.options[:class_name], redirect: current_model_record_path(object.id)), button_options: { class: 'btn btn-xs btn-danger' } do
17
- = fa_icon 'trash-alt'
16
+ - if ::Tramway::Admin.action_is_available?(association_object, project: (@application_engine || @application.name), model: association_object.model.class, role: current_user.role, action: :destroy)
17
+ = delete_button url: record_path(association_object.id, model: association.options[:class_name], redirect: current_model_record_path(object.id)), button_options: { class: 'btn btn-xs btn-danger' } do
18
+ = fa_icon 'trash-alt'
data/lib/tramway/admin.rb CHANGED
@@ -39,8 +39,24 @@ module Tramway
39
39
  instance_variable_get("@#{models_type}_models")&.map { |projects| projects[1][role]&.keys }&.flatten || []
40
40
  end
41
41
 
42
- def action_is_available?(project:, role:, model:, action:)
43
- @singleton_models[project][role][model][action]
42
+ def action_is_available?(record, project:, role:, model:, action:)
43
+ actions = select_actions(project: project, role: role, model: model)
44
+ availability = actions&.select do |a|
45
+ if a.is_a? Symbol
46
+ a == action.to_sym
47
+ elsif a.is_a? Hash
48
+ a.keys.first.to_sym == action.to_sym
49
+ end
50
+ end.first
51
+
52
+ return false unless availability.present?
53
+ return true if availability.is_a? Symbol
54
+
55
+ return availability.values.first.call record
56
+ end
57
+
58
+ def select_actions(project:, role:, model:)
59
+ @singleton_models&.dig(project, role, model) || @available_models&.dig(project, role, model)
44
60
  end
45
61
  end
46
62
  end
@@ -6,10 +6,9 @@ module Tramway::Admin::RecordsModels
6
6
  @available_models[project] ||= {}
7
7
  @available_models[project][role] ||= {}
8
8
  models.each do |model|
9
- case model.class
10
- when Class
9
+ if model.class == Class
11
10
  @available_models[project][role].merge! model => [ :index, :show, :update, :create, :destroy ]
12
- when Hash
11
+ elsif model.class == Hash
13
12
  @available_models[project][role].merge! model
14
13
  end
15
14
  end
@@ -6,11 +6,10 @@ module Tramway::Admin::SingletonModels
6
6
  @singleton_models[project] ||= {}
7
7
  @singleton_models[project][role] ||= []
8
8
  models.each do |model|
9
- case model.class
10
- when Class
11
- @available_models[project][role] << { model => [ :index, :show, :update, :create, :destroy ] }
12
- when Hash
13
- @available_models[project][role] << model
9
+ if model.class == Class
10
+ @singleton_models[project][role] << { model => [ :index, :show, :update, :create, :destroy ] }
11
+ elsif model.class == Hash
12
+ @singleton_models[project][role] << model
14
13
  end
15
14
  end
16
15
  @singleton_models = @singleton_models.with_indifferent_access
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Admin
5
- VERSION = '1.23.0.3'
5
+ VERSION = '1.24'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.23.0.3
4
+ version: '1.24'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-16 00:00:00.000000000 Z
11
+ date: 2020-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootstrap-kaminari-views