permissify 0.0.14 → 0.0.15
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.
- data/lib/generators/permissify/ability/template/ability.rb +4 -36
- data/lib/permissify/ability_class.rb +40 -0
- data/lib/permissify.rb +1 -0
- data/spec/spec_helper.rb +11 -0
- metadata +4 -4
- data/lib/permissify/ability.rb +0 -46
@@ -1,42 +1,10 @@
|
|
1
|
-
# TODO : this could be an
|
2
|
-
# - needs to support
|
1
|
+
# TODO : this could be an activerecord, does not need to be.
|
2
|
+
# - needs to support interface(s) : seed ?also: all, all_for, others?
|
3
3
|
class Ability
|
4
4
|
|
5
5
|
class << self
|
6
|
-
include Permissify::
|
6
|
+
include Permissify::AbilityClass
|
7
7
|
include SystemFixtures::Abilities
|
8
|
-
# @@abilities = []
|
9
|
-
#
|
10
|
-
# def all; seed if @@abilities.empty?; @@abilities; end
|
11
|
-
#
|
12
|
-
# def all_for(applicability_types)
|
13
|
-
# applicability_types = [applicability_types] if applicability_types.kind_of?(String)
|
14
|
-
# all.select{|a| (a[:applicability] & applicability_types) == applicability_types}
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# def add_category(category, section, applicability=['Role'], actions=%w(View Create Update Delete), category_allows = :multiple)
|
18
|
-
# actions = [actions] unless actions.kind_of?(Array)
|
19
|
-
# actions.collect do |action|
|
20
|
-
# add("#{key_token(category)}_#{key_token(action)}", category, section, action, applicability, 1, actions.index(action)+1, [false], '', category_allows)
|
21
|
-
# end
|
22
|
-
# end
|
23
|
-
#
|
24
|
-
# def create_permissions_hash(view_only_categories=[], remove_categories=[], applicability_types = 'Role')
|
25
|
-
# @@permissions = {}
|
26
|
-
# all_for(applicability_types).each{|permission| @@permissions[permission[:key]] = {'0' => '1'}}
|
27
|
-
# view_only_categories.each{|category| view_only(category)}
|
28
|
-
# remove_categories.each{|category| remove(category)}
|
29
|
-
# @@permissions
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# private
|
33
|
-
# def key_token(token); token.downcase.gsub('-','_').gsub(':','').gsub(' ',' ').gsub(' ','_'); end
|
34
|
-
# def view_only(category); %w(create update delete).each{|action| @@permissions.delete("#{category}_#{action}")}; end
|
35
|
-
# def remove(permission_prefix); @@permissions.keys.each{|key| @@permissions.delete(key) if key.starts_with?(permission_prefix)}; end
|
36
|
-
# def add(key, category, section, action, applicability, number_of_values, position, default_values, admin_expression='', category_allows = :multiple)
|
37
|
-
# @@abilities << { :key => key, :category => category, :section => section, :action => action,
|
38
|
-
# :applicability => applicability, :number_of_values => number_of_values, :position => position,
|
39
|
-
# :default_values => default_values, :administration_expression => admin_expression, :category_allows => category_allows}
|
40
|
-
# end
|
41
8
|
end
|
9
|
+
|
42
10
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Permissify
|
2
|
+
module AbilityClass
|
3
|
+
|
4
|
+
@@abilities = []
|
5
|
+
|
6
|
+
def clear; @@abilities = []; end
|
7
|
+
def all; seed if @@abilities.empty?; @@abilities; end
|
8
|
+
|
9
|
+
def all_for(applicability_types)
|
10
|
+
applicability_types = [applicability_types] if applicability_types.kind_of?(String)
|
11
|
+
all.select{|a| (a[:applicability] & applicability_types) == applicability_types}
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_category(category, section, applicability=['Role'], actions=%w(View Create Update Delete), category_allows = :multiple)
|
15
|
+
actions = [actions] unless actions.kind_of?(Array)
|
16
|
+
actions.collect do |action|
|
17
|
+
add("#{key_token(category)}_#{key_token(action)}", category, section, action, applicability, 1, actions.index(action)+1, [false], '', category_allows)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_permissions_hash(view_only_categories=[], remove_categories=[], applicability_types = 'Role')
|
22
|
+
@@permissions = {}
|
23
|
+
all_for(applicability_types).each{|permission| @@permissions[permission[:key]] = {'0' => '1'}}
|
24
|
+
view_only_categories.each{|category| view_only(category)}
|
25
|
+
remove_categories.each{|category| remove(category)}
|
26
|
+
@@permissions
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def key_token(token); token.downcase.gsub('-','_').gsub(':','').gsub(' ',' ').gsub(' ','_'); end
|
31
|
+
def view_only(category); %w(create update delete).each{|action| @@permissions.delete("#{category}_#{action}")}; end
|
32
|
+
def remove(permission_prefix); @@permissions.keys.each{|key| @@permissions.delete(key) if key.starts_with?(permission_prefix)}; end
|
33
|
+
def add(key, category, section, action, applicability, number_of_values, position, default_values, admin_expression='', category_allows = :multiple)
|
34
|
+
@@abilities << { :key => key, :category => category, :section => section, :action => action,
|
35
|
+
:applicability => applicability, :number_of_values => number_of_values, :position => position,
|
36
|
+
:default_values => default_values, :administration_expression => admin_expression, :category_allows => category_allows}
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/permissify.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -14,3 +14,14 @@ RSpec.configure do |config|
|
|
14
14
|
config.run_all_when_everything_filtered = true
|
15
15
|
config.filter_run :focus
|
16
16
|
end
|
17
|
+
|
18
|
+
class Ability
|
19
|
+
class << self
|
20
|
+
include Permissify::Ability
|
21
|
+
|
22
|
+
def seed
|
23
|
+
# required interface method : app Ability class must implement
|
24
|
+
# - use Permissify::Abilities helper methods or *ml or whatever : just get @@abilities set
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: permissify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 15
|
10
|
+
version: 0.0.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Frederick Fix
|
@@ -101,7 +101,7 @@ files:
|
|
101
101
|
- lib/generators/permissify/views/template/roles_helper.rb
|
102
102
|
- lib/generators/permissify/views/USAGE
|
103
103
|
- lib/generators/permissify/views/views_generator.rb
|
104
|
-
- lib/permissify/
|
104
|
+
- lib/permissify/ability_class.rb
|
105
105
|
- lib/permissify/aggregate.rb
|
106
106
|
- lib/permissify/controller.rb
|
107
107
|
- lib/permissify/model.rb
|
data/lib/permissify/ability.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# TODO : this could be an active record
|
2
|
-
# - needs to support a set of interfaces (all, all_for, others?)
|
3
|
-
# - very specific hash structure
|
4
|
-
# - does this need to be a module?
|
5
|
-
module Permissify
|
6
|
-
module Ability
|
7
|
-
|
8
|
-
# class << self
|
9
|
-
# include SystemFixtures::Abilities
|
10
|
-
@@abilities = []
|
11
|
-
|
12
|
-
def clear; @@abilities = []; end
|
13
|
-
def all; seed if @@abilities.empty?; @@abilities; end
|
14
|
-
|
15
|
-
def all_for(applicability_types)
|
16
|
-
applicability_types = [applicability_types] if applicability_types.kind_of?(String)
|
17
|
-
all.select{|a| (a[:applicability] & applicability_types) == applicability_types}
|
18
|
-
end
|
19
|
-
|
20
|
-
def add_category(category, section, applicability=['Role'], actions=%w(View Create Update Delete), category_allows = :multiple)
|
21
|
-
actions = [actions] unless actions.kind_of?(Array)
|
22
|
-
actions.collect do |action|
|
23
|
-
add("#{key_token(category)}_#{key_token(action)}", category, section, action, applicability, 1, actions.index(action)+1, [false], '', category_allows)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def create_permissions_hash(view_only_categories=[], remove_categories=[], applicability_types = 'Role')
|
28
|
-
@@permissions = {}
|
29
|
-
all_for(applicability_types).each{|permission| @@permissions[permission[:key]] = {'0' => '1'}}
|
30
|
-
view_only_categories.each{|category| view_only(category)}
|
31
|
-
remove_categories.each{|category| remove(category)}
|
32
|
-
@@permissions
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
def key_token(token); token.downcase.gsub('-','_').gsub(':','').gsub(' ',' ').gsub(' ','_'); end
|
37
|
-
def view_only(category); %w(create update delete).each{|action| @@permissions.delete("#{category}_#{action}")}; end
|
38
|
-
def remove(permission_prefix); @@permissions.keys.each{|key| @@permissions.delete(key) if key.starts_with?(permission_prefix)}; end
|
39
|
-
def add(key, category, section, action, applicability, number_of_values, position, default_values, admin_expression='', category_allows = :multiple)
|
40
|
-
@@abilities << { :key => key, :category => category, :section => section, :action => action,
|
41
|
-
:applicability => applicability, :number_of_values => number_of_values, :position => position,
|
42
|
-
:default_values => default_values, :administration_expression => admin_expression, :category_allows => category_allows}
|
43
|
-
end
|
44
|
-
# end
|
45
|
-
end
|
46
|
-
end
|