2015-05-05 03:10:25 +02:00
|
|
|
class ProjectPolicy < ApplicationPolicy
|
|
|
|
class Scope < Scope
|
|
|
|
def resolve
|
|
|
|
if user
|
|
|
|
scope.includes(:project_image, :machines, :users)
|
|
|
|
.where("state = 'published' OR (state = 'draft' AND (author_id = ? OR users.id = ?))", user.id, user.id)
|
|
|
|
.references(:users)
|
|
|
|
.order(created_at: :desc)
|
|
|
|
else
|
|
|
|
scope.includes(:project_image, :machines, :users)
|
|
|
|
.where("state = 'published'")
|
|
|
|
.order(created_at: :desc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
2019-01-14 12:57:31 +01:00
|
|
|
user.admin? or record.author == user or record.users.include?(user)
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy?
|
2019-01-14 12:57:31 +01:00
|
|
|
user.admin? or record.author == user
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
end
|