more rubocop updates

This commit is contained in:
Devin Howard 2016-09-24 12:27:34 +08:00
parent 5fab6de48a
commit f8c11f234d
26 changed files with 234 additions and 194 deletions

View file

@ -6,6 +6,7 @@ AllCops:
- 'bin/**/*' - 'bin/**/*'
- 'vendor/**/*' - 'vendor/**/*'
- 'app/assets/javascripts/node_modules/**/*' - 'app/assets/javascripts/node_modules/**/*'
- 'Vagrantfile'
Rails: Rails:
Enabled: true Enabled: true

1
Vagrantfile vendored
View file

@ -1,4 +1,3 @@
# frozen_string_literal: true
# -*- mode: ruby -*- # -*- mode: ruby -*-
# vi: set ft=ruby : # vi: set ft=ruby :

View file

@ -2,9 +2,11 @@
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

@ -52,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
@ -60,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
@ -95,33 +99,31 @@ module Api
end end
def pagination(collection) def pagination(collection)
per = (params[:per] || 25).to_i @pagination_data ||= {
current_page = (params[:page] || 1).to_i current_page: (params[:page] || 1).to_i,
total_pages = (collection.total_count.to_f / per).ceil next_page: current_page < total_pages ? current_page + 1 : 0,
prev_page = current_page > 1 ? current_page - 1 : 0 prev_page: current_page > 1 ? current_page - 1 : 0,
next_page = current_page < total_pages ? 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 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'] = 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

View file

@ -6,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
@ -42,23 +42,21 @@ 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
return true if authenticated? && admin? return true if authenticated? && admin?

View file

@ -1,14 +1,14 @@
# frozen_string_literal: true # 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
@ -17,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,35 +1,42 @@
# frozen_string_literal: true # 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)
}
end
end
contributorTip = '' def first_contributor_image(map)
firstContributorImage = 'https://s3.amazonaws.com/metamaps-assets/site/user.png' if map.contributors.count.positive?
if m.contributors.count.positive? return map.contributors[0].image.url(:thirtytwo)
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
'https://s3.amazonaws.com/metamaps-assets/site/user.png'
end end
map['contributorTip'] = contributorTip
map['mapContributorImage'] = firstContributorImage
temp.push map 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
temp end
output
end end
end end

View file

@ -2,33 +2,24 @@
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

@ -2,56 +2,38 @@
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.zero?
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 end
elsif node.relatives.empty? array
return array
end
end end
end end

View file

@ -3,13 +3,11 @@ 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
@ -18,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?
@ -26,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?
@ -34,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

@ -3,12 +3,12 @@ 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

@ -3,12 +3,11 @@ 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
@ -24,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

@ -7,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

