Merge pull request #656 from metamaps/feature/tech-debt

rubocop style updates
This commit is contained in:
Devin Howard 2016-09-24 13:59:27 +08:00 committed by GitHub
commit 03eacde753
162 changed files with 488 additions and 303 deletions

View file

@ -6,9 +6,16 @@ AllCops:
- 'bin/**/*' - 'bin/**/*'
- 'vendor/**/*' - 'vendor/**/*'
- 'app/assets/javascripts/node_modules/**/*' - 'app/assets/javascripts/node_modules/**/*'
- 'Vagrantfile'
Rails: Rails:
Enabled: true Enabled: true
Metrics/LineLength: Metrics/LineLength:
Max: 100 Max: 100
Metrics/AbcSize:
Max: 16
Style/Documentation:
Enabled: false

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
source 'https://rubygems.org' source 'https://rubygems.org'
ruby '2.3.0' ruby '2.3.0'

View file

@ -1,4 +1,5 @@
#!/usr/bin/env rake #!/usr/bin/env rake
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake, # Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

2
Vagrantfile vendored
View file

@ -31,7 +31,7 @@ sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '3112';"
SCRIPT SCRIPT
VAGRANTFILE_API_VERSION = '2'.freeze VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'trusty64' config.vm.box = 'trusty64'

View file

