Sha256: 7af6bccc8d3d916a88dfae2445058dd87b172b5ff47241bb711fed4d48bdf49d
Contents?: true
Size: 1.86 KB
Versions: 1
Compression:
Stored size: 1.86 KB
Contents
class UserPolicy < KojacBasePolicy def is_self? user.id == record.id end # def write? # return query_ring <= ADMIN_RING if @record==User # raise "Bad record given" unless record.is_a? User # return ((query_ring <= SYSADMIN_RING) || is_self? || ( # # )) # end allow_filter do |aPolicy,aResult,aRing,aAbility| if aRing <= SYSADMIN_RING # sysadmin can do all, so pass through aResult elsif (aPolicy.user.owner_id and aPolicy.record.owner_id != aPolicy.user.owner_id) # user has a ring that doesn't match record aResult = [] elsif aRing > USER_RING # outside of user, can't do anything aResult else if aPolicy.is_self? or (aRing < aPolicy.record.ring and aRing <= ADMIN_RING) # can admin if self or admin and lower rank case aAbility when :write aResult += User::PUBLIC_FIELDS + User::PRIVATE_FIELDS when :read aResult += User::PRIVATE_FIELDS end end aResult end end # allow_filter ring: :guest_admin, ability: :write do |aPolicy,aResult,aRing,aAbility| # aResult && aPolicy.is_self? # end # # allow_filter ability: [:create, :write] do |aPolicy,aRing,aAbility,aFields,aResult| # # logic here to set aResult # aResult # end # # # prevent guest_admin from creating or writing Users, even though outer rings can # allow_filter ring: :guest_admin, ability: [:create, :write] do |aUser,aRecord,aAbility,aFields,aResult| # false # end # def permitted_attributes(aAbility=nil) # case aAbility # when :write # return [] unless write? # when :read # return [] unless read? # end # # result = super(aAbility) # # if is_self? && query_ring <= USER_RING # case aAbility # when :write # result = (result | (User::PUBLIC_FIELDS + User::PRIVATE_FIELDS)).sort # when :read # result = (result | (User::PRIVATE_FIELDS)).sort # end # end # result # end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kojac-0.13.0 | spec/demo/app/policies/user_policy.rb |