the_role 2.5.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +178 -526
  3. data/gem_version.rb +3 -0
  4. data/lib/the_role/version.rb +1 -3
  5. data/lib/the_role.rb +3 -41
  6. data/the_role.gemspec +5 -5
  7. metadata +20 -231
  8. data/.ruby-gemset.example +0 -1
  9. data/.ruby-version.example +0 -1
  10. data/.rvmrc.example +0 -1
  11. data/.travis.yml +0 -5
  12. data/Bye_bye_CanCan_I_got_the_Role.png +0 -0
  13. data/app/controllers/admin/role_sections_controller.rb +0 -90
  14. data/app/controllers/admin/roles_controller.rb +0 -74
  15. data/app/controllers/concerns/controller.rb +0 -23
  16. data/app/models/_templates_/role.rb +0 -3
  17. data/app/models/concerns/base.rb +0 -37
  18. data/app/models/concerns/role.rb +0 -156
  19. data/app/models/concerns/user.rb +0 -57
  20. data/config/locales/en.yml +0 -44
  21. data/config/locales/es.yml +0 -42
  22. data/config/locales/nl.yml +0 -44
  23. data/config/locales/pl.yml +0 -43
  24. data/config/locales/pt_BR.yml +0 -43
  25. data/config/locales/ru.yml +0 -43
  26. data/config/locales/zh_CN.yml +0 -42
  27. data/config/routes.rb +0 -23
  28. data/db/migrate/20111025025129_create_roles.rb +0 -23
  29. data/docs/2.1.1.png +0 -0
  30. data/lib/generators/the_role/USAGE +0 -32
  31. data/lib/generators/the_role/templates/the_role.rb +0 -11
  32. data/lib/generators/the_role/the_role_generator.rb +0 -64
  33. data/lib/tasks/roles.rake +0 -137
  34. data/lib/the_role/activerecord.rb +0 -11
  35. data/lib/the_role/config.rb +0 -30
  36. data/lib/the_role/hash.rb +0 -58
  37. data/lib/the_role/the_class_exists.rb +0 -8
  38. data/pic.png +0 -0
  39. data/spec/dummy_app/.gitignore +0 -18
  40. data/spec/dummy_app/.rspec +0 -1
  41. data/spec/dummy_app/Gemfile +0 -43
  42. data/spec/dummy_app/README.md +0 -39
  43. data/spec/dummy_app/Rakefile +0 -6
  44. data/spec/dummy_app/app/assets/images/.keep +0 -0
  45. data/spec/dummy_app/app/assets/javascripts/application.js +0 -17
  46. data/spec/dummy_app/app/assets/stylesheets/app/style.css.scss +0 -23
  47. data/spec/dummy_app/app/assets/stylesheets/application.css +0 -3
  48. data/spec/dummy_app/app/controllers/application_controller.rb +0 -38
  49. data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
  50. data/spec/dummy_app/app/controllers/pages_controller.rb +0 -75
  51. data/spec/dummy_app/app/controllers/users_controller.rb +0 -32
  52. data/spec/dummy_app/app/controllers/welcome_controller.rb +0 -13
  53. data/spec/dummy_app/app/helpers/application_helper.rb +0 -2
  54. data/spec/dummy_app/app/mailers/.keep +0 -0
  55. data/spec/dummy_app/app/models/.keep +0 -0
  56. data/spec/dummy_app/app/models/concerns/.keep +0 -0
  57. data/spec/dummy_app/app/models/page.rb +0 -24
  58. data/spec/dummy_app/app/models/role.rb +0 -4
  59. data/spec/dummy_app/app/models/user.rb +0 -21
  60. data/spec/dummy_app/app/views/layouts/_current_user_info.html.haml +0 -17
  61. data/spec/dummy_app/app/views/layouts/application.html.haml +0 -68
  62. data/spec/dummy_app/app/views/pages/_form.html.haml +0 -19
  63. data/spec/dummy_app/app/views/pages/edit.html.haml +0 -7
  64. data/spec/dummy_app/app/views/pages/index.html.haml +0 -27
  65. data/spec/dummy_app/app/views/pages/manage.html.haml +0 -23
  66. data/spec/dummy_app/app/views/pages/my.html.haml +0 -10
  67. data/spec/dummy_app/app/views/pages/new.html.haml +0 -5
  68. data/spec/dummy_app/app/views/pages/show.html.haml +0 -15
  69. data/spec/dummy_app/app/views/users/edit.html.haml +0 -34
  70. data/spec/dummy_app/app/views/welcome/index.html.haml +0 -38
  71. data/spec/dummy_app/app/views/welcome/profile.html.haml +0 -2
  72. data/spec/dummy_app/bin/bundle +0 -3
  73. data/spec/dummy_app/bin/rails +0 -4
  74. data/spec/dummy_app/bin/rake +0 -4
  75. data/spec/dummy_app/config/application.rb +0 -25
  76. data/spec/dummy_app/config/boot.rb +0 -4
  77. data/spec/dummy_app/config/database.yml +0 -17
  78. data/spec/dummy_app/config/environment.rb +0 -5
  79. data/spec/dummy_app/config/environments/development.rb +0 -29
  80. data/spec/dummy_app/config/environments/production.rb +0 -80
  81. data/spec/dummy_app/config/environments/test.rb +0 -36
  82. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +0 -7
  83. data/spec/dummy_app/config/initializers/devise.rb +0 -227
  84. data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +0 -4
  85. data/spec/dummy_app/config/initializers/inflections.rb +0 -16
  86. data/spec/dummy_app/config/initializers/mime_types.rb +0 -5
  87. data/spec/dummy_app/config/initializers/secret_token.rb +0 -12
  88. data/spec/dummy_app/config/initializers/session_store.rb +0 -3
  89. data/spec/dummy_app/config/initializers/the_role.rb +0 -6
  90. data/spec/dummy_app/config/initializers/wrap_parameters.rb +0 -14
  91. data/spec/dummy_app/config/locales/devise.en.yml +0 -57
  92. data/spec/dummy_app/config/locales/en.yml +0 -7
  93. data/spec/dummy_app/config/locales/ru.yml +0 -4
  94. data/spec/dummy_app/config/routes.rb +0 -26
  95. data/spec/dummy_app/config.ru +0 -4
  96. data/spec/dummy_app/db/migrate/20120212061952_devise_create_users.rb +0 -63
  97. data/spec/dummy_app/db/migrate/20120212063249_create_roles.rb +0 -18
  98. data/spec/dummy_app/db/migrate/20120314061307_create_pages.rb +0 -14
  99. data/spec/dummy_app/db/schema.rb +0 -59
  100. data/spec/dummy_app/db/seeds.rb +0 -85
  101. data/spec/dummy_app/lib/assets/.keep +0 -0
  102. data/spec/dummy_app/lib/tasks/.keep +0 -0
  103. data/spec/dummy_app/lib/tasks/assets.rake +0 -15
  104. data/spec/dummy_app/lib/tasks/db_bootstrap.rake +0 -16
  105. data/spec/dummy_app/log/.keep +0 -0
  106. data/spec/dummy_app/public/404.html +0 -58
  107. data/spec/dummy_app/public/422.html +0 -58
  108. data/spec/dummy_app/public/500.html +0 -57
  109. data/spec/dummy_app/public/favicon.ico +0 -0
  110. data/spec/dummy_app/public/robots.txt +0 -5
  111. data/spec/dummy_app/spec/controllers/admin_roles_controller_spec.rb +0 -52
  112. data/spec/dummy_app/spec/controllers/pages_controller_spec.rb +0 -141
  113. data/spec/dummy_app/spec/controllers/welcome_controller_spec.rb +0 -66
  114. data/spec/dummy_app/spec/factories/page.rb +0 -6
  115. data/spec/dummy_app/spec/factories/role.rb +0 -55
  116. data/spec/dummy_app/spec/factories/user.rb +0 -11
  117. data/spec/dummy_app/spec/models/hash_spec.rb +0 -272
  118. data/spec/dummy_app/spec/models/param_process_spec.rb +0 -39
  119. data/spec/dummy_app/spec/models/role_spec.rb +0 -218
  120. data/spec/dummy_app/spec/models/user_spec.rb +0 -164
  121. data/spec/dummy_app/spec/routing/admin_roles_routing_spec.rb +0 -41
  122. data/spec/dummy_app/spec/routing/pages_routing_spec.rb +0 -35
  123. data/spec/dummy_app/spec/spec_helper.rb +0 -68
  124. data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
  125. data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
  126. data/the_role.yml.teamocil.example +0 -11