@ -1,9 +1,12 @@
# frozen_string_literal: true
module Api module Api
module V1 module V1
class DeprecatedController < ApplicationController class DeprecatedController < ApplicationController
# rubocop:disable Style/MethodMissing
def method_missing def method_missing
render json: { error: "/api/v1 is deprecated! Please use /api/v2 instead." } render json: { error: '/api/v1 is deprecated! Please use /api/v2 instead.' }
end end
# rubocop:enable Style/MethodMissing
end end
end end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V1 module V1
class MappingsController < DeprecatedController class MappingsController < DeprecatedController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V1 module V1
class MapsController < DeprecatedController class MapsController < DeprecatedController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V1 module V1
class SynapsesController < DeprecatedController class SynapsesController < DeprecatedController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V1 module V1
class TokensController < DeprecatedController class TokensController < DeprecatedController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V1 module V1
class TopicsController < DeprecatedController class TopicsController < DeprecatedController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class MappingsController < RestfulController class MappingsController < RestfulController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class MapsController < RestfulController class MapsController < RestfulController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class RestfulController < ActionController::Base class RestfulController < ActionController::Base
@ -51,7 +52,8 @@ module Api
"Api::V2::#{resource_name.camelize}Serializer".constantize "Api::V2::#{resource_name.camelize}Serializer".constantize
end end
def respond_with_resource(scope: default_scope, serializer: resource_serializer, root: serializer_root) def respond_with_resource(scope: default_scope, serializer: resource_serializer,
root: serializer_root)
if resource.errors.empty? if resource.errors.empty?
render json: resource, scope: scope, serializer: serializer, root: root render json: resource, scope: scope, serializer: serializer, root: root
else else
@ -59,8 +61,11 @@ module Api
end end
end end
def respond_with_collection(resources: collection, scope: default_scope, serializer: resource_serializer, root: serializer_root) def respond_with_collection(resources: collection, scope: default_scope,
render json: resources, scope: scope, each_serializer: serializer, root: root, meta: pagination(resources), meta_key: :page serializer: resource_serializer, root: serializer_root)
pagination_link_headers!(pagination(resources))
render json: resources, scope: scope, each_serializer: serializer, root: root,
meta: pagination(resources), meta_key: :page
end end
def default_scope def default_scope
@ -94,33 +99,36 @@ module Api
end end
def pagination(collection) def pagination(collection)
per = (params[:per] || 25).to_i return @pagination_data unless @pagination_data.nil?
current_page = (params[:page] || 1).to_i
total_pages = (collection.total_count.to_f / per).ceil
prev_page = current_page > 1 ? current_page - 1 : 0
next_page = current_page < total_pages ? current_page + 1 : 0
current_page = (params[:page] || 1).to_i
per = (params[:per] || 25).to_i
total_pages = (collection.total_count.to_f / per).ceil
@pagination_data = {
current_page: current_page,
next_page: current_page < total_pages ? current_page + 1 : 0,
prev_page: current_page > 1 ? current_page - 1 : 0,
total_pages: total_pages,
total_count: collection.total_count,
per: per
}
end
def pagination_link_headers!(data)
base_url = request.base_url + request.path base_url = request.base_url + request.path
nxt = request.query_parameters.merge(page: next_page).map{|x| x.join('=')}.join('&') old_query = request.query_parameters
prev = request.query_parameters.merge(page: prev_page).map{|x| x.join('=')}.join('&') nxt = old_query.merge(page: data[:next_page]).map { |x| x.join('=') }.join('&')
last = request.query_parameters.merge(page: total_pages).map{|x| x.join('=')}.join('&') prev = old_query.merge(page: data[:prev_page]).map { |x| x.join('=') }.join('&')
last = old_query.merge(page: data[:total_pages]).map { |x| x.join('=') }.join('&')
response.headers['Link'] = [ response.headers['Link'] = [
%(<#{base_url}?#{nxt}>; rel="next"), %(<#{base_url}?#{nxt}>; rel="next"),
%(<#{base_url}?#{prev}>; rel="prev"), %(<#{base_url}?#{prev}>; rel="prev"),
%(<#{base_url}?#{last}>; rel="last") %(<#{base_url}?#{last}>; rel="last")
].join(',') ].join(',')
response.headers['X-Total-Pages'] = collection.total_pages.to_s response.headers['X-Total-Pages'] = data[:total_pages].to_s
response.headers['X-Total-Count'] = collection.total_count.to_s response.headers['X-Total-Count'] = data[:total_count].to_s
response.headers['X-Per-Page'] = per.to_s response.headers['X-Per-Page'] = data[:per].to_s
{
current_page: current_page,
next_page: next_page,
prev_page: prev_page,
total_pages: total_pages,
total_count: collection.total_count,
per: per
}
end end
def instantiate_collection def instantiate_collection
@ -163,7 +171,7 @@ module Api
builder = builder.order(sort => direction) builder = builder.order(sort => direction)
end end
end end
return builder builder
end end
def visible_records def visible_records

View file

@ -1,9 +1,10 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class SessionsController < ApplicationController class SessionsController < ApplicationController
def create def create
@user = User.find_by(email: params[:email]) @user = User.find_by(email: params[:email])
if @user && @user.valid_password(params[:password]) if @user&.valid_password(params[:password])
sign_in(@user) sign_in(@user)
render json: @user render json: @user
else else

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class SynapsesController < RestfulController class SynapsesController < RestfulController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class TokensController < RestfulController class TokensController < RestfulController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class TopicsController < RestfulController class TopicsController < RestfulController

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
include ApplicationHelper include ApplicationHelper
include Pundit include Pundit
@ -5,7 +6,7 @@ class ApplicationController < ActionController::Base
rescue_from Pundit::NotAuthorizedError, with: :handle_unauthorized rescue_from Pundit::NotAuthorizedError, with: :handle_unauthorized
protect_from_forgery(with: :exception) protect_from_forgery(with: :exception)
before_action :get_invite_link before_action :invite_link
after_action :allow_embedding after_action :allow_embedding
def default_serializer_options def default_serializer_options
@ -41,29 +42,26 @@ class ApplicationController < ActionController::Base
private private
def get_invite_link def invite_link
@invite_link = "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '') @invite_link = "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
end end
def require_no_user def require_no_user
if authenticated? return true unless authenticated?
redirect_to edit_user_path(user), notice: 'You must be logged out.' redirect_to edit_user_path(user), notice: 'You must be logged out.'
return false return false
end
end end
def require_user def require_user
unless authenticated? return true if authenticated?
redirect_to new_user_session_path, notice: 'You must be logged in.' redirect_to new_user_session_path, notice: 'You must be logged in.'
return false return false
end
end end
def require_admin def require_admin
unless authenticated? && admin? return true if authenticated? && admin?
redirect_to root_url, notice: 'You need to be an admin for that.' redirect_to root_url, notice: 'You need to be an admin for that.'
return false false
end
end end
def user def user

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MainController < ApplicationController class MainController < ApplicationController
include TopicsHelper include TopicsHelper
include MapsHelper include MapsHelper
@ -12,13 +13,13 @@ class MainController < ApplicationController
def home def home
@maps = policy_scope(Map).order('updated_at DESC').page(1).per(20) @maps = policy_scope(Map).order('updated_at DESC').page(1).per(20)
respond_to do |format| respond_to do |format|
format.html { format.html do
if !authenticated? if !authenticated?
render 'main/home' render 'main/home'
else else
render 'maps/activemaps' render 'maps/activemaps'
end end
} end
end end
end end
@ -163,8 +164,8 @@ class MainController < ApplicationController
@synapses = [] @synapses = []
end end
#limit to 5 results # limit to 5 results
@synapses = @synapses.to_a.slice(0,5) @synapses = @synapses.to_a.slice(0, 5)
render json: autocomplete_synapse_array_json(@synapses) render json: autocomplete_synapse_array_json(@synapses)
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MappingsController < ApplicationController class MappingsController < ApplicationController
before_action :require_user, only: [:create, :update, :destroy] before_action :require_user, only: [:create, :update, :destroy]
after_action :verify_authorized, except: :index after_action :verify_authorized, except: :index

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MapsController < ApplicationController class MapsController < ApplicationController
before_action :require_user, only: [:create, :update, :access, :star, :unstar, :screenshot, :events, :destroy] before_action :require_user, only: [:create, :update, :access, :star, :unstar, :screenshot, :events, :destroy]
after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :starredmaps, :usermaps] after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :starredmaps, :usermaps]
@ -107,7 +108,7 @@ class MapsController < ApplicationController
# GET maps/new # GET maps/new
def new def new
@map = Map.new(name: "Untitled Map", permission: "public", arranged: true) @map = Map.new(name: 'Untitled Map', permission: 'public', arranged: true)
authorize @map authorize @map
respond_to do |format| respond_to do |format|
@ -305,9 +306,7 @@ class MapsController < ApplicationController
@map = Map.find(params[:id]) @map = Map.find(params[:id])
authorize @map authorize @map
star = Star.find_by_map_id_and_user_id(@map.id, current_user.id) star = Star.find_by_map_id_and_user_id(@map.id, current_user.id)
if not star star = Star.create(map_id: @map.id, user_id: current_user.id) unless star
star = Star.create(map_id: @map.id, user_id: current_user.id)
end
respond_to do |format| respond_to do |format|
format.json do format.json do
@ -321,9 +320,7 @@ class MapsController < ApplicationController
@map = Map.find(params[:id]) @map = Map.find(params[:id])
authorize @map authorize @map
star = Star.find_by_map_id_and_user_id(@map.id, current_user.id) star = Star.find_by_map_id_and_user_id(@map.id, current_user.id)
if star star&.delete
star.delete
end
respond_to do |format| respond_to do |format|
format.json do format.json do

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MessagesController < ApplicationController class MessagesController < ApplicationController
before_action :require_user, except: [:show] before_action :require_user, except: [:show]
after_action :verify_authorized after_action :verify_authorized

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MetacodeSetsController < ApplicationController class MetacodeSetsController < ApplicationController
before_action :require_admin before_action :require_admin

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
class MetacodesController < ApplicationController class MetacodesController < ApplicationController
before_action :require_admin, except: [:index, :show] before_action :require_admin, except: [:index, :show]
before_action :set_metacode, only: [:edit, :update]
# GET /metacodes # GET /metacodes
# GET /metacodes.json # GET /metacodes.json
@ -8,10 +10,7 @@ class MetacodesController < ApplicationController
respond_to do |format| respond_to do |format|
format.html do format.html do
unless authenticated? && user.admin return unless require_admin
redirect_to root_url, notice: 'You need to be an admin for that.'
return false
end
render :index render :index
end end
format.json { render json: @metacodes } format.json { render json: @metacodes }
@ -23,7 +22,7 @@ class MetacodesController < ApplicationController
# GET /metacodes/action.json # GET /metacodes/action.json
def show def show
@metacode = Metacode.where('DOWNCASE(name) = ?', downcase(params[:name])).first if params[:name] @metacode = Metacode.where('DOWNCASE(name) = ?', downcase(params[:name])).first if params[:name]
@metacode = Metacode.find(params[:id]) unless @metacode set_metacode unless @metacode
respond_to do |format| respond_to do |format|
format.json { render json: @metacode } format.json { render json: @metacode }
@ -36,14 +35,13 @@ class MetacodesController < ApplicationController
@metacode = Metacode.new @metacode = Metacode.new
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html
format.json { render json: @metacode } format.json { render json: @metacode }
end end
end end
# GET /metacodes/1/edit # GET /metacodes/1/edit
def edit def edit
@metacode = Metacode.find(params[:id])
end end
# POST /metacodes # POST /metacodes
@ -65,8 +63,6 @@ class MetacodesController < ApplicationController
# PUT /metacodes/1 # PUT /metacodes/1
# PUT /metacodes/1.json # PUT /metacodes/1.json
def update def update
@metacode = Metacode.find(params[:id])
respond_to do |format| respond_to do |format|
if @metacode.update(metacode_params) if @metacode.update(metacode_params)
format.html { redirect_to metacodes_url, notice: 'Metacode was successfully updated.' } format.html { redirect_to metacodes_url, notice: 'Metacode was successfully updated.' }
@ -84,4 +80,8 @@ class MetacodesController < ApplicationController
def metacode_params def metacode_params
params.require(:metacode).permit(:id, :name, :aws_icon, :manual_icon, :color) params.require(:metacode).permit(:id, :name, :aws_icon, :manual_icon, :color)
end end
def set_metacode
@metacode = Metacode.find(params[:id])
end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class SynapsesController < ApplicationController class SynapsesController < ApplicationController
include TopicsHelper include TopicsHelper

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class TopicsController < ApplicationController class TopicsController < ApplicationController
include TopicsHelper include TopicsHelper

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Users::PasswordsController < Devise::PasswordsController class Users::PasswordsController < Devise::PasswordsController
protected protected
@ -5,7 +6,7 @@ class Users::PasswordsController < Devise::PasswordsController
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)
new_user_session_path if is_navigational_format? new_user_session_path if is_navigational_format?
end end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Users::RegistrationsController < Devise::RegistrationsController class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_sign_up_params, only: [:create] before_action :configure_sign_up_params, only: [:create]
before_action :configure_account_update_params, only: [:update] before_action :configure_account_update_params, only: [:update]

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class UsersController < ApplicationController class UsersController < ApplicationController
before_action :require_user, only: [:edit, :update, :updatemetacodes] before_action :require_user, only: [:edit, :update, :updatemetacodes]

