From 3823c708fd0f65edba3b9f78801d676a3e3c4258 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 14 Mar 2016 11:09:27 +0800 Subject: [PATCH] update mapping policy --- app/policies/mapping_policy.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/policies/mapping_policy.rb b/app/policies/mapping_policy.rb index ed93bc66..40b71f61 100644 --- a/app/policies/mapping_policy.rb +++ b/app/policies/mapping_policy.rb @@ -16,20 +16,28 @@ class MappingPolicy < ApplicationPolicy end def show? - map = Pundit.policy(user, record.map) - mappable = Pundit.policy(user, record.mappable) - map.show? && mappable.show? + map_policy.show? && mappable_policy.show? end def create? - Pundit.policy(user, record.map).update? + map_policy.update? end def update? - Pundit.policy(user, record.map).update? + record.mappable_type == 'Topic' && map_policy.update? end 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