update mapping policy
This commit is contained in:
parent
c5009952f3
commit
3823c708fd
1 changed files with 14 additions and 6 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue