Patch #26747 ยป 26747-where_first-to-find_by.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
|
link = link_to_project(p, {:only_path => only_path}, :class => 'project')
|
||
|
end
|
||
|
when 'user'
|
||
|
u = User.visible.where(:id => oid, :type => 'User').first
|
||
|
u = User.visible.find_by(:id => oid, :type => 'User')
|
||
|
link = link_to_user(u, :only_path => only_path) if u
|
||
|
end
|
||
|
elsif sep == ':'
|
||
| ... | ... | |
|
link = link_to_project(p, {:only_path => only_path}, :class => 'project')
|
||
|
end
|
||
|
when 'user'
|
||
|
u = User.visible.where("LOWER(login) = :s AND type = 'User'", :s => name.downcase).first
|
||
|
u = User.visible.find_by("LOWER(login) = :s AND type = 'User'", :s => name.downcase)
|
||
|
link = link_to_user(u, :only_path => only_path) if u
|
||
|
end
|
||
|
elsif sep == "@"
|
||
|
name = remove_double_quotes(identifier)
|
||
|
u = User.visible.where("LOWER(login) = :s AND type = 'User'", :s => name.downcase).first
|
||
|
u = User.visible.find_by("LOWER(login) = :s AND type = 'User'", :s => name.downcase)
|
||
|
link = link_to_user(u, :only_path => only_path) if u
|
||
|
end
|
||
|
end
|
||
| app/models/attachment.rb | ||
|---|---|---|
|
def self.find_by_token(token)
|
||
|
if token.to_s =~ /^(\d+)\.([0-9a-f]+)$/
|
||
|
attachment_id, attachment_digest = $1, $2
|
||
|
attachment = Attachment.where(:id => attachment_id, :digest => attachment_digest).first
|
||
|
attachment = Attachment.find_by(:id => attachment_id, :digest => attachment_digest)
|
||
|
if attachment && attachment.container.nil?
|
||
|
attachment
|
||
|
end
|
||
| app/models/principal.rb | ||
|---|---|---|
|
end
|
||
|
def visible?(user=User.current)
|
||
|
Principal.visible(user).where(:id => id).first == self
|
||
|
Principal.visible(user).find_by(:id => id) == self
|
||
|
end
|
||
|
# Returns true if the principal is a member of project
|
||
| app/models/repository.rb | ||
|---|---|---|
|
return nil if name.blank?
|
||
|
s = name.to_s
|
||
|
if s.match(/^\d*$/)
|
||
|
changesets.where("revision = ?", s).first
|
||
|
changesets.find_by(:revision => s)
|
||
|
else
|
||
|
changesets.where("revision LIKE ?", s + '%').first
|
||
|
end
|
||
| app/models/repository/git.rb | ||
|---|---|---|
|
return false if v.nil?
|
||
|
v.to_s != '0'
|
||
|
end
|
||
|
|
||
|
def report_last_commit=(arg)
|
||
|
merge_extra_info "extra_report_last_commit" => arg
|
||
|
end
|
||
| ... | ... | |
|
def find_changeset_by_name(name)
|
||
|
if name.present?
|
||
|
changesets.where(:revision => name.to_s).first ||
|
||
|
changesets.find_by(:revision => name.to_s) ||
|
||
|
changesets.where('scmid LIKE ?', "#{name}%").first
|
||
|
end
|
||
|
end
|
||
| app/models/repository/mercurial.rb | ||
|---|---|---|
|
if /[^\d]/ =~ s or s.size > 8
|
||
|
cs = changesets.where(:scmid => s).first
|
||
|
else
|
||
|
cs = changesets.where(:revision => s).first
|
||
|
cs = changesets.find_by(:revision => s)
|
||
|
end
|
||
|
return cs if cs
|
||
|
changesets.where('scmid LIKE ?', "#{s}%").first
|
||
| app/models/role.rb | ||
|---|---|---|
|
end
|
||
|
def self.find_or_create_system_role(builtin, name)
|
||
|
role = unscoped.where(:builtin => builtin).first
|
||
|
role = unscoped.find_by(:builtin => builtin)
|
||
|
if role.nil?
|
||
|
role = unscoped.create(:name => name) do |r|
|
||
|
r.builtin = builtin
|
||
| app/models/token.rb | ||
|---|---|---|
|
key = key.to_s
|
||
|
return nil unless action.present? && key =~ /\A[a-z0-9]+\z/i
|
||
|
token = Token.where(:action => action, :value => key).first
|
||
|
token = Token.find_by(:action => action, :value => key)
|
||
|
if token && (token.action == action) && (token.value == key) && token.user
|
||
|
if validity_days.nil? || (token.created_on > validity_days.days.ago)
|
||
|
token
|
||
| app/models/user.rb | ||
|---|---|---|
|
user = where(:login => login).detect {|u| u.login == login}
|
||
|
unless user
|
||
|
# Fail over to case-insensitive if none was found
|
||
|
user = where("LOWER(login) = ?", login.downcase).first
|
||
|
user = find_by("LOWER(login) = ?", login.downcase)
|
||
|
end
|
||
|
user
|
||
|
end
|
||
| ... | ... | |
|
# eg. project.children.visible(user)
|
||
|
Project.unscoped do
|
||
|
return @project_ids_by_role if @project_ids_by_role
|
||
|
|
||
|
group_class = anonymous? ? GroupAnonymous : GroupNonMember
|
||
|
group_id = group_class.pluck(:id).first
|
||
|
|
||
|
members = Member.joins(:project, :member_roles).
|
||
|
where("#{Project.table_name}.status <> 9").
|
||
|
where("#{Member.table_name}.user_id = ? OR (#{Project.table_name}.is_public = ? AND #{Member.table_name}.user_id = ?)", self.id, true, group_id).
|
||
|
pluck(:user_id, :role_id, :project_id)
|
||
|
|
||
|
hash = {}
|
||
|
members.each do |user_id, role_id, project_id|
|
||
|
# Ignore the roles of the builtin group if the user is a member of the project
|
||
|
next if user_id != id && project_ids.include?(project_id)
|
||
|
|
||
|
hash[role_id] ||= []
|
||
|
hash[role_id] << project_id
|
||
|
end
|
||
|
|
||
|
result = Hash.new([])
|
||
|
if hash.present?
|
||
|
roles = Role.where(:id => hash.keys).to_a
|
||
| ... | ... | |
|
# Returns the anonymous user. If the anonymous user does not exist, it is created. There can be only
|
||
|
# one anonymous user per database.
|
||
|
def self.anonymous
|
||
|
anonymous_user = AnonymousUser.unscoped.first
|
||
|
anonymous_user = AnonymousUser.unscoped.find_by(:lastname => 'Anonymous')
|
||
|
if anonymous_user.nil?
|
||
|
anonymous_user = AnonymousUser.unscoped.create(:lastname => 'Anonymous', :firstname => '', :login => '', :status => 0)
|
||
|
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
|
||
| app/models/wiki.rb | ||
|---|---|---|
|
@page_found_with_redirect = false
|
||
|
title = start_page if title.blank?
|
||
|
title = Wiki.titleize(title)
|
||
|
page = pages.where("LOWER(title) = LOWER(?)", title).first
|
||
|
page = pages.find_by("LOWER(title) = LOWER(?)", title)
|
||
|
if page.nil? && options[:with_redirect] != false
|
||
|
# search for a redirect
|
||
|
redirect = redirects.where("LOWER(title) = LOWER(?)", title).first
|
||
| lib/redmine/field_format.rb | ||
|---|---|---|
|
def target_class
|
||
|
nil
|
||
|
end
|
||
|
|
||
|
def possible_custom_value_options(custom_value)
|
||
|
possible_values_options(custom_value.custom_field, custom_value.customized)
|
||
|
end
|
||
| ... | ... | |
|
value ||= label
|
||
|
checked = (custom_value.value.is_a?(Array) && custom_value.value.include?(value)) || custom_value.value.to_s == value
|
||
|
tag = view.send(tag_method, tag_name, value, checked, :id => nil)
|
||
|
s << view.content_tag('label', tag + ' ' + label)
|
||
|
s << view.content_tag('label', tag + ' ' + label)
|
||
|
end
|
||
|
if custom_value.custom_field.multiple?
|
||
|
s << view.hidden_field_tag(tag_name, '', :id => nil)
|
||
| ... | ... | |
|
def reset_target_class
|
||
|
@target_class = nil
|
||
|
end
|
||
|
|
||
|
def possible_custom_value_options(custom_value)
|
||
|
options = possible_values_options(custom_value.custom_field, custom_value.customized)
|
||
|
missing = [custom_value.value_was].flatten.reject(&:blank?) - options.map(&:last)
|
||
| ... | ... | |
|
class EnumerationFormat < RecordList
|
||
|
add 'enumeration'
|
||
|
self.form_partial = 'custom_fields/formats/enumeration'
|
||
|
|
||
|
def label
|
||
|
"label_field_format_enumeration"
|
||
|
end
|
||
| ... | ... | |
|
end
|
||
|
else
|
||
|
if custom_value.value.present?
|
||
|
attachment = Attachment.where(:id => custom_value.value.to_s).first
|
||
|
attachment = Attachment.find_by(:id => custom_value.value.to_s)
|
||
|
extensions = custom_value.custom_field.extensions_allowed
|
||
|
if attachment && extensions.present? && !attachment.extension_in?(extensions)
|
||
|
errors << "#{::I18n.t('activerecord.errors.messages.invalid')} (#{l(:setting_attachment_extensions_allowed)}: #{extensions})"
|
||
| ... | ... | |
|
def after_save_custom_value(custom_field, custom_value)
|
||
|
if custom_value.saved_change_to_value?
|
||
|
if custom_value.value.present?
|
||
|
attachment = Attachment.where(:id => custom_value.value.to_s).first
|
||
|
attachment = Attachment.find_by(:id => custom_value.value.to_s)
|
||
|
if attachment
|
||
|
attachment.container = custom_value
|
||
|
attachment.save!
|
||
|
end
|
||
|
end
|
||
|
if custom_value.value_before_last_save.present?
|
||
|
attachment = Attachment.where(:id => custom_value.value_before_last_save.to_s).first
|
||
|
attachment = Attachment.find_by(:id => custom_value.value_before_last_save.to_s)
|
||
|
if attachment
|
||
|
attachment.destroy
|
||
|
end
|
||
| lib/tasks/migrate_from_trac.rake | ||
|---|---|---|
|
puts
|
||
|
# Trac 'resolution' field as a Redmine custom field
|
||
|
r = IssueCustomField.where(:name => "Resolution").first
|
||
|
r = IssueCustomField.find_by(:name => "Resolution")
|
||
|
r = IssueCustomField.new(:name => 'Resolution',
|
||
|
:field_format => 'list',
|
||
|
:is_filter => true) if r.nil?
|
||