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 class MapsController < ApplicationController
before_action :require_user, only: %i(create update destroy events follow unfollow) 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 after_action :verify_authorized
# GET maps/:id # GET maps/:id

View file

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

View file

@ -153,11 +153,10 @@ class Map < ApplicationRecord
end end
def after_updated_async def after_updated_async
if ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } return unless ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) }
FollowService.follow(self, updated_by, 'contributed') FollowService.follow(self, updated_by, 'contributed')
# NotificationService.notify_followers(self, 'map_updated', changed_attributes) # NotificationService.notify_followers(self, 'map_updated', changed_attributes)
# or better yet publish an event # or better yet publish an event
end
end end
handle_asynchronously :after_updated_async handle_asynchronously :after_updated_async

View file

@ -53,17 +53,17 @@ class Mapping < ApplicationRecord
handle_asynchronously :after_created_async handle_asynchronously :after_created_async
def after_updated def after_updated
if (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?) return unless (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?)
meta = { 'x': xloc, 'y': yloc, 'mapping_id': id } meta = { 'x': xloc, 'y': yloc, 'mapping_id': id }
Events::TopicMovedOnMap.publish!(mappable, map, updated_by, meta) 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 ActionCable.server.broadcast('map_' + map.id.to_s, type: 'topicMoved',
end id: mappable.id, mapping_id: id,
x: xloc, y: yloc)
end end
def after_updated_async def after_updated_async
if (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?) return unless (mappable_type == 'Topic') && (xloc_changed? || yloc_changed?)
FollowService.follow(map, updated_by, 'contributed') FollowService.follow(map, updated_by, 'contributed')
end
end end
handle_asynchronously :after_updated_async 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' default_url: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png'
# Validate the attached icon is image/jpg, image/png, etc # 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 :aws_xor_manual_icon
validate :manual_icon_https validate :manual_icon_https
@ -56,10 +56,9 @@ class Metacode < ApplicationRecord
end end
def manual_icon_https def manual_icon_https
if manual_icon.present? return unless manual_icon.present?
unless manual_icon.starts_with? 'https' unless manual_icon.starts_with? 'https'
errors.add(:base, 'Manual icon must begin with https') errors.add(:base, 'Manual icon must begin with https')
end
end end
end end
end end

View file

@ -83,15 +83,15 @@ class Synapse < ApplicationRecord
handle_asynchronously :after_created_async handle_asynchronously :after_created_async
def after_updated def after_updated
if ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } 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) } new = attributes.select { |k| ATTRS_TO_WATCH.include?(k) }
meta = new.merge(old) # we are prioritizing the old values, keeping them old = changed_attributes.select { |k| ATTRS_TO_WATCH.include?(k) }
meta['changed'] = changed_attributes.keys.select { |k| ATTRS_TO_WATCH.include?(k) } meta = new.merge(old) # we are prioritizing the old values, keeping them
Events::SynapseUpdated.publish!(self, updated_by, meta) meta['changed'] = changed_attributes.keys.select { |k| ATTRS_TO_WATCH.include?(k) }
maps.each do |map| Events::SynapseUpdated.publish!(self, updated_by, meta)
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'synapseUpdated', id: id maps.each do |map|
end ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'synapseUpdated', id: id
end end
end end

View file

@ -137,9 +137,9 @@ class User < ApplicationRecord
def has_map_open(map) def has_map_open(map)
latest_event = Event.where(map: map, user: self) latest_event = Event.where(map: map, user: self)
.where(kind: %w(user_present_on_map user_not_present_on_map)) .where(kind: %w(user_present_on_map user_not_present_on_map))
.order(:created_at) .order(:created_at)
.last .last
latest_event && latest_event.kind == 'user_present_on_map' latest_event && latest_event.kind == 'user_present_on_map'
end end

View file

@ -3,8 +3,8 @@
class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base
def text def text
connector = eventable.desc.empty? ? '->' : eventable.desc connector = eventable.desc.empty? ? '->' : eventable.desc
"\"*#{eventable.topic1.name}* #{connector} *#{eventable.topic2.name}*\"" + "\"*#{eventable.topic1.name}* #{connector} *#{eventable.topic2.name}*\"" \
" was added as a connection by *#{event.user.name}*" + " was added as a connection by *#{event.user.name}*" \
" to the map *#{view_map_on_metamaps}*" " to the map *#{view_map_on_metamaps}*"
end end
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 # TODO: express correct directionality of arrows when desc is empty
"\"*#{eventable.topic1.name}* #{connector} *#{eventable.topic2.name}*\"" + "\"*#{eventable.topic1.name}* #{connector} *#{eventable.topic2.name}*\"" \
" was removed by *#{event.user.name}* as a connection" + " was removed by *#{event.user.name}* as a connection" \
" from the map *#{view_map_on_metamaps}*" " from the map *#{view_map_on_metamaps}*"
end end
end end

View file

@ -16,7 +16,7 @@ class SynapsePolicy < ApplicationPolicy
end end
def unauthenticated_scope def unauthenticated_scope
return scope.where(permission: %w(public commons)) scope.where(permission: %w(public commons))
end end
end end

View file

@ -3,8 +3,8 @@
class TopicPolicy < ApplicationPolicy class TopicPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
return authenticated_scope if user return authenticated_scope if user
unauthenticated_scope unauthenticated_scope
end end
private private

View file

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