View file

@ -1,13 +1,14 @@
# frozen_string_literal: true
module ApplicationHelper module ApplicationHelper
def get_metacodeset def metacodeset
@m = current_user.settings.metacodes metacodes = current_user.settings.metacodes
set = @m[0].include?('metacodeset') ? MetacodeSet.find(@m[0].sub('metacodeset-', '').to_i) : false return false unless metacodes[0].include?('metacodeset')
set MetacodeSet.find(metacodes[0].sub('metacodeset-', '').to_i)
end end
def user_metacodes def user_metacodes
@m = current_user.settings.metacodes @m = current_user.settings.metacodes
set = get_metacodeset set = metacodeset
@metacodes = if set @metacodes = if set
set.metacodes.to_a set.metacodes.to_a
else else
@ -16,7 +17,7 @@ module ApplicationHelper
@metacodes.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1) @metacodes.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1)
end end
def determine_invite_link def invite_link
"#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '') "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
end end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module ContentHelper module ContentHelper
def resource_name def resource_name
:user :user

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module DeviseHelper module DeviseHelper
def devise_error_messages! def devise_error_messages!
resource.errors.to_a[0] resource.errors.to_a[0]

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module InMetacodeSetsHelper module InMetacodeSetsHelper
end end

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module MainHelper module MainHelper
end end

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module MappingHelper module MappingHelper
end end

View file

@ -1,34 +1,42 @@
# frozen_string_literal: true
module MapsHelper module MapsHelper
## this one is for building our custom JSON autocomplete format for typeahead # JSON autocomplete format for typeahead
def autocomplete_map_array_json(maps) def autocomplete_map_array_json(maps)
temp = [] maps.map do |m|
maps.each do |m| {
map = {} id: m.id,
map['id'] = m.id label: m.name,
map['label'] = m.name value: m.name,
map['value'] = m.name description: m.desc.try(:truncate, 30),
map['description'] = m.desc.try(:truncate, 30) permission: m.permission,
map['permission'] = m.permission topicCount: m.topics.count,
map['topicCount'] = m.topics.count synapseCount: m.synapses.count,
map['synapseCount'] = m.synapses.count contributorCount: m.contributors.count,
map['contributorCount'] = m.contributors.count rtype: 'map',
map['rtype'] = 'map' contributorTip: contributor_tip(map),
mapContributorImage: first_contributor_image(map)
contributorTip = '' }
firstContributorImage = 'https://s3.amazonaws.com/metamaps-assets/site/user.png'
if m.contributors.count > 0
firstContributorImage = m.contributors[0].image.url(:thirtytwo)
m.contributors.each_with_index do |c, _index|
userImage = c.image.url(:thirtytwo)
name = c.name
contributorTip += '<li> <img class="tipUserImage" width="25" height="25" src=' + userImage + ' />' + '<span>' + name + '</span> </li>'
end
end
map['contributorTip'] = contributorTip
map['mapContributorImage'] = firstContributorImage
temp.push map
end end
temp end
def first_contributor_image(map)
if map.contributors.count.positive?
return map.contributors[0].image.url(:thirtytwo)
end
'https://s3.amazonaws.com/metamaps-assets/site/user.png'
end
def contributor_tip(map)
output = ''
if map.contributors.count.positive?
map.contributors.each_with_index do |contributor, _index|
user_image = contributor.image.url(:thirtytwo)
output += '<li>'
output += %(<img class="tipUserImage" width="25" height="25" src="#{user_image}" />)
output += "<span>#{contributor.name}</span>"
output += '</li>'
end
end
output
end end
end end

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module MetacodeSetsHelper module MetacodeSetsHelper
end end

