more changes

This commit is contained in:
Devin Howard 2017-11-06 19:53:49 -08:00
parent b4348a7e78
commit 794c647967
13 changed files with 43 additions and 44 deletions

View file

@ -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

View file

@ -18,6 +18,6 @@ class Follow < ApplicationRecord
private
def add_subsetting
follow_reason = FollowReason.create!(follow: self)
FollowReason.create!(follow: self)
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -17,7 +17,6 @@ module Api
object.image.url(:sixtyfour)
end
# rubocop:disable Style/PredicateName
def is_admin
object.admin
end

View file

@ -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?