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.

users_helper.rb 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 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 UsersHelper
  19. include ApplicationHelper
  20. def users_status_options_for_select(selected)
  21. user_count_by_status = User.group('status').count.to_hash
  22. options_for_select([[l(:label_all), '']] + (User.valid_statuses.map {|c| ["#{l('status_' + User::LABEL_BY_STATUS[c])} (#{user_count_by_status[c].to_i})", c]}), selected.to_s)
  23. end
  24. def user_mail_notification_options(user)
  25. user.valid_notification_options.collect {|o| [l(o.last), o.first]}
  26. end
  27. def textarea_font_options
  28. [[l(:label_font_default), '']] + UserPreference::TEXTAREA_FONT_OPTIONS.map {|o| [l("label_font_#{o}"), o]}
  29. end
  30. def change_status_link(user)
  31. url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
  32. if user.locked?
  33. link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
  34. elsif user.registered?
  35. link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
  36. elsif user != User.current
  37. link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'icon icon-lock'
  38. end
  39. end
  40. def additional_emails_link(user)
  41. if user.email_addresses.count > 1 || Setting.max_additional_emails.to_i > 0
  42. link_to l(:label_email_address_plural), user_email_addresses_path(@user), :class => 'icon icon-email-add', :remote => true
  43. end
  44. end
  45. def user_settings_tabs
  46. tabs = [{:name => 'general', :partial => 'users/general', :label => :label_general},
  47. {:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural}
  48. ]
  49. if Group.givable.any?
  50. tabs.insert 1, {:name => 'groups', :partial => 'users/groups', :label => :label_group_plural}
  51. end
  52. tabs
  53. end
  54. def users_to_csv(users)
  55. Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
  56. columns = [
  57. 'login',
  58. 'firstname',
  59. 'lastname',
  60. 'mail',
  61. 'admin',
  62. 'created_on',
  63. 'last_login_on',
  64. 'status'
  65. ]
  66. # csv header fields
  67. csv << columns.map{|column| l('field_' + column)}
  68. # csv lines
  69. users.each do |user|
  70. csv << columns.map do |column|
  71. if column == 'status'
  72. l(("status_#{User::LABEL_BY_STATUS[user.status]}"))
  73. else
  74. format_object(user.send(column), false)
  75. end
  76. end
  77. end
  78. end
  79. end
  80. end