Revert "remove usage of eval() in User#name"

This reverts commit 18a66e9601.

Conflicts:
	doc/CHANGELOG.md
pull/607/head
Martin Czuchra 11 years ago
parent 0be2b5f3d5
commit 9b8e1aad51
  1. 2
      app/controllers/settings_controller.rb
  2. 40
      app/models/user.rb
  3. 2
      app/views/projects/settings/_members.html.erb
  4. 3
      doc/CHANGELOG.md

@ -50,7 +50,7 @@ class SettingsController < ApplicationController
redirect_to :action => 'edit', :tab => params[:tab]
else
@options = {}
@options[:user_format] = User.available_user_formats.collect {|f| [User.current.name(f), f.to_s] }
@options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] }
@deliveries = ActionMailer::Base.perform_deliveries
@guessed_host_and_path = request.host_with_port.dup + Redmine::Utils.relative_url_root.to_s

@ -41,27 +41,25 @@ class User < Principal
:locked => 3
}
# strings are taken as-is, symbols are user attributes
USER_FORMATS_STRUCTURE = {
:firstname_lastname => [:firstname, ' ', :lastname],
:firstname_lastname => [:firstname, :lastname],
:firstname => [:firstname],
:lastname_firstname => [:lastname, ' ', :firstname],
:lastname_coma_firstname => [:lastname, ', ', :firstname],
:lastname_firstname => [:lastname, :firstname],
:lastname_coma_firstname => [:lastname, :firstname],
:username => [:login]
}
##
# returns the user attributes (in the right order)
# which are used to display the user name in the given format
def self.user_format_fields(format)
USER_FORMATS_STRUCTURE[format].select do |e|
e.is_a?(Symbol) and columns.map(&:name).include?(e.to_s)
end
def self.user_format_structure_to_format(key, delimiter = " ")
USER_FORMATS_STRUCTURE[key].map{|elem| "\#{#{elem.to_s}}"}.join(delimiter)
end
def self.available_user_formats
USER_FORMATS_STRUCTURE.keys
end
USER_FORMATS = {
:firstname_lastname => User.user_format_structure_to_format(:firstname_lastname, " "),
:firstname => User.user_format_structure_to_format(:firstname),
:lastname_firstname => User.user_format_structure_to_format(:lastname_firstname, " "),
:lastname_coma_firstname => User.user_format_structure_to_format(:lastname_coma_firstname, ", "),
:username => User.user_format_structure_to_format(:username)
}
USER_MAIL_OPTION_ALL = ['all', :label_user_mail_option_all]
USER_MAIL_OPTION_SELECTED = ['selected', :label_user_mail_option_selected]
@ -303,15 +301,11 @@ class User < Principal
# Return user's full name for display
def name(formatter = nil)
formatter ||= Setting.user_format
formatter = :firstname_lastname unless self.class.available_user_formats.include?(formatter)
USER_FORMATS_STRUCTURE[formatter].map do |e|
if e.is_a?(Symbol) and attributes[e.to_s]
attributes[e.to_s]
else
e.to_s
end
end.join('')
if formatter
eval('"' + (USER_FORMATS[formatter] || USER_FORMATS[:firstname_lastname]) + '"')
else
@name ||= eval('"' + (USER_FORMATS[Setting.user_format] || USER_FORMATS[:firstname_lastname]) + '"')
end
end
def status_name

@ -35,7 +35,7 @@ See doc/COPYRIGHT.rdoc for more details.
member_per_page = 20
@members = @project.member_principals.includes(:roles, :principal, :member_roles)
.order(User.user_format_fields(Setting.user_format).map(&:to_s))
.order(User::USER_FORMATS_STRUCTURE[Setting.user_format].map{|attr| attr.to_s}.join(", "))
.page(params[:page])
.per_page(per_page_param)
%>

@ -31,12 +31,13 @@ See doc/COPYRIGHT.rdoc for more details.
* `#2564` Support custom fields in REST API v2 for work packages and projects
* `#2586` Query available custom fields in REST API v2
* Reverts `#2645` Remove usage of eval()
## 3.0.0pre26
* `#2624` [Journals] Fix: Work package journals that migrated from legacy planning elements lack default references
* `#2642` [Migration] Empty timelines options cannot be migrated
* `#2645` Remove usage of eval()
* `#2645` Remove usage of eval()
* `#2585` Special characters in wiki page title
## 3.0.0pre25

Loading…
Cancel
Save