Feature #13767 » issue_13767.patch
app/controllers/roles_controller.rb | ||
---|---|---|
23 | 23 |
before_filter :find_role, :only => [:show, :edit, :update, :destroy] |
24 | 24 |
accept_api_auth :index, :show |
25 | 25 | |
26 |
include RolesHelper |
|
27 | ||
26 | 28 |
require_sudo_mode :create, :update, :destroy |
27 | 29 | |
28 | 30 |
def index |
... | ... | |
106 | 108 |
flash[:notice] = l(:notice_successful_update) |
107 | 109 |
redirect_to roles_path |
108 | 110 |
end |
111 |
respond_to do |format| |
|
112 |
format.html |
|
113 |
format.csv { send_data(permissions_to_csv(@roles, @permissions), :type => 'text/csv; header=present', :filename => 'permissions_export.csv') } |
|
114 |
end |
|
109 | 115 |
end |
110 | 116 | |
111 | 117 |
private |
app/helpers/roles_helper.rb | ||
---|---|---|
18 | 18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | 19 | |
20 | 20 |
module RolesHelper |
21 |
def permissions_to_csv(roles, permissions) |
|
22 |
Redmine::Export::CSV.generate do |csv| |
|
23 |
# csv header fields |
|
24 |
headers = [l(:field_cvs_module), l(:label_permissions)] + roles.collect {|role| role.name} |
|
25 |
csv << headers |
|
26 |
# csv lines |
|
27 |
permissions.each do |p| |
|
28 |
names = [ |
|
29 |
l_or_humanize(p.project_module.to_s, :prefix => 'project_module_'), |
|
30 |
l_or_humanize(p.name, :prefix => 'permission_').to_s, |
|
31 |
] |
|
32 |
fields = names + roles.collect do |role| |
|
33 |
if role.setable_permissions.include?(p) |
|
34 |
role.permissions.include?(p.name) ? 1 : 0 |
|
35 |
else |
|
36 |
"" |
|
37 |
end |
|
38 | ||
39 |
end |
|
40 |
csv << fields |
|
41 |
end |
|
42 |
end |
|
43 |
end |
|
21 | 44 |
end |
app/views/roles/permissions.html.erb | ||
---|---|---|
54 | 54 |
</tbody> |
55 | 55 |
</table> |
56 | 56 |
</div> |
57 |
<% other_formats_links do |f| %> |
|
58 |
<%= f.link_to 'CSV' %> |
|
59 |
<% end %> |
|
57 | 60 |
<p><%= check_all_links 'permissions_form' %></p> |
58 | 61 |
<p><%= submit_tag l(:button_save) %></p> |
59 | 62 |
<% end %> |