diff --git a/.rubocop.yml b/.rubocop.yml index 897484b7..6bdcbfc3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,7 @@ AllCops: - 'bin/**/*' - 'vendor/**/*' - 'app/assets/javascripts/node_modules/**/*' + - 'Vagrantfile' Rails: Enabled: true diff --git a/Vagrantfile b/Vagrantfile index 0fa3e8da..6ee6cb35 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,4 +1,3 @@ -# frozen_string_literal: true # -*- mode: ruby -*- # vi: set ft=ruby : diff --git a/app/controllers/api/v1/deprecated_controller.rb b/app/controllers/api/v1/deprecated_controller.rb index 6f6b5f15..b9e07214 100644 --- a/app/controllers/api/v1/deprecated_controller.rb +++ b/app/controllers/api/v1/deprecated_controller.rb @@ -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 diff --git a/app/controllers/api/v2/restful_controller.rb b/app/controllers/api/v2/restful_controller.rb index d7a1856e..74a8f472 100644 --- a/app/controllers/api/v2/restful_controller.rb +++ b/app/controllers/api/v2/restful_controller.rb @@ -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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7735c681..83889619 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 57b24106..1c9b4da5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/helpers/maps_helper.rb b/app/helpers/maps_helper.rb index 8ca7b047..0ca99c15 100644 --- a/app/helpers/maps_helper.rb +++ b/app/helpers/maps_helper.rb @@ -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 += '
  • ' + '' + name + '
  • ' - 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 += '
  • ' + output += %() + output += "#{contributor.name}" + output += '
  • ' + end + end + output end end diff --git a/app/helpers/synapses_helper.rb b/app/helpers/synapses_helper.rb index 471f0e05..def3b985 100644 --- a/app/helpers/synapses_helper.rb +++ b/app/helpers/synapses_helper.rb @@ -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 diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb index 32697db5..e1a1d179 100644 --- a/app/helpers/topics_helper.rb +++ b/app/helpers/topics_helper.rb @@ -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 diff --git a/app/policies/map_policy.rb b/app/policies/map_policy.rb index 3894520c..b2a04cbe 100644 --- a/app/policies/map_policy.rb +++ b/app/policies/map_policy.rb @@ -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 diff --git a/app/policies/synapse_policy.rb b/app/policies/synapse_policy.rb index f9557e70..eae820b3 100644 --- a/app/policies/synapse_policy.rb +++ b/app/policies/synapse_policy.rb @@ -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 diff --git a/app/policies/topic_policy.rb b/app/policies/topic_policy.rb index 2484ee54..cbde51d8 100644 --- a/app/policies/topic_policy.rb +++ b/app/policies/topic_policy.rb @@ -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 diff --git a/app/serializers/api/v2/application_serializer.rb b/app/serializers/api/v2/application_serializer.rb index 55a9b8a0..a5da830a 100644 --- a/app/serializers/api/v2/application_serializer.rb +++ b/app/serializers/api/v2/application_serializer.rb @@ -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 diff --git a/app/serializers/api/v2/user_serializer.rb b/app/serializers/api/v2/user_serializer.rb index e97bc420..ec58775d 100644 --- a/app/serializers/api/v2/user_serializer.rb +++ b/app/serializers/api/v2/user_serializer.rb @@ -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 diff --git a/app/services/map_export_service.rb b/app/services/map_export_service.rb index bd256140..2ded756c 100644 --- a/app/services/map_export_service.rb +++ b/app/services/map_export_service.rb @@ -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 { diff --git a/app/views/layouts/_lightboxes.html.erb b/app/views/layouts/_lightboxes.html.erb index 68fa9e27..89b5a6b4 100644 --- a/app/views/layouts/_lightboxes.html.erb +++ b/app/views/layouts/_lightboxes.html.erb @@ -94,7 +94,7 @@

    As a valued beta tester, you have the ability to invite your peers, colleagues and collaborators onto the platform.

    Below is a personal invite link containing your unique access code, which can be used multiple times.

    -

    <%= determine_invite_link %> +

    <%= invite_link() %>

    diff --git a/app/views/maps/_newtopic.html.erb b/app/views/maps/_newtopic.html.erb index ba3d1797..8e10c7a7 100644 --- a/app/views/maps/_newtopic.html.erb +++ b/app/views/maps/_newtopic.html.erb @@ -1,29 +1,34 @@ +<% @metacodes = user_metacodes() %> + <%= form_for Topic.new, url: topics_url, remote: true do |form| %>
    Switch Metacodes
    +
    Pin Open
    Unpin
    +
    - <% @metacodes = user_metacodes() %> - <% set = get_metacodeset() %> <% @metacodes.each do |metacode| %> <%= metacode.name %> <% end %>
    + <%= form.text_field :name, :maxlength => 140, :placeholder => "title..." %> +
    - + + <% end %> diff --git a/config/initializers/access_codes.rb b/config/initializers/access_codes.rb index 543ce6e9..fdf4e4b3 100644 --- a/config/initializers/access_codes.rb +++ b/config/initializers/access_codes.rb @@ -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 diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index d0f0d3b5..5b98aef4 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -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! diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index a086584d..6740cdc9 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -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 diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index 33073f45..40de1df8 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -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' diff --git a/config/initializers/uservoice.rb b/config/initializers/uservoice.rb index 3aa65a46..9375e3a1 100644 --- a/config/initializers/uservoice.rb +++ b/config/initializers/uservoice.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index c64c188e..fe48b6ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/script/rails b/script/rails index 1267847e..6f9d9941 100644 --- a/script/rails +++ b/script/rails @@ -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__) diff --git a/spec/api/v2/mappings_api_spec.rb b/spec/api/v2/mappings_api_spec.rb index f3ec6a75..4d802865 100644 --- a/spec/api/v2/mappings_api_spec.rb +++ b/spec/api/v2/mappings_api_spec.rb @@ -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) diff --git a/spec/api/v2/synapses_api_spec.rb b/spec/api/v2/synapses_api_spec.rb index c422f3bc..093bc41e 100644 --- a/spec/api/v2/synapses_api_spec.rb +++ b/spec/api/v2/synapses_api_spec.rb @@ -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)