fix codeclimate style issues (#1046)
* bunch of code climate fixes * more
This commit is contained in:
parent
0ad10c0f5a
commit
d16709e8e7
39 changed files with 266 additions and 213 deletions
|
@ -19,3 +19,6 @@ Metrics/AbcSize:
|
|||
|
||||
Style/Documentation:
|
||||
Enabled: false
|
||||
|
||||
Style/EmptyMethod:
|
||||
EnforcedStyle: expanded
|
||||
|
|
8
Gemfile
8
Gemfile
|
@ -9,7 +9,6 @@ gem 'aws-sdk'
|
|||
gem 'best_in_place'
|
||||
gem 'delayed_job'
|
||||
gem 'delayed_job_active_record'
|
||||
gem 'sucker_punch'
|
||||
gem 'devise'
|
||||
gem 'doorkeeper'
|
||||
gem 'dotenv-rails'
|
||||
|
@ -20,6 +19,7 @@ gem 'kaminari'
|
|||
gem 'mailboxer'
|
||||
gem 'paperclip'
|
||||
gem 'pg'
|
||||
gem 'puma'
|
||||
gem 'pundit'
|
||||
gem 'pundit_extra'
|
||||
gem 'rack-attack'
|
||||
|
@ -27,7 +27,7 @@ gem 'rack-cors'
|
|||
gem 'redis'
|
||||
gem 'slack-notifier'
|
||||
gem 'snorlax'
|
||||
gem 'puma'
|
||||
gem 'sucker_punch'
|
||||
|
||||
# asset stuff
|
||||
gem 'jquery-rails'
|
||||
|
@ -36,12 +36,12 @@ gem 'sass-rails'
|
|||
gem 'uglifier'
|
||||
|
||||
group :test do
|
||||
gem 'brakeman', require: false
|
||||
gem 'factory_girl_rails'
|
||||
gem 'json-schema'
|
||||
gem 'rspec-rails'
|
||||
gem 'shoulda-matchers'
|
||||
gem 'simplecov', require: false
|
||||
gem 'brakeman', require: false
|
||||
end
|
||||
|
||||
group :development, :test do
|
||||
|
@ -49,6 +49,6 @@ group :development, :test do
|
|||
gem 'binding_of_caller'
|
||||
gem 'pry-byebug'
|
||||
gem 'pry-rails'
|
||||
gem 'tunemygc'
|
||||
gem 'rubocop'
|
||||
gem 'tunemygc'
|
||||
end
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// eslint-disable spaced-comment
|
||||
// JS and CSS bundles
|
||||
//= link_directory ../javascripts .js
|
||||
//= link_directory ../stylesheets .css
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// eslint-disable spaced-comment
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
|
@ -11,6 +10,7 @@
|
|||
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
||||
// GO AFTER THE REQUIRES BELOW.
|
||||
//
|
||||
/* eslint-disable spaced-comment */
|
||||
//= require jquery3
|
||||
//= require jquery-ui
|
||||
//= require jquery_ujs
|
||||
|
@ -19,3 +19,4 @@
|
|||
//= require ./webpacked/metamaps.bundle
|
||||
//= require ./Metamaps.ServerData
|
||||
//= require homepageVimeoFallback
|
||||
/* eslint-enable spaced-comment */
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/* global $ */
|
||||
|
||||
$(document).ready(function () {
|
||||
$(document).ready(function() {
|
||||
if (window.location.pathname === '/') {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'https://player.vimeo.com',
|
||||
error: function (e) {
|
||||
error: function(e) {
|
||||
$('.homeVideo').hide()
|
||||
$('.homeVideo').replaceWith($('<video/>', {
|
||||
poster: '/assets/metamaps-intro-poster.webp',
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
module ApplicationCable
|
||||
class Channel < ActionCable::Channel::Base
|
||||
end
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
class MapChannel < ApplicationCable::Channel
|
||||
# Called when the consumer has successfully
|
||||
# become a subscriber of this channel.
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
class AccessController < ApplicationController
|
||||
before_action :require_user, only: [:access, :access_request, :approve_access, :approve_access_post,
|
||||
before_action :require_user, only: [:access, :access_request,
|
||||
:approve_access, :approve_access_post,
|
||||
:deny_access, :deny_access_post, :request_access]
|
||||
before_action :set_map, only: [:access, :access_request, :approve_access, :approve_access_post,
|
||||
before_action :set_map, only: [:access, :access_request,
|
||||
:approve_access, :approve_access_post,
|
||||
:deny_access, :deny_access_post, :request_access]
|
||||
after_action :verify_authorized
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ module Api
|
|||
|
||||
def token_user
|
||||
token = params[:access_token]
|
||||
access_token = Token.find_by_token(token)
|
||||
access_token = Token.find_by(token: token)
|
||||
@token_user ||= access_token.user if access_token
|
||||
end
|
||||
|
||||
|
@ -160,7 +160,7 @@ module Api
|
|||
def search_by_q(collection)
|
||||
table = resource_class.arel_table
|
||||
safe_query = "%#{params[:q].gsub(/[%_]/, '\\\\\0')}%"
|
||||
search_column = -> (column) { table[column].matches(safe_query) }
|
||||
search_column = ->(column) { table[column].matches(safe_query) }
|
||||
|
||||
condition = searchable_columns.reduce(nil) do |prev, column|
|
||||
next search_column.call(column) if prev.nil?
|
||||
|
|
|
@ -5,7 +5,6 @@ class HacksController < ApplicationController
|
|||
include ActionView::Helpers::TextHelper # string truncate method
|
||||
|
||||
# rate limited by rack-attack - currently 5r/s
|
||||
# TODO: what else can we do to make get_with_redirects safer?
|
||||
def load_url_title
|
||||
authorize :Hack
|
||||
url = params[:url]
|
||||
|
|
|
@ -55,8 +55,13 @@ class MetacodeSetsController < ApplicationController
|
|||
@metacodes.each do |m|
|
||||
InMetacodeSet.create(metacode_id: m, metacode_set_id: @metacode_set.id)
|
||||
end
|
||||
format.html { redirect_to metacode_sets_url, notice: 'Metacode set was successfully created.' }
|
||||
format.json { render json: @metacode_set, status: :created, location: metacode_sets_url }
|
||||
format.html do
|
||||
redirect_to metacode_sets_url,
|
||||
notice: 'Metacode set was successfully created.'
|
||||
end
|
||||
format.json do
|
||||
render json: @metacode_set, status: :created, location: metacode_sets_url
|
||||
end
|
||||
else
|
||||
format.html { render action: 'new' }
|
||||
format.json { render json: @metacode_set.errors, status: :unprocessable_entity }
|
||||
|
@ -73,20 +78,20 @@ class MetacodeSetsController < ApplicationController
|
|||
if @metacode_set.update_attributes(metacode_set_params)
|
||||
|
||||
# build an array of the IDs of the metacodes currently in the set
|
||||
@currentMetacodes = @metacode_set.metacodes.map { |m| m.id.to_s }
|
||||
current_metacodes = @metacode_set.metacodes.map { |m| m.id.to_s }
|
||||
# get the list of desired metacodes for the set from the user input and build an array out of it
|
||||
@newMetacodes = params[:metacodes][:value].split(',')
|
||||
new_metacodes = params[:metacodes][:value].split(',')
|
||||
|
||||
# remove the metacodes that were in it, but now aren't
|
||||
@removedMetacodes = @currentMetacodes - @newMetacodes
|
||||
@removedMetacodes.each do |m|
|
||||
@inmetacodeset = InMetacodeSet.find_by_metacode_id_and_metacode_set_id(m, @metacode_set.id)
|
||||
@inmetacodeset.destroy
|
||||
removed_metacodes = current_metacodes - new_metacodes
|
||||
removed_metacodes.each do |m|
|
||||
inmetacodeset = InMetacodeSet.find_by(metacode_id: m, metacode_set_id: @metacode_set.id)
|
||||
inmetacodeset.destroy
|
||||
end
|
||||
|
||||
# add the new metacodes
|
||||
@addedMetacodes = @newMetacodes - @currentMetacodes
|
||||
@addedMetacodes.each do |m|
|
||||
added_metacodes = new_metacodes - current_metacodes
|
||||
added_metacodes.each do |m|
|
||||
InMetacodeSet.create(metacode_id: m, metacode_set_id: @metacode_set.id)
|
||||
end
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@ class SearchController < ApplicationController
|
|||
term = params[:term]
|
||||
user = params[:user] ? params[:user] : false
|
||||
|
||||
if term && !term.empty? && term.downcase[0..3] != 'map:' && term.downcase[0..6] != 'mapper:' && !term.casecmp('topic:').zero?
|
||||
if term.present? && term.downcase[0..3] != 'map:' &&
|
||||
term.downcase[0..6] != 'mapper:' && !term.casecmp('topic:').zero?
|
||||
|
||||
# remove "topic:" if appended at beginning
|
||||
term = term[6..-1] if term.downcase[0..5] == 'topic:'
|
||||
|
@ -34,28 +35,28 @@ class SearchController < ApplicationController
|
|||
end
|
||||
|
||||
# check whether there's a filter by metacode as part of the query
|
||||
filterByMetacode = false
|
||||
filter_by_metacode = false
|
||||
Metacode.all.each do |m|
|
||||
lOne = m.name.length + 1
|
||||
lTwo = m.name.length
|
||||
length_one = m.name.length + 1
|
||||
length_two = m.name.length
|
||||
|
||||
if term.downcase[0..lTwo] == m.name.downcase + ':'
|
||||
term = term[lOne..-1]
|
||||
filterByMetacode = m
|
||||
if term.downcase[0..length_two] == m.name.downcase + ':'
|
||||
term = term[length_one..-1]
|
||||
filter_by_metacode = m
|
||||
end
|
||||
end
|
||||
|
||||
search = '%' + term.downcase.strip + '%'
|
||||
builder = policy_scope(Topic)
|
||||
|
||||
if filterByMetacode
|
||||
if filter_by_metacode
|
||||
if term == ''
|
||||
builder = builder.none
|
||||
else
|
||||
builder = builder.where('LOWER("name") like ? OR
|
||||
LOWER("desc") like ? OR
|
||||
LOWER("link") like ?', search, search, search)
|
||||
builder = builder.where(metacode_id: filterByMetacode.id)
|
||||
builder = builder.where(metacode_id: filter_by_metacode.id)
|
||||
end
|
||||
elsif desc
|
||||
builder = builder.where('LOWER("desc") like ?', search)
|
||||
|
@ -82,7 +83,8 @@ class SearchController < ApplicationController
|
|||
term = params[:term]
|
||||
user = params[:user] ? params[:user] : nil
|
||||
|
||||
if term && !term.empty? && term.downcase[0..5] != 'topic:' && term.downcase[0..6] != 'mapper:' && !term.casecmp('map:').zero?
|
||||
if term.present? && term.downcase[0..5] != 'topic:' &&
|
||||
term.downcase[0..6] != 'mapper:' && !term.casecmp('map:').zero?
|
||||
|
||||
# remove "map:" if appended at beginning
|
||||
term = term[4..-1] if term.downcase[0..3] == 'map:'
|
||||
|
@ -115,7 +117,8 @@ class SearchController < ApplicationController
|
|||
# get /search/mappers?term=SOMETERM
|
||||
def mappers
|
||||
term = params[:term]
|
||||
if term && !term.empty? && term.downcase[0..3] != 'map:' && term.downcase[0..5] != 'topic:' && !term.casecmp('mapper:').zero?
|
||||
if term.present? && term.downcase[0..3] != 'map:' &&
|
||||
term.downcase[0..5] != 'topic:' && !term.casecmp('mapper:').zero?
|
||||
|
||||
# remove "mapper:" if appended at beginning
|
||||
term = term[7..-1] if term.downcase[0..6] == 'mapper:'
|
||||
|
@ -138,13 +141,15 @@ class SearchController < ApplicationController
|
|||
topic2id = params[:topic2id]
|
||||
|
||||
if term && !term.empty?
|
||||
@synapses = policy_scope(Synapse).where('LOWER("desc") like ?', '%' + term.downcase.strip + '%').order('"desc"')
|
||||
@synapses = policy_scope(Synapse)
|
||||
.where('LOWER("desc") like ?', '%' + term.downcase.strip + '%')
|
||||
.order('"desc"')
|
||||
|
||||
@synapses = @synapses.uniq(&:desc)
|
||||
elsif topic1id && !topic1id.empty?
|
||||
@one = policy_scope(Synapse).where(topic1_id: topic1id, topic2_id: topic2id)
|
||||
@two = policy_scope(Synapse).where(topic2_id: topic1id, topic1_id: topic2id)
|
||||
@synapses = @one + @two
|
||||
one = policy_scope(Synapse).where(topic1_id: topic1id, topic2_id: topic2id)
|
||||
two = policy_scope(Synapse).where(topic2_id: topic1id, topic1_id: topic2id)
|
||||
@synapses = one + two
|
||||
@synapses.sort! { |s1, s2| s1.desc <=> s2.desc }.to_a
|
||||
else
|
||||
skip_policy_scope
|
||||
|
|
|
@ -71,6 +71,8 @@ class SynapsesController < ApplicationController
|
|||
private
|
||||
|
||||
def synapse_params
|
||||
params.require(:synapse).permit(:id, :desc, :category, :weight, :permission, :topic1_id, :topic2_id, :user_id)
|
||||
params.require(:synapse).permit(
|
||||
:id, :desc, :category, :weight, :permission, :topic1_id, :topic2_id, :user_id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,16 +11,20 @@ class TopicsController < ApplicationController
|
|||
def autocomplete_topic
|
||||
term = params[:term]
|
||||
if term && !term.empty?
|
||||
@topics = policy_scope(Topic).where('LOWER("name") like ?', term.downcase + '%').order('"name"')
|
||||
@mapTopics = @topics.select { |t| t&.metacode&.name == 'Metamap' }
|
||||
topics = policy_scope(Topic)
|
||||
.where('LOWER("name") like ?', term.downcase + '%')
|
||||
.order('"name"')
|
||||
map_topics = topics.select { |t| t&.metacode&.name == 'Metamap' }
|
||||
# prioritize topics which point to maps, over maps
|
||||
@exclude = @mapTopics.length.positive? ? @mapTopics.map(&:name) : ['']
|
||||
@maps = policy_scope(Map).where('LOWER("name") like ? AND name NOT IN (?)', term.downcase + '%', @exclude).order('"name"')
|
||||
exclude = map_topics.length.positive? ? map_topics.map(&:name) : ['']
|
||||
maps = policy_scope(Map)
|
||||
.where('LOWER("name") like ? AND name NOT IN (?)', term.downcase + '%', exclude)
|
||||
.order('"name"')
|
||||
else
|
||||
@topics = []
|
||||
@maps = []
|
||||
topics = []
|
||||
maps = []
|
||||
end
|
||||
@all = @topics.to_a.concat(@maps.to_a).sort_by(&:name)
|
||||
@all = topics.to_a.concat(maps.to_a).sort_by(&:name)
|
||||
|
||||
render json: autocomplete_array_json(@all).to_json
|
||||
end
|
||||
|
@ -70,13 +74,13 @@ class TopicsController < ApplicationController
|
|||
@topic = Topic.find(params[:id])
|
||||
authorize @topic
|
||||
|
||||
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
|
||||
topics_already_has = params[:network] ? params[:network].split(',').map(&:to_i) : []
|
||||
|
||||
alltopics = policy_scope(Topic.relatives(@topic.id, current_user)).to_a
|
||||
alltopics.delete_if { |topic| topic.metacode_id != params[:metacode].to_i } if params[:metacode].present?
|
||||
alltopics.delete_if do |topic|
|
||||
!topicsAlreadyHas.index(topic.id).nil?
|
||||
if params[:metacode].present?
|
||||
alltopics.delete_if { |topic| topic.metacode_id != params[:metacode].to_i }
|
||||
end
|
||||
alltopics.delete_if { |topic| !topics_already_has.index(topic.id).nil? }
|
||||
|
||||
@json = Hash.new(0)
|
||||
alltopics.each do |t|
|
||||
|
@ -93,12 +97,14 @@ class TopicsController < ApplicationController
|
|||
@topic = Topic.find(params[:id])
|
||||
authorize @topic
|
||||
|
||||
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
|
||||
topics_already_has = params[:network] ? params[:network].split(',').map(&:to_i) : []
|
||||
|
||||
alltopics = policy_scope(Topic.relatives(@topic.id, current_user)).to_a
|
||||
alltopics.delete_if { |topic| topic.metacode_id != params[:metacode].to_i } if params[:metacode].present?
|
||||
if params[:metacode].present?
|
||||
alltopics.delete_if { |topic| topic.metacode_id != params[:metacode].to_i }
|
||||
end
|
||||
alltopics.delete_if do |topic|
|
||||
!topicsAlreadyHas.index(topic.id.to_s).nil?
|
||||
!topics_already_has.index(topic.id.to_s).nil?
|
||||
end
|
||||
|
||||
# find synapses between topics in alltopics array
|
||||
|
@ -108,9 +114,9 @@ class TopicsController < ApplicationController
|
|||
!synapse_ids.index(synapse.id).nil?
|
||||
end
|
||||
|
||||
creatorsAlreadyHas = params[:creators] ? params[:creators].split(',').map(&:to_i) : []
|
||||
creators_already_has = params[:creators] ? params[:creators].split(',').map(&:to_i) : []
|
||||
allcreators = (alltopics.map(&:user) + allsynapses.map(&:user)).uniq.delete_if do |user|
|
||||
!creatorsAlreadyHas.index(user.id).nil?
|
||||
!creators_already_has.index(user.id).nil?
|
||||
end
|
||||
|
||||
@json = {}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
class Users::PasswordsController < Devise::PasswordsController
|
||||
protected
|
||||
module Users
|
||||
class PasswordsController < Devise::PasswordsController
|
||||
protected
|
||||
|
||||
def after_resetting_password_path_for(resource)
|
||||
signed_in_root_path(resource)
|
||||
end
|
||||
def after_resetting_password_path_for(resource)
|
||||
signed_in_root_path(resource)
|
||||
end
|
||||
|
||||
def after_sending_reset_password_instructions_path_for(_resource_name)
|
||||
sign_in_path if is_navigational_format?
|
||||
def after_sending_reset_password_instructions_path_for(_resource_name)
|
||||
sign_in_path if is_navigational_format?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,37 +1,39 @@
|
|||
# frozen_string_literal: true
|
||||
class Users::RegistrationsController < Devise::RegistrationsController
|
||||
before_action :configure_sign_up_params, only: [:create]
|
||||
before_action :configure_account_update_params, only: [:update]
|
||||
after_action :store_location, only: [:new]
|
||||
module Users
|
||||
class RegistrationsController < Devise::RegistrationsController
|
||||
before_action :configure_sign_up_params, only: [:create]
|
||||
before_action :configure_account_update_params, only: [:update]
|
||||
after_action :store_location, only: [:new]
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
def after_update_path_for(resource)
|
||||
signed_in_root_path(resource)
|
||||
end
|
||||
def after_update_path_for(resource)
|
||||
signed_in_root_path(resource)
|
||||
end
|
||||
|
||||
def after_sign_in_path_for(resource)
|
||||
stored = stored_location_for(User)
|
||||
return stored if stored
|
||||
def after_sign_in_path_for(resource)
|
||||
stored = stored_location_for(User)
|
||||
return stored if stored
|
||||
|
||||
if request.referer&.match(sign_in_url) || request.referer&.match(sign_up_url)
|
||||
super
|
||||
else
|
||||
request.referer || root_path
|
||||
if request.referer&.match(sign_in_url) || request.referer&.match(sign_up_url)
|
||||
super
|
||||
else
|
||||
request.referer || root_path
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def store_location
|
||||
store_location_for(User, params[:redirect_to]) if params[:redirect_to]
|
||||
end
|
||||
|
||||
def configure_sign_up_params
|
||||
devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :joinedwithcode])
|
||||
end
|
||||
|
||||
def configure_account_update_params
|
||||
devise_parameter_sanitizer.permit(:account_update, keys: [:image])
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def store_location
|
||||
store_location_for(User, params[:redirect_to]) if params[:redirect_to]
|
||||
end
|
||||
|
||||
def configure_sign_up_params
|
||||
devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :joinedwithcode])
|
||||
end
|
||||
|
||||
def configure_account_update_params
|
||||
devise_parameter_sanitizer.permit(:account_update, keys: [:image])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
module ApplicationHelper
|
||||
def metacodeset
|
||||
metacodes = current_user.settings.metacodes
|
||||
|
||||
return false unless metacodes[0].include?('metacodeset')
|
||||
if metacodes[0].sub('metacodeset-', '') == 'Most'
|
||||
return 'Most'
|
||||
elsif metacodes[0].sub('metacodeset-', '') == 'Recent'
|
||||
return 'Recent'
|
||||
end
|
||||
return 'Most' if metacodes[0].sub('metacodeset-', '') == 'Most'
|
||||
return 'Recent' if metacodes[0].sub('metacodeset-', '') == 'Recent'
|
||||
|
||||
MetacodeSet.find(metacodes[0].sub('metacodeset-', '').to_i)
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ module TopicsHelper
|
|||
def autocomplete_array_json(topics)
|
||||
topics.map do |t|
|
||||
is_map = t.is_a?(Map)
|
||||
metamapMetacode = Metacode.find_by_name('Metamap')
|
||||
metamap_metacode = Metacode.find_by(name: 'Metamap')
|
||||
{
|
||||
id: t.id,
|
||||
label: t.name,
|
||||
|
@ -17,8 +17,8 @@ module TopicsHelper
|
|||
rtype: is_map ? 'map' : 'topic',
|
||||
inmaps: is_map ? [] : t.inmaps(current_user),
|
||||
inmapsLinks: is_map ? [] : t.inmapsLinks(current_user),
|
||||
type: is_map ? metamapMetacode.name : t.metacode.name,
|
||||
typeImageURL: is_map ? metamapMetacode.icon : t.metacode.icon,
|
||||
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,
|
||||
synapseCount: is_map ? 0 : t.synapses.count
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class AccessRequest < ApplicationRecord
|
|||
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
|
||||
end
|
||||
|
||||
user_map = UserMap.create(user: user, map: map)
|
||||
UserMap.create(user: user, map: map)
|
||||
NotificationService.access_approved(self)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
class Event < ApplicationRecord
|
||||
KINDS = %w(user_present_on_map conversation_started_on_map
|
||||
topic_added_to_map topic_moved_on_map topic_removed_from_map
|
||||
synapse_added_to_map synapse_removed_from_map
|
||||
topic_updated synapse_updated).freeze
|
||||
topic_added_to_map topic_moved_on_map topic_removed_from_map
|
||||
synapse_added_to_map synapse_removed_from_map
|
||||
topic_updated synapse_updated).freeze
|
||||
|
||||
belongs_to :eventable, polymorphic: true
|
||||
belongs_to :map
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
class Events::ConversationStartedOnMap < Event
|
||||
# after_create :notify_users!
|
||||
module Events
|
||||
class ConversationStartedOnMap < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(map, user)
|
||||
create!(kind: 'conversation_started_on_map',
|
||||
eventable: map,
|
||||
map: map,
|
||||
user: user)
|
||||
def self.publish!(map, user)
|
||||
create!(kind: 'conversation_started_on_map',
|
||||
eventable: map,
|
||||
map: map,
|
||||
user: user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
class Events::SynapseAddedToMap < Event
|
||||
# after_create :notify_users!
|
||||
module Events
|
||||
class SynapseAddedToMap < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(synapse, map, user, meta)
|
||||
create!(kind: 'synapse_added_to_map',
|
||||
eventable: synapse,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
def self.publish!(synapse, map, user, meta)
|
||||
create!(kind: 'synapse_added_to_map',
|
||||
eventable: synapse,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
class Events::SynapseRemovedFromMap < Event
|
||||
# after_create :notify_users!
|
||||
module Events
|
||||
class SynapseRemovedFromMap < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(synapse, map, user, meta)
|
||||
create!(kind: 'synapse_removed_from_map',
|
||||
eventable: synapse,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
def self.publish!(synapse, map, user, meta)
|
||||
create!(kind: 'synapse_removed_from_map',
|
||||
eventable: synapse,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
class Events::SynapseUpdated < Event
|
||||
# after_create :notify_users!
|
||||
module Events
|
||||
class SynapseUpdated < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(synapse, user, meta)
|
||||
create!(kind: 'synapse_updated',
|
||||
eventable: synapse,
|
||||
user: user,
|
||||
meta: meta)
|
||||
def self.publish!(synapse, user, meta)
|
||||
create!(kind: 'synapse_updated',
|
||||
eventable: synapse,
|
||||
user: user,
|
||||
meta: meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
class Events::TopicAddedToMap < Event
|
||||
# after_create :notify_users!
|
||||
module Events
|
||||
class TopicAddedToMap < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(topic, map, user, meta)
|
||||
create!(kind: 'topic_added_to_map',
|
||||
eventable: topic,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
def self.publish!(topic, map, user, meta)
|
||||
create!(kind: 'topic_added_to_map',
|
||||
eventable: topic,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
class Events::TopicMovedOnMap < Event
|
||||
# after_create :notify_users!
|
||||
module Events
|
||||
class TopicMovedOnMap < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(topic, map, user, meta)
|
||||
create!(kind: 'topic_moved_on_map',
|
||||
eventable: topic,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
def self.publish!(topic, map, user, meta)
|
||||
create!(kind: 'topic_moved_on_map',
|
||||
eventable: topic,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
class Events::TopicRemovedFromMap < Event
|
||||
# after_create :notify_users!
|
||||
module Events
|
||||
class TopicRemovedFromMap < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(topic, map, user, meta)
|
||||
create!(kind: 'topic_removed_from_map',
|
||||
eventable: topic,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
def self.publish!(topic, map, user, meta)
|
||||
create!(kind: 'topic_removed_from_map',
|
||||
eventable: topic,
|
||||
map: map,
|
||||
user: user,
|
||||
meta: meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
class Events::TopicUpdated < Event
|
||||
# after_create :notify_users!
|
||||
module Events
|
||||
class TopicUpdated < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(topic, user, meta)
|
||||
create!(kind: 'topic_updated',
|
||||
eventable: topic,
|
||||
user: user,
|
||||
meta: meta)
|
||||
def self.publish!(topic, user, meta)
|
||||
create!(kind: 'topic_updated',
|
||||
eventable: topic,
|
||||
user: user,
|
||||
meta: meta)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
class Events::UserPresentOnMap < Event
|
||||
# after_create :notify_users!
|
||||
module Events
|
||||
class UserPresentOnMap < Event
|
||||
# after_create :notify_users!
|
||||
|
||||
def self.publish!(map, user)
|
||||
create!(kind: 'user_present_on_map',
|
||||
eventable: map,
|
||||
map: map,
|
||||
user: user)
|
||||
def self.publish!(map, user)
|
||||
create!(kind: 'user_present_on_map',
|
||||
eventable: map,
|
||||
map: map,
|
||||
user: user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,8 +3,10 @@ class Map < ApplicationRecord
|
|||
belongs_to :user
|
||||
belongs_to :source, class_name: :Map
|
||||
|
||||
has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping, dependent: :destroy
|
||||
has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping, dependent: :destroy
|
||||
has_many :topicmappings, -> { Mapping.topicmapping },
|
||||
class_name: :Mapping, dependent: :destroy
|
||||
has_many :synapsemappings, -> { Mapping.synapsemapping },
|
||||
class_name: :Mapping, dependent: :destroy
|
||||
has_many :topics, through: :topicmappings, source: :mappable, source_type: 'Topic'
|
||||
has_many :synapses, through: :synapsemappings, source: :mappable, source_type: 'Synapse'
|
||||
has_many :messages, as: :resource, dependent: :destroy
|
||||
|
@ -21,7 +23,6 @@ class Map < ApplicationRecord
|
|||
has_attached_file :screenshot,
|
||||
styles: {
|
||||
thumb: ['220x220#', :png]
|
||||
#:full => ['940x630#', :png]
|
||||
},
|
||||
default_url: 'https://s3.amazonaws.com/metamaps-assets/site/missing-map-square.png'
|
||||
|
||||
|
@ -31,7 +32,7 @@ class Map < ApplicationRecord
|
|||
validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) }
|
||||
|
||||
# Validate the attached image is image/jpg, image/png, etc
|
||||
validates_attachment_content_type :screenshot, content_type: /\Aimage\/.*\Z/
|
||||
validates_attachment_content_type :screenshot, content_type: %r{\Aimage/.*\Z}
|
||||
|
||||
after_update :after_updated
|
||||
after_save :update_deferring_topics_and_synapses, if: :permission_changed?
|
||||
|
@ -80,7 +81,12 @@ class Map < ApplicationRecord
|
|||
end
|
||||
|
||||
def as_json(_options = {})
|
||||
json = super(methods: [:user_name, :user_image, :star_count, :topic_count, :synapse_count, :contributor_count, :collaborator_ids, :screenshot_url], except: [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, :screenshot_updated_at])
|
||||
json = super(
|
||||
methods: [:user_name, :user_image, :star_count, :topic_count, :synapse_count,
|
||||
:contributor_count, :collaborator_ids, :screenshot_url],
|
||||
except: [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name,
|
||||
:screenshot_updated_at]
|
||||
)
|
||||
json[:created_at_clean] = created_at_str
|
||||
json[:updated_at_clean] = updated_at_str
|
||||
json
|
||||
|
@ -122,15 +128,14 @@ class Map < ApplicationRecord
|
|||
end
|
||||
|
||||
def after_updated
|
||||
attrs = ['name', 'desc', 'permission']
|
||||
if attrs.any? {|k| changed_attributes.key?(k)}
|
||||
ActionCable.server.broadcast 'map_' + id.to_s, type: 'mapUpdated'
|
||||
end
|
||||
attrs = %w(name desc permission)
|
||||
return unless attrs.any? { |k| changed_attributes.key?(k) }
|
||||
ActionCable.server.broadcast 'map_' + id.to_s, type: 'mapUpdated'
|
||||
end
|
||||
|
||||
def update_deferring_topics_and_synapses
|
||||
Topic.where(defer_to_map_id: id).update_all(permission: permission)
|
||||
Synapse.where(defer_to_map_id: id).update_all(permission: permission)
|
||||
Topic.where(defer_to_map_id: id).update(permission: permission)
|
||||
Synapse.where(defer_to_map_id: id).update(permission: permission)
|
||||
end
|
||||
|
||||
def invited_text
|
||||
|
|
|
@ -31,7 +31,7 @@ class Mapping < ApplicationRecord
|
|||
|
||||
def after_created
|
||||
if mappable_type == 'Topic'
|
||||
meta = {'x': xloc, 'y': yloc, 'mapping_id': id}
|
||||
meta = { 'x': xloc, 'y': yloc, 'mapping_id': id }
|
||||
Events::TopicAddedToMap.publish!(mappable, map, user, meta)
|
||||
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicAdded', topic: mappable.filtered, mapping_id: id
|
||||
elsif mappable_type == 'Synapse'
|
||||
|
@ -42,13 +42,14 @@ class Mapping < ApplicationRecord
|
|||
synapse: mappable.filtered,
|
||||
topic1: mappable.topic1.filtered,
|
||||
topic2: mappable.topic2.filtered,
|
||||
mapping_id: id)
|
||||
mapping_id: id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def after_updated
|
||||
if mappable_type == 'Topic' and (xloc_changed? or yloc_changed?)
|
||||
meta = {'x': xloc, 'y': yloc, 'mapping_id': id}
|
||||
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
|
||||
|
@ -61,7 +62,7 @@ class Mapping < ApplicationRecord
|
|||
mappable.save
|
||||
end
|
||||
|
||||
meta = {'mapping_id': id}
|
||||
meta = { 'mapping_id': id }
|
||||
if mappable_type == 'Topic'
|
||||
Events::TopicRemovedFromMap.publish!(mappable, map, updated_by, meta)
|
||||
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicRemoved', id: mappable.id, mapping_id: id
|
||||
|
|
|
@ -17,6 +17,6 @@ class Message < ApplicationRecord
|
|||
end
|
||||
|
||||
def after_created
|
||||
ActionCable.server.broadcast 'map_' + resource.id.to_s, type: 'messageCreated', message: self.as_json
|
||||
ActionCable.server.broadcast 'map_' + resource.id.to_s, type: 'messageCreated', message: as_json
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,16 +64,16 @@ class Synapse < ApplicationRecord
|
|||
end
|
||||
|
||||
def after_updated
|
||||
attrs = ['desc', 'category', 'permission', 'defer_to_map_id']
|
||||
if attrs.any? {|k| changed_attributes.key?(k)}
|
||||
new = self.attributes.select {|k| attrs.include?(k) }
|
||||
old = changed_attributes.select {|k| attrs.include?(k) }
|
||||
attrs = %w(desc category permission defer_to_map_id)
|
||||
if attrs.any? { |k| changed_attributes.key?(k) }
|
||||
new = attributes.select { |k| attrs.include?(k) }
|
||||
old = changed_attributes.select { |k| attrs.include?(k) }
|
||||
meta = new.merge(old) # we are prioritizing the old values, keeping them
|
||||
meta['changed'] = changed_attributes.keys.select {|k| attrs.include?(k) }
|
||||
meta['changed'] = changed_attributes.keys.select { |k| attrs.include?(k) }
|
||||
Events::SynapseUpdated.publish!(self, user, meta)
|
||||
maps.each {|map|
|
||||
maps.each do |map|
|
||||
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'synapseUpdated', id: id
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -160,16 +160,16 @@ class Topic < ApplicationRecord
|
|||
end
|
||||
|
||||
def after_updated
|
||||
attrs = ['name', 'desc', 'link', 'metacode_id', 'permission', 'defer_to_map_id']
|
||||
if attrs.any? {|k| changed_attributes.key?(k)}
|
||||
new = self.attributes.select {|k| attrs.include?(k) }
|
||||
old = changed_attributes.select {|k| attrs.include?(k) }
|
||||
attrs = %w(name desc link metacode_id permission defer_to_map_id)
|
||||
if attrs.any? { |k| changed_attributes.key?(k) }
|
||||
new = attributes.select { |k| attrs.include?(k) }
|
||||
old = changed_attributes.select { |k| attrs.include?(k) }
|
||||
meta = new.merge(old) # we are prioritizing the old values, keeping them
|
||||
meta['changed'] = changed_attributes.keys.select {|k| attrs.include?(k) }
|
||||
meta['changed'] = changed_attributes.keys.select { |k| attrs.include?(k) }
|
||||
Events::TopicUpdated.publish!(self, user, meta)
|
||||
maps.each {|map|
|
||||
maps.each do |map|
|
||||
ActionCable.server.broadcast 'map_' + map.id.to_s, type: 'topicUpdated', id: id
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -104,7 +104,7 @@ class User < ApplicationRecord
|
|||
if code == joinedwithcode
|
||||
update(generation: 0)
|
||||
else
|
||||
update(generation: User.find_by_code(joinedwithcode).generation + 1)
|
||||
update(generation: User.find_by(code: joinedwithcode).generation + 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class UserPreference
|
|||
array = []
|
||||
%w(Action Aim Idea Question Note Wildcard Subject).each do |m|
|
||||
begin
|
||||
metacode = Metacode.find_by_name(m)
|
||||
metacode = Metacode.find_by(name: m)
|
||||
array.push(metacode.id.to_s) if metacode
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
if m == 'Action'
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
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
|
||||
# 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}*"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ const {
|
|||
LEAVE_MAP,
|
||||
SEND_COORDS,
|
||||
SEND_MAPPER_INFO,
|
||||
DRAG_TOPIC,
|
||||
DRAG_TOPIC
|
||||
} = require('../frontend/src/Metamaps/Realtime/events')
|
||||
|
||||
const { mapRoom, userMapRoom } = require('./rooms')
|
||||
|
|
|
@ -23,7 +23,7 @@ if (NODE_ENV === 'production') {
|
|||
|
||||
const devtool = NODE_ENV === 'production' ? undefined : 'cheap-module-eval-source-map'
|
||||
|
||||
const config = module.exports = {
|
||||
module.exports = {
|
||||
context: __dirname,
|
||||
plugins,
|
||||
devtool,
|
||||
|
|
Loading…
Reference in a new issue