diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-03-30 12:29:07 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-03-30 12:29:07 +0000 |
commit | 287d86e3632546b06aeb955db8b0e5eea139082b (patch) | |
tree | 38d14393e22d0a577e0bed0f733c17c092c49e1b /app/models | |
parent | faf1f1e812b385dcf88591eac6fc898f86947c75 (diff) | |
download | redmine-287d86e3632546b06aeb955db8b0e5eea139082b.tar.gz redmine-287d86e3632546b06aeb955db8b0e5eea139082b.zip |
Queries can be marked as 'For all projects'. Such queries will be available on all projects and on the global issue list (#897, closes #671).
Only admin users can create/edit queries that are public and for all projects.
Note: this change does not allow to save a query from the global issue list. You have to be inside a project but then you can mark the query as 'For all projects'.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1311 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/query.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index dfdfa909b..c54c143e2 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -116,6 +116,11 @@ class Query < ActiveRecord::Base set_language_if_valid(User.current.language) end + def after_initialize + # Store the fact that project is nil (used in #editable_by?) + @is_for_all = project.nil? + end + def validate filters.each_key do |field| errors.add label_for(field), :activerecord_error_blank unless @@ -128,8 +133,10 @@ class Query < ActiveRecord::Base def editable_by?(user) return false unless user - return true if !is_public && self.user_id == user.id - is_public && user.allowed_to?(:manage_public_queries, project) + # Admin can edit them all and regular users can edit their private queries + return true if user.admin? || (!is_public && 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) end def available_filters |