asciinema.org/app/policies/asciicast_policy.rb

58 lines
878 B
Ruby
Raw Normal View History

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
if user.admin? || record.owner?(user)
attrs = [:title, :description, :theme_name, :snapshot_at]
2014-07-05 12:59:42 +00:00
attrs << :featured if user.admin?
attrs << :private if record.owner?(user)
2014-07-05 12:59:42 +00:00
attrs
else
[]
end
end
def update?
return false unless user
user.admin? || record.owner?(user)
2014-07-05 12:59:42 +00:00
end
def destroy?
return false unless user
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
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