more rubocop updates
This commit is contained in:
parent
5fab6de48a
commit
f8c11f234d
26 changed files with 234 additions and 194 deletions
|
@ -6,6 +6,7 @@ AllCops:
|
|||
- 'bin/**/*'
|
||||
- 'vendor/**/*'
|
||||
- 'app/assets/javascripts/node_modules/**/*'
|
||||
- 'Vagrantfile'
|
||||
|
||||
Rails:
|
||||
Enabled: true
|
||||
|
|
1
Vagrantfile
vendored
1
Vagrantfile
vendored
|
@ -1,4 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
module Api
|
||||
module V1
|
||||
class DeprecatedController < ApplicationController
|
||||
# rubocop:disable Style/MethodMissing
|
||||
def method_missing
|
||||
render json: { error: '/api/v1 is deprecated! Please use /api/v2 instead.' }
|
||||
end
|
||||
# rubocop:enable Style/MethodMissing
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,7 +52,8 @@ module Api
|
|||
"Api::V2::#{resource_name.camelize}Serializer".constantize
|
||||
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?
|
||||
render json: resource, scope: scope, serializer: serializer, root: root
|
||||
else
|
||||
|
@ -60,8 +61,11 @@ module Api
|
|||
end
|
||||
end
|
||||
|
||||
def respond_with_collection(resources: collection, scope: default_scope, serializer: resource_serializer, root: serializer_root)
|
||||
render json: resources, scope: scope, each_serializer: serializer, root: root, meta: pagination(resources), meta_key: :page
|
||||
def respond_with_collection(resources: collection, scope: default_scope,
|
||||
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
|
||||
|
||||
def default_scope
|
||||
|
@ -95,33 +99,31 @@ module Api
|
|||
end
|
||||
|
||||
def pagination(collection)
|
||||
per = (params[:per] || 25).to_i
|
||||
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
|
||||
@pagination_data ||= {
|
||||
current_page: (params[:page] || 1).to_i,
|
||||
next_page: current_page < total_pages ? current_page + 1 : 0,
|
||||
prev_page: current_page > 1 ? current_page - 1 : 0,
|
||||
total_pages: (collection.total_count.to_f / per).ceil,
|
||||
total_count: collection.total_count,
|
||||
per: (params[:per] || 25).to_i
|
||||
}
|
||||
end
|
||||
|
||||
def pagination_link_headers!(data)
|
||||
base_url = request.base_url + request.path
|
||||
nxt = request.query_parameters.merge(page: next_page).map { |x| x.join('=') }.join('&')
|
||||
prev = request.query_parameters.merge(page: prev_page).map { |x| x.join('=') }.join('&')
|
||||
last = request.query_parameters.merge(page: total_pages).map { |x| x.join('=') }.join('&')
|
||||
old_query = request_query_parameters
|
||||
nxt = old_query.merge(page: data[:next_page]).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'] = [
|
||||
%(<#{base_url}?#{nxt}>; rel="next"),
|
||||
%(<#{base_url}?#{prev}>; rel="prev"),
|
||||
%(<#{base_url}?#{last}>; rel="last")
|
||||
].join(',')
|
||||
response.headers['X-Total-Pages'] = collection.total_pages.to_s
|
||||
response.headers['X-Total-Count'] = collection.total_count.to_s
|
||||
response.headers['X-Total-Pages'] = data[:total_pages].to_s
|
||||
response.headers['X-Total-Count'] = data[:total_count].to_s
|
||||
response.headers['X-Per-Page'] = 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
|
||||
|
||||
def instantiate_collection
|
||||
|
|
|
@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base
|
|||
rescue_from Pundit::NotAuthorizedError, with: :handle_unauthorized
|
||||
protect_from_forgery(with: :exception)
|
||||
|
||||
before_action :get_invite_link
|
||||
before_action :invite_link
|
||||
after_action :allow_embedding
|
||||
|
||||
def default_serializer_options
|
||||
|
@ -42,22 +42,20 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
private
|
||||
|
||||
def get_invite_link
|
||||
def invite_link
|
||||
@invite_link = "#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
|
||||
end
|
||||
|
||||
def require_no_user
|
||||
if authenticated?
|
||||
redirect_to edit_user_path(user), notice: 'You must be logged out.'
|
||||
return false
|
||||
end
|
||||
return true unless authenticated?
|
||||
redirect_to edit_user_path(user), notice: 'You must be logged out.'
|
||||
return false
|
||||
end
|
||||
|
||||
def require_user
|
||||
unless authenticated?
|
||||
redirect_to new_user_session_path, notice: 'You must be logged in.'
|
||||
return false
|
||||
end
|
||||
return true if authenticated?
|
||||
redirect_to new_user_session_path, notice: 'You must be logged in.'
|
||||
return false
|
||||
end
|
||||
|
||||
def require_admin
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
module ApplicationHelper
|
||||
def get_metacodeset
|
||||
@m = current_user.settings.metacodes
|
||||
set = @m[0].include?('metacodeset') ? MetacodeSet.find(@m[0].sub('metacodeset-', '').to_i) : false
|
||||
set
|
||||
def metacodeset
|
||||
metacodes = current_user.settings.metacodes
|
||||
return false unless metacodes[0].include?('metacodeset')
|
||||
MetacodeSet.find(metacodes[0].sub('metacodeset-', '').to_i)
|
||||
end
|
||||
|
||||
def user_metacodes
|
||||
@m = current_user.settings.metacodes
|
||||
set = get_metacodeset
|
||||
set = metacodeset
|
||||
@metacodes = if set
|
||||
set.metacodes.to_a
|
||||
else
|
||||
|
@ -17,7 +17,7 @@ module ApplicationHelper
|
|||
@metacodes.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1)
|
||||
end
|
||||
|
||||
def determine_invite_link
|
||||
def invite_link
|
||||
"#{request.base_url}/join" + (current_user ? "?code=#{current_user.code}" : '')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,35 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
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)
|
||||
temp = []
|
||||
maps.each do |m|
|
||||
map = {}
|
||||
map['id'] = m.id
|
||||
map['label'] = m.name
|
||||
map['value'] = m.name
|
||||
map['description'] = m.desc.try(:truncate, 30)
|
||||
map['permission'] = m.permission
|
||||
map['topicCount'] = m.topics.count
|
||||
map['synapseCount'] = m.synapses.count
|
||||
map['contributorCount'] = m.contributors.count
|
||||
map['rtype'] = 'map'
|
||||
|
||||
contributorTip = ''
|
||||
firstContributorImage = 'https://s3.amazonaws.com/metamaps-assets/site/user.png'
|
||||
if m.contributors.count.positive?
|
||||
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
|
||||
maps.map do |m|
|
||||
{
|
||||
id: m.id,
|
||||
label: m.name,
|
||||
value: m.name,
|
||||
description: m.desc.try(:truncate, 30),
|
||||
permission: m.permission,
|
||||
topicCount: m.topics.count,
|
||||
synapseCount: m.synapses.count,
|
||||
contributorCount: m.contributors.count,
|
||||
rtype: 'map',
|
||||
contributorTip: contributor_tip(map),
|
||||
mapContributorImage: first_contributor_image(map)
|
||||
}
|
||||
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
|
||||
|
|
|
@ -2,33 +2,24 @@
|
|||
module SynapsesHelper
|
||||
## this one is for building our custom JSON autocomplete format for typeahead
|
||||
def autocomplete_synapse_generic_json(unique)
|
||||
temp = []
|
||||
unique.each do |s|
|
||||
synapse = {}
|
||||
synapse['label'] = s.desc
|
||||
synapse['value'] = s.desc
|
||||
|
||||
temp.push synapse
|
||||
unique.map do |s|
|
||||
{ label: s.desc, value: s.desc }
|
||||
end
|
||||
temp
|
||||
end
|
||||
|
||||
## this one is for building our custom JSON autocomplete format for typeahead
|
||||
def autocomplete_synapse_array_json(synapses)
|
||||
temp = []
|
||||
synapses.each do |s|
|
||||
synapse = {}
|
||||
synapse['id'] = s.id
|
||||
synapse['label'] = s.desc.nil? || s.desc == '' ? '(no description)' : s.desc
|
||||
synapse['value'] = s.desc
|
||||
synapse['permission'] = s.permission
|
||||
synapse['mapCount'] = s.maps.count
|
||||
synapse['originator'] = s.user.name
|
||||
synapse['originatorImage'] = s.user.image.url(:thirtytwo)
|
||||
synapse['rtype'] = 'synapse'
|
||||
|
||||
temp.push synapse
|
||||
synapses.map do |s|
|
||||
{
|
||||
id: s.id,
|
||||
label: s.desc.blank? ? '(no description)' : s.desc,
|
||||
value: s.desc,
|
||||
permission: s.permission,
|
||||
mapCount: s.maps.count,
|
||||
originator: s.user.name,
|
||||
originatorImage: s.user.image.url(:thirtytwo),
|
||||
rtype: 'synapse'
|
||||
}
|
||||
end
|
||||
temp
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,56 +2,38 @@
|
|||
module TopicsHelper
|
||||
## this one is for building our custom JSON autocomplete format for typeahead
|
||||
def autocomplete_array_json(topics)
|
||||
temp = []
|
||||
topics.each do |t|
|
||||
topic = {}
|
||||
topic['id'] = t.id
|
||||
topic['label'] = t.name
|
||||
topic['value'] = t.name
|
||||
topic['description'] = t.desc ? t.desc&.truncate(70) # make this return matched results
|
||||
topic['type'] = t.metacode.name
|
||||
topic['typeImageURL'] = t.metacode.icon
|
||||
topic['permission'] = t.permission
|
||||
topic['mapCount'] = t.maps.count
|
||||
topic['synapseCount'] = t.synapses.count
|
||||
topic['originator'] = t.user.name
|
||||
topic['originatorImage'] = t.user.image.url(:thirtytwo)
|
||||
topic['rtype'] = 'topic'
|
||||
topic['inmaps'] = t.inmaps
|
||||
topic['inmapsLinks'] = t.inmapsLinks
|
||||
|
||||
temp.push topic
|
||||
topics.map do |t|
|
||||
{
|
||||
id: t.id,
|
||||
label: t.name,
|
||||
value: t.name,
|
||||
description: t.desc ? t.desc&.truncate(70) : '', # make this return matched results
|
||||
type: t.metacode.name,
|
||||
typeImageURL: t.metacode.icon,
|
||||
permission: t.permission,
|
||||
mapCount: t.maps.count,
|
||||
synapseCount: t.synapses.count,
|
||||
originator: t.user.name,
|
||||
originatorImage: t.user.image.url(:thirtytwo),
|
||||
rtype: :topic,
|
||||
inmaps: t.inmaps,
|
||||
inmapsLinks: t.inmapsLinks
|
||||
}
|
||||
end
|
||||
temp
|
||||
end
|
||||
|
||||
# find all nodes in any given nodes network
|
||||
# recursively find all nodes in any given nodes network
|
||||
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?
|
||||
|
||||
# add the node to the array
|
||||
array.push(node)
|
||||
|
||||
return array if count.zero?
|
||||
|
||||
count -= 1
|
||||
|
||||
# check if each relative is already in the array and if not, call the network function again
|
||||
if !node.relatives.empty?
|
||||
if (node.relatives - array).empty?
|
||||
return array
|
||||
else
|
||||
(node.relatives - array).each do |relative|
|
||||
array = (array | network(relative, array, count))
|
||||
end
|
||||
return array
|
||||
end
|
||||
|
||||
elsif node.relatives.empty?
|
||||
return array
|
||||
remaining_relatives = node.relatives.to_a - array
|
||||
remaining_relatives.each do |relative|
|
||||
array = (array | network(relative, array, count - 1))
|
||||
end
|
||||
|
||||
array
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,13 +3,11 @@ class MapPolicy < ApplicationPolicy
|
|||
class Scope < Scope
|
||||
def resolve
|
||||
visible = %w(public commons)
|
||||
permission = 'maps.permission IN (?)'
|
||||
if user
|
||||
shared_maps = user.shared_maps.map(&:id)
|
||||
scope.where(permission + ' OR maps.id IN (?) OR maps.user_id = ?', visible, shared_maps, user.id)
|
||||
else
|
||||
scope.where(permission, visible)
|
||||
end
|
||||
return scope.where(permission: visible) unless user
|
||||
|
||||
scope.where(permission: visible)
|
||||
.or(scope.where(id: user.shared_maps.map(&:id)))
|
||||
.or(scope.where(user_id: user.id))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -18,7 +16,9 @@ class MapPolicy < ApplicationPolicy
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def create?
|
||||
|
@ -26,7 +26,10 @@ class MapPolicy < ApplicationPolicy
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def destroy?
|
||||
|
@ -34,7 +37,7 @@ class MapPolicy < ApplicationPolicy
|
|||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@ class SynapsePolicy < ApplicationPolicy
|
|||
class Scope < Scope
|
||||
def resolve
|
||||
visible = %w(public commons)
|
||||
permission = 'synapses.permission IN (?)'
|
||||
if 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)
|
||||
end
|
||||
|
||||
return scope.where(permission: visible) unless user
|
||||
|
||||
scope.where(permission: visible)
|
||||
.or(scope.where(defer_to_map_id: user.shared_maps.map(&:id)))
|
||||
.or(scope.where(user_id: user.id))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@ class TopicPolicy < ApplicationPolicy
|
|||
class Scope < Scope
|
||||
def resolve
|
||||
visible = %w(public commons)
|
||||
permission = 'topics.permission IN (?)'
|
||||
if user
|
||||
scope.where(permission + ' OR topics.defer_to_map_id IN (?) OR topics.user_id = ?', visible, user.shared_maps.map(&:id), user.id)
|
||||
else
|
||||
scope.where(permission, visible)
|
||||
end
|
||||
return scope.where(permission: visible) unless user
|
||||
|
||||
scope.where(permission: visible)
|
||||
.or(scope.where(defer_to_map_id: user.shared_maps.map(&:id)))
|
||||
.or(scope.where(user_id: user.id))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,14 +23,13 @@ class TopicPolicy < ApplicationPolicy
|
|||
if record.defer_to_map.present?
|
||||
map_policy.show?
|
||||
else
|
||||
record.permission == 'commons' || record.permission == 'public' || record.user == user
|
||||
record.permission.in?('commons', 'public') || record.user == user
|
||||
end
|
||||
end
|
||||
|
||||
def update?
|
||||
if !user.present?
|
||||
false
|
||||
elsif record.defer_to_map.present?
|
||||
return false unless user.present?
|
||||
if record.defer_to_map.present?
|
||||
map_policy.update?
|
||||
else
|
||||
record.permission == 'commons' || record.user == user
|
||||
|
|
|
@ -7,21 +7,40 @@ module Api
|
|||
end
|
||||
|
||||
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) }
|
||||
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
|
||||
embeddable.each_pair do |key, opts|
|
||||
attr = opts.delete(:attr) || key
|
||||
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)
|
||||
end
|
||||
has_many attr, opts.merge(if: -> { embeds.include?(key) })
|
||||
has_many(attr, opts.merge(if: -> { embeds.include?(key) }))
|
||||
else
|
||||
id_opts = opts.merge(key: "#{key}_id")
|
||||
attribute "#{attr}_id".to_sym, id_opts.merge(unless: -> { embeds.include?(key) })
|
||||
attribute key, opts.merge(if: -> { embeds.include?(key) })
|
||||
attribute("#{attr}_id".to_sym,
|
||||
id_opts.merge(unless: -> { embeds.include?(key) }))
|
||||
attribute(key, opts.merge(if: -> { embeds.include?(key) }))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,9 +12,11 @@ module Api
|
|||
object.image.url(:sixtyfour)
|
||||
end
|
||||
|
||||
# rubocop:disable Style/PredicateName
|
||||
def is_admin
|
||||
object.admin
|
||||
end
|
||||
# rubocop:enable Style/PredicateName
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
class MapExportService < Struct.new(:user, :map)
|
||||
class MapExportService
|
||||
attr_reader :user, :map
|
||||
def initialize(user, map)
|
||||
@user = user
|
||||
@map = map
|
||||
end
|
||||
|
||||
def json
|
||||
# marshal_dump turns OpenStruct into a Hash
|
||||
{
|
||||
|
|
|
@ -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>Below is a personal invite link containing your unique access code, which can be used multiple times.</p>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,29 +1,34 @@
|
|||
<% @metacodes = user_metacodes() %>
|
||||
|
||||
<%= form_for Topic.new, url: topics_url, remote: true do |form| %>
|
||||
<div class="openMetacodeSwitcher openLightbox" data-open="switchMetacodes">
|
||||
<div class="tooltipsAbove">Switch Metacodes</div>
|
||||
</div>
|
||||
|
||||
<div class="pinCarousel">
|
||||
<div class="tooltipsAbove helpPin">Pin Open</div>
|
||||
<div class="tooltipsAbove helpUnpin">Unpin</div>
|
||||
</div>
|
||||
|
||||
<div id="metacodeImg">
|
||||
<% @metacodes = user_metacodes() %>
|
||||
<% set = get_metacodeset() %>
|
||||
<% @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 %>" />
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= form.text_field :name, :maxlength => 140, :placeholder => "title..." %>
|
||||
|
||||
<div id="metacodeImgTitle"></div>
|
||||
<div class="clearfloat"></div>
|
||||
<script>
|
||||
<% @metacodes.each do |metacode| %>
|
||||
<% if !set %>
|
||||
Metamaps.Create.selectedMetacodes.push("<%= metacode.id %>");
|
||||
Metamaps.Create.newSelectedMetacodes.push("<%= metacode.id %>");
|
||||
Metamaps.Create.selectedMetacodeNames.push("<%= metacode.name %>");
|
||||
Metamaps.Create.newSelectedMetacodeNames.push("<%= metacode.name %>");
|
||||
<% end %>
|
||||
<% end %>
|
||||
</script>
|
||||
|
||||
<script>
|
||||
<% @metacodes.each do |metacode| %>
|
||||
<% if !metacodeset() %>
|
||||
Metamaps.Create.selectedMetacodes.push("<%= metacode.id %>");
|
||||
Metamaps.Create.newSelectedMetacodes.push("<%= metacode.id %>");
|
||||
Metamaps.Create.selectedMetacodeNames.push("<%= metacode.name %>");
|
||||
Metamaps.Create.newSelectedMetacodeNames.push("<%= metacode.name %>");
|
||||
<% end %>
|
||||
<% end %>
|
||||
</script>
|
||||
<% end %>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
$codes = []
|
||||
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
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
||||
# You can add backtrace silencers for libraries that you're using but don't
|
||||
# wish to see in your backtraces.
|
||||
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
||||
|
||||
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
||||
# You can also remove all the silencers if you're trying to debug a problem
|
||||
# that might stem from framework code.
|
||||
# Rails.backtrace_cleaner.remove_silencers!
|
||||
|
|
|
@ -7,7 +7,8 @@ Devise.setup do |config|
|
|||
# confirmation, reset password and unlock tokens in the database.
|
||||
# Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key`
|
||||
# by default. You can change it below and use your own secret key.
|
||||
# config.secret_key = '4d38a819bcea6314ffccb156a8e84b1b52c51ed446d11877c973791b3cd88449e9dbd7990cbc6e7f37d84702168ec36391467000c842ed5bed4f0b05df2b9507'
|
||||
# config.secret_key = '4d38a819bcea6314ffccb156a8e84b1b52c51ed446d11877c973791b3cd88' +
|
||||
# '449e9dbd7990cbc6e7f37d84702168ec36391467000c842ed5bed4f0b05df2b9507'
|
||||
|
||||
# ==> Mailer Configuration
|
||||
# Configure the e-mail address which will be shown in Devise::Mailer,
|
||||
|
@ -92,7 +93,8 @@ Devise.setup do |config|
|
|||
config.stretches = Rails.env.test? ? 1 : 10
|
||||
|
||||
# Setup a pepper to generate the encrypted password.
|
||||
# config.pepper = "640ad415cb5292ac9ddbfa6ad7d9653d1537f1184e4037c2453db3eccb98e1c82facc6d3de7bf9d4c41d9967d41194c6e120f36f430e195ba840cd00e02dea59"
|
||||
# config.pepper = "640ad415cb5292ac9ddbfa6ad7d9653d1537f1184e4037c2453db3eccb98e1c82" +
|
||||
# "facc6d3de7bf9d4c41d9967d41194c6e120f36f430e195ba840cd00e02dea59"
|
||||
|
||||
# ==> Configuration for :confirmable
|
||||
# A period that the user is allowed to access the website even without
|
||||
|
|
|
@ -8,7 +8,8 @@ Doorkeeper.configure do
|
|||
current_user || redirect_to(new_user_session_url)
|
||||
end
|
||||
|
||||
# If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
|
||||
# If you want to restrict access to the web interface for adding oauth authorized applications,
|
||||
# you need to declare the block below.
|
||||
admin_authenticator do
|
||||
current_user || redirect_to(new_user_session_url)
|
||||
end
|
||||
|
@ -39,7 +40,9 @@ Doorkeeper.configure do
|
|||
# Provide support for an owner to be assigned to each registered application (disabled by default)
|
||||
# Optional parameter :confirmation => true (default false) if you want to enforce ownership of
|
||||
# a registered application
|
||||
# Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support
|
||||
# Note: you must also run the rails g doorkeeper:application_owner generator to provide the
|
||||
# necessary support
|
||||
#
|
||||
# enable_application_owner :confirmation => false
|
||||
|
||||
# Define access token scopes for your provider
|
||||
|
@ -61,9 +64,11 @@ Doorkeeper.configure do
|
|||
# access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
|
||||
|
||||
# Change the native redirect uri for client apps
|
||||
# When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider
|
||||
# The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
|
||||
# (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
|
||||
# When clients register with the following redirect uri, they won't be redirected to any server
|
||||
# and the authorization code will be displayed within the provider
|
||||
# The value can be any string. Use nil to disable this feature. When disabled, clients
|
||||
# must provide a valid URL (Similar behaviour:
|
||||
# https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
|
||||
#
|
||||
# native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
|
||||
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
require 'uservoice-ruby'
|
||||
|
||||
def current_sso_token
|
||||
@current_sso_token ||= UserVoice.generate_sso_token('metamapscc', ENV['SSO_KEY'], {
|
||||
email: current_user.email
|
||||
}, 300) # Default expiry time is 5 minutes = 300 seconds
|
||||
@current_sso_token ||= UserVoice.generate_sso_token(
|
||||
'metamapscc',
|
||||
ENV['SSO_KEY'],
|
||||
{ email: current_user.email },
|
||||
300 # Default expiry time is 5 minutes = 300 seconds
|
||||
)
|
||||
end
|
||||
|
|
|
@ -64,7 +64,11 @@ Metamaps::Application.routes.draw do
|
|||
get 'explore/starred', to: 'maps#starredmaps'
|
||||
get 'explore/mapper/:id', to: 'maps#usermaps'
|
||||
|
||||
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, skip: :sessions
|
||||
devise_for :users, skip: :sessions, controllers: {
|
||||
registrations: 'users/registrations',
|
||||
passwords: 'users/passwords',
|
||||
sessions: 'devise/sessions'
|
||||
}
|
||||
|
||||
devise_scope :user do
|
||||
get 'login' => 'devise/sessions#new', :as => :new_user_session
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env ruby.exe
|
||||
# frozen_string_literal: true
|
||||
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
||||
|
||||
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
||||
require File.expand_path('../../config/boot', __FILE__)
|
||||
|
|
|
@ -24,7 +24,9 @@ RSpec.describe 'mappings API', type: :request do
|
|||
end
|
||||
|
||||
it 'POST /api/v2/mappings' do
|
||||
post '/api/v2/mappings', params: { mapping: mapping.attributes, access_token: token }
|
||||
post '/api/v2/mappings', params: {
|
||||
mapping: mapping.attributes, access_token: token
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to match_json_schema(:mapping)
|
||||
|
@ -32,7 +34,9 @@ RSpec.describe 'mappings API', type: :request do
|
|||
end
|
||||
|
||||
it 'PATCH /api/v2/mappings/:id' do
|
||||
patch "/api/v2/mappings/#{mapping.id}", params: { mapping: mapping.attributes, access_token: token }
|
||||
patch "/api/v2/mappings/#{mapping.id}", params: {
|
||||
mapping: mapping.attributes, access_token: token
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to match_json_schema(:mapping)
|
||||
|
|
|
@ -24,7 +24,9 @@ RSpec.describe 'synapses API', type: :request do
|
|||
end
|
||||
|
||||
it 'POST /api/v2/synapses' do
|
||||
post '/api/v2/synapses', params: { synapse: synapse.attributes, access_token: token }
|
||||
post '/api/v2/synapses', params: {
|
||||
synapse: synapse.attributes, access_token: token
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to match_json_schema(:synapse)
|
||||
|
@ -32,7 +34,9 @@ RSpec.describe 'synapses API', type: :request do
|
|||
end
|
||||
|
||||
it 'PATCH /api/v2/synapses/:id' do
|
||||
patch "/api/v2/synapses/#{synapse.id}", params: { synapse: synapse.attributes, access_token: token }
|
||||
patch "/api/v2/synapses/#{synapse.id}", params: {
|
||||
synapse: synapse.attributes, access_token: token
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to match_json_schema(:synapse)
|
||||
|
|
Loading…
Reference in a new issue