View file

@ -1,2 +1,3 @@
# frozen_string_literal: true
module MetacodesHelper module MetacodesHelper
end end

View file

@ -1,33 +1,25 @@
# frozen_string_literal: true
module SynapsesHelper module SynapsesHelper
## this one is for building our custom JSON autocomplete format for typeahead ## this one is for building our custom JSON autocomplete format for typeahead
def autocomplete_synapse_generic_json(unique) def autocomplete_synapse_generic_json(unique)
temp = [] unique.map do |s|
unique.each do |s| { label: s.desc, value: s.desc }
synapse = {}
synapse['label'] = s.desc
synapse['value'] = s.desc
temp.push synapse
end end
temp
end end
## this one is for building our custom JSON autocomplete format for typeahead ## this one is for building our custom JSON autocomplete format for typeahead
def autocomplete_synapse_array_json(synapses) def autocomplete_synapse_array_json(synapses)
temp = [] synapses.map do |s|
synapses.each do |s| {
synapse = {} id: s.id,
synapse['id'] = s.id label: s.desc.blank? ? '(no description)' : s.desc,
synapse['label'] = s.desc.nil? || s.desc == '' ? '(no description)' : s.desc value: s.desc,
synapse['value'] = s.desc permission: s.permission,
synapse['permission'] = s.permission mapCount: s.maps.count,
synapse['mapCount'] = s.maps.count originator: s.user.name,
synapse['originator'] = s.user.name originatorImage: s.user.image.url(:thirtytwo),
synapse['originatorImage'] = s.user.image.url(:thirtytwo) rtype: 'synapse'
synapse['rtype'] = 'synapse' }
temp.push synapse
end end
temp
end end
end end

View file

