Module: UsersHelper

Includes:
ApplicationHelper
Included in:
UsersController
Defined in:
app/helpers/users_helper.rb

Overview

Redmine - project management software Copyright © 2006-2022 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::ATTACHMENT_CONTAINER_LINK, ApplicationHelper::HEADING_RE, ApplicationHelper::LINKS_RE, ApplicationHelper::MACROS_RE, ApplicationHelper::MACRO_SUB_RE, ApplicationHelper::RECORD_LINK, ApplicationHelper::TOC_RE

Instance Method Summary collapse

Methods included from ApplicationHelper

#accesskey, #actions_dropdown, #anchor, #api_meta, #authoring, #authorize_for, #back_url_hidden_field_tag, #body_css_classes, #breadcrumb, #bulk_edit_error_messages, #calendar_for, #cancel_button_tag, #catch_macros, #check_all_links, #checked_image, #context_menu, #copy_object_url_link, #default_search_project_scope, #delete_link, #due_date_distance_in_words, #email_delivery_enabled?, #error_messages_for, #export_csv_encoding_select_tag, #favicon, #favicon_path, #favicon_url, #form_tag_html, #format_activity_day, #format_activity_description, #format_activity_title, #format_changeset_comments, #format_object, #format_version_name, #get_tab_action, #heads_for_auto_complete, #html_hours, #html_title, #image_tag, #include_calendar_headers_tags, #include_in_api_response?, #inject_macros, #javascript_heads, #javascript_include_tag, #labelled_fields_for, #labelled_form_for, #lang_options_for_select, #link_to_attachment, #link_to_attachment_container, #link_to_context_menu, #link_to_function, #link_to_group, #link_to_if_authorized, #link_to_issue, #link_to_message, #link_to_month, #link_to_next_month, #link_to_previous_month, #link_to_principal, #link_to_project, #link_to_project_settings, #link_to_record, #link_to_revision, #link_to_user, #link_to_version, #markdown_formatter, #option_tag, #other_formats_links, #page_header_title, #parse_headings, #parse_hires_images, #parse_inline_attachments, #parse_non_pre_blocks, #parse_redmine_links, #parse_sections, #parse_wiki_links, #principals_check_box_tags, #principals_options_for_select, #progress_bar, #project_tree, #project_tree_options_for_select, #projects_for_jump_box, #raw_json, #render_error_messages, #render_flash_messages, #render_if_exist, #render_page_hierarchy, #render_project_jump_box, #render_project_nested_lists, #render_projects_for_jump_box, #render_tabs, #reorder_handle, #replace_toc, #robot_exclusion_tag, #sanitize_anchor_name, #sidebar_content?, #simple_format_without_paragraph, #stylesheet_link_tag, #syntax_highlight, #syntax_highlight_lines, #textilizable, #thumbnail_tag, #time_tag, #title, #to_path_param, #toggle_checkboxes_link, #toggle_link, #truncate_lines, #truncate_single_line_raw, #update_data_sources_for_auto_complete, #view_layouts_base_sidebar_hook_response, #wiki_page_path

Methods included from Redmine::Helpers::URL

#uri_with_link_safe_scheme?, #uri_with_safe_scheme?

Methods included from Redmine::Hook::Helper

#call_hook

Methods included from Redmine::Themes::Helper

#current_theme, #heads_for_theme

Methods included from Redmine::SudoMode::Helper

#hash_to_hidden_fields

Methods included from Redmine::Pagination::Helper

#pagination_links_each, #pagination_links_full, #per_page_links, #per_page_options

Methods included from Redmine::I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, included, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Methods included from Redmine::WikiFormatting::Macros::Definitions

#exec_macro, #extract_macro_options, #macro_exists?

Instance Method Details



81
82
83
84
85
# File 'app/helpers/users_helper.rb', line 81

def additional_emails_link(user)
  if user.email_addresses.count > 1 || Setting.max_additional_emails.to_i > 0
    link_to l(:label_email_address_plural), user_email_addresses_path(@user), :class => 'icon icon-email-add', :remote => true
  end
end


69
70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/users_helper.rb', line 69

def change_status_link(user)
  url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}

  if user.locked?
    link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
  elsif user.registered?
    link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
  elsif user != User.current
    link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'icon icon-lock'
  end
end

#csv_content(column_name, user) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/helpers/users_helper.rb', line 105

def csv_content(column_name, user)
  case column_name
  when 'status'
    l("status_#{User::LABEL_BY_STATUS[user.status]}")
  when 'twofa_scheme'
    if user.twofa_active?
      l("twofa__#{user.twofa_scheme}__name")
    else
      l(:label_disabled)
    end
  else
    user.send(column_name)
  end