@ -12,9 +12,11 @@ module Api
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,5 +1,11 @@
# frozen_string_literal: true # 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 def json
# marshal_dump turns OpenStruct into a Hash # marshal_dump turns OpenStruct into a Hash
{ {

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| %>
<% if !metacodeset() %>
Metamaps.Create.selectedMetacodes.push("<%= metacode.id %>"); Metamaps.Create.selectedMetacodes.push("<%= metacode.id %>");
Metamaps.Create.newSelectedMetacodes.push("<%= metacode.id %>"); Metamaps.Create.newSelectedMetacodes.push("<%= metacode.id %>");
Metamaps.Create.selectedMetacodeNames.push("<%= metacode.name %>"); Metamaps.Create.selectedMetacodeNames.push("<%= metacode.name %>");
Metamaps.Create.newSelectedMetacodeNames.push("<%= metacode.name %>"); Metamaps.Create.newSelectedMetacodeNames.push("<%= metacode.name %>");
<% end %> <% end %>
<% end %> <% end %>
</script> </script>
<% end %> <% end %>

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true # 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

View file

@ -1,8 +1,10 @@
# frozen_string_literal: true # frozen_string_literal: true
# Be sure to restart your server when you modify this file. # 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/ } # 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! # Rails.backtrace_cleaner.remove_silencers!

View file

@ -7,7 +7,8 @@ Devise.setup do |config|
# confirmation, reset password and unlock tokens in the database. # confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key` # 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. # by default. You can change it below and use your own secret key.
# config.secret_key = '4d38a819bcea6314ffccb156a8e84b1b52c51ed446d11877c973791b3cd88449e9dbd7990cbc6e7f37d84702168ec36391467000c842ed5bed4f0b05df2b9507' # config.secret_key = '4d38a819bcea6314ffccb156a8e84b1b52c51ed446d11877c973791b3cd88' +
# '449e9dbd7990cbc6e7f37d84702168ec36391467000c842ed5bed4f0b05df2b9507'
# ==> Mailer Configuration # ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer, # 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 config.stretches = Rails.env.test? ? 1 : 10
# Setup a pepper to generate the encrypted password. # Setup a pepper to generate the encrypted password.
# config.pepper = "640ad415cb5292ac9ddbfa6ad7d9653d1537f1184e4037c2453db3eccb98e1c82facc6d3de7bf9d4c41d9967d41194c6e120f36f430e195ba840cd00e02dea59" # config.pepper = "640ad415cb5292ac9ddbfa6ad7d9653d1537f1184e4037c2453db3eccb98e1c82" +
# "facc6d3de7bf9d4c41d9967d41194c6e120f36f430e195ba840cd00e02dea59"
# ==> Configuration for :confirmable # ==> Configuration for :confirmable
# A period that the user is allowed to access the website even without # A period that the user is allowed to access the website even without

View file

@ -8,7 +8,8 @@ Doorkeeper.configure do
current_user || redirect_to(new_user_session_url) current_user || redirect_to(new_user_session_url)
end 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 admin_authenticator do
current_user || redirect_to(new_user_session_url) current_user || redirect_to(new_user_session_url)
end end
@ -39,7 +40,9 @@ Doorkeeper.configure do
# Provide support for an owner to be assigned to each registered application (disabled by default) # 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 # Optional parameter :confirmation => true (default false) if you want to enforce ownership of
# a registered application # 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 # enable_application_owner :confirmation => false
# Define access token scopes for your provider # 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 # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
# Change the native redirect uri for client apps # 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 # When clients register with the following redirect uri, they won't be redirected to any server
# The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL # and the authorization code will be displayed within the provider
# (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi) # 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' # native_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'

View file

@ -2,7 +2,10 @@
require 'uservoice-ruby' require 'uservoice-ruby'
def current_sso_token def current_sso_token
@current_sso_token ||= UserVoice.generate_sso_token('metamapscc', ENV['SSO_KEY'], { @current_sso_token ||= UserVoice.generate_sso_token(
email: current_user.email 'metamapscc',
}, 300) # Default expiry time is 5 minutes = 300 seconds ENV['SSO_KEY'],
{ email: current_user.email },
300 # Default expiry time is 5 minutes = 300 seconds
)
end end

View file

@ -64,7 +64,11 @@ Metamaps::Application.routes.draw do
get 'explore/starred', to: 'maps#starredmaps' get 'explore/starred', to: 'maps#starredmaps'
get 'explore/mapper/:id', to: 'maps#usermaps' 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 devise_scope :user do
get 'login' => 'devise/sessions#new', :as => :new_user_session get 'login' => 'devise/sessions#new', :as => :new_user_session

View file

@ -1,6 +1,5 @@
#!/usr/bin/env ruby.exe #!/usr/bin/env ruby.exe
# frozen_string_literal: true # 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__) APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__) require File.expand_path('../../config/boot', __FILE__)

View file

@ -24,7 +24,9 @@ RSpec.describe 'mappings API', type: :request do
end end
it 'POST /api/v2/mappings' do 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 have_http_status(:success)
expect(response).to match_json_schema(:mapping) expect(response).to match_json_schema(:mapping)
@ -32,7 +34,9 @@ RSpec.describe 'mappings API', type: :request do
end end
it 'PATCH /api/v2/mappings/:id' do 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 have_http_status(:success)
expect(response).to match_json_schema(:mapping) expect(response).to match_json_schema(:mapping)

View file

@ -24,7 +24,9 @@ RSpec.describe 'synapses API', type: :request do
end end
it 'POST /api/v2/synapses' do 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 have_http_status(:success)
expect(response).to match_json_schema(:synapse) expect(response).to match_json_schema(:synapse)
@ -32,7 +34,9 @@ RSpec.describe 'synapses API', type: :request do
end end
it 'PATCH /api/v2/synapses/:id' do 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 have_http_status(:success)
expect(response).to match_json_schema(:synapse) expect(response).to match_json_schema(:synapse)