@ -1,56 +1,39 @@
# frozen_string_literal: true
module TopicsHelper module TopicsHelper
## this one is for building our custom JSON autocomplete format for typeahead ## this one is for building our custom JSON autocomplete format for typeahead
def autocomplete_array_json(topics) def autocomplete_array_json(topics)
temp = [] topics.map do |t|
topics.each do |t| {
topic = {} id: t.id,
topic['id'] = t.id label: t.name,
topic['label'] = t.name value: t.name,
topic['value'] = t.name description: t.desc ? t.desc&.truncate(70) : '', # make this return matched results
topic['description'] = t.desc ? t.desc.truncate(70) : '' # make this return matched results type: t.metacode.name,
topic['type'] = t.metacode.name typeImageURL: t.metacode.icon,
topic['typeImageURL'] = t.metacode.icon permission: t.permission,
topic['permission'] = t.permission mapCount: t.maps.count,
topic['mapCount'] = t.maps.count synapseCount: t.synapses.count,
topic['synapseCount'] = t.synapses.count originator: t.user.name,
topic['originator'] = t.user.name originatorImage: t.user.image.url(:thirtytwo),
topic['originatorImage'] = t.user.image.url(:thirtytwo) rtype: :topic,
topic['rtype'] = 'topic' inmaps: t.inmaps,
topic['inmaps'] = t.inmaps inmapsLinks: t.inmapsLinks
topic['inmapsLinks'] = t.inmapsLinks }
temp.push topic
end end
temp
end end
# find all nodes in any given nodes network # recursively find all nodes in any given nodes network
def network(node, array, count) def network(node, array, count)
# recurse starting with a node to find all connected nodes and return an array of topics that constitutes the starting nodes network
# if the array of nodes is empty initialize it
array = [] if array.nil? array = [] if array.nil?
# add the node to the array
array.push(node) array.push(node)
return array if count.zero?
return array if count == 0
count -= 1
# check if each relative is already in the array and if not, call the network function again # check if each relative is already in the array and if not, call the network function again
if !node.relatives.empty? remaining_relatives = node.relatives.to_a - array
if (node.relatives - array).empty? remaining_relatives.each do |relative|
return array array = (array | network(relative, array, count - 1))
else
(node.relatives - array).each do |relative|
array = (array | network(relative, array, count))
end
return array
end
elsif node.relatives.empty?
return array
end end
array
end end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module UsersHelper module UsersHelper
# build custom json autocomplete for typeahead # build custom json autocomplete for typeahead
def autocomplete_user_array_json(users) def autocomplete_user_array_json(users)

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class ApplicationMailer < ActionMailer::Base class ApplicationMailer < ActionMailer::Base
default from: 'team@metamaps.cc' default from: 'team@metamaps.cc'
layout 'mailer' layout 'mailer'

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MapMailer < ApplicationMailer class MapMailer < ApplicationMailer
default from: 'team@metamaps.cc' default from: 'team@metamaps.cc'

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Routing module Routing
extend ActiveSupport::Concern extend ActiveSupport::Concern
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Event < ApplicationRecord class Event < ApplicationRecord
KINDS = %w(user_present_on_map conversation_started_on_map topic_added_to_map synapse_added_to_map).freeze KINDS = %w(user_present_on_map conversation_started_on_map topic_added_to_map synapse_added_to_map).freeze

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Events::ConversationStartedOnMap < Event class Events::ConversationStartedOnMap < Event
# after_create :notify_users! # after_create :notify_users!

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Events::NewMapping < Event class Events::NewMapping < Event
# after_create :notify_users! # after_create :notify_users!

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Events::UserPresentOnMap < Event class Events::UserPresentOnMap < Event
# after_create :notify_users! # after_create :notify_users!

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class InMetacodeSet < ApplicationRecord class InMetacodeSet < ApplicationRecord
belongs_to :metacode, class_name: 'Metacode', foreign_key: 'metacode_id' belongs_to :metacode, class_name: 'Metacode', foreign_key: 'metacode_id'
belongs_to :metacode_set, class_name: 'MetacodeSet', foreign_key: 'metacode_set_id' belongs_to :metacode_set, class_name: 'MetacodeSet', foreign_key: 'metacode_set_id'

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Map < ApplicationRecord class Map < ApplicationRecord
belongs_to :user belongs_to :user
@ -19,7 +20,7 @@ class Map < ApplicationRecord
thumb: ['188x126#', :png] thumb: ['188x126#', :png]
#:full => ['940x630#', :png] #:full => ['940x630#', :png]
}, },
default_url: 'https://s3.amazonaws.com/metamaps-assets/site/missing-map-white.png' default_url: 'https://s3.amazonaws.com/metamaps-assets/site/missing-map-white.png'
validates :name, presence: true validates :name, presence: true
validates :arranged, inclusion: { in: [true, false] } validates :arranged, inclusion: { in: [true, false] }

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Mapping < ApplicationRecord class Mapping < ApplicationRecord
scope :topicmapping, -> { where(mappable_type: :Topic) } scope :topicmapping, -> { where(mappable_type: :Topic) }
scope :synapsemapping, -> { where(mappable_type: :Synapse) } scope :synapsemapping, -> { where(mappable_type: :Synapse) }

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Message < ApplicationRecord class Message < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :resource, polymorphic: true belongs_to :resource, polymorphic: true

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Metacode < ApplicationRecord class Metacode < ApplicationRecord
has_many :in_metacode_sets has_many :in_metacode_sets
has_many :metacode_sets, through: :in_metacode_sets has_many :metacode_sets, through: :in_metacode_sets

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MetacodeSet < ApplicationRecord class MetacodeSet < ApplicationRecord
belongs_to :user belongs_to :user
has_many :in_metacode_sets has_many :in_metacode_sets

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class PermittedParams < Struct.new(:params) class PermittedParams < Struct.new(:params)
%w(map synapse topic mapping token).each do |kind| %w(map synapse topic mapping token).each do |kind|
define_method(kind) do define_method(kind) do

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Star < ActiveRecord::Base class Star < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :map belongs_to :map

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Synapse < ApplicationRecord class Synapse < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :defer_to_map, class_name: 'Map', foreign_key: 'defer_to_map_id' belongs_to :defer_to_map, class_name: 'Map', foreign_key: 'defer_to_map_id'
@ -21,17 +22,12 @@ class Synapse < ApplicationRecord
where('node1_id = ? OR node2_id = ?', topic_id, topic_id) where('node1_id = ? OR node2_id = ?', topic_id, topic_id)
} }
# :nocov:
delegate :name, to: :user, prefix: true delegate :name, to: :user, prefix: true
# :nocov:
# :nocov:
def user_image def user_image
user.image.url user.image.url
end end
# :nocov:
# :nocov:
def collaborator_ids def collaborator_ids
if defer_to_map if defer_to_map
defer_to_map.editors.select { |mapper| mapper != user }.map(&:id) defer_to_map.editors.select { |mapper| mapper != user }.map(&:id)
@ -39,21 +35,12 @@ class Synapse < ApplicationRecord
[] []
end end
end end
# :nocov:
# :nocov:
def calculated_permission def calculated_permission
if defer_to_map defer_to_map&.permission || permission
defer_to_map.permission
else
permission
end
end end
# :nocov:
# :nocov:
def as_json(_options = {}) def as_json(_options = {})
super(methods: [:user_name, :user_image, :calculated_permission, :collaborator_ids]) super(methods: [:user_name, :user_image, :calculated_permission, :collaborator_ids])
end end
# :nocov:
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Token < ApplicationRecord class Token < ApplicationRecord
belongs_to :user belongs_to :user

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Topic < ApplicationRecord class Topic < ApplicationRecord
include TopicsHelper include TopicsHelper
@ -73,11 +74,7 @@ class Topic < ApplicationRecord
end end
def calculated_permission def calculated_permission
if defer_to_map defer_to_map&.permission || permission
defer_to_map.permission
else
permission
end
end end
def as_json(_options = {}) def as_json(_options = {})

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'open-uri' require 'open-uri'
class User < ApplicationRecord class User < ApplicationRecord
@ -41,7 +42,7 @@ class User < ApplicationRecord
default_url: 'https://s3.amazonaws.com/metamaps-assets/site/user.png' default_url: 'https://s3.amazonaws.com/metamaps-assets/site/user.png'
# Validate the attached image is image/jpg, image/png, etc # Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :image, content_type: %r(\Aimage/.*\Z) validates_attachment_content_type :image, content_type: %r{\Aimage/.*\Z}
# override default as_json # override default as_json
def as_json(_options = {}) def as_json(_options = {})
@ -80,7 +81,7 @@ class User < ApplicationRecord
end end
def starred_map?(map) def starred_map?(map)
return self.stars.where(map_id: map.id).exists? stars.where(map_id: map.id).exists?
end end
def settings def settings

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class UserMap < ApplicationRecord class UserMap < ApplicationRecord
belongs_to :map belongs_to :map
belongs_to :user belongs_to :user

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class UserPreference class UserPreference
attr_accessor :metacodes attr_accessor :metacodes
@ -9,7 +10,7 @@ class UserPreference
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'
Rails.logger.warn("TODO: remove this travis workaround in user_preference.rb") Rails.logger.warn('TODO: remove this travis workaround in user_preference.rb')
end end
end end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Webhook < ApplicationRecord class Webhook < ApplicationRecord
belongs_to :hookable, polymorphic: true belongs_to :hookable, polymorphic: true

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
Webhooks::Slack::Base = Struct.new(:event) do Webhooks::Slack::Base = Struct.new(:event) do
include Routing include Routing

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Webhooks::Slack::ConversationStartedOnMap < Webhooks::Slack::Base class Webhooks::Slack::ConversationStartedOnMap < Webhooks::Slack::Base
def text def text
"There is a live conversation starting on map *#{event.map.name}*. #{view_map_on_metamaps('Join in!')}" "There is a live conversation starting on map *#{event.map.name}*. #{view_map_on_metamaps('Join in!')}"

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base class Webhooks::Slack::SynapseAddedToMap < Webhooks::Slack::Base
def text def text
"\"*#{eventable.mappable.topic1.name}* #{eventable.mappable.desc || '->'} *#{eventable.mappable.topic2.name}*\" was added as a connection to the map *#{view_map_on_metamaps}*" "\"*#{eventable.mappable.topic1.name}* #{eventable.mappable.desc || '->'} *#{eventable.mappable.topic2.name}*\" was added as a connection to the map *#{view_map_on_metamaps}*"

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Webhooks::Slack::TopicAddedToMap < Webhooks::Slack::Base class Webhooks::Slack::TopicAddedToMap < Webhooks::Slack::Base
def text def text
"New #{eventable.mappable.metacode.name} topic *#{eventable.mappable.name}* was added to the map *#{view_map_on_metamaps}*" "New #{eventable.mappable.metacode.name} topic *#{eventable.mappable.name}* was added to the map *#{view_map_on_metamaps}*"

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Webhooks::Slack::UserPresentOnMap < Webhooks::Slack::Base class Webhooks::Slack::UserPresentOnMap < Webhooks::Slack::Base
def text def text
"Mapper *#{event.user.name}* has joined the map *#{event.map.name}*. #{view_map_on_metamaps('Map with them')}" "Mapper *#{event.user.name}* has joined the map *#{event.map.name}*. #{view_map_on_metamaps('Map with them')}"

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class ApplicationPolicy class ApplicationPolicy
attr_reader :user, :record attr_reader :user, :record
@ -39,7 +40,7 @@ class ApplicationPolicy
# explicitly say they want to (E.g. seeing/editing/deleting private # explicitly say they want to (E.g. seeing/editing/deleting private
# maps - they should be able to, but not by accident) # maps - they should be able to, but not by accident)
def admin_override def admin_override
user && user.admin user&.admin
end end
def scope def scope

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MainPolicy < ApplicationPolicy class MainPolicy < ApplicationPolicy
def initialize(user, _record) def initialize(user, _record)
@user = user @user = user

