faalis 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 211e5ba2ce64c3da64cb9977367eb4a2ae1594cc
4
- data.tar.gz: 6a81b397d0532901c7025ef829c25acb8d368bf1
3
+ metadata.gz: 51c65def59ed76316939971e4a3ea8f73aa9bcdc
4
+ data.tar.gz: 3ff82b9fa6aab48e7c09a889dc6c27a8d846762c
5
5
  SHA512:
6
- metadata.gz: 7b71d8ad541c9fb372730de7907c9b61963163cabb44b0fbef81f2b83874190bf3884835994ba98318bd696cc0ef854dbf8d2648c5f162d5a6299a86e8122766
7
- data.tar.gz: dbd7e18ca0c10d0a29852edf7ae93f1024469cff6e1c117c6a811e09504839de2a0933f603717ba8305c0ba6b053f5cf511345ca1c9e02cc6bf07efdeb0940e3
6
+ metadata.gz: 353e68754e80ee0079e9ec5b816ef51bb46592054e4df572dedf95b2cbc72201749e12917a192759d4af4171fe826481c164fccdf2a70b35123b71a66947ad54
7
+ data.tar.gz: 686429d477d1e789649dad65b864f2dcb42c204a11b7c6f7ff43e71b1b71555d869f0da874c270153cffcc5bfd38ce761838e8acf1d85f32379de09c900ef83d
@@ -12,11 +12,22 @@ module Faalis
12
12
  def index
13
13
  @permissions = []
14
14
 
15
- Faalis::Engine.models_with_permission.each do |model|
16
- model = Object.const_get(model)
17
- @permissions.concat(model.permission_strings(model))
15
+ ::ApplicationModels.all.each do |m|
16
+
17
+ model = m.model.constantize
18
+ if model.respond_to? :permission_strings
19
+ @permissions.concat(model.permission_strings(model))
20
+ end
18
21
  end
19
- respond_with(@permissions)
22
+
23
+ Faalis::Engine.models_with_permission.each do |m|
24
+ model = m.constantize
25
+ if model.respond_to? :permission_strings
26
+ @permissions.concat(model.permission_strings(model))
27
+ end
28
+ end
29
+
30
+ respond_with(@permissions.uniq)
20
31
  end
21
32
 
22
33
  # @api GET permissions/user
@@ -26,14 +37,23 @@ module Faalis
26
37
  perms = []
27
38
  if current_user.group_id == 1
28
39
  # Generate all possible permissions for admin group
29
- Faalis::Engine.models_with_permission.each do |model|
30
- Object.const_get(model).possible_permissions.each do |p|
40
+ ::ApplicationModels.all.each do |model|
41
+ model.model.constantize.possible_permissions.each do |p|
42
+ perm = DummyPerm.new
43
+ perm.model = model.model
44
+ perm.permission_type = p
45
+ perms << perm
46
+ end
47
+ end
48
+ Faalis::Engine.models_with_permission.each do |m|
49
+ m.constantize.possible_permissions.each do |p|
31
50
  perm = DummyPerm.new
32
- perm.model = model
51
+ perm.model = m
33
52
  perm.permission_type = p
34
53
  perms << perm
35
54
  end
36
55
  end
56
+ perms.uniq!
37
57
  else
38
58
  perms = current_user.group.permissions
39
59
  end
@@ -1,3 +1,7 @@
1
1
  class Faalis::Permissions::Auth
2
2
  include Faalis::Permissions
3
+
4
+ def self.humanize_class_name
5
+ "Auth Module"
6
+ end
3
7
  end
data/lib/faalis/engine.rb CHANGED
@@ -25,7 +25,7 @@ require "devise"
25
25
  require "warden"
26
26
  require "cancan"
27
27
  require "mailboxer"
28
-
28
+ require "model_discovery"
29
29
 
30
30
  module Faalis
31
31
  class Engine < ::Rails::Engine
@@ -2,7 +2,9 @@ module Faalis
2
2
  module Permissions
3
3
  extend ActiveSupport::Concern
4
4
 
5
+
5
6
  module ClassMethods
7
+
6
8
  # Default permission hash
7
9
  @@permissions = {
8
10
  :read => nil,
@@ -16,10 +18,16 @@ module Faalis
16
18
  # @return an array of strings representation of permissions
17
19
  def permission_strings(model)
18
20
  strings = []
21
+ model_name = model.to_s
22
+ humanize_name = ActiveModel::Name.new(model).human
23
+ if model.respond_to? :model_name
24
+ model_name = model.model_name
25
+ humanize_name = model_name.human
26
+ end
19
27
  @@permissions.each do |key, value|
20
28
  strings << {
21
- :name => "#{key}|#{model.model_name}",
22
- :string => _("can %s %s") % [_(key.to_s), model.model_name.human]
29
+ :name => "#{key}|#{model_name}",
30
+ :string => _("can %s %s") % [_(key.to_s), humanize_name]
23
31
  }
24
32
  end
25
33
  strings
@@ -61,5 +69,4 @@ module Faalis
61
69
 
62
70
  end
63
71
  end
64
-
65
72
  end
@@ -18,5 +18,5 @@
18
18
  # -----------------------------------------------------------------------------
19
19
 
20
20
  module Faalis
21
- VERSION = "0.11.0"
21
+ VERSION = "0.11.1"
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faalis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sameer Rahmani