@@ -1,108 +1,108 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2014 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class RolesController < ApplicationController |
|
18 | class RolesController < ApplicationController | |
19 | layout 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin, :except => [:index, :show] |
|
21 | before_filter :require_admin, :except => [:index, :show] | |
22 | before_filter :require_admin_or_api_request, :only => [:index, :show] |
|
22 | before_filter :require_admin_or_api_request, :only => [:index, :show] | |
23 | before_filter :find_role, :only => [:show, :edit, :update, :destroy] |
|
23 | before_filter :find_role, :only => [:show, :edit, :update, :destroy] | |
24 | accept_api_auth :index, :show |
|
24 | accept_api_auth :index, :show | |
25 |
|
25 | |||
26 | def index |
|
26 | def index | |
27 | respond_to do |format| |
|
27 | respond_to do |format| | |
28 | format.html { |
|
28 | format.html { | |
29 | @role_pages, @roles = paginate Role.sorted, :per_page => 25 |
|
29 | @role_pages, @roles = paginate Role.sorted, :per_page => 25 | |
30 | render :action => "index", :layout => false if request.xhr? |
|
30 | render :action => "index", :layout => false if request.xhr? | |
31 | } |
|
31 | } | |
32 | format.api { |
|
32 | format.api { | |
33 | @roles = Role.givable.to_a |
|
33 | @roles = Role.givable.to_a | |
34 | } |
|
34 | } | |
35 | end |
|
35 | end | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def show |
|
38 | def show | |
39 | respond_to do |format| |
|
39 | respond_to do |format| | |
40 | format.api |
|
40 | format.api | |
41 | end |
|
41 | end | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def new |
|
44 | def new | |
45 | # Prefills the form with 'Non member' role permissions by default |
|
45 | # Prefills the form with 'Non member' role permissions by default | |
46 | @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) |
|
46 | @role = Role.new(params[:role] || {:permissions => Role.non_member.permissions}) | |
47 | if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy]) |
|
47 | if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy]) | |
48 | @role.copy_from(@copy_from) |
|
48 | @role.copy_from(@copy_from) | |
49 | end |
|
49 | end | |
50 | @roles = Role.sorted.to_a |
|
50 | @roles = Role.sorted.to_a | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def create |
|
53 | def create | |
54 | @role = Role.new(params[:role]) |
|
54 | @role = Role.new(params[:role]) | |
55 | if request.post? && @role.save |
|
55 | if request.post? && @role.save | |
56 | # workflow copy |
|
56 | # workflow copy | |
57 | if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) |
|
57 | if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from])) | |
58 | @role.workflow_rules.copy(copy_from) |
|
58 | @role.workflow_rules.copy(copy_from) | |
59 | end |
|
59 | end | |
60 | flash[:notice] = l(:notice_successful_create) |
|
60 | flash[:notice] = l(:notice_successful_create) | |
61 | redirect_to roles_path |
|
61 | redirect_to roles_path | |
62 | else |
|
62 | else | |
63 | @roles = Role.sorted.to_a |
|
63 | @roles = Role.sorted.to_a | |
64 | render :action => 'new' |
|
64 | render :action => 'new' | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def edit |
|
68 | def edit | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | def update |
|
71 | def update | |
72 | if @role.update_attributes(params[:role]) |
|
72 | if @role.update_attributes(params[:role]) | |
73 | flash[:notice] = l(:notice_successful_update) |
|
73 | flash[:notice] = l(:notice_successful_update) | |
74 | redirect_to roles_path |
|
74 | redirect_to roles_path(:page => params[:page]) | |
75 | else |
|
75 | else | |
76 | render :action => 'edit' |
|
76 | render :action => 'edit' | |
77 | end |
|
77 | end | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def destroy |
|
80 | def destroy | |
81 | @role.destroy |
|
81 | @role.destroy | |
82 | redirect_to roles_path |
|
82 | redirect_to roles_path | |
83 | rescue |
|
83 | rescue | |
84 | flash[:error] = l(:error_can_not_remove_role) |
|
84 | flash[:error] = l(:error_can_not_remove_role) | |
85 | redirect_to roles_path |
|
85 | redirect_to roles_path | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def permissions |
|
88 | def permissions | |
89 | @roles = Role.sorted.to_a |
|
89 | @roles = Role.sorted.to_a | |
90 | @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } |
|
90 | @permissions = Redmine::AccessControl.permissions.select { |p| !p.public? } | |
91 | if request.post? |
|
91 | if request.post? | |
92 | @roles.each do |role| |
|
92 | @roles.each do |role| | |
93 | role.permissions = params[:permissions][role.id.to_s] |
|
93 | role.permissions = params[:permissions][role.id.to_s] | |
94 | role.save |
|
94 | role.save | |
95 | end |
|
95 | end | |
96 | flash[:notice] = l(:notice_successful_update) |
|
96 | flash[:notice] = l(:notice_successful_update) | |
97 | redirect_to roles_path |
|
97 | redirect_to roles_path | |
98 | end |
|
98 | end | |
99 | end |
|
99 | end | |
100 |
|
100 | |||
101 | private |
|
101 | private | |
102 |
|
102 | |||
103 | def find_role |
|
103 | def find_role | |
104 | @role = Role.find(params[:id]) |
|
104 | @role = Role.find(params[:id]) | |
105 | rescue ActiveRecord::RecordNotFound |
|
105 | rescue ActiveRecord::RecordNotFound | |
106 | render_404 |
|
106 | render_404 | |
107 | end |
|
107 | end | |
108 | end |
|
108 | end |
@@ -1,34 +1,34 | |||||
1 | <div class="contextual"> |
|
1 | <div class="contextual"> | |
2 | <%= link_to l(:label_role_new), new_role_path, :class => 'icon icon-add' %> |
|
2 | <%= link_to l(:label_role_new), new_role_path, :class => 'icon icon-add' %> | |
3 | <%= link_to l(:label_permissions_report), permissions_roles_path, :class => 'icon icon-summary' %> |
|
3 | <%= link_to l(:label_permissions_report), permissions_roles_path, :class => 'icon icon-summary' %> | |
4 | </div> |
|
4 | </div> | |
5 |
|
5 | |||
6 | <h2><%=l(:label_role_plural)%></h2> |
|
6 | <h2><%=l(:label_role_plural)%></h2> | |
7 |
|
7 | |||
8 | <table class="list"> |
|
8 | <table class="list"> | |
9 | <thead><tr> |
|
9 | <thead><tr> | |
10 | <th><%=l(:label_role)%></th> |
|
10 | <th><%=l(:label_role)%></th> | |
11 | <th><%=l(:button_sort)%></th> |
|
11 | <th><%=l(:button_sort)%></th> | |
12 | <th></th> |
|
12 | <th></th> | |
13 | </tr></thead> |
|
13 | </tr></thead> | |
14 | <tbody> |
|
14 | <tbody> | |
15 | <% for role in @roles %> |
|
15 | <% for role in @roles %> | |
16 | <tr class="<%= cycle("odd", "even") %>"> |
|
16 | <tr class="<%= cycle("odd", "even") %>"> | |
17 | <td class="name"><%= content_tag(role.builtin? ? 'em' : 'span', link_to(h(role.name), edit_role_path(role))) %></td> |
|
17 | <td class="name"><%= content_tag(role.builtin? ? 'em' : 'span', link_to(h(role.name), edit_role_path(role))) %></td> | |
18 | <td class="reorder"> |
|
18 | <td class="reorder"> | |
19 | <% unless role.builtin? %> |
|
19 | <% unless role.builtin? %> | |
20 | <%= reorder_links('role', {:action => 'update', :id => role}, :put) %> |
|
20 | <%= reorder_links('role', {:action => 'update', :id => role, :page => params[:page]}, :put) %> | |
21 | <% end %> |
|
21 | <% end %> | |
22 | </td> |
|
22 | </td> | |
23 | <td class="buttons"> |
|
23 | <td class="buttons"> | |
24 | <%= link_to l(:button_copy), new_role_path(:copy => role), :class => 'icon icon-copy' %> |
|
24 | <%= link_to l(:button_copy), new_role_path(:copy => role), :class => 'icon icon-copy' %> | |
25 | <%= delete_link role_path(role) unless role.builtin? %> |
|
25 | <%= delete_link role_path(role) unless role.builtin? %> | |
26 | </td> |
|
26 | </td> | |
27 | </tr> |
|
27 | </tr> | |
28 | <% end %> |
|
28 | <% end %> | |
29 | </tbody> |
|
29 | </tbody> | |
30 | </table> |
|
30 | </table> | |
31 |
|
31 | |||
32 | <p class="pagination"><%= pagination_links_full @role_pages %></p> |
|
32 | <p class="pagination"><%= pagination_links_full @role_pages %></p> | |
33 |
|
33 | |||
34 | <% html_title(l(:label_role_plural)) -%> |
|
34 | <% html_title(l(:label_role_plural)) -%> |
General Comments 0
You need to be logged in to leave comments.
Login now