View file

@ -1,14 +1,13 @@
# frozen_string_literal: true
class MapPolicy < ApplicationPolicy class MapPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = %w(public commons) visible = %w(public commons)
permission = 'maps.permission IN (?)' return scope.where(permission: visible) unless user
if user
shared_maps = user.shared_maps.map(&:id) scope.where(permission: visible)
scope.where(permission + ' OR maps.id IN (?) OR maps.user_id = ?', visible, shared_maps, user.id) .or(scope.where(id: user.shared_maps.map(&:id)))
else .or(scope.where(user_id: user.id))
scope.where(permission, visible)
end
end end
end end
@ -17,7 +16,9 @@ class MapPolicy < ApplicationPolicy
end end
def show? def show?
record.permission == 'commons' || record.permission == 'public' || record.collaborators.include?(user) || record.user == user record.permission.in?(['commons', 'public']) ||
record.collaborators.include?(user) ||
record.user == user
end end
def create? def create?
@ -25,7 +26,10 @@ class MapPolicy < ApplicationPolicy
end end
def update? def update?
user.present? && (record.permission == 'commons' || record.collaborators.include?(user) || record.user == user) return false unless user.present?
record.permission == 'commons' ||
record.collaborators.include?(user) ||
record.user == user
end end
def destroy? def destroy?
@ -33,7 +37,7 @@ class MapPolicy < ApplicationPolicy
end end
def access? def access?
# note that this is to edit access # note that this is to edit who can access the map
user.present? && record.user == user user.present? && record.user == user
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MappingPolicy < ApplicationPolicy class MappingPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class MessagePolicy < ApplicationPolicy class MessagePolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve

View file

@ -1,13 +1,14 @@
# frozen_string_literal: true
class SynapsePolicy < ApplicationPolicy class SynapsePolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = %w(public commons) visible = %w(public commons)
permission = 'synapses.permission IN (?)'
if user return scope.where(permission: visible) unless user
scope.where(permission + ' OR synapses.defer_to_map_id IN (?) OR synapses.user_id = ?', visible, user.shared_maps.map(&:id), user.id)
else scope.where(permission: visible)
scope.where(permission, visible) .or(scope.where(defer_to_map_id: user.shared_maps.map(&:id)))
end .or(scope.where(user_id: user.id))
end end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class TokenPolicy < ApplicationPolicy class TokenPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve

View file

