Index: app/models/query.rb =================================================================== --- app/models/query.rb (Revision 17216) +++ app/models/query.rb (Arbeitskopie) @@ -222,6 +222,7 @@ errors.add(:base, l(:label_role_plural) + ' ' + l('activerecord.errors.messages.blank')) if query.visibility == VISIBILITY_ROLES && roles.blank? end + after_initialize :set_global_attribute after_save do |query| if query.saved_change_to_visibility? && query.visibility != VISIBILITY_ROLES query.roles.clear @@ -359,11 +360,14 @@ @queried_table_name ||= self.class.queried_class.table_name end - def initialize(attributes=nil, *args) - super attributes - @is_for_all = project.nil? + def set_global_attribute + @global_query = project.nil? end + def is_for_all_projects? + @global_query ||= project.nil? + end + # Builds the query from the given params def build_from_params(params, defaults={}) if params[:fields] || params[:f] @@ -446,7 +450,7 @@ # Admin can edit them all and regular users can edit their private queries return true if user.admin? || (is_private? && self.user_id == user.id) # Members can not edit public queries that are for all project (only admin is allowed to) - is_public? && !@is_for_all && user.allowed_to?(:manage_public_queries, project) + is_public? && !is_for_all_projects? && user.allowed_to?(:manage_public_queries, project) end def trackers