"me" value is now available in queries for "assigned to" and "author" filters.

When executing the query, it is replaced by the currently logged in user.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@520 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-05-08 12:46:15 +00:00
parent 50429d0819
commit df0a49ff14
14 changed files with 33 additions and 4 deletions

View File

@ -37,6 +37,7 @@ class FeedsController < ApplicationController
def issues def issues
if @project && params[:query_id] if @project && params[:query_id]
query = Query.find(params[:query_id]) query = Query.find(params[:query_id])
query.executed_by = @user
# ignore query if it's not valid # ignore query if it's not valid
query = nil unless query.valid? query = nil unless query.valid?
# override with query conditions # override with query conditions
@ -56,6 +57,7 @@ class FeedsController < ApplicationController
def history def history
if @project && params[:query_id] if @project && params[:query_id]
query = Query.find(params[:query_id]) query = Query.find(params[:query_id])
query.executed_by = @user
# ignore query if it's not valid # ignore query if it's not valid
query = nil unless query.valid? query = nil unless query.valid?
# override with query conditions # override with query conditions

View File

@ -647,11 +647,12 @@ private
def retrieve_query def retrieve_query
if params[:query_id] if params[:query_id]
@query = @project.queries.find(params[:query_id]) @query = @project.queries.find(params[:query_id])
@query.executed_by = logged_in_user
session[:query] = @query session[:query] = @query
else else
if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
# Give it a name, required to be valid # Give it a name, required to be valid
@query = Query.new(:name => "_") @query = Query.new(:name => "_", :executed_by => logged_in_user)
@query.project = @project @query.project = @project
if params[:fields] and params[:fields].is_a? Array if params[:fields] and params[:fields].is_a? Array
params[:fields].each do |field| params[:fields].each do |field|

View File

@ -42,6 +42,7 @@ class QueriesController < ApplicationController
private private
def find_query def find_query
@query = Query.find(params[:id]) @query = Query.find(params[:id])
@query.executed_by = logged_in_user
@project = @query.project @project = @query.project
# check if user is allowed to manage queries (same permission as add_query) # check if user is allowed to manage queries (same permission as add_query)
authorize('projects', 'add_query') authorize('projects', 'add_query')

View File

@ -21,6 +21,7 @@ class Query < ActiveRecord::Base
serialize :filters serialize :filters
attr_protected :project, :user attr_protected :project, :user
attr_accessor :executed_by
validates_presence_of :name, :on => :save validates_presence_of :name, :on => :save
@ -59,6 +60,11 @@ class Query < ActiveRecord::Base
self.is_public = true self.is_public = true
end end
def executed_by=(user)
@executed_by = user
set_language_if_valid(user.language) if user
end
def validate def validate
filters.each_key do |field| filters.each_key do |field|
errors.add label_for(field), :activerecord_error_blank unless errors.add label_for(field), :activerecord_error_blank unless
@ -81,8 +87,12 @@ class Query < ActiveRecord::Base
"due_date" => { :type => :date, :order => 12 } } "due_date" => { :type => :date, :order => 12 } }
unless project.nil? unless project.nil?
# project specific filters # project specific filters
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => @project.users.collect{|s| [s.name, s.id.to_s] } } user_values = []
@available_filters["author_id"] = { :type => :list, :order => 5, :values => @project.users.collect{|s| [s.name, s.id.to_s] } } user_values << ["<< #{l(:label_me)} >>", "me"] if executed_by
user_values += @project.users.collect{|s| [s.name, s.id.to_s] }
@available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values }
@available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values }
@available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } } @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
@available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.collect{|s| [s.name, s.id.to_s] } } @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.collect{|s| [s.name, s.id.to_s] } }
unless @project.children.empty? unless @project.children.empty?
@ -162,7 +172,7 @@ class Query < ActiveRecord::Base
end end
filters.each_key do |field| filters.each_key do |field|
next if field == "subproject_id" next if field == "subproject_id"
v = values_for field v = values_for(field).clone
next unless v and !v.empty? next unless v and !v.empty?
sql = sql + " AND " unless sql.empty? sql = sql + " AND " unless sql.empty?
@ -179,6 +189,11 @@ class Query < ActiveRecord::Base
db_field = field db_field = field
end end
# "me" value subsitution
if %w(assigned_to_id author_id).include?(field)
v.push(executed_by ? executed_by.id.to_s : "0") if v.delete("me")
end
case operator_for field case operator_for field
when "=" when "="
sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" sql = sql + "#{db_table}.#{db_field} IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")"

