You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

roles_helper.rb 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. module RolesHelper
  19. include ApplicationHelper
  20. def permissions_to_csv(roles, permissions)
  21. Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
  22. # csv header fields
  23. headers = [l(:field_cvs_module), l(:label_permissions)] + roles.collect(&:name)
  24. csv << headers
  25. # csv lines
  26. perms_by_module = permissions.group_by {|p| p.project_module.to_s}
  27. perms_by_module.keys.sort.each do |mod|
  28. perms_by_module[mod].each do |p|
  29. names = [
  30. l_or_humanize(p.project_module.to_s, :prefix => 'project_module_'),
  31. l_or_humanize(p.name, :prefix => 'permission_').to_s,
  32. ]
  33. fields = names + roles.collect do |role|
  34. if role.setable_permissions.include?(p)
  35. format_object(role.permissions.include?(p.name), false)
  36. else
  37. ''
  38. end
  39. end
  40. csv << fields
  41. end
  42. end
  43. end
  44. end
  45. end