the_role 2.1.1 → 2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +27 -3
  3. data/.ruby-gemset.example +1 -0
  4. data/.ruby-version.example +1 -0
  5. data/.rvmrc.example +1 -1
  6. data/.travis.yml +2 -2
  7. data/README.md +46 -47
  8. data/app/assets/javascripts/the_role_editinplace.js.coffee +32 -0
  9. data/app/controllers/admin/role_sections_controller.rb +2 -2
  10. data/app/controllers/admin/roles_controller.rb +2 -2
  11. data/app/controllers/concerns/controller.rb +23 -0
  12. data/{lib/generators/the_role/templates → app/models/_templates_}/role.rb +1 -1
  13. data/app/models/concerns/base.rb +37 -0
  14. data/app/models/concerns/role.rb +134 -0
  15. data/app/models/concerns/user.rb +57 -0
  16. data/app/views/admin/roles/_role.html.haml +90 -69
  17. data/app/views/admin/roles/_sidebar.html.haml +16 -9
  18. data/app/views/admin/roles/new.html.haml +11 -10
  19. data/config/locales/en.yml +1 -0
  20. data/config/locales/es.yml +28 -28
  21. data/config/locales/ru.yml +1 -1
  22. data/db/migrate/20111025025129_create_roles.rb +7 -1
  23. data/docs/2.1.1.png +0 -0
  24. data/lib/generators/the_role/USAGE +1 -1
  25. data/lib/generators/the_role/templates/the_role.rb +7 -2
  26. data/lib/generators/the_role/the_role_generator.rb +8 -5
  27. data/lib/tasks/roles.rake +1 -1
  28. data/lib/the_role/activerecord.rb +11 -0
  29. data/lib/the_role/config.rb +7 -0
  30. data/lib/the_role/version.rb +1 -1
  31. data/lib/the_role.rb +19 -5
  32. data/spec/dummy_app/.gitignore +18 -0
  33. data/spec/dummy_app/.rspec +1 -0
  34. data/spec/dummy_app/Gemfile +32 -0
  35. data/spec/dummy_app/README.md +39 -0
  36. data/spec/dummy_app/Rakefile +6 -0
  37. data/spec/dummy_app/app/assets/images/.keep +0 -0
  38. data/spec/dummy_app/app/assets/javascripts/application.js +17 -0
  39. data/spec/dummy_app/app/assets/stylesheets/app/style.css.scss +23 -0
  40. data/spec/dummy_app/app/assets/stylesheets/application.css +3 -0
  41. data/spec/dummy_app/app/controllers/application_controller.rb +38 -0
  42. data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
  43. data/spec/dummy_app/app/controllers/pages_controller.rb +75 -0
  44. data/spec/dummy_app/app/controllers/users_controller.rb +32 -0
  45. data/spec/dummy_app/app/controllers/welcome_controller.rb +13 -0
  46. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  47. data/spec/dummy_app/app/mailers/.keep +0 -0
  48. data/spec/dummy_app/app/models/.keep +0 -0
  49. data/spec/dummy_app/app/models/concerns/.keep +0 -0
  50. data/spec/dummy_app/app/models/page.rb +24 -0
  51. data/spec/dummy_app/app/models/role.rb +4 -0
  52. data/spec/dummy_app/app/models/user.rb +21 -0
  53. data/spec/dummy_app/app/views/layouts/_current_user_info.html.haml +17 -0
  54. data/spec/dummy_app/app/views/layouts/application.html.haml +68 -0
  55. data/spec/dummy_app/app/views/pages/_form.html.haml +19 -0
  56. data/spec/dummy_app/app/views/pages/edit.html.haml +7 -0
  57. data/spec/dummy_app/app/views/pages/index.html.haml +27 -0
  58. data/spec/dummy_app/app/views/pages/manage.html.haml +23 -0
  59. data/spec/dummy_app/app/views/pages/my.html.haml +10 -0
  60. data/spec/dummy_app/app/views/pages/new.html.haml +5 -0
  61. data/spec/dummy_app/app/views/pages/show.html.haml +15 -0
  62. data/spec/dummy_app/app/views/users/edit.html.haml +34 -0
  63. data/spec/dummy_app/app/views/welcome/index.html.haml +38 -0
  64. data/spec/dummy_app/app/views/welcome/profile.html.haml +2 -0
  65. data/spec/dummy_app/bin/bundle +3 -0
  66. data/spec/dummy_app/bin/rails +4 -0
  67. data/spec/dummy_app/bin/rake +4 -0
  68. data/spec/dummy_app/config/application.rb +23 -0
  69. data/spec/dummy_app/config/boot.rb +4 -0
  70. data/spec/dummy_app/config/database.yml +17 -0
  71. data/spec/dummy_app/config/environment.rb +5 -0
  72. data/spec/dummy_app/config/environments/development.rb +29 -0
  73. data/spec/dummy_app/config/environments/production.rb +80 -0
  74. data/spec/dummy_app/config/environments/test.rb +36 -0
  75. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  76. data/spec/dummy_app/config/initializers/devise.rb +227 -0
  77. data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
  78. data/spec/dummy_app/config/initializers/inflections.rb +16 -0
  79. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  80. data/spec/dummy_app/config/initializers/secret_token.rb +12 -0
  81. data/spec/dummy_app/config/initializers/session_store.rb +3 -0
  82. data/spec/dummy_app/config/initializers/the_role.rb +6 -0
  83. data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
  84. data/spec/dummy_app/config/locales/devise.en.yml +57 -0
  85. data/spec/dummy_app/config/locales/en.yml +7 -0
  86. data/spec/dummy_app/config/locales/ru.yml +4 -0
  87. data/spec/dummy_app/config/routes.rb +20 -0
  88. data/spec/dummy_app/config.ru +4 -0
  89. data/spec/dummy_app/db/migrate/20120212061952_devise_create_users.rb +63 -0
  90. data/spec/dummy_app/db/migrate/20120212063249_create_roles.rb +18 -0
  91. data/spec/dummy_app/db/migrate/20120314061307_create_pages.rb +14 -0
  92. data/spec/dummy_app/db/schema.rb +59 -0
  93. data/spec/dummy_app/db/seeds.rb +85 -0
  94. data/spec/dummy_app/lib/assets/.keep +0 -0
  95. data/spec/dummy_app/lib/tasks/.keep +0 -0
  96. data/spec/dummy_app/lib/tasks/assets.rake +15 -0
  97. data/spec/dummy_app/lib/tasks/db_bootstrap.rake +16 -0
  98. data/spec/dummy_app/log/.keep +0 -0
  99. data/spec/dummy_app/public/404.html +58 -0
  100. data/spec/dummy_app/public/422.html +58 -0
  101. data/spec/dummy_app/public/500.html +57 -0
  102. data/spec/dummy_app/public/favicon.ico +0 -0
  103. data/spec/dummy_app/public/robots.txt +5 -0
  104. data/spec/dummy_app/spec/controllers/admin_roles_controller_spec.rb +52 -0
  105. data/spec/dummy_app/spec/controllers/pages_controller_spec.rb +141 -0
  106. data/spec/dummy_app/spec/controllers/welcome_controller_spec.rb +66 -0
  107. data/spec/dummy_app/spec/factories/page.rb +6 -0
  108. data/spec/dummy_app/spec/factories/role.rb +55 -0
  109. data/spec/dummy_app/spec/factories/user.rb +11 -0
  110. data/spec/dummy_app/spec/models/hash_spec.rb +272 -0
  111. data/spec/dummy_app/spec/models/param_process_spec.rb +44 -0
  112. data/spec/dummy_app/spec/models/role_spec.rb +218 -0
  113. data/spec/dummy_app/spec/models/user_spec.rb +164 -0
  114. data/spec/dummy_app/spec/routing/admin_roles_routing_spec.rb +41 -0
  115. data/spec/dummy_app/spec/routing/pages_routing_spec.rb +35 -0
  116. data/spec/dummy_app/spec/spec_helper.rb +68 -0
  117. data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
  118. data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
  119. data/the_role.gemspec +2 -1
  120. data/the_role.yml.teamocil.example +11 -0
  121. metadata +213 -16
  122. data/app/assets/javascripts/the_role.js.coffee +0 -31
  123. data/app/assets/stylesheets/the_role/bootstrap_sass.css.scss +0 -20
  124. data/app/assets/stylesheets/the_role.css.scss +0 -47
  125. data/app/controllers/the_role_controller.rb +0 -18
  126. data/app/models/concerns/role_model.rb +0 -125
  127. data/app/models/concerns/the_role_base.rb +0 -35
  128. data/app/models/concerns/the_role_user_model.rb +0 -54
