the_role 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc.example +1 -0
- data/Gemfile +0 -2
- data/README.md +53 -91
- data/app/assets/stylesheets/the_role/form.css +57 -55
- data/app/assets/stylesheets/the_role/headers.css.scss +14 -12
- data/app/assets/stylesheets/the_role/style.css.scss +68 -69
- data/app/controllers/admin/role_sections_controller.rb +55 -0
- data/app/controllers/admin/roles_controller.rb +11 -69
- data/app/views/admin/roles/_form.haml +3 -3
- data/app/views/admin/roles/edit.html.haml +39 -34
- data/app/views/admin/roles/index.haml +14 -8
- data/app/views/admin/roles/new.html.haml +22 -13
- data/config/locales/en.yml +34 -33
- data/config/locales/ru.yml +34 -33
- data/config/routes.rb +10 -12
- data/db/migrate/20111025025129_create_roles.rb +4 -4
- data/lib/the_role.rb +9 -104
- data/lib/the_role/hash.rb +22 -18
- data/lib/the_role/modules/base.rb +23 -0
- data/lib/the_role/modules/controller_requires.rb +28 -0
- data/lib/the_role/modules/param_helper.rb +7 -0
- data/lib/the_role/modules/role_model.rb +121 -0
- data/lib/the_role/modules/user_model.rb +32 -0
- data/lib/the_role/version.rb +1 -1
- data/pic.png +0 -0
- data/the_role.gemspec +4 -5
- metadata +39 -12
- data/app/assets/stylesheets/the_role/reset.css.scss +0 -63
- data/app/controllers/admin/role_section_controller.rb +0 -41
- data/app/views/layouts/the_role.html.haml +0 -15
@@ -0,0 +1,55 @@
|
|
1
|
+
class Admin::RoleSectionsController < ApplicationController
|
2
|
+
include TheRole::Requires
|
3
|
+
|
4
|
+
before_filter :role_login_required
|
5
|
+
before_filter :role_require
|
6
|
+
before_filter :role_find, :only => [:create, :create_rule, :destroy, :destroy_rule]
|
7
|
+
before_filter :owner_require, :only => [:create, :create_rule, :destroy, :destroy_rule]
|
8
|
+
|
9
|
+
def create
|
10
|
+
if @role.create_section params[:section_name]
|
11
|
+
flash[:notice] = t('the_role.section_created')
|
12
|
+
redirect_to edit_admin_role_path(@role)
|
13
|
+
else
|
14
|
+
render :action => :edit
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_rule
|
19
|
+
if @role.create_rule(params[:section_name], params[:section_rule])
|
20
|
+
flash[:notice] = t('the_role.section_created')
|
21
|
+
redirect_to edit_admin_role_path(@role)
|
22
|
+
else
|
23
|
+
render :action => :edit
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def destroy
|
28
|
+
section_name = params[:id]
|
29
|
+
|
30
|
+
if @role.delete_section section_name
|
31
|
+
flash[:notice] = t('the_role.section_deleted')
|
32
|
+
redirect_to edit_admin_role_path(@role)
|
33
|
+
else
|
34
|
+
render :action => :edit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy_rule
|
39
|
+
section_name = params[:id]
|
40
|
+
rule_name = params[:name]
|
41
|
+
if @role.delete_rule(section_name, rule_name)
|
42
|
+
flash[:notice] = t('the_role.section_rule_deleted')
|
43
|
+
redirect_to edit_admin_role_path(@role)
|
44
|
+
else
|
45
|
+
render :action => :edit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def role_find
|
52
|
+
@role = Role.find params[:role_id]
|
53
|
+
@object_for_ownership_checking = @role
|
54
|
+
end
|
55
|
+
end
|
@@ -1,14 +1,11 @@
|
|
1
|
-
require 'the_role'
|
2
|
-
|
3
1
|
class Admin::RolesController < ApplicationController
|
4
|
-
|
5
|
-
|
6
|
-
before_filter :
|
7
|
-
|
8
|
-
before_filter :
|
9
|
-
before_filter :
|
10
|
-
|
11
|
-
|
2
|
+
include TheRole::Requires
|
3
|
+
|
4
|
+
before_filter :role_login_required
|
5
|
+
before_filter :role_require
|
6
|
+
before_filter :role_find, :only => [:show, :edit, :update, :destroy]
|
7
|
+
before_filter :owner_require, :only => [:show, :edit, :update, :destroy]
|
8
|
+
|
12
9
|
def index
|
13
10
|
@roles = Role.all(:order => "created_at ASC")
|
14
11
|
end
|
@@ -31,69 +28,13 @@ class Admin::RolesController < ApplicationController
|
|
31
28
|
end
|
32
29
|
|
33
30
|
def update
|
34
|
-
role
|
35
|
-
new_role = params[:role] ? params[:role][:the_role] : Hash.new
|
36
|
-
role.the_merge!(new_role)
|
37
|
-
if @role.update_attribute(:the_role, role.to_yaml)
|
31
|
+
if @role.update_role params[:role].try(:[],:the_role)
|
38
32
|
flash[:notice] = t('the_role.role_updated')
|
39
33
|
redirect_to edit_admin_role_path(@role)
|
40
34
|
else
|
41
35
|
render :action => :edit
|
42
36
|
end
|
43
37
|
end
|
44
|
-
|
45
|
-
def new_role_section
|
46
|
-
# validate 1
|
47
|
-
if params[:section_name].blank?
|
48
|
-
flash[:error] = t('the_role.section_name_is_blank')
|
49
|
-
redirect_to edit_admin_role_path(@role) and return
|
50
|
-
end
|
51
|
-
|
52
|
-
# validate 2
|
53
|
-
section_name = params[:section_name]
|
54
|
-
unless section_name.match(TheRole::NAME_SYMBOLS)
|
55
|
-
flash[:error] = t('the_role.section_name_is_wrong')
|
56
|
-
redirect_to edit_admin_role_path(@role) and return
|
57
|
-
end
|
58
|
-
|
59
|
-
section_name.downcase!
|
60
|
-
role = TheRole.get(@role.the_role)
|
61
|
-
|
62
|
-
# validate 3
|
63
|
-
if role[section_name.to_sym]
|
64
|
-
flash[:error] = t('the_role.section_exists')
|
65
|
-
redirect_to edit_admin_role_path(@role) and return
|
66
|
-
end
|
67
|
-
|
68
|
-
role[section_name.to_sym] = Hash.new
|
69
|
-
|
70
|
-
if @role.update_attributes({:the_role => role.to_yaml})
|
71
|
-
flash[:notice] = t('the_role.section_created')
|
72
|
-
redirect_to edit_admin_role_path(@role)
|
73
|
-
else
|
74
|
-
render :action => :edit
|
75
|
-
end
|
76
|
-
end#new_role_section
|
77
|
-
|
78
|
-
def new_role_policy
|
79
|
-
params[:section_policy].downcase!
|
80
|
-
|
81
|
-
# validate 1
|
82
|
-
unless params[:section_policy].match(TheRole::NAME_SYMBOLS)
|
83
|
-
flash[:error] = t('the_role.section_policy_wrong_name')
|
84
|
-
redirect_to edit_admin_role_path(@role)
|
85
|
-
end
|
86
|
-
|
87
|
-
role = TheRole.get(@role.the_role)
|
88
|
-
role[params[:section_name].to_sym][params[:section_policy].to_sym] = true
|
89
|
-
|
90
|
-
if @role.update_attributes({:the_role => role.to_yaml})
|
91
|
-
flash[:notice] = t('the_role.section_policy_created')
|
92
|
-
redirect_to edit_admin_role_path(@role)
|
93
|
-
else
|
94
|
-
render :action => :edit
|
95
|
-
end
|
96
|
-
end#new_role_policy
|
97
38
|
|
98
39
|
def destroy
|
99
40
|
@role.destroy
|
@@ -102,8 +43,9 @@ class Admin::RolesController < ApplicationController
|
|
102
43
|
|
103
44
|
protected
|
104
45
|
|
105
|
-
def
|
106
|
-
@role = Role.find
|
46
|
+
def role_find
|
47
|
+
@role = Role.find params[:id]
|
48
|
+
@object_for_ownership_checking = @role
|
107
49
|
end
|
108
50
|
|
109
51
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
- role =
|
1
|
+
- role = @role.to_hash
|
2
2
|
|
3
3
|
- if role.blank?
|
4
4
|
%h3= t('.empty')
|
@@ -7,7 +7,7 @@
|
|
7
7
|
%h4
|
8
8
|
= name
|
9
9
|
%span.controls
|
10
|
-
= link_to(t('.delete'),
|
10
|
+
= link_to(t('.delete'), admin_role_section_path(@role, name), :method => :delete, :confirm => t('.destroy_section_confirm'))
|
11
11
|
|
12
12
|
- if set.is_a?(Hash)
|
13
13
|
%ul.rights
|
@@ -16,7 +16,7 @@
|
|
16
16
|
= check_box_tag "role[the_role][#{name}][#{n}]", true, v
|
17
17
|
= n
|
18
18
|
.controls
|
19
|
-
= link_to t('.delete'),
|
19
|
+
= link_to t('.delete'), destroy_rule_admin_role_section_path(@role, name, :name => n), :method => :delete, :confirm => t('.delete_rule_confirm')
|
20
20
|
|
21
21
|
= f.submit button
|
22
22
|
|
@@ -1,37 +1,42 @@
|
|
1
1
|
- content_for :title do
|
2
2
|
= t('.title')
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
%
|
11
|
-
|
12
|
-
=
|
13
|
-
|
14
|
-
=
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
=
|
22
|
-
|
23
|
-
|
24
|
-
%h4= t('.
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
=
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
%
|
36
|
-
-
|
37
|
-
|
4
|
+
- content_for :css do
|
5
|
+
= stylesheet_link_tag 'the_role/style'
|
6
|
+
= stylesheet_link_tag 'the_role/headers'
|
7
|
+
= stylesheet_link_tag 'the_role/form'
|
8
|
+
|
9
|
+
.the_role
|
10
|
+
%p= flash[:notice]
|
11
|
+
|
12
|
+
%h1= t('.title')
|
13
|
+
|
14
|
+
%p= link_to raw(t('.back')), admin_roles_path
|
15
|
+
|
16
|
+
%h2
|
17
|
+
= @role.name
|
18
|
+
\-
|
19
|
+
= @role.title
|
20
|
+
|
21
|
+
= form_for :role, :url => {:action=> :update }, :html => {:method => :put, :class => :the_form } do |f|
|
22
|
+
= render :partial => 'form', :locals => {:f => f, :button => t('.update')}
|
23
|
+
|
24
|
+
%h4= t('.create_section')
|
25
|
+
- role = @role.to_hash
|
26
|
+
= form_tag(admin_role_sections_path(@role), :method => :post, :class => :new_rule) do
|
27
|
+
= text_field_tag :section_name
|
28
|
+
= submit_tag t('.create_section')
|
29
|
+
|
30
|
+
%h4= t('.create_access_rule')
|
31
|
+
- unless @role.to_hash.empty?
|
32
|
+
= form_tag(create_rule_admin_role_sections_path(@role), :method => :post, :class => :new_rule) do
|
33
|
+
= text_field_tag :section_rule
|
34
|
+
|
35
|
+
%select{ :name => :section_name }
|
36
|
+
-role.each do |name, set|
|
37
|
+
%option{ :value => name }
|
38
|
+
= name
|
39
|
+
|
40
|
+
%input{ :type => :submit, :value => t('.create_rule') }
|
41
|
+
- else
|
42
|
+
%p= t('.section_needs')
|
@@ -1,9 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
%p
|
6
|
-
= link_to role.title, edit_admin_role_url(role)
|
7
|
-
= link_to t('.delete') + role.title , admin_role_url(role), :method => :delete, :class => :delete
|
1
|
+
- content_for :css do
|
2
|
+
= stylesheet_link_tag 'the_role/style'
|
3
|
+
= stylesheet_link_tag 'the_role/headers'
|
4
|
+
= stylesheet_link_tag 'the_role/form'
|
8
5
|
|
9
|
-
|
6
|
+
.the_role
|
7
|
+
%h3= t('.list')
|
8
|
+
%ul.index
|
9
|
+
- @roles.each do |role|
|
10
|
+
%li
|
11
|
+
%p
|
12
|
+
= link_to role.title, edit_admin_role_url(role)
|
13
|
+
= link_to t('.delete'), admin_role_url(role), :method => :delete, :title => role.title, :confirm => t('the_role.delete_role'), :class => :delete
|
14
|
+
|
15
|
+
%p= link_to t('.new'), new_admin_role_path
|
@@ -1,13 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
%
|
12
|
-
|
13
|
-
|
1
|
+
.the_role
|
2
|
+
%p= link_to raw(t('.back')), admin_roles_path
|
3
|
+
|
4
|
+
- @role.errors.each do |field, message|
|
5
|
+
%p
|
6
|
+
= field
|
7
|
+
\:
|
8
|
+
= message
|
9
|
+
|
10
|
+
.form
|
11
|
+
%h5= raw t('.create')
|
12
|
+
= form_for(@role, :url => admin_roles_path) do |f|
|
13
|
+
%label= t('.name')
|
14
|
+
%p= f.text_field :name
|
15
|
+
|
16
|
+
%label= t('.title')
|
17
|
+
%p= f.text_field :title
|
18
|
+
|
19
|
+
%label= t('.description')
|
20
|
+
%p= f.text_field :description
|
21
|
+
|
22
|
+
= f.submit t('.new')
|
data/config/locales/en.yml
CHANGED
@@ -1,42 +1,43 @@
|
|
1
1
|
# Sample localization file for English. Add more files in this directory for other locales.
|
2
2
|
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
-
|
3
|
+
en:
|
4
4
|
the_role:
|
5
|
-
name_presence:
|
6
|
-
title_presence:
|
7
|
-
section_created:
|
8
|
-
|
9
|
-
section_deleted:
|
10
|
-
|
11
|
-
section_name_is_wrong:
|
12
|
-
|
13
|
-
section_name_is_blank:
|
14
|
-
section_exists:
|
15
|
-
role_created:
|
16
|
-
role_updated:
|
5
|
+
name_presence: Set the role name
|
6
|
+
title_presence: Set title of role
|
7
|
+
section_created: Section is successfully created
|
8
|
+
section_rule_created: In a given group is successfully created an access rule
|
9
|
+
section_deleted: access rule is removed
|
10
|
+
section_rule_deleted: access rule is removed
|
11
|
+
section_name_is_wrong: Wrong name of Role
|
12
|
+
section_rule_wrong_name: Wrong name of Rule
|
13
|
+
section_name_is_blank: The name of the Role team was empty
|
14
|
+
section_exists: Section already exists
|
15
|
+
role_created: The Role of successfully established
|
16
|
+
role_updated: Role updated successfully
|
17
|
+
delete_role: It is can make big problems. Delete this role?
|
17
18
|
admin:
|
18
19
|
roles:
|
19
20
|
index:
|
20
|
-
list:
|
21
|
-
delete: '
|
22
|
-
new:
|
21
|
+
list: list of roles
|
22
|
+
delete: 'Delete Role'
|
23
|
+
new: Create a new role
|
23
24
|
edit:
|
24
|
-
title:
|
25
|
-
back: '
|
26
|
-
name: '
|
27
|
-
create_section:
|
28
|
-
|
29
|
-
|
30
|
-
section_needs:
|
31
|
-
update:
|
25
|
+
title: Editing role
|
26
|
+
back: '← To the list of roles'
|
27
|
+
name: 'Name of role -'
|
28
|
+
create_section: Create a Section
|
29
|
+
create_access_rule: Create an access rule
|
30
|
+
create_rule: New Rule
|
31
|
+
section_needs: Create at least one Section
|
32
|
+
update: Update
|
32
33
|
form:
|
33
|
-
destroy_section_confirm:
|
34
|
-
empty:
|
35
|
-
|
36
|
-
delete:
|
34
|
+
destroy_section_confirm: Remove a role section?
|
35
|
+
empty: There is no role section
|
36
|
+
delete_rule_confirm: Remove the access rule?
|
37
|
+
delete: Delete
|
37
38
|
new:
|
38
|
-
back: '
|
39
|
-
create:
|
40
|
-
name:
|
41
|
-
title:
|
42
|
-
new:
|
39
|
+
back: '← To the list of roles'
|
40
|
+
create: Create a new role
|
41
|
+
name: Name of the role (Latin)
|
42
|
+
title: Title of role
|
43
|
+
new: Create
|
data/config/locales/ru.yml
CHANGED
@@ -1,42 +1,43 @@
|
|
1
1
|
# Sample localization file for English. Add more files in this directory for other locales.
|
2
2
|
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
-
|
3
|
+
ru:
|
4
4
|
the_role:
|
5
|
-
name_presence:
|
6
|
-
title_presence:
|
7
|
-
section_created:
|
8
|
-
|
9
|
-
section_deleted:
|
10
|
-
|
11
|
-
section_name_is_wrong:
|
12
|
-
|
13
|
-
section_name_is_blank:
|
14
|
-
section_exists:
|
15
|
-
role_created:
|
16
|
-
role_updated:
|
5
|
+
name_presence: Установите имя роли
|
6
|
+
title_presence: Установите название роли
|
7
|
+
section_created: Правовая группа успешно создана
|
8
|
+
section_rule_created: В заданной группе успешно создана политика доступа
|
9
|
+
section_deleted: Политика доступа удалена
|
10
|
+
section_rule_deleted: Политика доступа удалена
|
11
|
+
section_name_is_wrong: Ошибочное название правовой группы
|
12
|
+
section_rule_wrong_name: Ошибочное название правовой политики
|
13
|
+
section_name_is_blank: Имя правовой группы оказалось пустым
|
14
|
+
section_exists: Правовая группа уже существует
|
15
|
+
role_created: Роль успешно создана
|
16
|
+
role_updated: Роль успешно обновлена
|
17
|
+
delete_role: Удаление роли может повлиять не работу всей системы. Удалить эту роль?
|
17
18
|
admin:
|
18
19
|
roles:
|
19
20
|
index:
|
20
|
-
list:
|
21
|
-
delete: '
|
22
|
-
new:
|
21
|
+
list: Список ролей
|
22
|
+
delete: 'Удалить роль '
|
23
|
+
new: Создать новую роль
|
23
24
|
edit:
|
24
|
-
title:
|
25
|
-
back: '
|
26
|
-
name: '
|
27
|
-
create_section:
|
28
|
-
|
29
|
-
|
30
|
-
section_needs:
|
31
|
-
update:
|
25
|
+
title: Редактирование роли
|
26
|
+
back: '← К списку ролей'
|
27
|
+
name: 'Название роли — '
|
28
|
+
create_section: Создать правовую группу
|
29
|
+
create_access_rule: Создать политику доступа
|
30
|
+
create_rule: Создать политику
|
31
|
+
section_needs: Создайте хотя бы одну правовую группу
|
32
|
+
update: Обновить
|
32
33
|
form:
|
33
|
-
destroy_section_confirm:
|
34
|
-
empty:
|
35
|
-
|
36
|
-
delete:
|
34
|
+
destroy_section_confirm: Удалить правовую группу?
|
35
|
+
empty: Нет ни одной правовой группы
|
36
|
+
delete_rule_confirm: Удалить политику доступа?
|
37
|
+
delete: Удалить
|
37
38
|
new:
|
38
|
-
back: '
|
39
|
-
create:
|
40
|
-
name:
|
41
|
-
title:
|
42
|
-
new:
|
39
|
+
back: '← К списку ролей'
|
40
|
+
create: Создать новую роль
|
41
|
+
name: Имя роли (латиницей)
|
42
|
+
title: Название роли
|
43
|
+
new: Создать
|