@ -1,13 +1,13 @@
# frozen_string_literal: true
class TopicPolicy < ApplicationPolicy class TopicPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = %w(public commons) visible = %w(public commons)
permission = 'topics.permission IN (?)' return scope.where(permission: visible) unless user
if user
scope.where(permission + ' OR topics.defer_to_map_id IN (?) OR topics.user_id = ?', visible, user.shared_maps.map(&:id), user.id) scope.where(permission: visible)
else .or(scope.where(defer_to_map_id: user.shared_maps.map(&:id)))
scope.where(permission, visible) .or(scope.where(user_id: user.id))
end
end end
end end
@ -23,14 +23,13 @@ class TopicPolicy < ApplicationPolicy
if record.defer_to_map.present? if record.defer_to_map.present?
map_policy.show? map_policy.show?
else else
record.permission == 'commons' || record.permission == 'public' || record.user == user record.permission.in?(['commons', 'public']) || record.user == user
end end
end end
def update? def update?
if !user.present? return false unless user.present?
false if record.defer_to_map.present?
elsif record.defer_to_map.present?
map_policy.update? map_policy.update?
else else
record.permission == 'commons' || record.user == user record.permission == 'commons' || record.user == user

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class ApplicationSerializer < ActiveModel::Serializer class ApplicationSerializer < ActiveModel::Serializer
@ -6,21 +7,40 @@ module Api
end end
def embeds def embeds
# subclasses can override self.embeddable, and then it will whitelist
# scope[:embeds] based on the contents. That way scope[:embeds] can just pull
# from params and the whitelisting happens here
@embeds ||= (scope[:embeds] || []).select { |e| self.class.embeddable.keys.include?(e) } @embeds ||= (scope[:embeds] || []).select { |e| self.class.embeddable.keys.include?(e) }
end end
# self.embeddable might look like this:
# topic1: { attr: :node1, serializer: TopicSerializer }
# topic2: { attr: :node2, serializer: TopicSerializer }
# contributors: { serializer: UserSerializer}
# This method will remove the :attr key if the underlying attribute name
# is different than the name provided in the final json output. All other keys
# in the hash will be passed to the ActiveModel::Serializer `attribute` method
# directly (e.g. serializer in the examples will be passed).
#
# This setup means if you passed this self.embeddable config and sent no
# ?embed= query param with your API request, you would get the regular attributes
# plus topic1_id, topic2_id, and contributor_ids. If you pass
# ?embed=topic1,topic2,contributors, then instead of two ids and an array of ids,
# you would get two serialized topics and an array of serialized users
def self.embed_dat def self.embed_dat
embeddable.each_pair do |key, opts| embeddable.each_pair do |key, opts|
attr = opts.delete(:attr) || key attr = opts.delete(:attr) || key
if attr.to_s.pluralize == attr.to_s if attr.to_s.pluralize == attr.to_s
attribute "#{attr.to_s.singularize}_ids".to_sym, opts.merge(unless: -> { embeds.include?(key) }) do attribute("#{attr.to_s.singularize}_ids".to_sym,
opts.merge(unless: -> { embeds.include?(key) })) do
object.send(attr).map(&:id) object.send(attr).map(&:id)
end end
has_many attr, opts.merge(if: -> { embeds.include?(key) }) has_many(attr, opts.merge(if: -> { embeds.include?(key) }))
else else
id_opts = opts.merge(key: "#{key}_id") id_opts = opts.merge(key: "#{key}_id")
attribute "#{attr}_id".to_sym, id_opts.merge(unless: -> { embeds.include?(key) }) attribute("#{attr}_id".to_sym,
attribute key, opts.merge(if: -> { embeds.include?(key) }) id_opts.merge(unless: -> { embeds.include?(key) }))
attribute(key, opts.merge(if: -> { embeds.include?(key) }))
end end
end end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class EventSerializer < ApplicationSerializer class EventSerializer < ApplicationSerializer

View file

@ -1,13 +1,14 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class MapSerializer < ApplicationSerializer class MapSerializer < ApplicationSerializer
attributes :id, attributes :id,
:name, :name,
:desc, :desc,
:permission, :permission,
:screenshot, :screenshot,
:created_at, :created_at,
:updated_at :updated_at
def self.embeddable def self.embeddable
{ {
@ -20,7 +21,7 @@ module Api
} }
end end
self.class_eval do class_eval do
embed_dat embed_dat
end end
end end

View file

@ -1,11 +1,12 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class MappingSerializer < ApplicationSerializer class MappingSerializer < ApplicationSerializer
attributes :id, attributes :id,
:created_at, :created_at,
:updated_at, :updated_at,
:mappable_id, :mappable_id,
:mappable_type :mappable_type
attribute :xloc, if: -> { object.mappable_type == 'Topic' } attribute :xloc, if: -> { object.mappable_type == 'Topic' }
attribute :yloc, if: -> { object.mappable_type == 'Topic' } attribute :yloc, if: -> { object.mappable_type == 'Topic' }
@ -17,7 +18,7 @@ module Api
} }
end end
self.class_eval do class_eval do
embed_dat embed_dat
end end
end end

View file

@ -1,11 +1,12 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class MetacodeSerializer < ApplicationSerializer class MetacodeSerializer < ApplicationSerializer
attributes :id, attributes :id,
:name, :name,
:manual_icon, :manual_icon,
:color, :color,
:aws_icon :aws_icon
end end
end end
end end

View file

@ -1,12 +1,13 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class SynapseSerializer < ApplicationSerializer class SynapseSerializer < ApplicationSerializer
attributes :id, attributes :id,
:desc, :desc,
:category, :category,
:permission, :permission,
:created_at, :created_at,
:updated_at :updated_at
def self.embeddable def self.embeddable
{ {
@ -16,7 +17,7 @@ module Api
} }
end end
self.class_eval do class_eval do
embed_dat embed_dat
end end
end end

View file

@ -1,10 +1,11 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class TokenSerializer < ApplicationSerializer class TokenSerializer < ApplicationSerializer
attributes :id, attributes :id,
:token, :token,
:description, :description,
:created_at :created_at
end end
end end
end end

View file

@ -1,13 +1,14 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class TopicSerializer < ApplicationSerializer class TopicSerializer < ApplicationSerializer
attributes :id, attributes :id,
:name, :name,
:desc, :desc,
:link, :link,
:permission, :permission,
:created_at, :created_at,
:updated_at :updated_at
def self.embeddable def self.embeddable
{ {
@ -16,7 +17,7 @@ module Api
} }
end end
self.class_eval do class_eval do
embed_dat embed_dat
end end
end end

View file

@ -1,19 +1,22 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class UserSerializer < ApplicationSerializer class UserSerializer < ApplicationSerializer
attributes :id, attributes :id,
:name, :name,
:avatar, :avatar,
:is_admin, :is_admin,
:generation :generation
def avatar def avatar
object.image.url(:sixtyfour) object.image.url(:sixtyfour)
end end
# rubocop:disable Style/PredicateName
def is_admin def is_admin
object.admin object.admin
end end
# rubocop:enable Style/PredicateName
end end
end end
end end

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Api module Api
module V2 module V2
class WebhookSerializer < ApplicationSerializer class WebhookSerializer < ApplicationSerializer