@@ -1,76 +1,97 @@
1
- - content_for :role_main do
2
- .well
3
- = form_for(role, :url => change_admin_role_path(role)) do |f|
4
- %h3.name
5
- %b= t '.role_name'
6
- %span.a= role.name
7
- %span.b{style: 'visibility:hidden'}
8
- = f.text_field :name
9
- .btn-group
10
- %a.btn.btn-warning
11
- %i.icon-repeat
12
- %a.btn.btn-success
13
- %i.icon-ok
14
-
15
- %h5.title
16
- %b= t '.title'
17
- %span.a= role.title
18
- %span.b{style: 'visibility:hidden'}
19
- = f.text_field :title
20
- .btn-group
21
- %a.btn.btn-warning
22
- %i.icon-repeat
23
- %a.btn.btn-success
24
- %i.icon-ok
25
-
26
- %h5.description
27
- %b= t '.role_description'
28
- %span.a= role.description
29
- %span.b{style: 'visibility:hidden'}
30
- = f.text_field :description
31
- .btn-group
32
- %a.btn.btn-warning
33
- %i.icon-repeat
34
- %a.btn.btn-success
35
- %i.icon-ok
1
+ - content_for :role_update_btn_set do
2
+ .btn-group
3
+ %a.btn.btn-warning
4
+ %i.icon-repeat.glyphicon.glyphicon-repeat
5
+ %a.btn.btn-success
6
+ %i.icon-ok.glyphicon.glyphicon-ok
36
7
 
