mrpin-sdk 1.0.24 → 1.0.25

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
  SHA1:
3
- metadata.gz: 447964f5cfee8e0ffbfc55b355d460ab921f7c2c
4
- data.tar.gz: e633defee39f26b62d7e129b49130fcf6d9ac257
3
+ metadata.gz: 616c069c5fbd21d6fb8ee7e4b1a074192b77bdc7
4
+ data.tar.gz: baf2f822d61c24f3bc823024b8947fa5ab758e7b
5
5
  SHA512:
6
- metadata.gz: 64d83df629aaa686237d6905a33d5cf6fff3537d90582cd3187a2c8d96e5bf48235de4b5062d208a4699eec9691bea2ef357fed2abfef23d0885967a337c402f
7
- data.tar.gz: 79e185c733874752fb886798b31fb94d6b1ef59b2fd0bedc123497172d6f588f12d8c1ebecb191a70c10664845fa7bfab5194263156e26ce6f752b9235e58602
6
+ metadata.gz: 24fd4ae0225ff19c4749d95d88967618129ebf1e75179396a00d68fb9872a4dc98f4e316938ad948a7218247f9c3b6bff72002762e705e2c815816c215429dd7
7
+ data.tar.gz: 32f28f0b60bfca44620fb7d3682d02d6f6413582e2940e25f0049a68262c1066390eaa8be63556ba7407e8dd93dd561b3884ca55d926644273e521f34624a074
@@ -0,0 +1,25 @@
1
+ # See the wiki for details:
2
+ # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
3
+ class Ability
4
+ include CanCan::Ability
5
+
6
+ public
7
+ def self.rails_admin_config=(value)
8
+ @rails_admin_config = value
9
+ end
10
+
11
+ public
12
+ def self.rails_admin_config
13
+ @rails_admin_config
14
+ end
15
+
16
+ def initialize(user)
17
+ models_can_manage = self.class.rails_admin_config.get_models_can_manage_for(user.role)
18
+
19
+ can :access, :rails_admin # only allow admin users to access Rails Admin
20
+ can :dashboard # allow access to dashboard
21
+ can :manage, models_can_manage
22
+ #use if need
23
+ # cannot :manage, models_cannot_manage
24
+ end
25
+ end
@@ -14,6 +14,8 @@ class RailsAdminConfiguratorBase
14
14
 
15
15
  public
16
16
  def initialize
17
+ Ability.rails_admin_config = self
18
+
17
19
  @models_names = []
18
20
  @models_names_sorted = []
19
21
 
@@ -73,8 +75,11 @@ class RailsAdminConfiguratorBase
73
75
  nil
74
76
  end
75
77
 
76
- private
78
+ protected
77
79
  def configure_auth
80
+ # == CanCanCan ==
81
+ @config.authorize_with :cancan
82
+
78
83
  # == Devise ==
79
84
  @config.authenticate_with do
80
85
  warden.authenticate! scope: :admin_user
@@ -85,7 +90,7 @@ class RailsAdminConfiguratorBase
85
90
  nil
86
91
  end
87
92
 
88
- private
93
+ protected
89
94
  def configure_actions
90
95
  @config.actions do
91
96
  dashboard do
@@ -106,7 +111,7 @@ class RailsAdminConfiguratorBase
106
111
  nil
107
112
  end
108
113
 
109
- private
114
+ protected
110
115
  def configure_models
111
116
  # setup models
112
117
  @config.included_models.each do |model|
@@ -127,7 +132,7 @@ class RailsAdminConfiguratorBase
127
132
  nil
128
133
  end
129
134
 
130
- private
135
+ protected
131
136
  def configure_view
132
137
  @config.show_gravatar = false
133
138
  @config.total_columns_width = 1000
@@ -137,7 +142,7 @@ class RailsAdminConfiguratorBase
137
142
  nil
138
143
  end
139
144
 
140
- private
145
+ protected
141
146
  def configure_model(model_class, fields_for_list, fields_for_edit, fields_for_show)
142
147
  models_names_sorted = @models_names_sorted
143
148
  model_group = get_group_name(model_class)
@@ -145,11 +150,6 @@ class RailsAdminConfiguratorBase
145
150
  configurator = self
146
151
 
147
152
  @config.model(model_class.to_s) do
148
-
149
- if model_class.respond_to?(:need_show_for_admin_user?)
150
- visible { model_class.need_show_for_admin_user?(bindings[:controller].current_admin_user) }
151
- end
152
-
153
153
  if model_class.instance_methods.include?(:admin_object_title)
154
154
  object_label_method { :admin_object_title }
155
155
  end
@@ -210,4 +210,21 @@ class RailsAdminConfiguratorBase
210
210
  nil
211
211
  end
212
212
 
213
+ public
214
+ def get_models_can_manage_for(role)
215
+ result = []
216
+
217
+ case role
218
+ when EAdminUserRole::EAUR_ADMIN
219
+ result = @models_names.dup
220
+ result.map! { |name| get_class_by_name(name) }
221
+ when EAdminUserRole::EAUR_TRANSLATOR
222
+ result = [LocalizationBase]
223
+ else
224
+ #do nothing
225
+ end
226
+
227
+ result
228
+ end
229
+
213
230
  end
@@ -1,4 +1,5 @@
1
1
  class EAdminUserRole
2
- EAUR_ADMIN = 'admin'
3
- EAUR_MODERATOR = 'moderator'
2
+ EAUR_ADMIN = 'admin'
3
+ EAUR_MODERATOR = 'moderator'
4
+ EAUR_TRANSLATOR = 'translator'
4
5
  end
@@ -129,11 +129,6 @@ class ModelBase
129
129
  scope scope_name.to_sym, -> { where(criteria) }
130
130
  end
131
131
 
132
- public
133
- def self.need_show_for_admin_user?(user)
134
- user.role == EAdminUserRole::EAUR_ADMIN
135
- end
136
-
137
132
  #
138
133
  # Properties
139
134
  #
@@ -21,11 +21,6 @@ class LocalizationBase < ModelBase
21
21
  end
22
22
  end
23
23
 
24
- public
25
- def self.need_show_for_admin_user?(user)
26
- user.role == EAdminUserRole::EAUR_MODERATOR || super
27
- end
28
-
29
24
  #
30
25
  # db
31
26
  #
data/lib/mrpin/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mrpin
2
- VERSION = '1.0.24'
2
+ VERSION = '1.0.25'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mrpin-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.24
4
+ version: 1.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory
@@ -336,7 +336,8 @@ files:
336
336
  - lib/mrpin/config/initializers/01_devise.rb
337
337
  - lib/mrpin/config/initializers/02_mongo.rb
338
338
  - lib/mrpin/config/initializers/03_i18n.rb
339
- - lib/mrpin/config/initializers/04_rails_admin_configurator.rb
339
+ - lib/mrpin/config/initializers/04_rails_admin_cancan_ability.rb
340
+ - lib/mrpin/config/initializers/05_rails_admin_configurator.rb
340
341
  - lib/mrpin/config/locales/rails_admin.en.yml
341
342
  - lib/mrpin/controllers/application_controller_base.rb
342
343
  - lib/mrpin/controllers/system_controller_base.rb