View file

@ -1,4 +1,11 @@
class MapExportService < Struct.new(:user, :map) # frozen_string_literal: true
class MapExportService
attr_reader :user, :map
def initialize(user, map)
@user = user
@map = map
end
def json def json
# marshal_dump turns OpenStruct into a Hash # marshal_dump turns OpenStruct into a Hash
{ {

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class Perm class Perm
# e.g. Perm::ISSIONS # e.g. Perm::ISSIONS
ISSIONS = [:commons, :public, :private].freeze ISSIONS = [:commons, :public, :private].freeze

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
class WebhookService class WebhookService
def self.publish!(webhook:, event:) def self.publish!(webhook:, event:)
return false unless webhook.event_types.include? event.kind return false unless webhook.event_types.include? event.kind

View file

@ -94,7 +94,7 @@
<p>As a valued beta tester, you have the ability to invite your peers, colleagues and collaborators onto the platform.</p> <p>As a valued beta tester, you have the ability to invite your peers, colleagues and collaborators onto the platform.</p>
<p>Below is a personal invite link containing your unique access code, which can be used multiple times.</p> <p>Below is a personal invite link containing your unique access code, which can be used multiple times.</p>
<div id="joinCodesBox"> <div id="joinCodesBox">
<p class="joinCodes"><%= determine_invite_link %> <p class="joinCodes"><%= invite_link() %>
<button class="button" onclick="Metamaps.GlobalUI.shareInvite('<%= @invite_link %>');">COPY INVITE LINK!</button> <button class="button" onclick="Metamaps.GlobalUI.shareInvite('<%= @invite_link %>');">COPY INVITE LINK!</button>
</div> </div>

View file

@ -1,29 +1,34 @@
<% @metacodes = user_metacodes() %>
<%= form_for Topic.new, url: topics_url, remote: true do |form| %> <%= form_for Topic.new, url: topics_url, remote: true do |form| %>
<div class="openMetacodeSwitcher openLightbox" data-open="switchMetacodes"> <div class="openMetacodeSwitcher openLightbox" data-open="switchMetacodes">
<div class="tooltipsAbove">Switch Metacodes</div> <div class="tooltipsAbove">Switch Metacodes</div>
</div> </div>
<div class="pinCarousel"> <div class="pinCarousel">
<div class="tooltipsAbove helpPin">Pin Open</div> <div class="tooltipsAbove helpPin">Pin Open</div>
<div class="tooltipsAbove helpUnpin">Unpin</div> <div class="tooltipsAbove helpUnpin">Unpin</div>
</div> </div>
<div id="metacodeImg"> <div id="metacodeImg">
<% @metacodes = user_metacodes() %>
<% set = get_metacodeset() %>
<% @metacodes.each do |metacode| %> <% @metacodes.each do |metacode| %>
<img class="cloudcarousel" width="40" height="40" src="<%= asset_path metacode.icon %>" alt="<%= metacode.name %>" title="<%= metacode.name %>" data-id="<%= metacode.id %>" /> <img class="cloudcarousel" width="40" height="40" src="<%= asset_path metacode.icon %>" alt="<%= metacode.name %>" title="<%= metacode.name %>" data-id="<%= metacode.id %>" />
<% end %> <% end %>
</div> </div>
<%= form.text_field :name, :maxlength => 140, :placeholder => "title..." %> <%= form.text_field :name, :maxlength => 140, :placeholder => "title..." %>
<div id="metacodeImgTitle"></div> <div id="metacodeImgTitle"></div>
<div class="clearfloat"></div> <div class="clearfloat"></div>
<script>
<% @metacodes.each do |metacode| %> <script>
<% if !set %> <% @metacodes.each do |metacode| %>
Metamaps.Create.selectedMetacodes.push("<%= metacode.id %>"); <% if !metacodeset() %>
Metamaps.Create.newSelectedMetacodes.push("<%= metacode.id %>"); Metamaps.Create.selectedMetacodes.push("<%= metacode.id %>");
Metamaps.Create.selectedMetacodeNames.push("<%= metacode.name %>"); Metamaps.Create.newSelectedMetacodes.push("<%= metacode.id %>");
Metamaps.Create.newSelectedMetacodeNames.push("<%= metacode.name %>"); Metamaps.Create.selectedMetacodeNames.push("<%= metacode.name %>");
<% end %> Metamaps.Create.newSelectedMetacodeNames.push("<%= metacode.name %>");
<% end %> <% end %>
</script> <% end %>
</script>
<% end %> <% end %>

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# This file is used by Rack-based servers to start the application. # This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__) require ::File.expand_path('../config/environment', __FILE__)

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative 'boot' require_relative 'boot'
require 'csv' require 'csv'

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'rubygems' require 'rubygems'
require 'rails/commands/server' require 'rails/commands/server'

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
# Load the Rails application. # Load the Rails application.
require_relative 'application' require_relative 'application'

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
Metamaps::Application.configure do Metamaps::Application.configure do
# Settings specified here will take precedence over those in config/application.rb # Settings specified here will take precedence over those in config/application.rb

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
Rails.application.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb # Settings specified here will take precedence over those in config/application.rb

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
Metamaps::Application.configure do Metamaps::Application.configure do
# Settings specified here will take precedence over those in config/application.rb # Settings specified here will take precedence over those in config/application.rb

View file

@ -1,4 +1,7 @@
# frozen_string_literal: true
$codes = [] $codes = []
if ActiveRecord::Base.connection.data_source_exists? 'users' if ActiveRecord::Base.connection.data_source_exists? 'users'
$codes = ActiveRecord::Base.connection.execute('SELECT code FROM users').map { |user| user['code'] } $codes = ActiveRecord::Base.connection
.execute('SELECT code FROM users')
.map { |user| user['code'] }
end end

Some files were not shown because too many files have changed in this diff Show more