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