From b7761a3627367a9e04dee6cd780c19bf8fb4a891 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 21 Jan 2018 14:21:00 -0800 Subject: [PATCH] manual rubocop fixes (#1163) --- .rubocop.yml | 5 ++ app/controllers/maps_controller.rb | 4 +- app/helpers/topics_helper.rb | 2 +- app/models/event.rb | 2 +- app/models/follow.rb | 6 +-- app/models/map.rb | 9 ++-- app/models/mapping.rb | 20 ++++---- app/models/metacode.rb | 25 ++++------ app/models/permitted_params.rb | 8 +++- app/models/synapse.rb | 24 +++++----- app/models/topic.rb | 45 ++++++++---------- app/models/user.rb | 30 +++++++----- app/models/user_preference.rb | 18 ++++--- .../webhooks/slack/synapse_added_to_map.rb | 4 +- .../slack/synapse_removed_from_map.rb | 6 ++- app/policies/map_policy.rb | 2 +- app/policies/synapse_policy.rb | 11 ++++- app/policies/topic_policy.rb | 11 ++++- app/serializers/api/v2/user_serializer.rb | 1 - app/services/follow_service.rb | 30 +++++------- app/services/map_activity_service.rb | 20 +++++--- app/services/notification_service.rb | 14 ++++-- app/views/metacode_sets/_form.html.erb | 8 ++-- app/views/metacode_sets/edit.html.erb | 2 +- app/views/metacode_sets/new.html.erb | 2 +- config/environments/development.rb | 2 +- config/environments/production.rb | 4 +- config/initializers/delayed_job.rb | 2 +- config/initializers/internal_testers.rb | 5 +- spec/controllers/explore_controller_spec.rb | 2 +- spec/controllers/synapses_controller_spec.rb | 5 +- .../previews/map_activity_mailer_preview.rb | 14 ++++-- spec/rails_helper.rb | 4 +- spec/services/map_activity_service_spec.rb | 47 +++++++++++++------ spec/support/schema_matcher.rb | 9 ++-- 35 files changed, 234 insertions(+), 169 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index efb2fbab..05142581 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -22,3 +22,8 @@ Style/Documentation: Style/EmptyMethod: EnforcedStyle: expanded + +# I like this cop, but occasionally code is more readable without a guard clause, +# and I don't want to write rubocop:disable comments every time that happens +Style/GuardClause: + Enabled: false diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index b6a6687e..f253efd5 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/helpers/topics_helper.rb b/app/helpers/topics_helper.rb index 2cc5e85d..9a605835 100644 --- a/app/helpers/topics_helper.rb +++ b/app/helpers/topics_helper.rb @@ -17,7 +17,7 @@ module TopicsHelper rtype: is_map ? 'map' : 'topic', inmaps: is_map ? [] : t.inmaps(current_user), - inmapsLinks: is_map ? [] : t.inmapsLinks(current_user), + inmapsLinks: is_map ? [] : t.inmaps_links(current_user), type: is_map ? metamap_metacode.name : t.metacode.name, typeImageURL: is_map ? metamap_metacode.icon : t.metacode.icon, mapCount: is_map ? 0 : t.maps.count, diff --git a/app/models/event.rb b/app/models/event.rb index e4da5c82..21e4640d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -11,7 +11,7 @@ class Event < ApplicationRecord belongs_to :map belongs_to :user - scope :chronologically, -> { order('created_at asc') } + scope :chronologically, (-> { order('created_at asc') }) after_create :notify_webhooks!, if: :map diff --git a/app/models/follow.rb b/app/models/follow.rb index 66fdb230..dc61ae8c 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -11,13 +11,11 @@ class Follow < ApplicationRecord after_create :add_subsetting - scope :active, -> { - where(muted: false) - } + scope :active, (-> { where(muted: false) }) 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 321c3de1..d07e7df0 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 a3ea037b..5d04fe64 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class Mapping < ApplicationRecord - scope :topicmapping, -> { where(mappable_type: :Topic) } - scope :synapsemapping, -> { where(mappable_type: :Synapse) } + scope :topicmapping, (-> { where(mappable_type: :Topic) }) + scope :synapsemapping, (-> { where(mappable_type: :Synapse) }) belongs_to :mappable, polymorphic: true belongs_to :map, class_name: 'Map', foreign_key: 'map_id', touch: true @@ -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..445967c1 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -6,13 +6,11 @@ class Metacode < ApplicationRecord has_many :topics # This method associates the attribute ":aws_icon" with a file attachment - has_attached_file :aws_icon, styles: { - ninetysix: ['96x96#', :png] - }, + has_attached_file :aws_icon, styles: { ninetysix: ['96x96#', :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 - 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 @@ -31,15 +29,13 @@ class Metacode < ApplicationRecord def as_json(options = {}) default = super(options) default[:icon] = icon - default.except('aws_icon_file_name', 'aws_icon_content_type', 'aws_icon_file_size', 'aws_icon_updated_at', 'manual_icon') + default.except( + 'aws_icon_file_name', 'aws_icon_content_type', 'aws_icon_file_size', 'aws_icon_updated_at', + 'manual_icon' + ) end - def hasSelected(user) - return true if user.settings.metacodes.include? id.to_s - false - end - - def inMetacodeSet(metacode_set) + def in_metacode_set(metacode_set) return true if metacode_sets.include? metacode_set false end @@ -56,10 +52,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 if manual_icon.blank? + unless manual_icon.starts_with? 'https' + errors.add(:base, 'Manual icon must begin with https') end end end diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb index 5916c870..83ed67f2 100644 --- a/app/models/permitted_params.rb +++ b/app/models/permitted_params.rb @@ -1,14 +1,18 @@ # frozen_string_literal: true -class PermittedParams < Struct.new(:params) +class PermittedParams %w[map synapse topic mapping token].each do |kind| define_method(kind) do permitted_attributes = send("#{kind}_attributes") - params.require(kind).permit(*permitted_attributes) + @params.require(kind).permit(*permitted_attributes) end alias_method :"api_#{kind}", kind.to_sym end + def initialize(params) + @params = params + end + alias read_attribute_for_serialization send def token_attributes diff --git a/app/models/synapse.rb b/app/models/synapse.rb index 9ffc5cf7..c016a58c 100644 --- a/app/models/synapse.rb +++ b/app/models/synapse.rb @@ -22,9 +22,9 @@ class Synapse < ApplicationRecord validates :category, inclusion: { in: ['from-to', 'both'], allow_nil: true } - scope :for_topic, ->(topic_id = nil) { + scope :for_topic, (lambda do |topic_id = nil| where(topic1_id: topic_id).or(where(topic2_id: topic_id)) - } + end) before_create :set_perm_by_defer after_create :after_created_async @@ -73,7 +73,7 @@ class Synapse < ApplicationRecord protected def set_perm_by_defer - permission = defer_to_map.permission if defer_to_map + defer_to_map&.permission end def after_created_async @@ -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/topic.rb b/app/models/topic.rb index 538f0c0e..5c7e3127 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -39,13 +39,13 @@ class Topic < ApplicationRecord topics1.or(topics2) end - scope :relatives, ->(topic_id = nil, user = nil) { + scope :relatives, (lambda do |topic_id = nil, user = nil| # should only see topics through *visible* synapses # e.g. Topic A (commons) -> synapse (private) -> Topic B (commons) must be filtered out topic_ids = Pundit.policy_scope(user, Synapse.where(topic1_id: topic_id)).pluck(:topic2_id) topic_ids += Pundit.policy_scope(user, Synapse.where(topic2_id: topic_id)).pluck(:topic1_id) where(id: topic_ids.uniq) - } + end) delegate :name, to: :user, prefix: true @@ -65,13 +65,13 @@ class Topic < ApplicationRecord Pundit.policy_scope(user, maps).map(&:name) end - def inmapsLinks(user) + def inmaps_links(user) Pundit.policy_scope(user, maps).map(&:id) end def as_json(options = {}) super(methods: %i[user_name user_image collaborator_ids]) - .merge(inmaps: inmaps(options[:user]), inmapsLinks: inmapsLinks(options[:user]), + .merge(inmaps: inmaps(options[:user]), inmapsLinks: inmaps_links(options[:user]), map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user])) end @@ -127,14 +127,9 @@ class Topic < ApplicationRecord end end end - if output_format == 'array' - return output - elsif output_format == 'text' - return output.join('; ') - else - raise 'invalid argument to synapses_csv' - end - output + return output if output_format == 'array' + return output.join('; ') if output_format == 'text' + raise 'invalid argument to synapses_csv' end def topic_autocomplete_method @@ -144,7 +139,7 @@ class Topic < ApplicationRecord protected def set_perm_by_defer - permission = defer_to_map.permission if defer_to_map + self.permission = defer_to_map.permission if defer_to_map end def create_metamap? @@ -163,22 +158,22 @@ class Topic < 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::TopicUpdated.publish!(self, updated_by, meta) - maps.each do |map| - ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicUpdated', 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::TopicUpdated.publish!(self, updated_by, meta) + maps.each do |map| + ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicUpdated', id: id end end def after_updated_async - if ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } - FollowService.follow(self, updated_by, 'contributed') - end + return unless ATTRS_TO_WATCH.any? { |k| changed_attributes.key?(k) } + + FollowService.follow(self, updated_by, 'contributed') end handle_asynchronously :after_updated_async diff --git a/app/models/user.rb b/app/models/user.rb index cc70c0a2..033e3ff6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,24 +52,24 @@ class User < ApplicationRecord validates_attachment_content_type :image, content_type: %r{\Aimage/.*\Z} # override default as_json - def as_json(_options = {}) + def as_json(options = {}) json = { id: id, name: name, image: image.url(:sixtyfour), admin: admin } - if _options[:follows] + if options[:follows] json['follows'] = { topics: following.active.where(followed_type: 'Topic').to_a.map(&:followed_id), maps: following.active.where(followed_type: 'Map').to_a.map(&:followed_id) } end - if _options[:follow_settings] + if options[:follow_settings] json['follow_topic_on_created'] = settings.follow_topic_on_created == '1' json['follow_topic_on_contributed'] = settings.follow_topic_on_contributed == '1' json['follow_map_on_created'] = settings.follow_map_on_created == '1' json['follow_map_on_contributed'] = settings.follow_map_on_contributed == '1' end - json['email'] = email if _options[:email] + json['email'] = email if options[:email] json end @@ -106,10 +106,14 @@ class User < ApplicationRecord end def most_used_metacodes - topics.to_a.each_with_object(Hash.new(0)) do |topic, memo| - memo[topic.metacode_id] += 1 - memo - end.to_a.sort { |a, b| b[1] <=> a[1] }.map { |i| i[0] }.slice(0, 5) + metacode_counts = topics.to_a.each_with_object(Hash.new(0)) do |topic, list_so_far| + list_so_far[topic.metacode_id] += 1 + list_so_far + end + id_count_pairs = metacode_counts.to_a + id_count_pairs.sort! { |a, b| b[1] <=> a[1] } + metacode_ids = id_count_pairs.map { |i| i[0] } + metacode_ids.slice(0, 5) end # generate a random 8 letter/digit code that they can use to invite people @@ -132,11 +136,11 @@ class User < ApplicationRecord end def has_map_open(map) - latestEvent = Event.where(map: map, user: self) - .where(kind: %w[user_present_on_map user_not_present_on_map]) - .order(:created_at) - .last - latestEvent && latestEvent.kind == 'user_present_on_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 + latest_event && latest_event.kind == 'user_present_on_map' end def has_map_with_synapse_open(synapse) diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index e227f601..7d725274 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -5,20 +5,24 @@ class UserPreference :follow_map_on_created, :follow_map_on_contributed def initialize - array = [] - %w[Action Aim Idea Question Note Wildcard Subject].each do |m| + @metacodes = init_metacodes.compact + @metacode_focus = @metacodes[0] + initialize_follow_settings + end + + private + + def init_metacodes + %w[Action Aim Idea Question Note Wildcard Subject].map do |m| begin metacode = Metacode.find_by(name: m) - array.push(metacode.id.to_s) if metacode + metacode.id.to_s if metacode rescue ActiveRecord::StatementInvalid if m == 'Action' Rails.logger.warn('TODO: remove this travis workaround in user_preference.rb') end end - end - @metacodes = array - @metacode_focus = array[0] - initialize_follow_settings + end.compact end def initialize_follow_settings diff --git a/app/models/webhooks/slack/synapse_added_to_map.rb b/app/models/webhooks/slack/synapse_added_to_map.rb index 5f9ad239..5ee2b8f9 100644 --- a/app/models/webhooks/slack/synapse_added_to_map.rb +++ b/app/models/webhooks/slack/synapse_added_to_map.rb @@ -3,6 +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 01940a7c..9617d0ab 100644 --- a/app/models/webhooks/slack/synapse_removed_from_map.rb +++ b/app/models/webhooks/slack/synapse_removed_from_map.rb @@ -3,7 +3,11 @@ class Webhooks::Slack::SynapseRemovedFromMap < Webhooks::Slack::Base def text connector = eventable.desc.empty? ? '->' : eventable.desc + # 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/map_policy.rb b/app/policies/map_policy.rb index 308d1ce9..07829b9f 100644 --- a/app/policies/map_policy.rb +++ b/app/policies/map_policy.rb @@ -23,7 +23,7 @@ class MapPolicy < ApplicationPolicy end def conversation? - show? && %w[connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com].include?(user.email) + show? && is_tester(user) end def create? diff --git a/app/policies/synapse_policy.rb b/app/policies/synapse_policy.rb index 0658343f..0d9e8efa 100644 --- a/app/policies/synapse_policy.rb +++ b/app/policies/synapse_policy.rb @@ -3,12 +3,21 @@ class SynapsePolicy < ApplicationPolicy class Scope < Scope def resolve - return scope.where(permission: %w[public commons]) unless user + return authenticated_scope if user + unauthenticated_scope + end + private + + def authenticated_scope scope.where(permission: %w[public commons]) .or(scope.where(defer_to_map_id: user.all_accessible_maps.map(&:id))) .or(scope.where(user_id: user.id)) end + + def unauthenticated_scope + scope.where(permission: %w[public commons]) + end end def index? diff --git a/app/policies/topic_policy.rb b/app/policies/topic_policy.rb index fa19a4f1..025010f0 100644 --- a/app/policies/topic_policy.rb +++ b/app/policies/topic_policy.rb @@ -3,12 +3,21 @@ class TopicPolicy < ApplicationPolicy class Scope < Scope def resolve - return scope.where(permission: %w[public commons]) unless user + return authenticated_scope if user + unauthenticated_scope + end + private + + def authenticated_scope scope.where(permission: %w[public commons]) .or(scope.where(defer_to_map_id: user.all_accessible_maps.map(&:id))) .or(scope.where(user_id: user.id)) end + + def unauthenticated_scope + scope.where(permission: %w[public commons]) + end end def index? 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/follow_service.rb b/app/services/follow_service.rb index 173d56ba..09f33240 100644 --- a/app/services/follow_service.rb +++ b/app/services/follow_service.rb @@ -18,20 +18,20 @@ class FollowService def unfollow(entity, user) follow = Follow.where(followed: entity, user: user).first - if follow - unless follow.update(muted: true) - raise follow.errors.full_messages.join("\n") - end + return unless follow + + unless follow.update(muted: true) + raise follow.errors.full_messages.join("\n") end end def remove_reason(entity, user, reason) return unless FollowReason::REASONS.include?(reason) follow = Follow.where(followed: entity, user: user).first - if follow - follow.follow_reason.update_attribute(reason, false) - follow.destroy unless follow.follow_reason.has_reason - end + return unless follow + + follow.follow_reason.update_attribute(reason, false) + follow.destroy unless follow.follow_reason.has_reason end protected @@ -40,17 +40,11 @@ class FollowService follow = Follow.where(followed: entity, user: user).first return false if follow && follow.muted if entity.class == Topic - if reason == 'created' - return user.settings.follow_topic_on_created == '1' - elsif reason == 'contributed' - return user.settings.follow_topic_on_contributed == '1' - end + return user.settings.follow_topic_on_created == '1' if reason == 'created' + return user.settings.follow_topic_on_contributed == '1' if reason == 'contributed' elsif entity.class == Map - if reason == 'created' - return user.settings.follow_map_on_created == '1' - elsif reason == 'contributed' - return user.settings.follow_map_on_contributed == '1' - end + return user.settings.follow_map_on_created == '1' if reason == 'created' + return user.settings.follow_map_on_contributed == '1' if reason == 'contributed' end end end diff --git a/app/services/map_activity_service.rb b/app/services/map_activity_service.rb index 5bfafa24..d58f0a63 100644 --- a/app/services/map_activity_service.rb +++ b/app/services/map_activity_service.rb @@ -5,7 +5,7 @@ class MapActivityService 'Activity on map ' + map.name end - def self.summarize_data(map, user, until_moment = DateTime.now) + def self.summarize_data(map, user, until_moment = DateTime.current) results = { stats: {} } @@ -18,7 +18,7 @@ class MapActivityService message_count = Message.where(resource: map) .where('created_at > ? AND created_at < ?', since, until_moment) .where.not(user: user).count - results[:stats][:messages_sent] = message_count if message_count > 0 + results[:stats][:messages_sent] = message_count if message_count.positive? moved_count = Event.where(kind: 'topic_moved_on_map', map: map) .where('created_at > ? AND created_at < ?', since, until_moment) @@ -42,7 +42,9 @@ class MapActivityService topics_added_events.each do |ta| num_adds = topics_added_events.where(eventable_id: ta.eventable_id).count num_removes = topics_removed_events.where(eventable_id: ta.eventable_id).count - topics_added_to_include[ta.eventable_id] = ta if num_adds > num_removes && scoped_topic_ids.include?(ta.eventable.id) + if num_adds > num_removes && scoped_topic_ids.include?(ta.eventable.id) + topics_added_to_include[ta.eventable_id] = ta + end end unless topics_added_to_include.keys.empty? results[:stats][:topics_added] = topics_added_to_include.keys.length @@ -53,7 +55,9 @@ class MapActivityService topics_removed_events.each do |ta| num_adds = topics_added_events.where(eventable_id: ta.eventable_id).count num_removes = topics_removed_events.where(eventable_id: ta.eventable_id).count - topics_removed_to_include[ta.eventable_id] = ta if num_removes > num_adds && TopicPolicy.new(user, ta.eventable).show? + if num_removes > num_adds && TopicPolicy.new(user, ta.eventable).show? + topics_removed_to_include[ta.eventable_id] = ta + end end unless topics_removed_to_include.keys.empty? results[:stats][:topics_removed] = topics_removed_to_include.keys.length @@ -74,7 +78,9 @@ class MapActivityService synapses_added_events.each do |ta| num_adds = synapses_added_events.where(eventable_id: ta.eventable_id).count num_removes = synapses_removed_events.where(eventable_id: ta.eventable_id).count - synapses_added_to_include[ta.eventable_id] = ta if num_adds > num_removes && scoped_synapse_ids.include?(ta.eventable.id) + if num_adds > num_removes && scoped_synapse_ids.include?(ta.eventable.id) + synapses_added_to_include[ta.eventable_id] = ta + end end unless synapses_added_to_include.keys.empty? results[:stats][:synapses_added] = synapses_added_to_include.keys.length @@ -85,7 +91,9 @@ class MapActivityService synapses_removed_events.each do |ta| num_adds = synapses_added_events.where(eventable_id: ta.eventable_id).count num_removes = synapses_removed_events.where(eventable_id: ta.eventable_id).count - synapses_removed_to_include[ta.eventable_id] = ta if num_removes > num_adds && SynapsePolicy.new(user, ta.eventable).show? + if num_removes > num_adds && SynapsePolicy.new(user, ta.eventable).show? + synapses_removed_to_include[ta.eventable_id] = ta + end end unless synapses_removed_to_include.keys.empty? results[:stats][:synapses_removed] = synapses_removed_to_include.keys.length diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index e78c1bd3..f3ccf9c8 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -7,7 +7,7 @@ class NotificationService include ActionView::Helpers::SanitizeHelper def self.renderer - renderer ||= ApplicationController.renderer.new( + @renderer ||= ApplicationController.renderer.new( http_host: ENV['MAILER_DEFAULT_URL'], https: Rails.env.production? ? true : false ) @@ -70,19 +70,25 @@ class NotificationService def self.access_request(request) subject = access_request_subject(request.map) - body = renderer.render(template: 'map_mailer/access_request', locals: { map: request.map, request: request }, layout: false) + body = renderer.render(template: 'map_mailer/access_request', + locals: { map: request.map, request: request }, + layout: false) request.map.user.notify(subject, body, request, false, MAP_ACCESS_REQUEST, true, request.user) end def self.access_approved(request) subject = access_approved_subject(request.map) - body = renderer.render(template: 'map_mailer/access_approved', locals: { map: request.map }, layout: false) + body = renderer.render(template: 'map_mailer/access_approved', + locals: { map: request.map }, + layout: false) request.user.notify(subject, body, request, false, MAP_ACCESS_APPROVED, true, request.map.user) end def self.invite_to_edit(user_map) subject = invite_to_edit_subject(user_map.map) - body = renderer.render(template: 'map_mailer/invite_to_edit', locals: { map: user_map.map, inviter: user_map.map.user }, layout: false) + body = renderer.render(template: 'map_mailer/invite_to_edit', + locals: { map: user_map.map, inviter: user_map.map.user }, + layout: false) user_map.user.notify(subject, body, user_map, false, MAP_INVITE_TO_EDIT, true, user_map.map.user) end diff --git a/app/views/metacode_sets/_form.html.erb b/app/views/metacode_sets/_form.html.erb index b3d3f018..f209eece 100644 --- a/app/views/metacode_sets/_form.html.erb +++ b/app/views/metacode_sets/_form.html.erb @@ -35,7 +35,7 @@ <% $i = 0 %> <% @m = Metacode.order("name").all %> <% while $i < (Metacode.all.length / 4) do %> -
  • class="toggledOff"<% end %> +
  • class="toggledOff"<% end %> onclick="Metamaps.Admin.liClickHandler.call(this);"> <%= @m[$i].name %>

    <%= @m[$i].name.downcase %>

    @@ -46,7 +46,7 @@