permissify 0.0.7 → 0.0.8
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/abilities.rb +11 -78
- data/lib/generators/permissify/ability/template/ability.rb +8 -0
- data/lib/generators/permissify/controller/template/interface/permissified_controller.rb +3 -5
- data/lib/generators/permissify/role/template/role.rb +9 -9
- data/lib/generators/permissify/role/template/roles.rb +11 -52
- data/lib/permissify/model.rb +1 -1
- metadata +4 -4
@@ -1,83 +1,16 @@
|
|
1
1
|
module SystemFixtures::Abilities
|
2
2
|
def seed
|
3
|
-
|
4
|
-
# and remember to trigger in seed process by including, for example, Ability.seed in your db/seed.rb file
|
5
|
-
# allows you to organize permissions into categories that correspond to your client's/product team's view of the system
|
6
|
-
# { 'Marketing Campaign Templates' => 'PS Admin Portal',
|
7
|
-
# 'Product Configurations' => 'PS Admin Portal',
|
8
|
-
# 'PS Marketings' => 'PS Admin Portal',
|
9
|
-
# 'Roles and Permissions' => 'PS Admin Portal',
|
10
|
-
# 'Dealer User Management' => 'PS Admin Portal',
|
11
|
-
# 'Information and Contact' => 'Branch and Location Portals : Settings',
|
12
|
-
# 'Branch User Management' => 'Branch and Location Portals : Settings',
|
13
|
-
# 'Product Types' => 'Branch and Location Portals : Settings',
|
14
|
-
# 'Marketing Campaigns' => 'Branch and Location Portals : Marketing Engine',
|
15
|
-
# 'Landing Pages' => 'Branch and Location Portals : Marketing Engine',
|
16
|
-
# 'Offers and Incentives' => 'Branch and Location Portals : Marketing Engine',
|
17
|
-
# 'Loyalty ID' => 'Branch and Location Portals : Loyalty Application',
|
18
|
-
# 'Reservation Book' => 'Branch and Location Portals : Reservation Application',
|
19
|
-
# 'Reservation General Settings' => 'Branch and Location Portals : Reservation Application',
|
20
|
-
# 'Restaurant Exception Days' => 'Branch and Location Portals : Reservation Application',
|
21
|
-
# 'Restaurant Messaging and Notifications' => 'Branch and Location Portals : Reservation Application',
|
22
|
-
# 'Restaurant Profile' => 'Branch and Location Portals : Web Page',
|
23
|
-
# 'Restaurant Website CSS' => 'Branch and Location Portals : Web Page',
|
24
|
-
# 'Restaurant Website Images' => 'Branch and Location Portals : Web Page',
|
25
|
-
# 'Web Page Analytics' => 'Branch and Location Portals : Web Page',
|
26
|
-
# 'Customer Profiles' => 'Branch and Location Portals : Customer Profiles',
|
27
|
-
# 'Corporate Portal' => 'Corporate Portal',
|
28
|
-
# 'Corporate User Management' => 'Corporate Portal',
|
29
|
-
# 'Brand Portal' => 'Brand Portal',
|
30
|
-
# 'Brand User Management' => 'Brand Portal',
|
31
|
-
# }.each{ |category, section| add_category(category, section) }
|
32
|
-
#
|
33
|
-
# add_category('Restaurant Dashboard', 'PS Admin Portal', ['Role'], 'View')
|
34
|
-
# add_category('SMS', 'Branch and Location Portals : Settings', %w(Product Role))
|
35
|
-
# add('sms_send', 'SMS', 'Branch and Location Portals : Settings', 'Send Test Message', %w(Product Role), 1, 4, [false])
|
36
|
-
# add_category('Email', 'Branch and Location Portals : Settings', %w(Product Role))
|
37
|
-
# add('email_limit', 'Email', 'Branch and Location Portals : Settings', 'Send', %w(Product Role), 2, 4, [false,0], " up to ***1:text:9** Emails")
|
38
|
-
#
|
39
|
-
# add_category('Transactional Templates', 'PS Admin Portal', ['Role'], %w(create view delete updatemerchant updateadmin updatedealer))
|
40
|
-
# add_category('Administrative Settings', 'PS Admin Portal', ['Role'], %w(update))
|
41
|
-
#
|
42
|
-
# add_category('Social Media', 'Branch and Location Portals : Social Media', %w(Product Role), %w(FacebookConnect TwitterConnect WebsiteConnect SocialFeedback Reports))
|
43
|
-
# add_category('Social Media Posts', 'Branch and Location Portals : Social Media', %w(Product Role))
|
44
|
-
# %w(Contact Home Menu Press WhatsNew).each do |name|
|
45
|
-
# add_category("Web Pages : #{name}", 'Branch and Location Portals : Web Page', %w(Product Role))
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# ['Marketing Engine', 'Online Ordering', 'Loyalty', 'Webpage Builder', 'eGift', 'Guest Management', 'Mobile Marketing', 'Offers and Incentives'].each do |feature_bit|
|
49
|
-
# add_category(feature_bit, 'Solutions', %w(Product), %w(On))
|
50
|
-
# end
|
51
|
-
# add_category('Online Reservations', 'Solutions', %w(Product), %w(Integrated Standalone))
|
52
|
-
#
|
53
|
-
# add_category('GM Application Roles', 'Guest Management', %w(Role), %w(ApplicationAdmin StoreAdmin Host), :one_or_none)
|
54
|
-
#
|
55
|
-
# add_category('OO Roles', 'Online Ordering', %w(Role), %w(MerchantManager ReportManager CallCenterEmployee), :one_or_none)
|
56
|
-
# add_category('Report Manager User Rights', 'Online Ordering', %w(Role), %w(ConsoleUser MercuryPaymentsEdit StoreManager VoidOrder TransferOrder))
|
57
|
-
#
|
58
|
-
# add_category('eGift Roles', 'eGift', %w(Role), %w(Admin Staff Merchant), :one_or_none)
|
59
|
-
# add_category('eGift Rights', 'eGift', %w(Role), %w(SalesPageOption GiftCards EmailCampaign SystemVariables SiteContent IPRestriction PaymentConfiguration NewMerchant Reports Search))
|
60
|
-
#
|
61
|
-
# add_category('Store ID', 'Branch and Location Portals : Settings', ['Role'], 'View')
|
62
|
-
#
|
63
|
-
# add_category('POS API Key', 'Branch and Location Portals : Settings', ['Role'], 'Generate')
|
64
|
-
#
|
65
|
-
# add_category('Opt-in Opt-out', 'Branch and Location Portals : Customer Profiles', ['Role'], %w(opt-in opt-out))
|
66
|
-
#
|
67
|
-
# ['Branch and Location Portals : Settings', 'Brand Portal', 'Corporate Portal'].each do |section|
|
68
|
-
# add_category("#{section.split(' ').first} Zoura Account", section, ['Role'], 'Update')
|
69
|
-
# end
|
70
|
-
#
|
71
|
-
# add('offers_and_incentives_redeem', 'Offers and Incentives', 'Branch and Location Portals : Marketing Engine', 'Redeem', %w(Product Role), 1, 4, [false])
|
72
|
-
end
|
3
|
+
SPECIFY_ABILITIES_IN__APP__MODELS__SYSTEM_FIXTURES__ABILITIES
|
4
|
+
# and remember to trigger in seed process by including in, for example, Ability.seed in your db/seed.rb file
|
73
5
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
6
|
+
# # organize permissions into categories that correspond to your client's/product team's view of the system
|
7
|
+
# add_category('Tabs', 'Tabs', ['Role'], %w(Admin Dealer Corporate Brand Merchant))
|
8
|
+
# { 'Roles' => 'Admin',
|
9
|
+
# 'Admin Users' => 'Admin',
|
10
|
+
# 'Dealer Users' => 'Dealer Admin',
|
11
|
+
# 'Corporate Users' => 'Corporate Admin',
|
12
|
+
# 'Brand Users' => 'Brand Admin',
|
13
|
+
# 'Merchant Users' => 'Merchant Admin',
|
14
|
+
# }.each{ |category, section| add_category(category, section) }
|
80
15
|
end
|
81
|
-
|
82
|
-
def key_token(token); token.downcase.gsub('-','_').gsub(':','').gsub(' ',' ').gsub(' ','_'); end
|
83
16
|
end
|
@@ -10,6 +10,13 @@ class Ability
|
|
10
10
|
applicability_types = [applicability_types] if applicability_types.kind_of?(String)
|
11
11
|
all.select{|a| (a[:applicability] & applicability_types) == applicability_types}
|
12
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
|
13
20
|
|
14
21
|
def create_permissions_hash(view_only_categories=[], remove_categories=[], applicability_types = 'Role')
|
15
22
|
@@permissions = {}
|
@@ -20,6 +27,7 @@ class Ability
|
|
20
27
|
end
|
21
28
|
|
22
29
|
private
|
30
|
+
def key_token(token); token.downcase.gsub('-','_').gsub(':','').gsub(' ',' ').gsub(' ','_'); end
|
23
31
|
def view_only(category); %w(create update delete).each{|action| @@permissions.delete("#{category}_#{action}")}; end
|
24
32
|
def remove(permission_prefix); @@permissions.keys.each{|key| @@permissions.delete(key) if key.starts_with?(permission_prefix)}; end
|
25
33
|
def add(key, category, section, action, applicability, number_of_values, position, default_values, admin_expression='', category_allows = :multiple)
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module PermissifiedController # Interface : override/rewrite as needed for your app
|
2
2
|
|
3
|
-
# app-specific consideration for whether operating on a
|
4
|
-
# merchant/business, brand, corporation, dealer or
|
5
|
-
# admin (special case : nil? null object that defines PERMISSIBLE_PRODUCTS?)
|
3
|
+
# app-specific consideration for whether operating on a merchant/business, brand, corporation, dealer or admin
|
6
4
|
def current_entity
|
7
|
-
return @current_entity if @current_entity
|
8
5
|
TODO_IMPLEMENT_PERMISSIFY_CONTROLLER_CURRENT_ENTITY_INTERFACE_METHOD
|
9
|
-
|
6
|
+
# return @current_entity if @current_entity
|
7
|
+
# nil
|
10
8
|
end
|
11
9
|
|
12
10
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class Role < ActiveRecord::Base
|
2
2
|
DOMAIN_TYPES = %w(Admin Dealer Corporate Brand Merchant)
|
3
|
-
include
|
3
|
+
include Permissify::Model
|
4
4
|
# is_paranoid
|
5
|
-
has_and_belongs_to_many :users, :order => "userable_type ASC"
|
6
5
|
# default_scope :conditions => {:deleted_at => nil}, :order => "roles.name"
|
6
|
+
has_and_belongs_to_many :users
|
7
7
|
validates_presence_of :name, :domain_type
|
8
8
|
validates_uniqueness_of :name
|
9
9
|
before_create :initialize_permissions
|
@@ -13,14 +13,14 @@ class Role < ActiveRecord::Base
|
|
13
13
|
after_save :propagate_managed_by
|
14
14
|
|
15
15
|
class << self
|
16
|
-
include
|
16
|
+
include Permissify::ModelClass
|
17
17
|
include SystemFixtures::Roles
|
18
|
-
def super_user; locate(1, 'super user'); end
|
19
|
-
def system_admin; locate(2, 'system admin'); end
|
20
|
-
def dealer_admin; locate(3, 'dealer admin'); end
|
21
|
-
def corporate_admin; locate(4, 'corporate admin'); end
|
22
|
-
def brand_admin; locate(5, 'brand admin'); end
|
23
|
-
def merchant_admin; locate(6, 'merchant admin'); end
|
18
|
+
# def super_user; locate(1, 'super user'); end
|
19
|
+
# def system_admin; locate(2, 'system admin'); end
|
20
|
+
# def dealer_admin; locate(3, 'dealer admin'); end
|
21
|
+
# def corporate_admin; locate(4, 'corporate admin'); end
|
22
|
+
# def brand_admin; locate(5, 'brand admin'); end
|
23
|
+
# def merchant_admin; locate(6, 'merchant admin'); end
|
24
24
|
end
|
25
25
|
|
26
26
|
def initialize_non_permission_values
|
@@ -2,7 +2,7 @@ module SystemFixtures::Roles
|
|
2
2
|
SEEDED_ORDERED_ROLES = ['super user', 'system admin', 'dealer admin', 'corporate admin', 'brand admin', 'merchant admin']
|
3
3
|
SEED_SPECIFICATIONS = (1..SEEDED_ORDERED_ROLES.length).zip(SEEDED_ORDERED_ROLES)
|
4
4
|
|
5
|
-
def seeded?(role); role.id
|
5
|
+
def seeded?(role); role.id <= SEEDED_ORDERED_ROLES.length; end
|
6
6
|
def seed; create_seeds :roles, SEED_SPECIFICATIONS; end
|
7
7
|
|
8
8
|
def create_super_user; create_with(1, SEEDED_ORDERED_ROLES, 'Admin') ; end
|
@@ -21,73 +21,32 @@ module SystemFixtures::Roles
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def super_user_permissions
|
24
|
-
@@permissions = Ability.create_permissions_hash
|
25
|
-
select_gm_application_role
|
26
|
-
select_oo_role
|
27
|
-
select_egift_permissions :admin, %w(salespageoption giftcards emailcampaign systemvariables sitecontent iprestriction search)
|
28
|
-
remove %w(opt_in_opt_out_opt_in)
|
24
|
+
@@permissions = Ability.create_permissions_hash
|
29
25
|
end
|
30
26
|
def system_admin_permissions
|
31
|
-
@@permissions = Ability.create_permissions_hash
|
32
|
-
select_gm_application_role
|
33
|
-
select_oo_role
|
34
|
-
select_egift_permissions :staff, %w(salespageoption giftcards emailcampaign systemvariables sitecontent iprestriction search)
|
35
|
-
remove %w(opt_in_opt_out_opt_in)
|
27
|
+
@@permissions = Ability.create_permissions_hash 'roles'
|
36
28
|
end
|
37
29
|
def dealer_admin_permissions
|
38
|
-
@@permissions = Ability.create_permissions_hash(
|
39
|
-
|
40
|
-
%w(product_configurations roles_and_permissions marketing_campaign_templates ps_marketing store_id branch_zoura brand_zoura corporate_zoura offers_and_incentives))
|
41
|
-
remove %w(email_limit sms_send opt_in_opt_out_opt_in transactional_templates administrative_settings_update)
|
42
|
-
remove %w(transactional_templates_updatemerchant transactional_templates_view marketing_campaign_templates_view marketing_campaign_templates_update)
|
43
|
-
select_gm_application_role nil
|
44
|
-
select_oo_role
|
45
|
-
select_egift_permissions :staff, []
|
30
|
+
@@permissions = Ability.create_permissions_hash( [], %w(roles admin))
|
31
|
+
remove %w(tabs_admin)
|
46
32
|
end
|
47
33
|
|
48
34
|
def corporate_admin_permissions
|
49
35
|
msa_permissions %w(corporate_portal_create brand_portal_create)
|
50
|
-
select_gm_application_role
|
51
|
-
select_oo_role
|
52
|
-
select_view_only_loyalty_id
|
53
36
|
end
|
54
37
|
def brand_admin_permissions
|
55
38
|
msa_permissions %w(corporate brand_portal_create brand_portal_update)
|
56
|
-
|
57
|
-
select_oo_role
|
58
|
-
select_view_only_loyalty_id
|
39
|
+
remove %w(tabs_corporate)
|
59
40
|
end
|
60
41
|
def merchant_admin_permissions
|
61
|
-
msa_permissions %w(
|
62
|
-
|
63
|
-
select_oo_role :reportmanager
|
64
|
-
select_view_only_loyalty_id
|
65
|
-
remove %w(report_manager_user_rights_consoleuser report_manager_user_rights_voidorder report_manager_user_rights_transferorder pos_api_key_generate)
|
42
|
+
msa_permissions %w(corporate brand)
|
43
|
+
remove %w(tabs_brand tabs_corporate)
|
66
44
|
end
|
67
45
|
def msa_permissions(exclude_abilities)
|
68
|
-
no_abilities = exclude_abilities + %w(
|
46
|
+
no_abilities = exclude_abilities + %w(admin roles dealer)
|
69
47
|
@@permissions = Ability.create_permissions_hash([], no_abilities)
|
70
|
-
|
48
|
+
remove %w(tabs_admin tabs_dealer)
|
71
49
|
end
|
72
|
-
|
73
|
-
def select_view_only_loyalty_id(role = :storeadmin)
|
74
|
-
select :loyalty_id, %w(create update delete), role
|
75
|
-
end
|
76
|
-
def select_gm_application_role(role = :storeadmin)
|
77
|
-
select :gm_application_roles, %w(applicationadmin storeadmin brandadmin host), role
|
78
|
-
end
|
79
|
-
def select_oo_role(role = :merchantmanager)
|
80
|
-
select :oo_roles, %w(merchantmanager reportmanager callcenteremployee), role
|
81
|
-
remove [:report_manager_user_rights_mercurypaymentsedit] if role == :merchantmanager
|
82
|
-
end
|
83
|
-
def select_egift_permissions(role = :staff, rights = %w(salespageoption giftcards emailcampaign systemvariables sitecontent iprestriction))
|
84
|
-
select :egift_roles, %w(admin staff merchant), role
|
85
|
-
select :egift_rights, %w(salespageoption giftcards emailcampaign systemvariables sitecontent iprestriction paymentconfiguration newmerchant reports search), rights
|
86
|
-
end
|
87
|
-
def select(category, options, selected)
|
88
|
-
selected = [selected.to_s] unless selected.kind_of?(Array)
|
89
|
-
remove((options - selected).collect{|permission_option| "#{category}_#{permission_option}"})
|
90
|
-
end
|
91
|
-
|
50
|
+
|
92
51
|
def remove(permissions); permissions.each{|permission| @@permissions.delete(permission.to_s)}; @@permissions; end
|
93
52
|
end
|
data/lib/permissify/model.rb
CHANGED
@@ -10,7 +10,7 @@ module Permissify
|
|
10
10
|
self.permissions ||= self.from.nil? ? {} : establish_from_permissions_model.permissions
|
11
11
|
end
|
12
12
|
|
13
|
-
def allows?(ability_key)
|
13
|
+
def allows?(ability_key)
|
14
14
|
allowed = self.permissions[ability_key];
|
15
15
|
allowed && allowed['0'];
|
16
16
|
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: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Frederick Fix
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-06-02 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|