Project

General

Profile

Feature #24013 » Basic_Fb_support.patch

Andrey Lobanov (RedSoft), 2016-10-06 23:34

View differences:

app/controllers/versions_controller.rb (revision fed3e767d8c476e6a3bd414a497e179b5c872788)
respond_to do |format|
format.html {
@trackers = @project.trackers.sorted.to_a
retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
retrieve_selected_tracker_ids(@trackers, @trackers.select { |t| t.is_in_roadmap? })
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
......
@issues_by_version = {}
if @selected_tracker_ids.any? && @versions.any?
issues = Issue.visible.
includes(:project, :tracker).
preload(:status, :priority, :fixed_version).
where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)).
includes(:project, :tracker).
preload(:status, :priority, :fixed_version).
where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)).
order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
order(Project.arel_table[:lft].asc, Tracker.arel_table[:position].asc, Issue.arel_table[:id].asc)
@issues_by_version = issues.group_by(&:fixed_version)
end
@versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
@versions.reject! { |version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank? }
}
format.api {
@versions = @project.shared_versions.to_a
......
respond_to do |format|
format.html {
@issues = @version.fixed_issues.visible.
includes(:status, :tracker, :priority).
preload(:project).
includes(:status, :tracker, :priority).
preload(:project).
reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
reorder(Issue.arel_table[:id].asc).
to_a
to_a
}
format.api
end
......
else
respond_to do |format|
format.html { render :action => 'new' }
format.js { render :action => 'new' }
format.js { render :action => 'new' }
format.api { render_validation_errors(@version) }
format.api { render_validation_errors(@version) }
end
end
end
......
flash[:notice] = l(:notice_successful_update)
redirect_back_or_default settings_project_path(@project, :tab => 'versions')
}
format.api { render_api_ok }
format.api { render_api_ok }
end
else
respond_to do |format|
format.html { render :action => 'edit' }
format.api { render_validation_errors(@version) }
format.api { render_validation_errors(@version) }
end
end
end
......
@version.destroy
respond_to do |format|
format.html { redirect_back_or_default settings_project_path(@project, :tab => 'versions') }
format.api { render_api_ok }
format.api { render_api_ok }
end
else
respond_to do |format|
......
flash[:error] = l(:notice_unable_delete_version)
redirect_to settings_project_path(@project, :tab => 'versions')
}
format.api { head :unprocessable_entity }
format.api { head :unprocessable_entity }
end
end
end
......
if ids = params[:tracker_ids]
@selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
else
@selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
@selected_tracker_ids = (default_trackers || selectable_trackers).collect { |t| t.id.to_s }
end
end
end
app/helpers/my_helper.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
limit(10).
includes(:status, :project, :tracker, :priority).
references(:status, :project, :tracker, :priority).
order("#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC")
order(IssuePriority.arel_table[:position].desc, Issue.arel_table[:updated_on].desc)
end
def issuesreportedbyme_items
......
joins(:activity, :project).
references(:issue => [:tracker, :status]).
includes(:issue => [:tracker, :status]).
order("#{TimeEntry.table_name}.spent_on DESC, #{Project.table_name}.name ASC, #{Tracker.table_name}.position ASC, #{Issue.table_name}.id ASC").
order(TimeEntry.arel_table[:spent_on].desc, Project.arel_table[:name].asc, Tracker.arel_table[:position].asc, Issue.arel_table[:id].asc).
to_a
end
end
app/models/enumeration.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918)
class Enumeration < ActiveRecord::Base
include Redmine::SubclassFactory
default_scope lambda {order(:position)}
default_scope lambda { order(:position) }
belongs_to :project
......
acts_as_tree
before_destroy :check_integrity
before_save :check_default
before_save :check_default
attr_protected :type
......
scope :sorted, lambda { order(:position) }
scope :active, lambda { where(:active => true) }
scope :system, lambda { where(:project_id => nil) }
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
scope :named, lambda { |arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip) }
def self.default
# Creates a fake default scope so Enumeration.default will check
......
position <=> enumeration.position
end
def to_s; name end
def to_s;
name
end
# Returns the Subclasses of Enumeration. Each Subclass needs to be
# required in development mode.
......
# Does the +new+ Hash override the previous Enumeration?
def self.overriding_change?(new, previous)
if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous)
if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new, previous)
return false
else
return true
......
def update_position
super
if position_changed?
self.class.where.not(:parent_id => nil).update_all(
"position = coalesce((
select position
from (select id, position from enumerations) as parent
where parent_id = parent.id), 1)"
)
from = Enumeration.select(:id, :position)
self.class.where.not(:parent_id => nil).update_all(:position => "coalesce(#{Enumeration.where(nil).
from("(#{from.to_sql}) as parent").
where('parent_id = parent.id').select(:position).to_sql}), 1)")
end
end
app/models/issue.rb (revision e3cbc3d2f583d6a93fe4c01281991e21d34a88b3)
if issue_id && p = Issue.find_by_id(issue_id)
if p.priority_derived?
# priority = highest priority of open children
if priority_position = p.children.open.joins(:priority).maximum("#{IssuePriority.table_name}.position")
if priority_position = p.children.open.joins(:priority).reorder(nil).select(IssuePriority.arel_table[:position].maximum).first[:max]
p.priority = IssuePriority.find_by_position(priority_position)
else
p.priority = IssuePriority.default
app/models/issue_query.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
self.available_columns = [
QueryColumn.new(:id, :sortable => "#{Issue.table_name}.id", :default_order => 'desc', :caption => '#', :frozen => true),
QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true),
QueryColumn.new(:tracker, :sortable => Tracker.arel_table[:position].asc.to_sql, :groupable => true),
QueryColumn.new(:parent, :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"], :default_order => 'desc', :caption => :field_parent_issue),
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true),
QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc', :groupable => true),
QueryColumn.new(:status, :sortable => IssueStatus.arel_table[:position].asc.to_sql, :groupable => true),
QueryColumn.new(:priority, :sortable => IssuePriority.arel_table[:position].desc.to_sql, :groupable => true),
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
QueryColumn.new(:author, :sortable => lambda {User.fields_for_order_statement("authors")}, :groupable => true),
QueryColumn.new(:assigned_to, :sortable => lambda {User.fields_for_order_statement}, :groupable => true),
app/models/issue_status.rb (revision 1199798be728002c93d6241bf33b919fdfeb7918)
attr_protected :id
scope :sorted, lambda { order(:position) }
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
scope :named, lambda { |arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip) }
safe_attributes 'name',
'is_closed',
'position',
'default_done_ratio'
'is_closed',
'position',
'default_done_ratio'
# Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
def self.update_issue_done_ratios
......
def new_statuses_allowed_to(roles, tracker, author=false, assignee=false)
self.class.new_statuses_allowed(self, roles, tracker, author, assignee)
end
alias :find_new_statuses_allowed_to :new_statuses_allowed_to
def self.new_statuses_allowed(status, roles, tracker, author=false, assignee=false)
......
status_id = status.try(:id) || 0
scope = IssueStatus.
joins(:workflow_transitions_as_new_status).
where(:workflows => {:old_status_id => status_id, :role_id => roles.map(&:id), :tracker_id => tracker.id})
joins(:workflow_transitions_as_new_status).
where(:workflows => {:old_status_id => status_id, :role_id => roles.map(&:id), :tracker_id => tracker.id})
unless author && assignee
if author || assignee
......
position <=> status.position
end
def to_s; name end
def to_s;
name
end
private
......
if is_closed_changed? && is_closed == true
# First we update issues that have a journal for when the current status was set,
# a subselect is used to update all issues with a single query
subselect = "SELECT MAX(j.created_on) FROM #{Journal.table_name} j" +
" JOIN #{JournalDetail.table_name} d ON d.journal_id = j.id" +
" WHERE j.journalized_type = 'Issue' AND j.journalized_id = #{Issue.table_name}.id" +
" AND d.property = 'attr' AND d.prop_key = 'status_id' AND d.value = :status_id"
subselect = Journal.joins(:details).where(:journalized_type => 'Issue').where("#{Journal.table_name}.
journalized_id = #{Issue.table_name}.id").where(:journal_details => {:property => 'attr', :prop_key => 'status_id', :value => ':status_id'}).
select("MAX(#{Journal.table_name}.created_on)").to_sql.gsub(/':status_id'/, ":status_id")
Issue.where(:status_id => id, :closed_on => nil).
update_all(["closed_on = (#{subselect})", {:status_id => id.to_s}])
update_all(["closed_on = (#{subselect})", {:status_id => id.to_s}])
# Then we update issues that don't have a journal which means the
# current status was set on creation
app/models/project.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
has_many :documents, :dependent => :destroy
has_many :news, lambda {includes(:author)}, :dependent => :destroy
has_many :issue_categories, lambda {order("#{IssueCategory.table_name}.name")}, :dependent => :delete_all
has_many :boards, lambda {order("position ASC")}, :dependent => :destroy
has_many :boards, lambda { order(:position) }, :dependent => :destroy
has_one :repository, lambda {where(["is_default = ?", true])}
has_many :repositories, :dependent => :destroy
has_many :changesets, :through => :repository
has_one :wiki, :dependent => :destroy
# Custom field for the project issues
has_and_belongs_to_many :issue_custom_fields,
lambda {order("#{CustomField.table_name}.position")},
lambda { order(CustomField.arel_table[:position].asc) },
:class_name => 'IssueCustomField',
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
:association_foreign_key => 'custom_field_id'
app/models/query.rb (revision b795289685e02d24a79a08eacd9d55cabc8bec9e)
def sql_for_custom_field(field, operator, value, custom_field_id)
db_table = CustomValue.table_name
db_field = 'value'
db_field = ActiveRecord::Base.connection.quote_column_name('value')
filter = @available_filters[field]
return nil unless filter
if filter[:field].format.target_class && filter[:field].format.target_class <= User
......
int_values = value.first.to_s.scan(/[+-]?\d+/).map(&:to_i).join(",")
if int_values.present?
if is_custom_filter
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) IN (#{int_values}))"
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) IN (#{int_values}))"
else
sql = "#{db_table}.#{db_field} IN (#{int_values})"
end
......
end
when :float
if is_custom_filter
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})"
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})"
else
sql = "#{db_table}.#{db_field} BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5}"
end
......
sql = date_clause(db_table, db_field, parse_date(value.first), nil, is_custom_filter)
else
if is_custom_filter
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) >= #{value.first.to_f})"
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) >= #{value.first.to_f})"
else
sql = "#{db_table}.#{db_field} >= #{value.first.to_f}"
end
......
sql = date_clause(db_table, db_field, nil, parse_date(value.first), is_custom_filter)
else
if is_custom_filter
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) <= #{value.first.to_f})"
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) <= #{value.first.to_f})"
else
sql = "#{db_table}.#{db_field} <= #{value.first.to_f}"
end
......
sql = date_clause(db_table, db_field, parse_date(value[0]), parse_date(value[1]), is_custom_filter)
else
if is_custom_filter
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f})"
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(18,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f})"
else
sql = "#{db_table}.#{db_field} BETWEEN #{value[0].to_f} AND #{value[1].to_f}"
end
app/models/repository.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
# Notes:
# - this hash honnors the users mapping defined for the repository
def stats_by_author
commits = Changeset.where("repository_id = ?", id).select("committer, user_id, count(*) as count").group("committer, user_id")
commits = Changeset.where("repository_id = ?", id).select("committer, user_id, count(*)").group("committer, user_id")
#TODO: restore ordering ; this line probably never worked
#commits.to_a.sort! {|x, y| x.last <=> y.last}
changes = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).select("committer, user_id, count(*) as count").group("committer, user_id")
changes = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).select("committer, user_id, count(*)").group("committer, user_id")
user_ids = changesets.map(&:user_id).compact.uniq
authors_names = User.where(:id => user_ids).inject({}) do |memo, user|
app/models/time_entry_query.rb (revision 4d10162d2a58c14765bf6abc8b5ed12ea4af73d2)
QueryColumn.new(:spent_on, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :default_order => 'desc', :groupable => true),
QueryColumn.new(:tweek, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :caption => l(:label_week)),
QueryColumn.new(:user, :sortable => lambda {User.fields_for_order_statement}, :groupable => true),
QueryColumn.new(:activity, :sortable => "#{TimeEntryActivity.table_name}.position", :groupable => true),
QueryColumn.new(:activity, :sortable => TimeEntryActivity.arel_table[:position].asc.to_sql, :groupable => true),
QueryColumn.new(:issue, :sortable => "#{Issue.table_name}.id"),
QueryAssociationColumn.new(:issue, :tracker, :caption => :field_tracker, :sortable => "#{Tracker.table_name}.position"),
QueryAssociationColumn.new(:issue, :status, :caption => :field_status, :sortable => "#{IssueStatus.table_name}.position"),
QueryAssociationColumn.new(:issue, :tracker, :caption => :field_tracker, :sortable => Tracker.arel_table[:position].asc.to_sql),
QueryAssociationColumn.new(:issue, :status, :caption => :field_status, :sortable => IssueStatus.arel_table[:position].asc.to_sql),
QueryColumn.new(:comments),
QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours", :totalable => true),
]
app/models/user.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
# Returns true if the user is allowed to delete the user's own account
def own_account_deletable?
Setting.unsubscribe? &&
(!admin? || User.active.where("admin = ? AND id <> ?", true, id).exists?)
(!admin? || User.active.where("id <> ?", id).where(:admin => true).exists?)
end
safe_attributes 'firstname',
db/migrate/007_create_journals.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
end
# indexes
add_index "journals", ["journalized_id", "journalized_type"], :name => "journals_journalized_id"
add_index "journals", ["journalized_id", "journalized_type"]
add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id"
Permission.create :controller => "issues", :action => "history", :description => "label_history", :sort => 1006, :is_public => true, :mail_option => 0, :mail_enabled => 0
db/migrate/107_add_open_id_authentication_tables.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
class AddOpenIdAuthenticationTables < ActiveRecord::Migration
def self.up
create_table :open_id_authentication_associations, :force => true do |t|
create_table :open_id_auth_associations, :force => true do |t|
t.integer :issued, :lifetime
t.string :handle, :assoc_type
t.binary :server_url, :secret
end
create_table :open_id_authentication_nonces, :force => true do |t|
create_table :open_id_auth_nonces, :force => true do |t|
t.integer :timestamp, :null => false
t.string :server_url, :null => true
t.string :salt, :null => false
......
end
def self.down
drop_table :open_id_authentication_associations
drop_table :open_id_authentication_nonces
drop_table :open_id_auth_associations
drop_table :open_id_auth_nonces
end
end
db/migrate/20130201184705_add_unique_index_on_tokens_value.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
def up
say_with_time "Adding unique index on tokens, this may take some time..." do
# Just in case
duplicates = Token.connection.select_values("SELECT value FROM #{Token.table_name} GROUP BY value HAVING COUNT(id) > 1")
duplicates = Token.group(:value).having('COUNT(id) > 1').select(:value).to_a
Token.where(:value => duplicates).delete_all
add_index :tokens, :value, :unique => true, :name => 'tokens_value'
db/migrate/20130215111141_populate_issues_closed_on.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
" AND #{Journal.table_name}.journalized_type = 'Issue' AND #{Journal.table_name}.journalized_id = #{Issue.table_name}.id" +
" AND #{JournalDetail.table_name}.property = 'attr' AND #{JournalDetail.table_name}.prop_key = 'status_id'" +
" AND #{JournalDetail.table_name}.old_value NOT IN (#{closed_status_values})" +
" AND #{JournalDetail.table_name}.value IN (#{closed_status_values})"
" AND " + JournalDetail.arel_table[:value].in(closed_status_values).to_sql
Issue.update_all "closed_on = (#{subselect})"
# Then set closed_on for closed issues that weren't up updated by the above UPDATE
lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
return if self.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)
cattr_accessor :customizable_options
self.customizable_options = options
has_many :custom_values, lambda {includes(:custom_field).order("#{CustomField.table_name}.position")},
has_many :custom_values, lambda { joins(:custom_field).merge(CustomField.order(:position)) },
:as => :customized,
:dependent => :delete_all,
:validate => false
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb (revision 08bc581cf543157c294f6194f9062d42fcb1652a)
unless options[:attachments] == 'only'
r = fetch_ranks_and_ids(
search_scope(user, projects, options).
where(search_tokens_condition(columns, tokens, options[:all_words])),
options[:limit]
search_scope(user, projects, options).
where(search_tokens_condition(columns, tokens, options[:all_words])),
options[:limit]
)
queries += 1
if !options[:titles_only] && searchable_options[:search_custom_fields]
searchable_custom_fields = CustomField.where(:type => "#{self.name}CustomField", :searchable => true).to_a
if searchable_custom_fields.any?
fields_by_visibility = searchable_custom_fields.group_by {|field|
fields_by_visibility = searchable_custom_fields.group_by { |field|
field.visibility_by_project_condition(searchable_options[:project_key], user, "#{CustomValue.table_name}.custom_field_id")
}
clauses = []
......
clauses << "(#{CustomValue.table_name}.custom_field_id IN (#{fields.map(&:id).join(',')}) AND (#{visibility}))"
end
visibility = clauses.join(' OR ')
r |= fetch_ranks_and_ids(
search_scope(user, projects, options).
joins(:custom_values).
where(visibility).
search_scope(user, projects, options).
joins(:custom_values).
where(visibility).
where(search_tokens_condition(["#{CustomValue.table_name}.value"], tokens, options[:all_words])),
where(search_tokens_condition(["#{ActiveRecord::Base.connection.quote_table_name(CustomValue.table_name)}.#{ActiveRecord::Base.connection.quote_column_name('value')}"], tokens, options[:all_words])),
options[:limit]
options[:limit]
)
queries += 1
end
......
if !options[:titles_only] && searchable_options[:search_journals]
r |= fetch_ranks_and_ids(
search_scope(user, projects, options).
joins(:journals).
where("#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes)})", false).
where(search_tokens_condition(["#{Journal.table_name}.notes"], tokens, options[:all_words])),
options[:limit]
search_scope(user, projects, options).
joins(:journals).
where("#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes)})", false).
where(search_tokens_condition(["#{Journal.table_name}.notes"], tokens, options[:all_words])),
options[:limit]
)
queries += 1
end
......
if searchable_options[:search_attachments] && (options[:titles_only] ? options[:attachments] == 'only' : options[:attachments] != '0')
r |= fetch_ranks_and_ids(
search_scope(user, projects, options).
joins(:attachments).
where(search_tokens_condition(["#{Attachment.table_name}.filename", "#{Attachment.table_name}.description"], tokens, options[:all_words])),
options[:limit]
search_scope(user, projects, options).
joins(:attachments).
where(search_tokens_condition(["#{Attachment.table_name}.filename", "#{Attachment.table_name}.description"], tokens, options[:all_words])),
options[:limit]
)
queries += 1
end
......
end
def search_tokens_condition(columns, tokens, all_words)
token_clauses = columns.map {|column| "(#{search_token_match_statement(column)})"}
token_clauses = columns.map { |column|
column = "lower(#{column})"
"(#{search_token_match_statement(column)})"
}
sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(all_words ? ' AND ' : ' OR ')
[sql, * (tokens.collect {|w| "%#{w}%"} * token_clauses.size).sort]
[sql, * (tokens.collect { |w| "%#{w}%" } * token_clauses.size).sort]
end
private :search_tokens_condition
def search_token_match_statement(column, value='?')
Redmine::Database.like(column, value)
end
private :search_token_match_statement
def fetch_ranks_and_ids(scope, limit)
scope.
reorder(searchable_options[:date_column] => :desc, :id => :desc).
limit(limit).
distinct.
pluck(searchable_options[:date_column], :id).
# converts timestamps to integers for faster sort
reorder(searchable_options[:date_column] => :desc, :id => :desc).
limit(limit).
distinct.
pluck(searchable_options[:date_column], :id).
# converts timestamps to integers for faster sort
map {|timestamp, id| [timestamp.to_i, id]}
map { |timestamp, id| [timestamp.to_i, id] }
end
private :fetch_ranks_and_ids
# Returns the search scope for user and projects
......
end
scope
end
private :search_scope
# Returns search results of given ids
lib/plugins/open_id_authentication/lib/open_id_authentication/association.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
module OpenIdAuthentication
class Association < ActiveRecord::Base
self.table_name = :open_id_authentication_associations
self.table_name = :open_id_auth_associations
def from_record
OpenID::Association.new(handle, secret, issued, lifetime, assoc_type)
lib/redmine/acts/positioned.rb (revision f1a9cc676b43afdf7de6c12ef3b40c192f98cfed)
end
def insert_position
position_scope.where("position >= ? AND id <> ?", position, id).update_all("position = position + 1")
position_scope.where(self.class.arel_table[:position].gteq(position)).where('id <> ?', id).update_all(:position => (self.class.arel_table[:position] + 1).to_sql)
end
def remove_position
position_scope_was.where("position >= ? AND id <> ?", position_was, id).update_all("position = position - 1")
position_scope_was.where(self.class.arel_table[:position].gteq(position_was)).where('id <> ?', id).update_all(:position => (self.class.arel_table[:position] - 1).to_sql)
end
def position_scope_changed?
......
def shift_positions
offset = position_was <=> position
min, max = [position, position_was].sort
r = position_scope.where("id <> ? AND position BETWEEN ? AND ?", id, min, max).update_all("position = position + #{offset}")
r = position_scope.where('id <> ?', id).where(self.class.arel_table[:position].between(min..max)).update_all(:position => (self.class.arel_table[:position] + offset).to_sql)
if r != max - min
reset_positions_in_list
end
lib/redmine/field_format.rb (revision 08bc581cf543157c294f6194f9062d42fcb1652a)
# Returns nil if the custom field can not be used for sorting.
def order_statement(custom_field)
# COALESCE is here to make sure that blank and NULL values are sorted equally
"COALESCE(#{join_alias custom_field}.value, '')"
"COALESCE(#{join_alias custom_field}.#{value_column}, '')"
end
# Returns a GROUP BY clause that can used to group by custom value
......
" AND #{alias_name}.customized_id = #{custom_field.class.customized_class.table_name}.id" +
" AND #{alias_name}.custom_field_id = #{custom_field.id}" +
" AND (#{custom_field.visibility_by_project_condition})" +
" AND #{alias_name}.value <> ''" +
" AND #{alias_name}.#{value_column} <> ''" +
" AND #{alias_name}.id = (SELECT max(#{alias_name}_2.id) FROM #{CustomValue.table_name} #{alias_name}_2" +
" WHERE #{alias_name}_2.customized_type = #{alias_name}.customized_type" +
" AND #{alias_name}_2.customized_id = #{alias_name}.customized_id" +
......
def join_alias(custom_field)
"cf_#{custom_field.id}"
end
def value_column
ActiveRecord::Base.connection.quote_column_name('value')
end
protected :join_alias
end
......
# Make the database cast values into numeric
# Postgresql will raise an error if a value can not be casted!
# CustomValue validations should ensure that it doesn't occur
"CAST(CASE #{join_alias custom_field}.value WHEN '' THEN '0' ELSE #{join_alias custom_field}.value END AS decimal(30,3))"
"CAST(CASE #{join_alias custom_field}.#{value_column} WHEN '' THEN '0' ELSE #{join_alias custom_field}.#{value_column} END AS decimal(18,3))"
end
# Returns totals for the given scope
......
scope.joins(:custom_values).
where(:custom_values => {:custom_field_id => custom_field.id}).
where.not(:custom_values => {:value => ''}).
sum("CAST(#{CustomValue.table_name}.value AS decimal(30,3))")
sum("CAST(#{CustomValue.table_name}.#{value_column} AS decimal(18,3))")
end
def cast_total_value(custom_field, value)
......
end
def group_statement(custom_field)
"COALESCE(#{join_alias custom_field}.value, '')"
"COALESCE(#{join_alias custom_field}.#{value_column}, '')"
end
def join_for_order_statement(custom_field)
......
" AND #{alias_name}.customized_id = #{custom_field.class.customized_class.table_name}.id" +
" AND #{alias_name}.custom_field_id = #{custom_field.id}" +
" AND (#{custom_field.visibility_by_project_condition})" +
" AND #{alias_name}.value <> ''" +
" AND #{alias_name}.#{value_column} <> ''" +
" AND #{alias_name}.id = (SELECT max(#{alias_name}_2.id) FROM #{CustomValue.table_name} #{alias_name}_2" +
" WHERE #{alias_name}_2.customized_type = #{alias_name}.customized_type" +
" AND #{alias_name}_2.customized_id = #{alias_name}.customized_id" +
" AND #{alias_name}_2.custom_field_id = #{alias_name}.custom_field_id)" +
" LEFT OUTER JOIN #{target_class.table_name} #{value_join_alias custom_field}" +
" ON CAST(CASE #{alias_name}.value WHEN '' THEN '0' ELSE #{alias_name}.value END AS decimal(30,0)) = #{value_join_alias custom_field}.id"
" ON CAST(CASE #{alias_name}.#{value_column} WHEN '' THEN '0' ELSE #{alias_name}.#{value_column} END AS decimal(18,0)) = #{value_join_alias custom_field}.id"
end
def value_join_alias(custom_field)
lib/tasks/migrate_from_mantis.rake (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
TRACKER_BUG = Tracker.find_by_position(1)
TRACKER_FEATURE = Tracker.find_by_position(2)
roles = Role.where(:builtin => 0).order('position ASC').all
roles = Role.where(:builtin => 0).order(:position).all
manager_role = roles[0]
developer_role = roles[1]
DEFAULT_ROLE = roles.last
lib/tasks/migrate_from_trac.rake (revision 615eb5fb585c9864694385bf7a3e2b382a9dd52a)
'patch' =>TRACKER_FEATURE
}
roles = Role.where(:builtin => 0).order('position ASC').all
roles = Role.where(:builtin => 0).order(:position).all
manager_role = roles[0]
developer_role = roles[1]
DEFAULT_ROLE = roles.last
(1-1/11)