update mapping policy

This commit is contained in:
Devin Howard 2016-03-14 11:09:27 +08:00
parent c5009952f3
commit 3823c708fd

View file

@ -16,20 +16,28 @@ class MappingPolicy < ApplicationPolicy
end end
def show? def show?
map = Pundit.policy(user, record.map) map_policy.show? && mappable_policy.show?
mappable = Pundit.policy(user, record.mappable)
map.show? && mappable.show?
end end
def create? def create?
Pundit.policy(user, record.map).update? map_policy.update?
end end
def update? def update?
Pundit.policy(user, record.map).update? record.mappable_type == 'Topic' && map_policy.update?
end end
def destroy? def destroy?
record.user == user || admin_override map_policy.update? || admin_override
end
# Helpers
def map_policy
@map_policy ||= Pundit.policy(user, record.map)
end
def mappable_policy
@mappable_policy ||= Pundit.policy(user, record.mappable)
end end
end end