|
|
@ -47,15 +47,19 @@ class Query < ActiveRecord::Base |
|
|
|
|
|
|
|
|
|
|
|
validate :validate_work_package_filters |
|
|
|
validate :validate_work_package_filters |
|
|
|
|
|
|
|
|
|
|
|
scope :visible, -> (to:) { |
|
|
|
scope :visible, -> (to:) do |
|
|
|
# User can see public queries and his own queries |
|
|
|
# User can see public queries and his own queries |
|
|
|
where('is_public = ? OR user_id = ?', |
|
|
|
scope = where(is_public: true) |
|
|
|
true, |
|
|
|
|
|
|
|
(to.logged? ? to.id : 0)) |
|
|
|
if to.logged? |
|
|
|
} |
|
|
|
scope.or(where(user_id: to.id)) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
scope |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
scope :global, -> { |
|
|
|
scope :global, -> { |
|
|
|
where('project_id IS NULL') |
|
|
|
where(project_id: nil) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# WARNING: sortable should not contain a column called id (except for the |
|
|
|
# WARNING: sortable should not contain a column called id (except for the |
|
|
|