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.
@@ -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
- layout 'the_role'
5
- before_filter :the_login_required
6
- before_filter :the_role_require
7
-
8
- before_filter :the_role_find, :only => [:show, :edit, :update, :destroy, :new_role_section, :new_role_policy]
9
- before_filter :the_role_object, :only => [:show, :edit, :update, :destroy, :new_role_section, :new_role_policy]
10
- before_filter :the_owner_require, :only => [:show, :edit, :update, :destroy, :new_role_section, :new_role_policy]
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 = TheRole.get(@role.the_role).the_reset!
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 the_role_find
106
- @role = Role.find(params[:id])
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 = TheRole.get(@role.the_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'), admin_role_section_url(@role, name), :method => :delete, :confirm => t('.destroy_section_confirm'))
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'), delete_policy_admin_role_section_path(@role, name, :name => n), :method => :delete, :confirm => t('.delete_policy_confirm')
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
- %p= flash[:notice]
5
-
6
- %h1= t('.title')
7
-
8
- %p= link_to raw(t('.back')), admin_roles_path
9
-
10
- %h2
11
- = raw t('.name')
12
- = @role.title
13
-
14
- = form_for :role, :url => {:action=> :update }, :html => {:method => :put, :class => :form } do |f|
15
- = render :partial => 'form', :locals => {:f => f, :button => t('.update')}
16
-
17
- %h4= t('.create_section')
18
- - role = TheRole.get(@role.the_role)
19
-
20
- = form_tag(new_role_section_admin_role_path, :method => :post, :class => :new_action) do
21
- = text_field_tag :section_name
22
- = submit_tag t('.create_section')
23
-
24
- %h4= t('.create_access_policy')
25
-
26
- - unless role.empty?
27
- = form_tag(new_role_policy_admin_role_path(@role), :method => :post, :class => :new_action) do
28
- = text_field_tag :section_policy
29
-
30
- %select{ :name => :section_name }
31
- -role.each do |name, set|
32
- %option{ :value => name }
33
- = name
34
-
35
- %input{ :type => :submit, :value => t('.create_policy') }
36
- - else
37
- %p= t('.section_needs')
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
- %h3= t('.list')
2
- %ul.index
3
- - @roles.each do |role|
4
- %li
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
- %p= link_to t('.new'), new_admin_role_path
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
- %p= link_to raw(t('.back')), admin_roles_path
2
-
3
- - @role.errors.each do |f, m|
4
- %p= m
5
-
6
- .form
7
- %h5= raw t('.create')
8
- = form_for(@role, :url => admin_roles_path) do |f|
9
- %label= t('.name')
10
- %p= f.text_field :name
11
- %label= t('.title')
12
- %p= f.text_field :title
13
- = f.submit t('.new')
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')
@@ -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
- ru:
3
+ en:
4
4
  the_role:
5
- name_presence: Установите имя роли
6
- title_presence: Установите название роли
7
- section_created: Правовая группа успешно создана
8
- section_policy_created: В заданной группе успешно создана политика доступа
9
- section_deleted: Политика доступа удалена
10
- section_policy_deleted: Политика доступа удалена
11
- section_name_is_wrong: Ошибочное название правовой группы
12
- section_policy_wrong_name: Ошибочное название правовой политики
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: '&larr; К списку ролей'
26
- name: 'Название роли &mdash; '
27
- create_section: Создать правовую группу
28
- create_access_policy: Создать политику доступа
29
- create_policy: Создать политику
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
- delete_policy_confirm: Удалить политику доступа?
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: '&larr; К списку ролей'
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
@@ -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
- en:
3
+ ru:
4
4
  the_role:
5
- name_presence: Set the role name
6
- title_presence: Set title of role
7
- section_created: Role group is successfully created
8
- section_policy_created: In a given group is successfully created an access policy
9
- section_deleted: access policy is removed
10
- section_policy_deleted: access policy is removed
11
- section_name_is_wrong: Wrong name of Role
12
- section_policy_wrong_name: Wrong name of Role Policy
13
- section_name_is_blank: The name of the Role team was empty
14
- section_exists: Role group already exists
15
- role_created: The Role of successfully established
16
- role_updated: Role updated successfully
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: list of roles
21
- delete: 'Delete role: '
22
- new: Create a new role
21
+ list: Список ролей
22
+ delete: 'Удалить роль '
23
+ new: Создать новую роль
23
24
  edit:
24
- title: Editing role
25
- back: ' To the list of roles'
26
- name: 'Name of role -'
27
- create_section: Create a Role group
28
- create_access_policy: Create an access policy
29
- create_policy: New Policy
30
- section_needs: Create at least one Role group
31
- update: Update
25
+ title: Редактирование роли
26
+ back: '&larr; К списку ролей'
27
+ name: 'Название роли &mdash; '
28
+ create_section: Создать правовую группу
29
+ create_access_rule: Создать политику доступа
30
+ create_rule: Создать политику
31
+ section_needs: Создайте хотя бы одну правовую группу
32
+ update: Обновить
32
33
  form:
33
- destroy_section_confirm: Remove a role section?
34
- empty: There is no role section
35
- delete_policy_confirm: Remove the access policy?
36
- delete: Delete
34
+ destroy_section_confirm: Удалить правовую группу?
35
+ empty: Нет ни одной правовой группы
36
+ delete_rule_confirm: Удалить политику доступа?
37
+ delete: Удалить
37
38
  new:
38
- back: ' To the list of roles'
39
- create: Create a new role
40
- name: Name of the role (Latin)
41
- title: Title of role
42
- new: Create
39
+ back: '&larr; К списку ролей'
40
+ create: Создать новую роль
41
+ name: Имя роли (латиницей)
42
+ title: Название роли
43
+ new: Создать