From 952cf4e79f8168c44a118b18d5d15dfd6a29f42b Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Sat, 28 Jan 2017 16:40:41 -0500 Subject: [PATCH] keep permission of topic/synapse in sync with map its deferring to from beginning (#1053) * Update topic.rb * Update synapse.rb --- app/models/synapse.rb | 7 +++++++ app/models/topic.rb | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 8106dfd8..326ca86f 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -22,6 +22,7 @@ class Synapse < ApplicationRecord where(topic1_id: topic_id).or(where(topic2_id: topic_id)) } + before_create :set_perm_by_defer after_update :after_updated delegate :name, to: :user, prefix: true @@ -62,6 +63,12 @@ class Synapse < ApplicationRecord output += %(\n) output end + + protected + + def set_perm_by_defer + permission = defer_to_map.permission if defer_to_map + end def after_updated attrs = %w(desc category permission defer_to_map_id) diff --git a/app/models/topic.rb b/app/models/topic.rb index f1c221f0..254be52b 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -16,6 +16,7 @@ class Topic < ApplicationRecord belongs_to :metacode + before_create :set_perm_by_defer before_create :create_metamap? after_update :after_updated @@ -134,6 +135,10 @@ class Topic < ApplicationRecord protected + def set_perm_by_defer + permission = defer_to_map.permission if defer_to_map + end + def create_metamap? return unless (link == '') && (metacode.name == 'Metamap')