@@ -1,156 +0,0 @@
1
- module TheRole
2
- module Role
3
- extend ActiveSupport::Concern
4
-
5
- include TheRole::Base
6
-
7
- def role_hash;
8
- to_hash;
9
- end
10
-
11
- alias_method :has?, :has_role?
12
- alias_method :any?, :any_role?
13
-
14
- def has_section? section_name
15
- to_hash.key? section_name.to_slug_param(sep: '_')
16
- end
17
-
18
- included do
19
- attr_accessor :based_on_role
20
-
21
- has_many :users, dependent: TheRole.config.destroy_strategy
22
- validates :name, presence: true, uniqueness: true
23
- validates :title, presence: true, uniqueness: true
24
- validates :description, presence: true
25
-
26
- private
27
-
28
- before_save do
29
- self.name = name.to_slug_param(sep: '_')
30
-
31
- rules_set = self.the_role
32
- self.the_role = {}.to_json if rules_set.blank?
33
- self.the_role = rules_set.to_json if rules_set.is_a?(Hash)
34
- end
35
-
36
- after_create do
37
- unless based_on_role.blank?
38
- if base_role = self.class.where(id: based_on_role).first
39
- update_role base_role.to_hash
40
- end
41
- end
42
- end
43
- end
44
-
45
- module ClassMethods
46
- def with_name name
47
- ::Role.where(name: name).first
48
- end
49
- end
50
-
51
- # C
52
-
53
- def create_section section_name = nil
54
- return false unless section_name
55
- role = to_hash
56
- section_name = section_name.to_slug_param(sep: '_')
57
- return false if section_name.blank?
58
- return true if role[section_name]
59
- role[section_name] = {}
60
- update(the_role: role)
61
- end
62
-
63
- def create_rule section_name, rule_name
64
- return false if rule_name.blank?
65
- return false unless create_section(section_name)
66
-
67
- role = to_hash
68
- rule_name = rule_name.to_slug_param(sep: '_')
69
- section_name = section_name.to_slug_param(sep: '_')
70
-
71
- return true if role[section_name][rule_name]
72
- role[section_name][rule_name] = false
73
- update(the_role: role)
74
- end
75
-
76
- # R
77
-
78
- def to_hash
79
- #return the hash if activerecord parsed the json from postgresql
80
- return the_role if the_role.kind_of? Hash
81
- begin
82
- JSON.load(the_role) rescue {}
83
- end
84
- end
85
-
86
- def to_json
87
- the_role
88
- end
89
-
90
- # U
91
-
92
- # source_hash will be reset to false
93
- # except true items from new_role_hash
94
- # all keys will become 'strings'
95
- # look at lib/the_role/hash.rb to find definition of *underscorify_keys* method
96
- def update_role new_role_hash
97
- new_role_hash = new_role_hash.try(:to_hash) || {}
98
- new_role = new_role_hash.underscorify_keys
99
- role = to_hash.underscorify_keys.deep_reset(false)
100
- role.deep_merge! new_role
101
- update(the_role: role)
102
- end
103
-
104
- def rule_on section_name, rule_name
105
- role = to_hash
106
- rule_name = rule_name.to_slug_param(sep: '_')
107
- section_name = section_name.to_slug_param(sep: '_')
108
-
109
- return false unless role[section_name]
110
- return false unless role[section_name].key? rule_name
111
- return true if role[section_name][rule_name]
112
-
113
- role[section_name][rule_name] = true
114
- update(the_role: role)
115
- end
116
-
117
- def rule_off section_name, rule_name
118
- role = to_hash
119
- rule_name = rule_name.to_slug_param(sep: '_')
120
- section_name = section_name.to_slug_param(sep: '_')
121
-
122
- return false unless role[section_name]
123
- return false unless role[section_name].key? rule_name
124
- return true unless role[section_name][rule_name]
125
-
126
- role[section_name][rule_name] = false
127
- update(the_role: role)
128
- end
129
-
130
- # D
131
-
132
- def delete_section section_name = nil
133
- return false unless section_name
134
- role = to_hash
135
- section_name = section_name.to_slug_param(sep: '_')
136
-
137
- return false if section_name.blank?
138
- return false unless role[section_name]
139
-
140
- role.delete section_name
141
- update(the_role: role)
142
- end
143
-
144
- def delete_rule section_name, rule_name
145
- role = to_hash
146
- rule_name = rule_name.to_slug_param(sep: '_')
147
- section_name = section_name.to_slug_param(sep: '_')
148
-
149
- return false unless role[section_name]
150
- return false unless role[section_name].key? rule_name
151
-
152
- role[section_name].delete rule_name
153
- update(the_role: role)
154
- end
155
- end
156
- end
@@ -1,57 +0,0 @@
1
- module TheRole
2
- module User
3
- extend ActiveSupport::Concern
4
-
5
- include TheRole::Base
6
-
7
- included do
8
- belongs_to :role
9
- before_validation :set_default_role, on: :create
10
- after_save { |user| user.instance_variable_set(:@role_hash, nil) }
11
- end
12
-
13
- module ClassMethods
14
- def with_role name
15
- ::Role.where(name: name).first.users
16
- end
17
- end
18
-
19
- def role_hash;
20
- @role_hash ||= role.try(:to_hash) || {}
21
- end
22
-
23
- # FALSE if object is nil
24
- # If object is a USER - check for youself
25
- # Check for owner field - :user_id
26
- # Check for owner _object_ if owner field is not :user_id
27
- def owner? obj
28
- return false unless obj
29
- return true if admin?
30
-
31
- section_name = obj.class.to_s.tableize
32
- return true if moderator?(section_name)
33
-
34
- # obj is User, simple way to define user_id
35
- return id == obj.id if obj.is_a?(self.class)
36
-
37
- # few ways to define user_id
38
- return id == obj.user_id if obj.respond_to? :user_id
39
- return id == obj[:user_id] if obj[:user_id]
40
- return id == obj[:user][:id] if obj[:user]
41
- false
42
- end
43
-
44
- private
45
-
46
- def set_default_role
47
- unless role
48
- default_role = ::Role.find_by_name(TheRole.config.default_user_role)
49
- self.role = default_role if default_role
50
- end
51
-
52
- if self.class.count.zero? && TheRole.config.first_user_should_be_admin
53
- self.role = TheRole.create_admin_role!
54
- end
55
- end
56
- end
57
- end
@@ -1,44 +0,0 @@
1
- en:
2
- the_role:
3
- role_created: Role created
4
- role_updated: Role updated
5
- role_deleted: Role deleted
6
- section_created: Section created
7
- section_not_created: Section not created
8
- section_rule_created: "Section rule created"
9
- section_rule_not_created: "Section rule not created"
10
- section_rule_on: "Section rule is enable"
11
- section_rule_off: "Section rule is disable"
12
- state_not_changed: "Section rule not changed"
13
- section_deleted: Section deleted
14
- section_not_deleted: Section not deleted
15
- section_rule_deleted: "Section rule deleted"
16
- section_rule_not_deleted: "Section rule not deleted"
17
- access_denied: "Access Denied"
18
-
19
- admin:
20
- roles:
21
- new:
22
- create: Create new Role
23
- name: Name of role (underscored latin string)
24
- title: Title of role (text)
25
- description: Description of role (text)
26
- based_on_role: "New role will be based on:"
27
- role:
28
- role_name: 'Role name:'
29
- title: 'Title:'
30
- role_description: 'Description of role:'
31
- delete_section: Delete section
32
- section_delete_confirm: 'Do you want to delete section?'
33
- rule_delete_confirm: 'Do you want to delete rule?'
34
- enable: Enable
35
- disable: Disable
36
- delete_rule: Delete rule
37
- new_section_placeholder: New section name
38
- create_section: Create new section
39
- new_rule_placeholder: New rule name
40
- create_rule: Create new rule
41
- sidebar:
42
- roles_list: Roles list
43
- new_role: Create new role
44
- delete_role_confirm: 'Are you sure? It can be dangerous!'
@@ -1,42 +0,0 @@
1
- es:
2
- the_role:
3
- role_created: Rol creado
4
- role_updated: Rol actualizado
5
- role_deleted: Rol eliminado
6
- section_created: Sección creada
7
- section_not_created: Sección no creada
8
- section_rule_created: Regla de sección creada
9
- section_rule_not_created: Regla de sección no creada
10
- section_rule_on: Regla de sección activada
11
- section_rule_off: Regla de sección desactivada
12
- state_not_changed: Regla de sección no modificada
13
- section_deleted: Sección eliminada
14
- section_not_deleted: Sección no eliminada
15
- section_rule_deleted: Regla de sección eliminada
16
- section_rule_not_deleted: Regla de sección no eliminada
17
-
18
- admin:
19
- roles:
20
- new:
21
- create: Crear nuevo rol
22
- name: Nombre del rol (cadena de caracteres simples + guión bajo)
23
- title: Título del rol
24
- description: Descripción del rol
25
- role:
26
- role_name: 'Nombre del rol:'
27
- title: 'Título:'
28
- role_description: 'Descripción del rol:'
29
- delete_section: Eliminar sección
30
- section_delete_confirm: "¿Quieres borrar la sección?"
31
- rule_delete_confirm: "¿Quieres eliminar la regla?"
32
- enable: Activar
33
- disable: Desactivar
34
- delete_rule: Eliminar regla
35
- new_section_placeholder: Nombre de la nueva sección
36
- create_section: Crear nueva sección
37
- new_rule_placeholder: Nombre de la nueva regla
38
- create_rule: Crear nueva regla
39
- sidebar:
40
- roles_list: Lista de roles
41
- new_role: Crear nuevo rol
42
- delete_role_confirm: "¿Estás seguro? ¡Puede ser peligroso!"
@@ -1,44 +0,0 @@
1
- nl:
2
- the_role:
3
- role_created: Toegangsprofiel aangemaakt
4
- role_updated: Toegangsprofiel bijgewerkt
5
- role_deleted: Toegangsprofiel verwijderd
6
- section_created: Sectie aangemaakt
7
- section_not_created: Sectie niet aangemaakt
8
- section_rule_created: "Sectieprofiel aangemaakt"
9
- section_rule_not_created: "Sectieprofiel niet aangemaakt"
10
- section_rule_on: "Sectieprofiel is geactiveerd"
11
- section_rule_off: "Sectieprofiel is gedeactiveerd"
12
- state_not_changed: "Sectieprofiel niet aangepast"
13
- section_deleted: Sectie verwijderd
14
- section_not_deleted: Sectie niet verwijderd
15
- section_rule_deleted: "Sectieprofiel verwijderd"
16
- section_rule_not_deleted: "Sectieprofiel niet verwijderd"
17
- access_denied: "Toegang geweigerd"
18
-
19
- admin:
20
- roles:
21
- new:
22
- create: Maak nieuwe toegangsprofiel aan
23
- name: Naam van toegangsprofiel (underscored latin string)
24
- title: Titel van toegangsprofiel (text)
25
- description: Beschrijving van toegangsprofiel (text)
26
- based_on_role: "Nieuwe toegansprofiel wordt gebaseerd op:"
27
- role:
28
- role_name: 'Toegangsprofiel naam:'
29
- title: 'Titel:'
30
- role_description: 'Omschrijving van het toegangsprofiel:'
31
- delete_section: Verwijder sectie
32
- section_delete_confirm: 'Wil je de sectie verwijderen?'
33
- rule_delete_confirm: 'Wil je het toegangsprofiel verwijderen?'
34
- enable: Activeren
35
- disable: Deactiveren
36
- delete_rule: Verwijder toegangsprofiel
37
- new_section_placeholder: Naam nieuwe sectie
38
- create_section: Maak nieuwe sectie aan
39
- new_rule_placeholder: Naam nieuw toegansprofiel
40
- create_rule: Maak nieuw toegansprofiel
41
- sidebar:
42
- roles_list: Lijst toegangsprofielen
43
- new_role: Maak nieuw toegansprofiel
44
- delete_role_confirm: 'Weet je het zeker? Dit kan gevaarlijk zijn!'
@@ -1,43 +0,0 @@
1
- pl:
2
- the_role:
3
- role_created: Rola dodana
4
- role_updated: Rola zaktualizowana
5
- role_deleted: Role skasowana
6
- section_created: Sekcja utworzona
7
- section_not_created: Sekcja nie utworzona
8
- section_rule_created: "Reguła utworzona"
9
- section_rule_not_created: "Reguła nie utworzona"
10
- section_rule_on: "Reguła uruchomiona"
11
- section_rule_off: "Reguła wyłączona"
12
- state_not_changed: "Reguła nie zmieniona"
13
- section_deleted: Sekcja skasowana
14
- section_not_deleted: Sekcja nie skasowana
15
- section_rule_deleted: "Reguła skasowana"
16
- section_rule_not_deleted: "Reguła nie skasowana"
17
- access_denied: "Odmowa dostępu"
18
-
19
- admin:
20
- roles:
21
- new:
22
- create: Utwórz nową rolę
23
- name: Nazwa roli
24
- title: Tytuł roli (text)
25
- description: Opis roli (text)
26
- role:
27
- role_name: 'Nazwa roli:'
28
- title: 'Tytuł:'
29
- role_description: 'Opis roli:'
30
- delete_section: Skasuj sekcje
31
- section_delete_confirm: 'Czy aby napewno chcesz skasować sekcję?'
32
- rule_delete_confirm: 'Czy aby na pewno chcesz usunąć rolę?'
33
- enable: Włącz
34
- disable: Wyłącz
35
- delete_rule: Skasuj regułę
36
- new_section_placeholder: Nazwa nowej sekcji
37
- create_section: Utwórz nową sekcję
38
- new_rule_placeholder: Nazwa nowej reguły
39
- create_rule: Utwórz nową regułę
40
- sidebar:
41
- roles_list: Lista ról
42
- new_role: Utwórz nową rolę
43
- delete_role_confirm: 'Czy jesteś pewien? To może być niebezpieczne!'
@@ -1,43 +0,0 @@
1
- pt-BR:
2
- the_role:
3
- role_created: Papel criado
4
- role_updated: Papel atualizado
5
- role_deleted: Papel excluído
6
- section_created: Seção criada
7
- section_not_created: Sessão não foi criada
8
- section_rule_created: "Regra de sessão criada"
9
- section_rule_not_created: "Regra de sessão não foi criada"
10
- section_rule_on: "Regra de sessão habilitada"
11
- section_rule_off: "Regra de sessão desabilitada"
12
- state_not_changed: "Regra de sessão não alterada"
13
- section_deleted: Sessão excluída
14
- section_not_deleted: Sessão não foi excluída
15
- section_rule_deleted: "Regra de sessão excluída"
16
- section_rule_not_deleted: "Regra de sessão não foi excluída"
17
- access_denied: "Acesso negado"
18
-
19
- admin:
20
- roles:
21
- new:
22
- create: Criar novo Papel
23
- name: "Nome do Papel (caracteres latinos, com underscore)"
24
- title: Título do papel (texto)
25
- description: Descrição do papel (texto)
26
- role:
27
- role_name: 'Nome do papel:'
28
- title: 'Título:'
29
- role_description: 'Descrição do papel:'
30
- delete_section: Excluir sessão
31
- section_delete_confirm: 'Deseja excluir a sessão?'
32
- rule_delete_confirm: 'Deseja excluir a regra?'
33
- enable: Habilitar
34
- disable: Desabilitar
35
- delete_rule: Excluir regra
36
- new_section_placeholder: Nome da nova sessão
37
- create_section: Criar nova sessão
38
- new_rule_placeholder: Nome da nova regra
39
- create_rule: Criar nova regra
40
- sidebar:
41
- roles_list: Lista de Papéis
42
- new_role: Criar novo papel
43
- delete_role_confirm: 'Tem certeza? Isto pode ser perigiso!'
@@ -1,43 +0,0 @@
1
- ru:
2
- the_role:
3
- role_created: Роль создана
4
- role_updated: Роль обновлена
5
- role_deleted: Роль удалена
6
- section_created: Раздел создан
7
- section_not_created: Раздел не создан
8
- section_rule_created: Правило создано
9
- section_rule_not_created: Правило не создано
10
- section_rule_on: Правило доступа включено
11
- section_rule_off: Правило доступа отключено
12
- state_not_changed: Состояние правила не изменилось
13
- section_deleted: Раздел удален
14
- section_not_deleted: Раздел не удален
15
- section_rule_deleted: Правило удалено
16
- section_rule_not_deleted: Правило не удалено
17
-
18
- admin:
19
- roles:
20
- new:
21
- create: Создать новую роль
22
- name: Имя роли (строка из латинских символов + нижнее подчеркивание)
23
- title: Заголовок роли
24
- description: Описание роли
25
- based_on_role: "Новая роль будет основана на:"
26
- role:
27
- role_name: 'Имя роли:'
28
- title: 'Заголовок:'
29
- role_description: 'Описание:'
30
- delete_section: Удалить раздел
31
- section_delete_confirm: 'Вы хотите удалить раздел?'
32
- rule_delete_confirm: 'Вы хотите удалить правило?'
33
- enable: Включено
34
- disable: Отключено
35
- delete_rule: Удалить правило
36
- new_section_placeholder: Имя нового раздела
37
- create_section: Создать раздел
38
- new_rule_placeholder: Имя нового правила
39
- create_rule: Создать правило
40
- sidebar:
41
- roles_list: Список ролей
42
- new_role: Создать новую Роль
43
- delete_role_confirm: 'Удалить роль? Это может быть опасно! Уверены?'
@@ -1,42 +0,0 @@
1
- zh_CN:
2
- the_role:
3
- role_created: 角色已创建
4
- role_updated: 角色已更新
5
- role_deleted: 角色已删除
6
- section_created: 章节已创建
7
- section_not_created: 章节没有被创建
8
- section_rule_created: "章节的规则已创建"
9
- section_rule_not_created: "章节的规则没有被创建"
10
- section_rule_on: "章节的规则可有"
11
- section_rule_off: "章节的规则不可有"
12
- state_not_changed: "章节的规则没有改变"
13
- section_deleted: 章节已删除
14
- section_not_deleted: 章节没有被删除
15
- section_rule_deleted: "章节的规则已被删除"
16
- section_rule_not_deleted: "章节的规则没有被删除"
17
-
18
- admin:
19
- roles:
20
- new:
21
- create: 创建新角色
22
- name: 角色名称 (字符串)
23
- title: 角色标题 (文本)
24
- description: 角色描述 (文本)
25
- role:
26
- role_name: '角色名称:'
27
- title: '角色标题:'
28
- role_description: '角色描述:'
29
- delete_section: 删除章节
30
- section_delete_confirm: '你想要删除章节?'
31
- rule_delete_confirm: '你想删除规则?'
32
- enable: 可用
33
- disable: 不可用
34
- delete_rule: 删除规则
35
- new_section_placeholder: 新章节名称
36
- create_section: 创建新章节
37
- new_rule_placeholder: 新规则名称
38
- create_rule: 创建新规则
39
- sidebar:
40
- roles_list: 角色列表
41
- new_role: 创建新角色
42
- delete_role_confirm: '你确定? 可能存在风险!'
data/config/routes.rb DELETED
@@ -1,23 +0,0 @@
1
- module TheRole
2
- class AdminRoutes
3
- def call mapper, options = {}
4
- mapper.resources :roles, :except => :show do
5
- mapper.patch 'change', on: :member
6
- mapper.resources :sections, :controller => :role_sections, :only => :none do
7
- mapper.collection do
8
- mapper.post :create
9
- mapper.post :create_rule
10
- end
11
-
12
- mapper.member do
13
- mapper.put :rule_on
14
- mapper.put :rule_off
15
-
16
- mapper.delete :destroy
17
- mapper.delete :destroy_rule
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- class CreateRoles < ActiveRecord::Migration
2
- def self.up
3
- create_table :roles do |t|
4
-
5
- t.string :name, :null => false
6
- t.string :title, :null => false
7
- t.text :description, :null => false
8
- #Use Postgresql's native json
9
- #Remove this test if you using PostgreSQL prior to 9.2
10
- if ::ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
11
- t.json :the_role, :null => false
12
- else
13
- t.text :the_role, :null => false
14
- end
15
-
16
- t.timestamps
17
- end
18
- end
19
-
20
- def self.down
21
- drop_table :roles
22
- end
23
- end
data/docs/2.1.1.png DELETED
Binary file
@@ -1,32 +0,0 @@
1
- ---------------------------------------
2
- TheRole
3
- ---------------------------------------
4
-
5
- Description:
6
- This generators helps to install TheRole gem into your Application
7
-
8
- This text:
9
- > bundle exec rails g the_role --help
10
-
11
- Generators:
12
- > bundle exec rails g the_role install
13
- - Install config file and models
14
-
15
- > bundle exec rails g the_role config
16
- - Install config file
17
-
18
- > bundle exec rails g the_role models
19
- - Install models
20
-
21
- > bundle exec rails g the_role admin
22
- - Create Admin Role
23
-
24
- > rake db:roles:admin
25
- - Create Admin Role
26
-
27
- Migrations:
28
- > bundle exec rake the_role_engine:install:migrations
29
-
30
- ---------------------------------------
31
- ~ TheRole
32
- ---------------------------------------
@@ -1,11 +0,0 @@
1
- # TheRole.config.param_name => value
2
-
3
- TheRole.configure do |config|
4
- # config.layout = :application
5
-
6
- # config.default_user_role = nil
7
- # config.first_user_should_be_admin = false
8
- # config.access_denied_method = :access_denied
9
- # config.login_required_method = :authenticate_user!
10
- # config.destroy_strategy = :restrict_with_exception # can be nil
11
- end
@@ -1,64 +0,0 @@
1
- class TheRoleGenerator < Rails::Generators::NamedBase
2
- source_root File.expand_path('../templates', __FILE__)
3
- # argument :xname, type: :string, default: :xname
4
-
5
- def generate_controllers
6
- if gen_name == 'install'
7
- cp_config
8
- cp_models
9
- elsif gen_name == 'config'
10
- cp_config
11
- elsif gen_name == 'models'
12
- cp_models
13
- elsif gen_name == 'admin'
14
- create_admin_role
15
- else
16
- puts 'TheRole Generator - wrong Name'
17
- puts 'Try to use install'
18
- end
19
- end
20
-
21
- private
22
-
23
- def root_path; TheRole::Engine.root; end
24
-
25
- def gen_name
26
- name.to_s.downcase
27
- end
28
-
29
- def cp_models
30
- copy_file "#{root_path}/app/models/_templates_/role.rb",
31
- "app/models/role.rb"
32
- end
33
-
34
- def cp_config
35
- copy_file 'the_role.rb', 'config/initializers/the_role.rb'
36
- end
37
-
38
- def create_admin_role
39
- puts `clear`
40
- puts '~'*40
41
- puts 'TheRole'
42
- puts '~'*40
43
-
44
- unless Role.with_name(:admin)
45
- role = Role.create(
46
- name: :admin,
47
- title: "role for admin",
48
- description:"this user can do anything"
49
- )
50
-
51
- role.create_rule(:system, :administrator)
52
- role.rule_on(:system, :administrator)
53
-
54
- puts "Admin role created"
55
- else
56
- puts "Admin role exists"
57
- end
58
-
59
- puts "Now you can makes any user as Admin:"
60
- puts "> bin/rails c"
61
- puts "> User.first.update( role: Role.with_name(:admin) )"
62
- puts '~'*40
63
- end
64
- end