2015-05-05 03:10:25 +02:00
|
|
|
class ProjectPolicy < ApplicationPolicy
|
|
|
|
class Scope < Scope
|
|
|
|
def resolve
|
|
|
|
if user
|
2019-06-06 16:34:53 +02:00
|
|
|
statistic_profile = StatisticProfile.find_by(user_id: user.id)
|
2015-05-05 03:10:25 +02:00
|
|
|
scope.includes(:project_image, :machines, :users)
|
2019-06-06 16:34:53 +02:00
|
|
|
.where("state = 'published' OR (state = 'draft' AND (author_statistic_profile_id = ? OR users.id = ?))", statistic_profile.id, user.id)
|
|
|
|
.references(:users)
|
|
|
|
.order(created_at: :desc)
|
2015-05-05 03:10:25 +02:00
|
|
|
else
|
|
|
|
scope.includes(:project_image, :machines, :users)
|
2019-06-06 16:34:53 +02:00
|
|
|
.where("state = 'published'")
|
|
|
|
.order(created_at: :desc)
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
2019-06-06 16:34:53 +02:00
|
|
|
user.admin? or record.author.user_id == user.id or record.users.include?(user)
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy?
|
2022-02-07 13:48:59 +01:00
|
|
|
user.admin? or record.author.user_id == user.id
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
end
|