end

#default_issue_query_options(user) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/users_helper.rb', line 32

def default_issue_query_options(user)
  global_queries = IssueQuery.for_all_projects
  global_public_queries = global_queries.only_public
  global_user_queries = global_queries.where(user_id: user.id).where.not(id: global_public_queries.pluck(:id))
  label = user == User.current ? 'label_my_queries' : 'label_default_queries.for_this_user'
  grouped = {
    l('label_default_queries.for_all_users') => global_public_queries.pluck(:name, :id),
    l(".#{label}") => global_user_queries.pluck(:name, :id),
  }
  grouped_options_for_select(grouped, user.pref.default_issue_query)
end

#default_project_query_options(user) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/users_helper.rb', line 44

def default_project_query_options(user)
  global_queries = ProjectQuery
  global_public_queries = global_queries.only_public
  global_user_queries = global_queries.where(user_id: user.id).where.not(id: global_public_queries.ids)
  label = user == User.current ? 'label_my_queries' : 'label_default_queries.for_this_user'
  grouped = {
    l('label_default_queries.for_all_users') => global_public_queries.pluck(:name, :id),
    l(".#{label}") => global_user_queries.pluck(:name, :id),
  }
  grouped_options_for_select(grouped, user.pref.default_project_query)
end

#history_default_tab_optionsObject



60
61
62
63
64
65
66
67
# File 'app/helpers/users_helper.rb', line 60

def history_default_tab_options
  [[l('label_issue_history_notes'), 'notes'],
   [l('label_history'), 'history'],
   [l('label_issue_history_properties'), 'properties'],
   [l('label_time_entry_plural'), 'time_entries'],
   [l('label_associated_revisions'), 'changesets'],
   [l('label_last_tab_visited'), 'last_tab_visited']]
end

#textarea_font_optionsObject



56
57
58
# File 'app/helpers/users_helper.rb', line 56

def textarea_font_options
  [[l(:label_font_default), '']] + UserPreference::TEXTAREA_FONT_OPTIONS.map {|o| [l("label_font_#{o}"), o]}
end

#user_emails(user) ⇒ Object



87
88
89
90
91
# File 'app/helpers/users_helper.rb', line 87

def user_emails(user)
  emails = [user.mail]
  emails += user.email_addresses.order(:id).where(:is_default => false).pluck(:address)
  emails.map {|email| mail_to(email, nil)}.join(', ').html_safe
end

#user_mail_notification_options(user) ⇒ Object



28
29
30
# File 'app/helpers/users_helper.rb', line 28

def user_mail_notification_options(user)
  user.valid_notification_options.collect {|o| [l(o.last), o.first]}
end

#user_settings_tabsObject



93
94
95
96
97
98
99
100
101
102
103
# File 'app/helpers/users_helper.rb', line 93

def 
  tabs =
    [
      {:name => 'general', :partial => 'users/general', :label => :label_general},
      {:name => 'memberships', :partial => 'users/memberships', :label => :label_project_plural}
    ]
  if Group.givable.any?
    tabs.insert 1, {:name => 'groups', :partial => 'users/groups', :label => :label_group_plural}
  end
  tabs
end

#users_status_options_for_select(selected) ⇒ Object



23
24
25
26
# File 'app/helpers/users_helper.rb', line 23

def users_status_options_for_select(selected)
  user_count_by_status = User.group('status').count.to_hash
  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)
end

#users_to_csv(users) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/helpers/users_helper.rb', line 120

def users_to_csv(users)
  Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
    columns = [
      'login',
      'firstname',
      'lastname',
      'mail',
      'admin',
      'status',
      'twofa_scheme',
      'created_on',
      'updated_on',
      'last_login_on',
      'passwd_changed_on'
    ]
    user_custom_fields = UserCustomField.sorted

    # csv header fields
    csv << columns.map {|column| l('field_' + column)} + user_custom_fields.pluck(:name)
    # csv lines
    users = users.preload(:custom_values)
    users.each do |user|
      values = columns.map {|c| csv_content(c, user)} +
               user_custom_fields.map {|custom_field| user.custom_value_for(custom_field)}

      csv << values.map do |value|
        format_object(value, false) do |v|
          case v.class.name
          when 'Float'
            sprintf('%.2f', v).gsub('.', l(:general_csv_decimal_separator))
          else
            v
          end
        end
      end
    end
  end
end