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?
|
2023-06-30 11:15:37 +02:00
|
|
|
user.admin? || record.author.user_id == user.id || record.users.include?(user)
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
|
2023-06-29 16:37:16 +02:00
|
|
|
def markdown?
|
2023-06-30 11:15:37 +02:00
|
|
|
user.admin? || user.manager? || record.author.user_id == user.id || record.users.include?(user)
|
2023-06-29 16:37:16 +02:00
|
|
|
end
|
|
|
|
|
2015-05-05 03:10:25 +02:00
|
|
|
def destroy?
|
2023-06-30 11:15:37 +02:00
|
|
|
user.admin? || record.author.user_id == user.id
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
end
|