2014-07-05 12:59:42 +00:00
|
|
|
class AsciicastPolicy < ApplicationPolicy
|
|
|
|
|
|
|
|
class Scope < Struct.new(:user, :scope)
|
|
|
|
def resolve
|
|
|
|
scope
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def permitted_attributes
|
2014-11-15 18:30:05 +00:00
|
|
|
if user.admin? || record.owner?(user)
|
2014-11-27 12:30:08 +00:00
|
|
|
attrs = [:title, :description, :theme_name, :snapshot_at]
|
2014-07-05 12:59:42 +00:00
|
|
|
attrs << :featured if user.admin?
|
2014-11-15 18:30:05 +00:00
|
|
|
attrs << :private if record.owner?(user)
|
2014-07-05 12:59:42 +00:00
|
|
|
|
|
|
|
attrs
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
|
|
|
return false unless user
|
|
|
|
|
2014-11-15 18:30:05 +00:00
|
|
|
user.admin? || record.owner?(user)
|
2014-07-05 12:59:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy?
|
|
|
|
return false unless user
|
|
|
|
|
2014-11-15 18:30:05 +00:00
|
|
|
user.admin? || record.owner?(user)
|
2014-07-05 12:59:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def feature?
|
|
|
|
return false unless user
|
|
|
|
|
|
|
|
user.admin?
|
|
|
|
end
|
|
|
|
|
|
|
|
def unfeature?
|
|
|
|
return false unless user
|
|
|
|
|
|
|
|
user.admin?
|
|
|
|
end
|
|
|
|
|
2014-11-15 18:30:05 +00:00
|
|
|
def make_public?
|
|
|
|
return false unless user
|
|
|
|
|
|
|
|
record.owner?(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_private?
|
|
|
|
return false unless user
|
|
|
|
|
|
|
|
record.owner?(user)
|
|
|
|
end
|
|
|
|
|
2014-07-05 12:59:42 +00:00
|
|
|
end
|