From 839ff66bcf2ed9b904d68d0df2755f85e2b3a389 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Thu, 15 Dec 2016 07:44:01 -0500 Subject: [PATCH] avoid the mapping gets deleted problem --- app/models/events/synapse_added_to_map.rb | 9 +++++---- app/models/events/synapse_removed_from_map.rb | 5 +++-- app/models/events/topic_added_to_map.rb | 6 +++--- app/models/events/topic_moved_on_map.rb | 6 +++--- app/models/events/topic_removed_from_map.rb | 5 +++-- app/models/mapping.rb | 15 ++++++++------- app/models/webhooks/slack/synapse_added_to_map.rb | 4 ++-- app/models/webhooks/slack/topic_added_to_map.rb | 2 +- app/models/webhooks/slack/topic_moved_on_map.rb | 2 +- 9 files changed, 29 insertions(+), 25 deletions(-) diff --git a/app/models/events/synapse_added_to_map.rb b/app/models/events/synapse_added_to_map.rb index c468fad6..5afa885d 100644 --- a/app/models/events/synapse_added_to_map.rb +++ b/app/models/events/synapse_added_to_map.rb @@ -2,10 +2,11 @@ class Events::SynapseAddedToMap < Event # after_create :notify_users! - def self.publish!(mapping, user) + def self.publish!(synapse, map, user, meta) create!(kind: 'synapse_added_to_map', - eventable: mapping, - map: mapping.map, - user: user) + eventable: synapse, + map: map, + user: user, + meta: meta) end end diff --git a/app/models/events/synapse_removed_from_map.rb b/app/models/events/synapse_removed_from_map.rb index bb53594c..b64035dd 100644 --- a/app/models/events/synapse_removed_from_map.rb +++ b/app/models/events/synapse_removed_from_map.rb @@ -2,10 +2,11 @@ class Events::SynapseRemovedFromMap < Event # after_create :notify_users! - def self.publish!(synapse, map, user) + def self.publish!(synapse, map, user, meta) create!(kind: 'synapse_removed_from_map', eventable: synapse, map: map, - user: user) + user: user, + meta: meta) end end diff --git a/app/models/events/topic_added_to_map.rb b/app/models/events/topic_added_to_map.rb index 70a4497d..a3fa62cf 100644 --- a/app/models/events/topic_added_to_map.rb +++ b/app/models/events/topic_added_to_map.rb @@ -2,10 +2,10 @@ class Events::TopicAddedToMap < Event # after_create :notify_users! - def self.publish!(mapping, user, meta) + def self.publish!(topic, map, user, meta) create!(kind: 'topic_added_to_map', - eventable: mapping, - map: mapping.map, + eventable: topic, + map: map, user: user, meta: meta) end diff --git a/app/models/events/topic_moved_on_map.rb b/app/models/events/topic_moved_on_map.rb index d2fcd96e..08d01277 100644 --- a/app/models/events/topic_moved_on_map.rb +++ b/app/models/events/topic_moved_on_map.rb @@ -2,10 +2,10 @@ class Events::TopicMovedOnMap < Event # after_create :notify_users! - def self.publish!(mapping, user, meta) + def self.publish!(topic, map, user, meta) create!(kind: 'topic_moved_on_map', - eventable: mapping, - map: mapping.map, + eventable: topic, + map: map, user: user, meta: meta) end diff --git a/app/models/events/topic_removed_from_map.rb b/app/models/events/topic_removed_from_map.rb index 26f563a5..2f03ec26 100644 --- a/app/models/events/topic_removed_from_map.rb +++ b/app/models/events/topic_removed_from_map.rb @@ -2,10 +2,11 @@ class Events::TopicRemovedFromMap < Event # after_create :notify_users! - def self.publish!(topic, map, user) + def self.publish!(topic, map, user, meta) create!(kind: 'topic_removed_from_map', eventable: topic, map: map, - user: user) + user: user, + meta: meta) end end diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 5573c155..4285f4b6 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -30,17 +30,17 @@ class Mapping < ApplicationRecord def after_created if mappable_type == 'Topic' - meta = {'x': xloc, 'y': yloc} - Events::TopicAddedToMap.publish!(self, user, meta) + meta = {'x': xloc, 'y': yloc, 'mapping_id': id} + Events::TopicAddedToMap.publish!(mappable, map, user, meta) elsif mappable_type == 'Synapse' - Events::SynapseAddedToMap.publish!(self, user) + Events::SynapseAddedToMap.publish!(mappable, map, user, meta) end end def after_updated if mappable_type == 'Topic' and (xloc_changed? or yloc_changed?) - meta = {'x': xloc, 'y': yloc} - Events::TopicMovedOnMap.publish!(self, user, meta) + meta = {'x': xloc, 'y': yloc, 'mapping_id': id} + Events::TopicMovedOnMap.publish!(mappable, map, user, meta) end end @@ -51,10 +51,11 @@ class Mapping < ApplicationRecord mappable.save end + meta = {'mapping_id': id} if mappable_type == 'Topic' - Events::TopicRemovedFromMap.publish!(mappable, map, user) + Events::TopicRemovedFromMap.publish!(mappable, map, user, meta) elsif mappable_type == 'Synapse' - Events::SynapseRemovedFromMap.publish!(mappable, map, user) + Events::SynapseRemovedFromMap.publish!(mappable, map, user, meta) end end end diff --git a/app/models/webhooks/slack/synapse_added_to_map.rb b/app/models/webhooks/slack/synapse_added_to_map.rb index 34e743ee..3d944878 100644 --- a/app/models/webhooks/slack/synapse_added_to_map.rb +++ b/app/models/webhooks/slack/synapse_added_to_map.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base def text - connector = eventable.mappable.desc.empty? ? '->' : eventable.mappable.desc - "\"*#{eventable.mappable.topic1.name}* #{connector} *#{eventable.mappable.topic2.name}*\" was added as a connection by *#{event.user.name}* to the map *#{view_map_on_metamaps}*" + connector = eventable.desc.empty? ? '->' : eventable.desc + "\"*#{eventable.topic1.name}* #{connector} *#{eventable.topic2.name}*\" was added as a connection by *#{event.user.name}* to the map *#{view_map_on_metamaps}*" end end diff --git a/app/models/webhooks/slack/topic_added_to_map.rb b/app/models/webhooks/slack/topic_added_to_map.rb index 38cd48dc..4f726069 100644 --- a/app/models/webhooks/slack/topic_added_to_map.rb +++ b/app/models/webhooks/slack/topic_added_to_map.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Webhooks::Slack::TopicAddedToMap < Webhooks::Slack::Base def text - "*#{eventable.mappable.name}* was added by *#{event.user.name}* to the map *#{view_map_on_metamaps}*" + "*#{eventable.name}* was added by *#{event.user.name}* to the map *#{view_map_on_metamaps}*" end # TODO: it would be sweet if it sends it with the metacode as the icon_url end diff --git a/app/models/webhooks/slack/topic_moved_on_map.rb b/app/models/webhooks/slack/topic_moved_on_map.rb index cb8c6aee..dfe088ed 100644 --- a/app/models/webhooks/slack/topic_moved_on_map.rb +++ b/app/models/webhooks/slack/topic_moved_on_map.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true class Webhooks::Slack::TopicMovedOnMap < Webhooks::Slack::Base def text - "*#{eventable.mappable.name}* was moved by *#{event.user.name}* on the map *#{view_map_on_metamaps}*" + "*#{eventable.name}* was moved by *#{event.user.name}* on the map *#{view_map_on_metamaps}*" end end