the_role 2.1.1 → 2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +27 -3
- data/.ruby-gemset.example +1 -0
- data/.ruby-version.example +1 -0
- data/.rvmrc.example +1 -1
- data/.travis.yml +2 -2
- data/README.md +46 -47
- data/app/assets/javascripts/the_role_editinplace.js.coffee +32 -0
- data/app/controllers/admin/role_sections_controller.rb +2 -2
- data/app/controllers/admin/roles_controller.rb +2 -2
- data/app/controllers/concerns/controller.rb +23 -0
- data/{lib/generators/the_role/templates → app/models/_templates_}/role.rb +1 -1
- data/app/models/concerns/base.rb +37 -0
- data/app/models/concerns/role.rb +134 -0
- data/app/models/concerns/user.rb +57 -0
- data/app/views/admin/roles/_role.html.haml +90 -69
- data/app/views/admin/roles/_sidebar.html.haml +16 -9
- data/app/views/admin/roles/new.html.haml +11 -10
- data/config/locales/en.yml +1 -0
- data/config/locales/es.yml +28 -28
- data/config/locales/ru.yml +1 -1
- data/db/migrate/20111025025129_create_roles.rb +7 -1
- data/docs/2.1.1.png +0 -0
- data/lib/generators/the_role/USAGE +1 -1
- data/lib/generators/the_role/templates/the_role.rb +7 -2
- data/lib/generators/the_role/the_role_generator.rb +8 -5
- data/lib/tasks/roles.rake +1 -1
- data/lib/the_role/activerecord.rb +11 -0
- data/lib/the_role/config.rb +7 -0
- data/lib/the_role/version.rb +1 -1
- data/lib/the_role.rb +19 -5
- data/spec/dummy_app/.gitignore +18 -0
- data/spec/dummy_app/.rspec +1 -0
- data/spec/dummy_app/Gemfile +32 -0
- data/spec/dummy_app/README.md +39 -0
- data/spec/dummy_app/Rakefile +6 -0
- data/spec/dummy_app/app/assets/images/.keep +0 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +17 -0
- data/spec/dummy_app/app/assets/stylesheets/app/style.css.scss +23 -0
- data/spec/dummy_app/app/assets/stylesheets/application.css +3 -0
- data/spec/dummy_app/app/controllers/application_controller.rb +38 -0
- data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
- data/spec/dummy_app/app/controllers/pages_controller.rb +75 -0
- data/spec/dummy_app/app/controllers/users_controller.rb +32 -0
- data/spec/dummy_app/app/controllers/welcome_controller.rb +13 -0
- data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_app/app/mailers/.keep +0 -0
- data/spec/dummy_app/app/models/.keep +0 -0
- data/spec/dummy_app/app/models/concerns/.keep +0 -0
- data/spec/dummy_app/app/models/page.rb +24 -0
- data/spec/dummy_app/app/models/role.rb +4 -0
- data/spec/dummy_app/app/models/user.rb +21 -0
- data/spec/dummy_app/app/views/layouts/_current_user_info.html.haml +17 -0
- data/spec/dummy_app/app/views/layouts/application.html.haml +68 -0
- data/spec/dummy_app/app/views/pages/_form.html.haml +19 -0
- data/spec/dummy_app/app/views/pages/edit.html.haml +7 -0
- data/spec/dummy_app/app/views/pages/index.html.haml +27 -0
- data/spec/dummy_app/app/views/pages/manage.html.haml +23 -0
- data/spec/dummy_app/app/views/pages/my.html.haml +10 -0
- data/spec/dummy_app/app/views/pages/new.html.haml +5 -0
- data/spec/dummy_app/app/views/pages/show.html.haml +15 -0
- data/spec/dummy_app/app/views/users/edit.html.haml +34 -0
- data/spec/dummy_app/app/views/welcome/index.html.haml +38 -0
- data/spec/dummy_app/app/views/welcome/profile.html.haml +2 -0
- data/spec/dummy_app/bin/bundle +3 -0
- data/spec/dummy_app/bin/rails +4 -0
- data/spec/dummy_app/bin/rake +4 -0
- data/spec/dummy_app/config/application.rb +23 -0
- data/spec/dummy_app/config/boot.rb +4 -0
- data/spec/dummy_app/config/database.yml +17 -0
- data/spec/dummy_app/config/environment.rb +5 -0
- data/spec/dummy_app/config/environments/development.rb +29 -0
- data/spec/dummy_app/config/environments/production.rb +80 -0
- data/spec/dummy_app/config/environments/test.rb +36 -0
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_app/config/initializers/devise.rb +227 -0
- data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy_app/config/initializers/inflections.rb +16 -0
- data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_app/config/initializers/secret_token.rb +12 -0
- data/spec/dummy_app/config/initializers/session_store.rb +3 -0
- data/spec/dummy_app/config/initializers/the_role.rb +6 -0
- data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_app/config/locales/devise.en.yml +57 -0
- data/spec/dummy_app/config/locales/en.yml +7 -0
- data/spec/dummy_app/config/locales/ru.yml +4 -0
- data/spec/dummy_app/config/routes.rb +20 -0
- data/spec/dummy_app/config.ru +4 -0
- data/spec/dummy_app/db/migrate/20120212061952_devise_create_users.rb +63 -0
- data/spec/dummy_app/db/migrate/20120212063249_create_roles.rb +18 -0
- data/spec/dummy_app/db/migrate/20120314061307_create_pages.rb +14 -0
- data/spec/dummy_app/db/schema.rb +59 -0
- data/spec/dummy_app/db/seeds.rb +85 -0
- data/spec/dummy_app/lib/assets/.keep +0 -0
- data/spec/dummy_app/lib/tasks/.keep +0 -0
- data/spec/dummy_app/lib/tasks/assets.rake +15 -0
- data/spec/dummy_app/lib/tasks/db_bootstrap.rake +16 -0
- data/spec/dummy_app/log/.keep +0 -0
- data/spec/dummy_app/public/404.html +58 -0
- data/spec/dummy_app/public/422.html +58 -0
- data/spec/dummy_app/public/500.html +57 -0
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/dummy_app/public/robots.txt +5 -0
- data/spec/dummy_app/spec/controllers/admin_roles_controller_spec.rb +52 -0
- data/spec/dummy_app/spec/controllers/pages_controller_spec.rb +141 -0
- data/spec/dummy_app/spec/controllers/welcome_controller_spec.rb +66 -0
- data/spec/dummy_app/spec/factories/page.rb +6 -0
- data/spec/dummy_app/spec/factories/role.rb +55 -0
- data/spec/dummy_app/spec/factories/user.rb +11 -0
- data/spec/dummy_app/spec/models/hash_spec.rb +272 -0
- data/spec/dummy_app/spec/models/param_process_spec.rb +44 -0
- data/spec/dummy_app/spec/models/role_spec.rb +218 -0
- data/spec/dummy_app/spec/models/user_spec.rb +164 -0
- data/spec/dummy_app/spec/routing/admin_roles_routing_spec.rb +41 -0
- data/spec/dummy_app/spec/routing/pages_routing_spec.rb +35 -0
- data/spec/dummy_app/spec/spec_helper.rb +68 -0
- data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
- data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
- data/the_role.gemspec +2 -1
- data/the_role.yml.teamocil.example +11 -0
- metadata +213 -16
- data/app/assets/javascripts/the_role.js.coffee +0 -31
- data/app/assets/stylesheets/the_role/bootstrap_sass.css.scss +0 -20
- data/app/assets/stylesheets/the_role.css.scss +0 -47
- data/app/controllers/the_role_controller.rb +0 -18
- data/app/models/concerns/role_model.rb +0 -125
- data/app/models/concerns/the_role_base.rb +0 -35
- data/app/models/concerns/the_role_user_model.rb +0 -54
@@ -1,76 +1,97 @@
|
|
1
|
-
- content_for :
|
2
|
-
.
|
3
|
-
|
4
|
-
%
|
5
|
-
|
6
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
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
|
-
.
|
4
|
+
- unless @role.errors.blank?
|
5
5
|
- @role.errors.each do |field, message|
|
6
|
-
|
7
|
-
= field
|
6
|
+
.alert.alert-danger
|
7
|
+
%b= t(".#{field}")
|
8
8
|
\:
|
9
9
|
= message
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
.panel.panel-success
|
12
|
+
.panel-heading= raw t('.create')
|
13
13
|
|
14
|
-
|
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'), :
|
25
|
+
= f.submit t('.create'), class: "btn btn-success"
|
data/config/locales/en.yml
CHANGED
data/config/locales/es.yml
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
es:
|
2
2
|
the_role:
|
3
|
-
role_created:
|
4
|
-
role_updated:
|
5
|
-
role_deleted:
|
6
|
-
section_created:
|
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:
|
9
|
-
section_rule_not_created:
|
10
|
-
section_rule_on:
|
11
|
-
section_rule_off:
|
12
|
-
state_not_changed:
|
13
|
-
section_deleted:
|
14
|
-
section_not_deleted: Sección no
|
15
|
-
section_rule_deleted: Regla eliminada
|
16
|
-
section_rule_not_deleted: Regla
|
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
|
22
|
-
name:
|
23
|
-
title:
|
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: "¿
|
31
|
-
rule_delete_confirm: "¿Quieres eliminar
|
32
|
-
enable:
|
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
|
36
|
-
create_section:
|
37
|
-
new_rule_placeholder:
|
38
|
-
create_rule:
|
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
|
40
|
+
roles_list: Lista de roles
|
41
41
|
new_role: Crear nuevo rol
|
42
|
-
delete_role_confirm: "
|
42
|
+
delete_role_confirm: "¿Estás seguro? ¡Puede ser peligroso!"
|
data/config/locales/ru.yml
CHANGED
@@ -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
|
-
|
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
|
@@ -1,6 +1,11 @@
|
|
1
1
|
# TheRole.config.param_name => value
|
2
2
|
|
3
3
|
TheRole.configure do |config|
|
4
|
-
config.layout
|
5
|
-
|
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
|
-
|
7
|
+
cp_config
|
8
8
|
cp_models
|
9
|
-
elsif gen_name == '
|
10
|
-
|
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
|
30
|
+
copy_file "#{root_path}/app/models/_templates_/role.rb",
|
31
|
+
"app/models/role.rb"
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
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
data/lib/the_role/config.rb
CHANGED
@@ -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
|
data/lib/the_role/version.rb
CHANGED
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
|
11
|
-
admin_role = Role.where(name: :admin).first_or_create(
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
+
```
|
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
|
+
}
|