37
- - role.to_hash.each_pair do |section, rules|
38
- .section
39
- %h3= section
40
- .delete
41
- .btn-group
42
- = button_to t('.delete_section'), admin_role_section_path(role, section), method: :delete, class: 'btn btn-danger', data: { confirm: t('.section_delete_confirm') }
8
+ - content_for :role_main do
9
+ - hidden = 'visibility:hidden'
10
+ .panel.panel-primary
11
+ .panel-heading Role Info (edit in place)
12
+ .panel-body
13
+ = form_for(role, url: change_admin_role_path(role), html: { class: "form-inline" } ) do |f|
14
+ .row
15
+ .col-md-12
16
+ %h3.holder
17
+ = t '.role_name'
18
+ %span.a= role.name
19
+ %span.b{ style: hidden }
20
+ .form-group= f.text_field :name, class: "form-control"
21
+ = yield(:role_update_btn_set)
43
22
 
44
- - rules.each_pair do |rule, value|
45
- .rule
46
- %h4
47
- →
48
- = rule
49
- .controls
50
- .btn-group
51
- - klass = value ? :success : :info
52
- - state = value ? t('.enable') : t('.disable')
53
- %button{ class: "btn btn-#{klass}" }= state
54
- %button{ class: "btn btn-#{klass} dropdown-toggle", 'data-toggle' => :dropdown }
55
- %span.caret
56
- %ul.dropdown-menu
57
- %li.success= link_to t('.enable'), rule_on_admin_role_section_path(role, section, :name => rule), :method => :put
58
- %li.info= link_to t('.disable'), rule_off_admin_role_section_path(role, section, :name => rule), :method => :put
59
- %li.divider
60
- %li.error= link_to t('.delete_rule'), destroy_rule_admin_role_section_path(role, section, :name => rule), method: :delete, data: { confirm: t(".rule_delete_confirm") }
23
+ .row
24
+ .col-md-12
25
+ %h5.holder
26
+ = t '.title'
27
+ %span.a= role.title
28
+ %span.b{ style: hidden }
29
+ .form-group= f.text_field :title, class: "form-control"
30
+ = yield(:role_update_btn_set)
61
31
 