View File

@ -384,6 +384,7 @@ label_start_to_end: start to end
label_stay_logged_in: Stay logged in label_stay_logged_in: Stay logged in
label_disabled: disabled label_disabled: disabled
label_show_completed_versions: Show completed versions label_show_completed_versions: Show completed versions
label_me: me
button_login: Вход button_login: Вход
button_submit: Изпращане button_submit: Изпращане

View File

@ -384,6 +384,7 @@ label_start_to_end: start to end
label_stay_logged_in: Stay logged in label_stay_logged_in: Stay logged in
label_disabled: disabled label_disabled: disabled
label_show_completed_versions: Show completed versions label_show_completed_versions: Show completed versions
label_me: me
button_login: Einloggen button_login: Einloggen
button_submit: OK button_submit: OK

View File

@ -384,6 +384,7 @@ label_start_to_end: start to end
label_stay_logged_in: Stay logged in label_stay_logged_in: Stay logged in
label_disabled: disabled label_disabled: disabled
label_show_completed_versions: Show completed versions label_show_completed_versions: Show completed versions
label_me: me
button_login: Login button_login: Login
button_submit: Submit button_submit: Submit

View File

@ -384,6 +384,7 @@ label_start_to_end: start to end
label_stay_logged_in: Stay logged in label_stay_logged_in: Stay logged in
label_disabled: disabled label_disabled: disabled
label_show_completed_versions: Show completed versions label_show_completed_versions: Show completed versions
label_me: me
button_login: Conexión button_login: Conexión
button_submit: Someter button_submit: Someter

View File

@ -384,6 +384,7 @@ label_start_to_end: début à fin
label_stay_logged_in: Rester connecté label_stay_logged_in: Rester connecté
label_disabled: désactivé label_disabled: désactivé
label_show_completed_versions: Voire les versions passées label_show_completed_versions: Voire les versions passées
label_me: moi
button_login: Connexion button_login: Connexion
button_submit: Soumettre button_submit: Soumettre

View File

@ -384,6 +384,7 @@ label_start_to_end: start to end
label_stay_logged_in: Stay logged in label_stay_logged_in: Stay logged in
label_disabled: disabled label_disabled: disabled
label_show_completed_versions: Show completed versions label_show_completed_versions: Show completed versions
label_me: me
button_login: Login button_login: Login
button_submit: Invia button_submit: Invia

View File

@ -385,6 +385,7 @@ label_start_to_end: start to end
label_stay_logged_in: Stay logged in label_stay_logged_in: Stay logged in
label_disabled: disabled label_disabled: disabled
label_show_completed_versions: Show completed versions label_show_completed_versions: Show completed versions
label_me: me
button_login: ログイン button_login: ログイン
button_submit: 変更 button_submit: 変更

View File

@ -384,6 +384,7 @@ label_start_to_end: start to end
label_stay_logged_in: Stay logged in label_stay_logged_in: Stay logged in
label_disabled: disabled label_disabled: disabled
label_show_completed_versions: Show completed versions label_show_completed_versions: Show completed versions
label_me: me
button_login: Login button_login: Login
button_submit: Enviar button_submit: Enviar

View File

@ -384,6 +384,7 @@ label_start_to_end: inícia ao fim
label_stay_logged_in: Rester connecté label_stay_logged_in: Rester connecté
label_disabled: désactivé label_disabled: désactivé
label_show_completed_versions: Voire les versions passées label_show_completed_versions: Voire les versions passées
label_me: me
button_login: Login button_login: Login
button_submit: Enviar button_submit: Enviar

View File

@ -387,6 +387,7 @@ label_start_to_end: start to end
label_stay_logged_in: Stay logged in label_stay_logged_in: Stay logged in
label_disabled: disabled label_disabled: disabled
label_show_completed_versions: Show completed versions label_show_completed_versions: Show completed versions
label_me: me
button_login: 登录 button_login: 登录
button_submit: 提交 button_submit: 提交