Module: SystemFixtures::Roles

Included in:
Role
Defined in:
lib/generators/permissify/role/template/roles.rb

Constant Summary collapse

SEEDED_ORDERED_ROLES =
['super user', 'system admin', 'dealer admin', 'corporation admin', 'brand admin', 'merchant admin']
SEED_SPECIFICATIONS =

SEEDED_ORDERED_ROLES = [‘super user’, ‘system admin’, ‘operations agent’, ‘call center agent’]

(1..SEEDED_ORDERED_ROLES.length).zip(SEEDED_ORDERED_ROLES)

Instance Method Summary collapse

Instance Method Details

#brand_admin_permissionsObject



45
46
47
48
# File 'lib/generators/permissify/role/template/roles.rb', line 45

def brand_admin_permissions
  msa_permissions %w(corporation brands_create brands_delete)
  Ability.remove_permissions %w(tabs_corporations brand_products_update merchant_products_update)
end

#corporation_admin_permissionsObject



42
43
44
# File 'lib/generators/permissify/role/template/roles.rb', line 42

def corporation_admin_permissions
  msa_permissions %w(corporations_create corporations_delete)
end

#create_brand_adminObject



21
# File 'lib/generators/permissify/role/template/roles.rb', line 21

def create_brand_admin;     create_with(5, 'Brand')     ; end

#create_corporation_adminObject



20
# File 'lib/generators/permissify/role/template/roles.rb', line 20

def create_corporation_admin; create_with(4, 'Corporation') ; end

#create_dealer_adminObject



19
# File 'lib/generators/permissify/role/template/roles.rb', line 19

def create_dealer_admin;    create_with(3, 'Dealer')    ; end

#create_merchant_adminObject



22
# File 'lib/generators/permissify/role/template/roles.rb', line 22

def create_merchant_admin;  create_with(6, 'Merchant')  ; end

#create_super_userObject



17
# File 'lib/generators/permissify/role/template/roles.rb', line 17

def create_super_user;      create_with(1, 'Admin')     ; end

#create_system_adminObject



18
# File 'lib/generators/permissify/role/template/roles.rb', line 18

def create_system_admin;    create_with(2, 'Admin')     ; end

#create_with(id, domain_type) ⇒ Object



24
25
26
27
28
29
# File 'lib/generators/permissify/role/template/roles.rb', line 24

def create_with(id, domain_type)
  role = create_with_id(:role, id, SEED_SPECIFICATIONS.assoc(id)[1])
  role.domain_type = domain_type
  role.save
  role
end

#dealer_admin_permissionsObject



37
38
39
40
# File 'lib/generators/permissify/role/template/roles.rb', line 37

def dealer_admin_permissions
  Ability.create_permissions_hash( [], %w(roles products admin))
  Ability.remove_permissions %w(tabs_admin dealers_create dealers_delete dealer_users_create dealer_users_delete)
end

#merchant_admin_permissionsObject



49
50
51
52
# File 'lib/generators/permissify/role/template/roles.rb', line 49

def merchant_admin_permissions
  msa_permissions %w(corporation brand)
  Ability.remove_permissions %w(tabs_brands tabs_corporations merchant_products_update)
end

#msa_permissions(exclude_abilities) ⇒ Object



53
54
55
56
57
# File 'lib/generators/permissify/role/template/roles.rb', line 53

def msa_permissions(exclude_abilities)
  no_abilities = exclude_abilities + %w(admin roles products dealer)
  Ability.create_permissions_hash([], no_abilities)
  Ability.remove_permissions %w(tabs_admin tabs_dealers)
end

#seedObject



7
8
9
10
11
12
13
14
15
# File 'lib/generators/permissify/role/template/roles.rb', line 7

def seed
  create_seeds SEED_SPECIFICATIONS
  Role.find(1).manage_ids = [2,3,4,5,6]
  Role.find(2).manage_ids = [2,3,4,5,6]
  Role.find(3).manage_ids = [3,4,5,6]
  Role.find(4).manage_ids = [4,5,6]
  Role.find(5).manage_ids = [6]
  Role.find(6).manage_ids = [6]
end

#seeded?(role) ⇒ Boolean

Returns:

  • (Boolean)


6
# File 'lib/generators/permissify/role/template/roles.rb', line 6

def seeded?(role); role.id <= SEEDED_ORDERED_ROLES.length; end

#super_user_permissionsObject



31
32
33
# File 'lib/generators/permissify/role/template/roles.rb', line 31

def super_user_permissions
  Ability.create_permissions_hash
end

#system_admin_permissionsObject



34
35
36
# File 'lib/generators/permissify/role/template/roles.rb', line 34

def system_admin_permissions
  Ability.create_permissions_hash %w(roles products)
end