62
- %h4= t '.create_section'
32
+ .row
33
+ .col-md-12
34
+ %h5.holder
35
+ = t '.role_description'
36
+ %span.a= role.description
37
+ %span.b{ style: hidden }
38
+ .form-group= f.text_field :description, class: "form-control"
39
+ = yield(:role_update_btn_set)
63
40
 
64
- = form_tag admin_role_sections_path(role), class: 'well form-inline' do |f|
65
- = text_field_tag :section_name, '', class: 'input-xlarge', :placeholder => t('.new_section_placeholder')
66
- = submit_tag t('.create_section'), class: :btn
41
+ .panel.panel-primary
42
+ .panel-heading Role rules
43
+ .panel-body
44
+ - role.to_hash.each_pair do |section, rules|
45
+ .panel.panel-info
46
+ .panel-heading
47
+ .row
48
+ .col-md-9
49
+ %h5= section
50
+ .col-md-3
51
+ .delete
52
+ .btn-group
53
+ = button_to t('.delete_section'), admin_role_section_path(role, section), method: :delete, class: 'btn btn-danger', data: { confirm: t('.section_delete_confirm') }
67
54
 
68
- %h4= t '.create_rule'
55
+ .panel-body
56
+ .rules
57
+ - rules.each_pair do |rule, value|
58
+ .row
59
+ .col-md-9
60
+ %h4
61
+ →
62
+ = rule
63
+ .col-md-3
64
+ .controls
65
+ .btn-group
66
+ - klass = value ? :success : :info
67
+ - state = value ? t('.enable') : t('.disable')
68
+ %button{ class: "btn btn-#{klass}" }= state
69
+ %button{ class: "btn btn-#{klass} dropdown-toggle", 'data-toggle' => :dropdown }
70
+ %span.caret
71
+ %ul.dropdown-menu
72
+ %li.success= link_to t('.enable'), rule_on_admin_role_section_path(role, section, :name => rule), :method => :put
73
+ %li.info= link_to t('.disable'), rule_off_admin_role_section_path(role, section, :name => rule), :method => :put
74
+ %li.divider
75
+ %li.error= link_to t('.delete_rule'), destroy_rule_admin_role_section_path(role, section, :name => rule), method: :delete, data: { confirm: t(".rule_delete_confirm") }
69
76
 
70
- = form_tag create_rule_admin_role_sections_path(role), class: 'well form-inline' do |f|
71
- %select.span3{ :name => :section_name }
72
- - role.to_hash.each_pair do |section, rules|
73
- %option{ :value => section }= section
77
+ .panel.panel-success
78
+ .panel-heading
79
+ = t '.create_section'
80
+ .panel-body
81
+ = form_tag admin_role_sections_path(role), class: "form-inline"do |f|
82
+ .form-group
83
+ = text_field_tag :section_name, '', class: "form-control", placeholder: t('.new_section_placeholder')
84
+ = submit_tag t('.create_section'), class: "btn btn-success"
74
85
 
