From 794c647967978f30b23543acc154347a35c36c43 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 6 Nov 2017 19:53:49 -0800 Subject: [PATCH] more changes --- app/controllers/maps_controller.rb | 4 +++- app/models/follow.rb | 2 +- app/models/map.rb | 9 ++++----- app/models/mapping.rb | 16 ++++++++-------- app/models/metacode.rb | 9 ++++----- app/models/synapse.rb | 18 +++++++++--------- app/models/user.rb | 6 +++--- .../webhooks/slack/synapse_added_to_map.rb | 6 +++--- .../webhooks/slack/synapse_removed_from_map.rb | 6 +++--- app/policies/synapse_policy.rb | 2 +- app/policies/topic_policy.rb | 4 ++-- app/serializers/api/v2/user_serializer.rb | 1 - app/services/map_activity_service.rb | 4 ++-- 13 files changed, 43 insertions(+), 44 deletions(-) diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index 573f2441..02937c6c 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -2,7 +2,9 @@ class MapsController < ApplicationController before_action :require_user, only: %i(create update destroy events follow unfollow) - before_action :set_map, only: %i(show conversation update destroy contains events export follow unfollow unfollow_from_email) + before_action :set_map, only: %i(show conversation update destroy + contains events export + follow unfollow unfollow_from_email) after_action :verify_authorized # GET maps/:id diff --git a/app/models/follow.rb b/app/models/follow.rb index 66fdb230..01226a8f 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -18,6 +18,6 @@ class Follow < ApplicationRecord private def add_subsetting - follow_reason = FollowReason.create!(follow: self) + FollowReason.create!(follow: self) end end diff --git a/app/models/map.rb b/app/models/map.rb index 6f58af2e..2bdd7b9c 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -153,11 +153,10 @@ class Map < ApplicationRecord end def after_updated_async - if ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } - FollowService.follow(self, updated_by, 'contributed') - # NotificationService.notify_followers(self, 'map_updated', changed_attributes) - # or better yet publish an event - end + return unless ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } + FollowService.follow(self, updated_by, 'contributed') + # NotificationService.notify_followers(self, 'map_updated', changed_attributes) + # or better yet publish an event end handle_asynchronously :after_updated_async diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 5139bad3..693d8ee4 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -53,17 +53,17 @@ class Mapping < ApplicationRecord handle_asynchronously :after_created_async def after_updated - if (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?) - meta = { 'x': xloc, 'y': yloc, 'mapping_id': id } - Events::TopicMovedOnMap.publish!(mappable, map, updated_by, meta) - ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicMoved', id: mappable.id, mapping_id: id, x: xloc, y: yloc - end + return unless (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?) + meta = { 'x': xloc, 'y': yloc, 'mapping_id': id } + Events::TopicMovedOnMap.publish!(mappable, map, updated_by, meta) + ActionCable.server.broadcast('map_' + map.id.to_s, type: 'topicMoved', + id: mappable.id, mapping_id: id, + x: xloc, y: yloc) end def after_updated_async - if (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?) - FollowService.follow(map, updated_by, 'contributed') - end + return unless (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?) + FollowService.follow(map, updated_by, 'contributed') end handle_asynchronously :after_updated_async diff --git a/app/models/metacode.rb b/app/models/metacode.rb index 4a099d76..672a32a3 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -12,7 +12,7 @@ class Metacode < ApplicationRecord default_url: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png' # Validate the attached icon is image/jpg, image/png, etc - validates_attachment_content_type :aws_icon, content_type: /\Aimage\/.*\Z/ + validates_attachment_content_type :aws_icon, content_type: %r(\Aimage/.*\Z) validate :aws_xor_manual_icon validate :manual_icon_https @@ -56,10 +56,9 @@ class Metacode < ApplicationRecord end def manual_icon_https - if manual_icon.present? - unless manual_icon.starts_with? 'https' - errors.add(:base, 'Manual icon must begin with https') - end + return unless manual_icon.present? + unless manual_icon.starts_with? 'https' + errors.add(:base, 'Manual icon must begin with https') end end end diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 7e09ad2e..296edc62 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -83,15 +83,15 @@ class Synapse < ApplicationRecord handle_asynchronously :after_created_async def after_updated - if ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } - new = attributes.select { |k| ATTRS_TO_WATCH.include?(k) } - old = changed_attributes.select { |k| ATTRS_TO_WATCH.include?(k) } - meta = new.merge(old) # we are prioritizing the old values, keeping them - meta['changed'] = changed_attributes.keys.select { |k| ATTRS_TO_WATCH.include?(k) } - Events::SynapseUpdated.publish!(self, updated_by, meta) - maps.each do |map| - ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'synapseUpdated', id: id - end + return unless ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } + + new = attributes.select { |k| ATTRS_TO_WATCH.include?(k) } + old = changed_attributes.select { |k| ATTRS_TO_WATCH.include?(k) } + meta = new.merge(old) # we are prioritizing the old values, keeping them + meta['changed'] = changed_attributes.keys.select { |k| ATTRS_TO_WATCH.include?(k) } + Events::SynapseUpdated.publish!(self, updated_by, meta) + maps.each do |map| + ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'synapseUpdated', id: id end end diff --git a/app/models/user.rb b/app/models/user.rb index f426aa1a..2e3258ac 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -137,9 +137,9 @@ class User < ApplicationRecord def has_map_open(map) latest_event = Event.where(map: map, user: self) - .where(kind: %w(user_present_on_map user_not_present_on_map)) - .order(:created_at) - .last + .where(kind: %w(user_present_on_map user_not_present_on_map)) + .order(:created_at) + .last latest_event && latest_event.kind == 'user_present_on_map' end diff --git a/app/models/webhooks/slack/synapse_added_to_map.rb b/app/models/webhooks/slack/synapse_added_to_map.rb index 06be478c..5ee2b8f9 100644 --- a/app/models/webhooks/slack/synapse_added_to_map.rb +++ b/app/models/webhooks/slack/synapse_added_to_map.rb @@ -3,8 +3,8 @@ class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base def text 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}*" + "\"*#{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/synapse_removed_from_map.rb b/app/models/webhooks/slack/synapse_removed_from_map.rb index d01de37a..9617d0ab 100644 --- a/app/models/webhooks/slack/synapse_removed_from_map.rb +++ b/app/models/webhooks/slack/synapse_removed_from_map.rb @@ -6,8 +6,8 @@ class Webhooks::Slack::SynapseRemovedFromMap < Webhooks::Slack::Base # TODO: express correct directionality of arrows when desc is empty - "\"*#{eventable.topic1.name}* #{connector} *#{eventable.topic2.name}*\"" + - " was removed by *#{event.user.name}* as a connection" + - " from the map *#{view_map_on_metamaps}*" + "\"*#{eventable.topic1.name}* #{connector} *#{eventable.topic2.name}*\"" \ + " was removed by *#{event.user.name}* as a connection" \ + " from the map *#{view_map_on_metamaps}*" end end diff --git a/app/policies/synapse_policy.rb b/app/policies/synapse_policy.rb index 69d2f9de..85a507b7 100644 --- a/app/policies/synapse_policy.rb +++ b/app/policies/synapse_policy.rb @@ -16,7 +16,7 @@ class SynapsePolicy < ApplicationPolicy end def unauthenticated_scope - return scope.where(permission: %w(public commons)) + scope.where(permission: %w(public commons)) end end diff --git a/app/policies/topic_policy.rb b/app/policies/topic_policy.rb index b7c19721..635dc286 100644 --- a/app/policies/topic_policy.rb +++ b/app/policies/topic_policy.rb @@ -3,8 +3,8 @@ class TopicPolicy < ApplicationPolicy class Scope < Scope def resolve - return authenticated_scope if user - unauthenticated_scope + return authenticated_scope if user + unauthenticated_scope end private diff --git a/app/serializers/api/v2/user_serializer.rb b/app/serializers/api/v2/user_serializer.rb index f23df5b7..f458e7a0 100644 --- a/app/serializers/api/v2/user_serializer.rb +++ b/app/serializers/api/v2/user_serializer.rb @@ -17,7 +17,6 @@ module Api object.image.url(:sixtyfour) end - # rubocop:disable Style/PredicateName def is_admin object.admin end diff --git a/app/services/map_activity_service.rb b/app/services/map_activity_service.rb index 31ba70ac..d58f0a63 100644 --- a/app/services/map_activity_service.rb +++ b/app/services/map_activity_service.rb @@ -43,7 +43,7 @@ class MapActivityService num_adds = topics_added_events.where(eventable_id: ta.eventable_id).count num_removes = topics_removed_events.where(eventable_id: ta.eventable_id).count if num_adds > num_removes && scoped_topic_ids.include?(ta.eventable.id) - topics_added_to_include[ta.eventable_id] = ta + topics_added_to_include[ta.eventable_id] = ta end end unless topics_added_to_include.keys.empty? @@ -79,7 +79,7 @@ class MapActivityService num_adds = synapses_added_events.where(eventable_id: ta.eventable_id).count num_removes = synapses_removed_events.where(eventable_id: ta.eventable_id).count if num_adds > num_removes && scoped_synapse_ids.include?(ta.eventable.id) - synapses_added_to_include[ta.eventable_id] = ta + synapses_added_to_include[ta.eventable_id] = ta end end unless synapses_added_to_include.keys.empty?