keep permission of topic/synapse in sync with map its deferring to from beginning (#1053)

* Update topic.rb

* Update synapse.rb
This commit is contained in:
Connor Turland 2017-01-28 16:40:41 -05:00 committed by GitHub
parent 53bc4ee1c8
commit 952cf4e79f
2 changed files with 12 additions and 0 deletions

View file

@ -22,6 +22,7 @@ class Synapse < ApplicationRecord
where(topic1_id: topic_id).or(where(topic2_id: topic_id)) where(topic1_id: topic_id).or(where(topic2_id: topic_id))
} }
before_create :set_perm_by_defer
after_update :after_updated after_update :after_updated
delegate :name, to: :user, prefix: true delegate :name, to: :user, prefix: true
@ -63,6 +64,12 @@ class Synapse < ApplicationRecord
output output
end end
protected
def set_perm_by_defer
permission = defer_to_map.permission if defer_to_map
end
def after_updated def after_updated
attrs = %w(desc category permission defer_to_map_id) attrs = %w(desc category permission defer_to_map_id)
if attrs.any? { |k| changed_attributes.key?(k) } if attrs.any? { |k| changed_attributes.key?(k) }

View file

@ -16,6 +16,7 @@ class Topic < ApplicationRecord
belongs_to :metacode belongs_to :metacode
before_create :set_perm_by_defer
before_create :create_metamap? before_create :create_metamap?
after_update :after_updated after_update :after_updated
@ -134,6 +135,10 @@ class Topic < ApplicationRecord
protected protected
def set_perm_by_defer
permission = defer_to_map.permission if defer_to_map
end
def create_metamap? def create_metamap?
return unless (link == '') && (metacode.name == 'Metamap') return unless (link == '') && (metacode.name == 'Metamap')