75
- = text_field_tag :rule_name, '', class: 'input-large', :placeholder => t('.new_rule_placeholder')
76
- = submit_tag t('.create_rule'), class: :btn
86
+ .panel.panel-success
87
+ .panel-heading
88
+ = t '.create_rule'
89
+ .panel-body
90
+ = form_tag create_rule_admin_role_sections_path(role), role: :form, class: "form-inline" do |f|
91
+ .form-group
92
+ %select.form-control{ name: :section_name }
93
+ - role.to_hash.each_pair do |section, rules|
94
+ %option{ value: section }= section
95
+ .form-group
96
+ = text_field_tag :rule_name, '', class: "form-control", placeholder: t('.new_rule_placeholder')
97
+ = submit_tag t('.create_rule'), class: "btn btn-success"
@@ -1,11 +1,18 @@
1
1
  - content_for :role_sidebar do
2
- %h3= link_to raw('← Home'), root_path
3
- %br
4
- %h3= t '.roles_list'
5
- - (@roles || Role.all).each do |role|
6
- %p
7
- = link_to role.title, edit_admin_role_url(role)
8
- (#{role.users.count})
9
- = link_to raw('×'), admin_role_url(role), :method => :delete, :title => role.title, :confirm => t('.delete_role_confirm'), :class => :delete
2
+ .panel.panel-primary
3
+ .panel-heading Role Nav
4
+ .panel-body
5
+ %h4= link_to raw('← Home'), root_path
10
6
 
11
- %p.new= link_to t('.new_role'), new_admin_role_path
7
+ .panel.panel-primary
8
+ .panel-heading= t '.roles_list'
9
+ .panel-body
10
+
11
+ - (@roles || Role.all).each do |role|
12
+ %p
13
+ = link_to role.title, edit_admin_role_url(role)
14
+ (#{role.users.count})
15
+ = link_to admin_role_url(role), method: :delete, title: role.title, confirm: t('.delete_role_confirm'), class: :delete do
16
+ %i.icon-remove.glyphicon.glyphicon-remove
17
+
18
+ %p.new= link_to t('.new_role'), new_admin_role_path
@@ -1,24 +1,25 @@
1
1
  = render partial: 'sidebar'
2
2
 
3
3
  - content_for :role_main do
4
- .well
4
+ - unless @role.errors.blank?
5
5
  - @role.errors.each do |field, message|
6
- %p
7
- = field
6
+ .alert.alert-danger
7
+ %b= t(".#{field}")
8
8
  \:
9
9
  = message
10
10
 
11
- .form
12
- %h3= raw t('.create')
11
+ .panel.panel-success
12
+ .panel-heading= raw t('.create')
13
13
 
14
- = form_for(@role, :url => admin_roles_path) do |f|
14
+ .panel-body
15
+ = form_for(@role, url: admin_roles_path, role: :form) do |f|
15
16
  %label= t('.name')
16
- %p= f.text_field :name
17
+ %p= f.text_field :name, class: "form-control"
17
18
 
18
19
  %label= t('.title')
19
- %p= f.text_field :title
20
+ %p= f.text_field :title, class: "form-control"
20
21
 
21
22
  %label= t('.description')
22
- %p= f.text_field :description
23
+ %p= f.text_field :description, class: "form-control"
23
24
 
24
- = f.submit t('.create'), :class => :btn
25
+ = f.submit t('.create'), class: "btn btn-success"
@@ -14,6 +14,7 @@ en:
14
14
  section_not_deleted: Section not deleted
15
15
  section_rule_deleted: "Section rule deleted"
16
16
  section_rule_not_deleted: "Section rule not deleted"
17
+ access_denied: "Access Denied"
17
18
 
18
19
  admin:
19
20
  roles:
@@ -1,42 +1,42 @@
1
1
  es:
2
2
  the_role:
3
- role_created: Establecer el rol
4
- role_updated: Actualizar el rol
5
- role_deleted: Eliminar el rol
6
- section_created: Crear sección
3
+ role_created: Rol creado
4
+ role_updated: Rol actualizado
5
+ role_deleted: Rol eliminado
6
+ section_created: Sección creada
7
7
  section_not_created: Sección no creada
8
- section_rule_created: Sección de roles creado
9
- section_rule_not_created: Sección de roles no creado
10
- section_rule_on: Rol de acceso incluye
11
- section_rule_off: Deshabilitar el rol
12
- state_not_changed: Rol de estado no se ha modificado
13
- section_deleted: sección eliminada
14
- section_not_deleted: Sección no se ha sido eliminada
15
- section_rule_deleted: Regla eliminada
16
- section_rule_not_deleted: Regla no ha sido eliminada
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
17
 
18
18
  admin:
19
19
  roles:
20
20
  new:
21
- create: Crear un nuevo rol
22
- name: El nombre de la función (una cadena de caracteres simples + subrayado)
23
- title: título del rol
21
+ create: Crear nuevo rol
22
+ name: Nombre del rol (cadena de caracteres simples + guión bajo)
23
+ title: Título del rol
24
24
  description: Descripción del rol
25
25
  role:
26
- role_name: 'Nombre del rol'
27
- title: 'Título'
28
- role_description: 'Descripción'
26
+ role_name: 'Nombre del rol:'
27
+ title: 'Título:'
28
+ role_description: 'Descripción del rol:'
29
29
  delete_section: Eliminar sección
30
- section_delete_confirm: "¿Quiere borrar la sección?"
31
- rule_delete_confirm: "¿Quieres eliminar una regla?"
32
- enable: Habilitar
30
+ section_delete_confirm: "¿Quieres borrar la sección?"
31
+ rule_delete_confirm: "¿Quieres eliminar la regla?"
32
+ enable: Activar
33
33
  disable: Desactivar
34
34
  delete_rule: Eliminar regla
35
- new_section_placeholder: Nombre de un nuevo tema
36
- create_section: "Crear una sección"
37
- new_rule_placeholder: El nombre de la nueva regla
38
- create_rule: Nueva 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
39
  sidebar:
40
- roles_list: Lista de funciones
40
+ roles_list: Lista de roles
41
41
  new_role: Crear nuevo rol
42
- delete_role_confirm: "Quitar el rol? Puede ser peligroso! ¿Está seguro?"
42
+ delete_role_confirm: "¿Estás seguro? ¡Puede ser peligroso!"
@@ -38,5 +38,5 @@ ru:
38
38
  create_rule: Создать правило
39
39
  sidebar:
40
40
  roles_list: Список ролей
41
- new_role: Создать новое правило
41
+ new_role: Создать новую Роль
42
42
  delete_role_confirm: 'Удалить роль? Это может быть опасно! Уверены?'
@@ -5,7 +5,13 @@ class CreateRoles < ActiveRecord::Migration
5
5
  t.string :name, :null => false
6
6
  t.string :title, :null => false
7
7
  t.text :description, :null => false
8
- t.text :the_role, :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
9
15
 
10
16
  t.timestamps
11
17
  end
data/docs/2.1.1.png ADDED
Binary file
@@ -12,7 +12,7 @@ Generators:
12
12
  > bundle exec rails g the_role install
13
13
  - Install config file and models
14
14
 
15
- > bundle exec rails g the_role setup
15
+ > bundle exec rails g the_role config
16
16
  - Install config file
17
17
 
18
18
  > bundle exec rails g the_role models
@@ -1,6 +1,11 @@
1
1
  # TheRole.config.param_name => value
2
2
 
3
3
  TheRole.configure do |config|
4
- config.layout = :application # default Layout for TheRole UI
5
- config.default_user_role = nil # set default role (name)
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
6
11
  end
@@ -4,10 +4,10 @@ class TheRoleGenerator < Rails::Generators::NamedBase
4
4
 
5
5
  def generate_controllers
6
6
  if gen_name == 'install'
7
- cp_setup
7
+ cp_config
8
8
  cp_models
9
- elsif gen_name == 'setup'
10
- cp_setup
9
+ elsif gen_name == 'config'
10
+ cp_config
11
11
  elsif gen_name == 'models'
12
12
  cp_models
13
13
  elsif gen_name == 'admin'
@@ -20,15 +20,18 @@ class TheRoleGenerator < Rails::Generators::NamedBase
20
20
 
21
21
  private
22
22
 
23
+ def root_path; TheRole::Engine.root; end
24
+
23
25
  def gen_name
24
26
  name.to_s.downcase
25
27
  end
26
28
 
27
29
  def cp_models
28
- copy_file 'role.rb', 'app/models/role.rb'
30
+ copy_file "#{root_path}/app/models/_templates_/role.rb",
31
+ "app/models/role.rb"
29
32
  end
30
33
 
31
- def cp_setup
34
+ def cp_config
32
35
  copy_file 'the_role.rb', 'config/initializers/the_role.rb'
33
36
  end
34
37
 
data/lib/tasks/roles.rake CHANGED
@@ -8,7 +8,7 @@ namespace :db do
8
8
  puts 'TheRole'
9
9
  puts '~'*40
10
10
 
11
- TheRole.create_admin
11
+ TheRole.create_admin!
12
12
 
13
13
  puts "Now you can makes any user as Admin:"
14
14
  puts "> rails c"
@@ -0,0 +1,11 @@
1
+ module TheRole
2
+ module ActiveRecord
3
+ def has_role
4
+ include TheRole::User
5
+ end
6
+
7
+ def acts_as_role
8
+ include TheRole::Role
9
+ end
10
+ end
11
+ end
@@ -11,13 +11,20 @@ module TheRole
11
11
  class Configuration
12
12
  include ActiveSupport::Configurable
13
13
  config_accessor :layout,
14
+ :destroy_strategy,
14
15
  :default_user_role,
16
+ :access_denied_method,
17
+ :login_required_method,
15
18
  :first_user_should_be_admin
16
19
  end
17
20
 
18
21
  configure do |config|
19
22
  config.layout = :application
23
+
20
24
  config.default_user_role = nil
21
25
  config.first_user_should_be_admin = false
26
+ config.access_denied_method = :access_denied
27
+ config.login_required_method = :authenticate_user!
28
+ config.destroy_strategy = :restrict_with_exception # can be nil
22
29
  end
23
30
  end
@@ -1,3 +1,3 @@
1
1
  module TheRole
2
- VERSION = "2.1.1"
2
+ VERSION = "2.3"
3
3
  end
data/lib/the_role.rb CHANGED
@@ -4,14 +4,15 @@ require 'the_role/hash'
4
4
  require 'the_role/config'
5
5
  require 'the_role/version'
6
6
  require 'the_role/param_helper'
7
+ require 'the_role/activerecord'
7
8
 
8
9
  module TheRole
9
10
  class << self
10
- def create_admin
11
- admin_role = Role.where(name: :admin).first_or_create(
12
- name: :admin,
13
- title: "Role for admin",
14
- description:"This user can do anything"
11
+ def create_admin_role!
12
+ admin_role = ::Role.where(name: :admin).first_or_create!(
13
+ name: :admin,
14
+ title: "Role for admin",
15
+ description: "This user can do anything"
15
16
  )
16
17
  admin_role.create_rule(:system, :administrator)
17
18
  admin_role.rule_on(:system, :administrator)
@@ -27,4 +28,17 @@ module TheRole
27
28
  # http://stackoverflow.com/questions/6279325/adding-to-rails-autoload-path-from-gem
28
29
  # config.to_prepare do; end
29
30
  end
31
+ end
32
+
33
+ _root_ = File.expand_path('../../', __FILE__)
34
+
35
+ # Loading of concerns
36
+ require "#{_root_}/app/controllers/concerns/controller.rb"
37
+
38
+ %w[ base role user ].each do |concern|
39
+ require "#{_root_}/app/models/concerns/#{concern}.rb"
40
+ end
41
+
42
+ if defined?(ActiveRecord::Base)
43
+ ActiveRecord::Base.extend TheRole::ActiveRecord
30
44
  end
@@ -0,0 +1,18 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.db
12
+ /db/*.sqlite3
13
+ /db/*.sqlite3-journal
14
+
15
+ # Ignore all logfiles and tempfiles.
16
+ .rvmrc
17
+ /log/*.log
18
+ /tmp
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,32 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.0.0'
4
+ gem 'rake', '~> 10.0.4'
5
+
6
+ gem 'sqlite3'
7
+ gem 'state_machine', '~> 1.2.0'
8
+ gem 'devise', git: 'https://github.com/plataformatec/devise.git'
9
+
10
+ gem 'sprockets-rails', github: 'rails/sprockets-rails'
11
+ gem 'coffee-rails', github: 'rails/coffee-rails'
12
+ gem 'sass-rails', github: 'rails/sass-rails'
13
+
14
+ gem 'bootstrap-sass', github: 'thomas-mcdonald/bootstrap-sass'
15
+
16
+ gem 'faker'
17
+ gem 'uglifier'
18
+
19
+ gem 'jquery-rails'
20
+ gem 'jbuilder', '~> 1.0.1'
21
+
22
+ gem 'the_role' , path: '../../'
23
+ gem 'haml' , git: 'https://github.com/haml/haml.git', tag: '4.0.1'
24
+
25
+ group :test do
26
+ gem 'factory_girl_rails', '~> 4.0'
27
+ gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git', tag: 'v1.0.0'
28
+
29
+ gem 'rspec', '2.14.1'
30
+ gem 'rspec-core', '2.14.4'
31
+ gem 'rspec-rails', '2.14.0'
32
+ end
@@ -0,0 +1,39 @@
1
+ ## TheRole test App
2
+
3
+ App for development and testing TheRole gem
4
+
5
+ ### How to get?
6
+
7
+ ```
8
+ git clone git@github.com:the-teacher/the_role.git
9
+
10
+ cd the_role/spec/the_role_on_devise/
11
+
12
+ bundle
13
+ ```
14
+
15
+ ### Start it!
16
+
17
+ ```
18
+ rake db:test_launch
19
+
20
+ rails s
21
+ ```
22
+
23
+ ### Test it!
24
+
25
+ ```
26
+ rake db:bootstrap RAILS_ENV=test
27
+ rspec --format documentation
28
+
29
+ rspec spec/models/ --format documentation
30
+ ```
31
+
32
+ ### Production mode
33
+
34
+ ```
35
+ rake assets:build RAILS_ENV=production
36
+ rake db:test_launch RAILS_ENV=production
37
+
38
+ rails s -e production
39
+ ```
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,17 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+
16
+ //= require bootstrap
17
+ //= require the_role_editinplace
@@ -0,0 +1,23 @@
1
+ .header{
2
+ margin: 10px 0;
3
+ background-color: #DCEAF4;
4
+ padding: 5px 10px 10px 10px;
5
+ border-radius: 5px;
6
+ }
7
+
8
+ .manage_panel, .main_content{
9
+ background-color: #DCEAF4;
10
+ padding: 5px 10px 10px 10px;
11
+ border-radius: 5px;
12
+ }
13
+
14
+ .main_content{
15
+ h1{
16
+ padding-bottom: 10px;
17
+ border-bottom: 1px solid gray;
18
+ }
19
+ }
20
+
21
+ .edit_role{
22
+ input{ margin: 0; }
23
+ }
@@ -0,0 +1,3 @@
1
+ /*
2
+ //= require bootstrap
3
+ */