Update code style automatically using rubocop gem (#563)

* install rubocop

* 1961 automatic rubocop fixes

* update rubocop.yml to ignore half of the remaining cops

* rubocop lint warnings

* random other warnings fixed
This commit is contained in:
Devin Howard 2016-07-26 08:14:23 +08:00 committed by GitHub
parent 17bccd809a
commit 7d4da81272
109 changed files with 1387 additions and 1570 deletions

14
.rubocop.yml Normal file
View file

@ -0,0 +1,14 @@
AllCops:
TargetRubyVersion: 2.3
Exclude:
- 'db/**/*'
- 'tmp/**/*'
- 'bin/**/*'
- 'vendor/**/*'
- 'app/assets/javascripts/node_modules/**/*'
Rails:
Enabled: true
Metrics/LineLength:
Max: 100

View file

@ -1 +1 @@
ruby-2.1.3 2.1.3

View file

@ -5,7 +5,7 @@ gem 'rails'
gem 'active_model_serializers', '~> 0.8.1' gem 'active_model_serializers', '~> 0.8.1'
gem 'aws-sdk', '< 2.0' gem 'aws-sdk', '< 2.0'
gem 'best_in_place' #in-place editing gem 'best_in_place' # in-place editing
gem 'delayed_job', '~> 4.0.2' gem 'delayed_job', '~> 4.0.2'
gem 'delayed_job_active_record', '~> 4.0.1' gem 'delayed_job_active_record', '~> 4.0.1'
gem 'devise' gem 'devise'
@ -40,7 +40,7 @@ group :assets do
end end
group :production do group :production do
gem 'rails_12factor' gem 'rails_12factor'
end end
group :test do group :test do
@ -59,4 +59,5 @@ group :development, :test do
gem 'pry-rails' gem 'pry-rails'
gem 'quiet_assets' gem 'quiet_assets'
gem 'tunemygc' gem 'tunemygc'
gem 'rubocop'
end end

View file

@ -40,6 +40,7 @@ GEM
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.3.8) addressable (2.3.8)
arel (6.0.3) arel (6.0.3)
ast (2.3.0)
aws-sdk (1.66.0) aws-sdk (1.66.0)
aws-sdk-v1 (= 1.66.0) aws-sdk-v1 (= 1.66.0)
aws-sdk-v1 (1.66.0) aws-sdk-v1 (1.66.0)
@ -151,8 +152,11 @@ GEM
cocaine (~> 0.5.5) cocaine (~> 0.5.5)
mime-types mime-types
mimemagic (= 0.3.0) mimemagic (= 0.3.0)
parser (2.3.1.2)
ast (~> 2.2)
pg (0.18.4) pg (0.18.4)
pkg-config (1.1.7) pkg-config (1.1.7)
powerpack (0.1.1)
pry (0.10.3) pry (0.10.3)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
@ -202,6 +206,7 @@ GEM
activesupport (= 4.2.6) activesupport (= 4.2.6)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
rake (11.2.2) rake (11.2.2)
redis (3.3.0) redis (3.3.0)
responders (2.2.0) responders (2.2.0)
@ -223,6 +228,13 @@ GEM
rspec-mocks (~> 3.4.0) rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0) rspec-support (~> 3.4.0)
rspec-support (3.4.1) rspec-support (3.4.1)
rubocop (0.41.1)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
sass (3.4.22) sass (3.4.22)
sass-rails (5.0.4) sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
@ -256,6 +268,7 @@ GEM
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (3.0.0) uglifier (3.0.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unicode-display_width (1.1.0)
uservoice-ruby (0.0.11) uservoice-ruby (0.0.11)
ezcrypto (>= 0.7.2) ezcrypto (>= 0.7.2)
json (>= 1.7.5) json (>= 1.7.5)
@ -303,6 +316,7 @@ DEPENDENCIES
rails_12factor rails_12factor
redis redis
rspec-rails rspec-rails
rubocop
sass-rails sass-rails
shoulda-matchers shoulda-matchers
simplecov simplecov

12
Vagrantfile vendored
View file

@ -31,15 +31,15 @@ sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '3112';"
SCRIPT SCRIPT
VAGRANTFILE_API_VERSION = "2" VAGRANTFILE_API_VERSION = '2'.freeze
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "trusty64" config.vm.box = 'trusty64'
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" config.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box'
config.vm.network :forwarded_port, guest: 3000, host: 3000 config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.network :forwarded_port, guest: 5001, host: 5001 config.vm.network :forwarded_port, guest: 5001, host: 5001
config.vm.network "private_network", ip: "10.0.1.11" config.vm.network 'private_network', ip: '10.0.1.11'
config.vm.synced_folder ".", "/vagrant", :nfs => true config.vm.synced_folder '.', '/vagrant', nfs: true
config.vm.provision "shell", inline: $script config.vm.provision 'shell', inline: $script
end end

View file

@ -1,3 +1,2 @@
class Api::MappingsController < API::RestfulController class Api::MappingsController < API::RestfulController
end end

View file

@ -1,3 +1,2 @@
class Api::MapsController < API::RestfulController class Api::MapsController < API::RestfulController
end end

View file

@ -35,9 +35,7 @@ class API::RestfulController < ActionController::Base
def token_user def token_user
token = params[:access_token] token = params[:access_token]
access_token = Token.find_by_token(token) access_token = Token.find_by_token(token)
if access_token @token_user ||= access_token.user if access_token
@token_user ||= access_token.user
end
end end
def doorkeeper_user def doorkeeper_user
@ -49,5 +47,4 @@ class API::RestfulController < ActionController::Base
def permitted_params def permitted_params
@permitted_params ||= PermittedParams.new(params) @permitted_params ||= PermittedParams.new(params)
end end
end end

View file

@ -1,3 +1,2 @@
class Api::SynapsesController < API::RestfulController class Api::SynapsesController < API::RestfulController
end end

View file

@ -1,7 +1,6 @@
class Api::TokensController < API::RestfulController class Api::TokensController < API::RestfulController
def my_tokens def my_tokens
raise Pundit::NotAuthorizedError.new unless current_user raise Pundit::NotAuthorizedError unless current_user
instantiate_collection page_collection: false, timeframe_collection: false instantiate_collection page_collection: false, timeframe_collection: false
respond_with_collection respond_with_collection
end end
@ -15,5 +14,4 @@ class Api::TokensController < API::RestfulController
def visible_records def visible_records
current_user.tokens current_user.tokens
end end
end end

View file

@ -1,3 +1,2 @@
class Api::TopicsController < API::RestfulController class Api::TopicsController < API::RestfulController
end end

View file

@ -20,12 +20,12 @@ class ApplicationController < ActionController::Base
helper_method :admin? helper_method :admin?
def after_sign_in_path_for(resource) def after_sign_in_path_for(resource)
sign_in_url = url_for(:action => 'new', :controller => 'sessions', :only_path => false, :protocol => 'https') sign_in_url = url_for(action: 'new', controller: 'sessions', only_path: false, protocol: 'https')
if request.referer == sign_in_url if request.referer == sign_in_url
super super
elsif params[:uv_login] == "1" elsif params[:uv_login] == '1'
"http://support.metamaps.cc/login_success?sso=" + current_sso_token 'http://support.metamaps.cc/login_success?sso=' + current_sso_token
else else
stored_location_for(resource) || request.referer || root_path stored_location_for(resource) || request.referer || root_path
end end
@ -33,35 +33,35 @@ class ApplicationController < ActionController::Base
def handle_unauthorized def handle_unauthorized
if authenticated? if authenticated?
head :forbidden # TODO make this better head :forbidden # TODO: make this better
else else
redirect_to new_user_session_path, notice: "Try signing in to do that." redirect_to new_user_session_path, notice: 'Try signing in to do that.'
end end
end end
private private
def get_invite_link def get_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? if 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 end
def require_user def require_user
unless authenticated? unless 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 end
def require_admin def require_admin
unless authenticated? && admin? unless 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 return false
end end
end end
@ -79,7 +79,7 @@ private
end end
def allow_embedding def allow_embedding
#allow all # allow all
response.headers.except! 'X-Frame-Options' response.headers.except! 'X-Frame-Options'
# or allow a whitelist # or allow a whitelist
# response.headers['X-Frame-Options'] = 'ALLOW-FROM http://blog.metamaps.cc' # response.headers['X-Frame-Options'] = 'ALLOW-FROM http://blog.metamaps.cc'

View file

@ -5,66 +5,66 @@ class MainController < ApplicationController
include SynapsesHelper include SynapsesHelper
after_action :verify_policy_scoped, except: [:requestinvite, :searchmappers] after_action :verify_policy_scoped, except: [:requestinvite, :searchmappers]
respond_to :html, :json respond_to :html, :json
# home page # home page
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 not authenticated? if !authenticated?
render 'main/home' render 'main/home'
else else
render 'maps/activemaps' render 'maps/activemaps'
end end
} end
end end
end end
### SEARCHING ### ### SEARCHING ###
# get /search/topics?term=SOMETERM # get /search/topics?term=SOMETERM
def searchtopics def searchtopics
term = params[:term] term = params[:term]
user = params[:user] ? params[:user] : false user = params[:user] ? params[:user] : false
if term && !term.empty? && term.downcase[0..3] != "map:" && term.downcase[0..6] != "mapper:" && term.downcase != "topic:" if term && !term.empty? && term.downcase[0..3] != 'map:' && term.downcase[0..6] != 'mapper:' && !term.casecmp('topic:').zero?
#remove "topic:" if appended at beginning # remove "topic:" if appended at beginning
term = term[6..-1] if term.downcase[0..5] == "topic:" term = term[6..-1] if term.downcase[0..5] == 'topic:'
#if desc: search desc instead # if desc: search desc instead
desc = false desc = false
if term.downcase[0..4] == "desc:" if term.downcase[0..4] == 'desc:'
term = term[5..-1] term = term[5..-1]
desc = true desc = true
end end
#if link: search link instead # if link: search link instead
link = false link = false
if term.downcase[0..4] == "link:" if term.downcase[0..4] == 'link:'
term = term[5..-1] term = term[5..-1]
link = true link = true
end end
#check whether there's a filter by metacode as part of the query # check whether there's a filter by metacode as part of the query
filterByMetacode = false filterByMetacode = false
Metacode.all.each do |m| Metacode.all.each do |m|
lOne = m.name.length+1 lOne = m.name.length + 1
lTwo = m.name.length lTwo = m.name.length
if term.downcase[0..lTwo] == m.name.downcase + ":" if term.downcase[0..lTwo] == m.name.downcase + ':'
term = term[lOne..-1] term = term[lOne..-1]
filterByMetacode = m filterByMetacode = m
end end
end end
search = '%' + term.downcase + '%' search = '%' + term.downcase + '%'
builder = policy_scope(Topic) builder = policy_scope(Topic)
if filterByMetacode if filterByMetacode
if term == "" if term == ''
builder = builder.none builder = builder.none
else else
builder = builder.where('LOWER("name") like ? OR builder = builder.where('LOWER("name") like ? OR
@ -76,7 +76,7 @@ class MainController < ApplicationController
builder = builder.where('LOWER("desc") like ?', search) builder = builder.where('LOWER("desc") like ?', search)
elsif link elsif link
builder = builder.where('LOWER("link") like ?', search) builder = builder.where('LOWER("link") like ?', search)
else #regular case, just search the name else # regular case, just search the name
builder = builder.where('LOWER("name") like ? OR builder = builder.where('LOWER("name") like ? OR
LOWER("desc") like ? OR LOWER("desc") like ? OR
LOWER("link") like ?', search, search, search) LOWER("link") like ?', search, search, search)
@ -90,59 +90,59 @@ class MainController < ApplicationController
render json: autocomplete_array_json(@topics) render json: autocomplete_array_json(@topics)
end end
# get /search/maps?term=SOMETERM # get /search/maps?term=SOMETERM
def searchmaps def searchmaps
term = params[:term] term = params[:term]
user = params[:user] ? params[:user] : nil user = params[:user] ? params[:user] : nil
if term && !term.empty? && term.downcase[0..5] != "topic:" && term.downcase[0..6] != "mapper:" && term.downcase != "map:" if term && !term.empty? && term.downcase[0..5] != 'topic:' && term.downcase[0..6] != 'mapper:' && !term.casecmp('map:').zero?
#remove "map:" if appended at beginning # remove "map:" if appended at beginning
term = term[4..-1] if term.downcase[0..3] == "map:" term = term[4..-1] if term.downcase[0..3] == 'map:'
#if desc: search desc instead # if desc: search desc instead
desc = false desc = false
if term.downcase[0..4] == "desc:" if term.downcase[0..4] == 'desc:'
term = term[5..-1] term = term[5..-1]
desc = true desc = true
end end
search = '%' + term.downcase + '%' search = '%' + term.downcase + '%'
builder = policy_scope(Map) builder = policy_scope(Map)
if desc builder = if desc
builder = builder.where('LOWER("desc") like ?', search) builder.where('LOWER("desc") like ?', search)
else else
builder = builder.where('LOWER("name") like ?', search) builder.where('LOWER("name") like ?', search)
end end
builder = builder.where(user: user) if user builder = builder.where(user: user) if user
@maps = builder.order(:name) @maps = builder.order(:name)
else else
@maps = [] @maps = []
end end
render json: autocomplete_map_array_json(@maps) render json: autocomplete_map_array_json(@maps)
end end
# get /search/mappers?term=SOMETERM # get /search/mappers?term=SOMETERM
def searchmappers def searchmappers
term = params[:term] term = params[:term]
if term && !term.empty? && term.downcase[0..3] != "map:" && term.downcase[0..5] != "topic:" && term.downcase != "mapper:" if term && !term.empty? && term.downcase[0..3] != 'map:' && term.downcase[0..5] != 'topic:' && !term.casecmp('mapper:').zero?
#remove "mapper:" if appended at beginning # remove "mapper:" if appended at beginning
term = term[7..-1] if term.downcase[0..6] == "mapper:" term = term[7..-1] if term.downcase[0..6] == 'mapper:'
search = term.downcase + '%' search = term.downcase + '%'
skip_policy_scope # TODO builder = policy_scope(User) skip_policy_scope # TODO: builder = policy_scope(User)
builder = User.where('LOWER("name") like ?', search) builder = User.where('LOWER("name") like ?', search)
@mappers = builder.order(:name) @mappers = builder.order(:name)
else else
@mappers = [] @mappers = []
end end
render json: autocomplete_user_array_json(@mappers) render json: autocomplete_user_array_json(@mappers)
end end
# get /search/synapses?term=SOMETERM OR # get /search/synapses?term=SOMETERM OR
# get /search/synapses?topic1id=SOMEID&topic2id=SOMEID # get /search/synapses?topic1id=SOMEID&topic2id=SOMEID
def searchsynapses def searchsynapses
@ -153,30 +153,30 @@ class MainController < ApplicationController
if term && !term.empty? if term && !term.empty?
@synapses = policy_scope(Synapse).where('LOWER("desc") like ?', '%' + term.downcase + '%').order('"desc"') @synapses = policy_scope(Synapse).where('LOWER("desc") like ?', '%' + term.downcase + '%').order('"desc"')
# remove any duplicate synapse types that just differ by # remove any duplicate synapse types that just differ by
# leading or trailing whitespaces # leading or trailing whitespaces
collectedDesc = [] collectedDesc = []
@synapses.to_a.uniq(&:desc).delete_if {|s| @synapses.to_a.uniq(&:desc).delete_if do |s|
desc = s.desc == nil || s.desc == "" ? "" : s.desc.strip desc = s.desc.nil? || s.desc == '' ? '' : s.desc.strip
if collectedDesc.index(desc) == nil if collectedDesc.index(desc).nil?
collectedDesc.push(desc) collectedDesc.push(desc)
boolean = false false # return this value
else else
boolean = true true # return this value
end end
} end
elsif topic1id && !topic1id.empty? elsif topic1id && !topic1id.empty?
@one = policy_scope(Synapse).where('node1_id = ? AND node2_id = ?', topic1id, topic2id) @one = policy_scope(Synapse).where('node1_id = ? AND node2_id = ?', topic1id, topic2id)
@two = policy_scope(Synapse).where('node2_id = ? AND node1_id = ?', topic1id, topic2id) @two = policy_scope(Synapse).where('node2_id = ? AND node1_id = ?', topic1id, topic2id)
@synapses = @one + @two @synapses = @one + @two
@synapses.sort! {|s1,s2| s1.desc <=> s2.desc }.to_a @synapses.sort! { |s1, s2| s1.desc <=> s2.desc }.to_a
else else
@synapses = [] @synapses = []
end end
#limit to 5 results # limit to 5 results
@synapses = @synapses.slice(0,5) @synapses = @synapses.slice(0, 5)
render json: autocomplete_synapse_array_json(@synapses) render json: autocomplete_synapse_array_json(@synapses)
end end
end end

View file

@ -1,11 +1,10 @@
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
after_action :verify_policy_scoped, only: :index after_action :verify_policy_scoped, only: :index
respond_to :json respond_to :json
# GET /mappings/1.json # GET /mappings/1.json
def show def show
@mapping = Mapping.find(params[:id]) @mapping = Mapping.find(params[:id])
@ -54,12 +53,13 @@ class MappingsController < ApplicationController
@mapping.destroy @mapping.destroy
head :no_content head :no_content
end end
private private
# Never trust parameters from the scary internet, only allow the white list through.
def mapping_params # Never trust parameters from the scary internet, only allow the white list through.
params.require(:mapping).permit(:id, :xloc, :yloc, :mappable_id, :mappable_type, :map_id) def mapping_params
end params.require(:mapping).permit(:id, :xloc, :yloc, :mappable_id, :mappable_type, :map_id)
end
end end

View file

@ -1,309 +1,308 @@
class MapsController < ApplicationController class MapsController < ApplicationController
before_action :require_user, only: [:create, :update, :access, :screenshot, :events, :destroy] before_action :require_user, only: [:create, :update, :access, :screenshot, :events, :destroy]
after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps, :events] after_action :verify_authorized, except: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps, :events]
after_action :verify_policy_scoped, only: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps] after_action :verify_policy_scoped, only: [:activemaps, :featuredmaps, :mymaps, :sharedmaps, :usermaps]
respond_to :html, :json, :csv respond_to :html, :json, :csv
autocomplete :map, :name, :full => true, :extra_data => [:user_id] autocomplete :map, :name, full: true, extra_data: [:user_id]
# GET /explore/active # GET /explore/active
def activemaps def activemaps
page = params[:page].present? ? params[:page] : 1 page = params[:page].present? ? params[:page] : 1
@maps = policy_scope(Map).order("updated_at DESC") @maps = policy_scope(Map).order('updated_at DESC')
.page(page).per(20) .page(page).per(20)
respond_to do |format| respond_to do |format|
format.html { format.html do
# root url => main/home. main/home renders maps/activemaps view. # root url => main/home. main/home renders maps/activemaps view.
redirect_to root_url and return if authenticated? redirect_to(root_url) && return if authenticated?
respond_with(@maps, @user) respond_with(@maps, @user)
}
format.json { render json: @maps }
end
end
# GET /explore/featured
def featuredmaps
page = params[:page].present? ? params[:page] : 1
@maps = policy_scope(
Map.where("maps.featured = ? AND maps.permission != ?",
true, "private")
).order("updated_at DESC").page(page).per(20)
respond_to do |format|
format.html { respond_with(@maps, @user) }
format.json { render json: @maps }
end
end
# GET /explore/mine
def mymaps
if !authenticated?
skip_policy_scope
return redirect_to explore_active_path
end end
format.json { render json: @maps }
end
end
page = params[:page].present? ? params[:page] : 1 # GET /explore/featured
@maps = policy_scope( def featuredmaps
Map.where("maps.user_id = ?", current_user.id) page = params[:page].present? ? params[:page] : 1
).order("updated_at DESC").page(page).per(20) @maps = policy_scope(
Map.where('maps.featured = ? AND maps.permission != ?',
true, 'private')
).order('updated_at DESC').page(page).per(20)
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
format.json { render json: @maps } format.json { render json: @maps }
end end
end
# GET /explore/mine
def mymaps
unless authenticated?
skip_policy_scope
return redirect_to explore_active_path
end end
# GET /explore/shared page = params[:page].present? ? params[:page] : 1
def sharedmaps @maps = policy_scope(
if !authenticated? Map.where('maps.user_id = ?', current_user.id)
skip_policy_scope ).order('updated_at DESC').page(page).per(20)
return redirect_to explore_active_path
end
page = params[:page].present? ? params[:page] : 1 respond_to do |format|
@maps = policy_scope( format.html { respond_with(@maps, @user) }
Map.where("maps.id IN (?)", current_user.shared_maps.map(&:id)) format.json { render json: @maps }
).order("updated_at DESC").page(page).per(20) end
end
respond_to do |format| # GET /explore/shared
format.html { respond_with(@maps, @user) } def sharedmaps
format.json { render json: @maps } unless authenticated?
end skip_policy_scope
return redirect_to explore_active_path
end end
# GET /explore/mapper/:id page = params[:page].present? ? params[:page] : 1
def usermaps @maps = policy_scope(
page = params[:page].present? ? params[:page] : 1 Map.where('maps.id IN (?)', current_user.shared_maps.map(&:id))
@user = User.find(params[:id]) ).order('updated_at DESC').page(page).per(20)
@maps = policy_scope(Map.where(user: @user))
.order("updated_at DESC").page(page).per(20)
respond_to do |format| respond_to do |format|
format.html { respond_with(@maps, @user) } format.html { respond_with(@maps, @user) }
format.json { render json: @maps } format.json { render json: @maps }
end
end end
end
# GET maps/:id # GET /explore/mapper/:id
def show def usermaps
@map = Map.find(params[:id]) page = params[:page].present? ? params[:page] : 1
authorize @map @user = User.find(params[:id])
@maps = policy_scope(Map.where(user: @user))
.order('updated_at DESC').page(page).per(20)
respond_to do |format| respond_to do |format|
format.html { format.html { respond_with(@maps, @user) }
@allmappers = @map.contributors format.json { render json: @maps }
@allcollaborators = @map.editors
@alltopics = @map.topics.to_a.delete_if {|t| not policy(t).show? }
@allsynapses = @map.synapses.to_a.delete_if {|s| not policy(s).show? }
@allmappings = @map.mappings.to_a.delete_if {|m| not policy(m).show? }
@allmessages = @map.messages.sort_by(&:created_at)
respond_with(@allmappers, @allcollaborators, @allmappings, @allsynapses, @alltopics, @allmessages, @map)
}
format.json { render json: @map }
format.csv { redirect_to action: :export, format: :csv }
format.xls { redirect_to action: :export, format: :xls }
end
end end
end
# GET maps/:id/export # GET maps/:id
def export def show
map = Map.find(params[:id]) @map = Map.find(params[:id])
authorize map authorize @map
exporter = MapExportService.new(current_user, map)
respond_to do |format|
format.json { render json: exporter.json }
format.csv { send_data exporter.csv }
format.xls { @spreadsheet = exporter.xls }
end
end
# POST maps/:id/events/:event
def events
map = Map.find(params[:id])
authorize map
valid_event = false
if params[:event] == 'conversation'
Events::ConversationStartedOnMap.publish!(map, current_user)
valid_event = true
elsif params[:event] == 'user_presence'
Events::UserPresentOnMap.publish!(map, current_user)
valid_event = true
end
respond_to do |format|
format.json {
head :ok if valid_event
head :bad_request if not valid_event
}
end
end
# GET maps/:id/contains
def contains
@map = Map.find(params[:id])
authorize @map
respond_to do |format|
format.html do
@allmappers = @map.contributors @allmappers = @map.contributors
@allcollaborators = @map.editors @allcollaborators = @map.editors
@alltopics = @map.topics.to_a.delete_if {|t| not policy(t).show? } @alltopics = @map.topics.to_a.delete_if { |t| !policy(t).show? }
@allsynapses = @map.synapses.to_a.delete_if {|s| not policy(s).show? } @allsynapses = @map.synapses.to_a.delete_if { |s| !policy(s).show? }
@allmappings = @map.mappings.to_a.delete_if {|m| not policy(m).show? } @allmappings = @map.mappings.to_a.delete_if { |m| !policy(m).show? }
@allmessages = @map.messages.sort_by(&:created_at)
respond_with(@allmappers, @allcollaborators, @allmappings, @allsynapses, @alltopics, @allmessages, @map)
end
format.json { render json: @map }
format.csv { redirect_to action: :export, format: :csv }
format.xls { redirect_to action: :export, format: :xls }
end
end
@json = Hash.new() # GET maps/:id/export
@json['map'] = @map def export
@json['topics'] = @alltopics map = Map.find(params[:id])
@json['synapses'] = @allsynapses authorize map
@json['mappings'] = @allmappings exporter = MapExportService.new(current_user, map)
@json['mappers'] = @allmappers respond_to do |format|
@json['collaborators'] = @allcollaborators format.json { render json: exporter.json }
@json['messages'] = @map.messages.sort_by(&:created_at) format.csv { send_data exporter.csv }
format.xls { @spreadsheet = exporter.xls }
end
end
respond_to do |format| # POST maps/:id/events/:event
format.json { render json: @json } def events
end map = Map.find(params[:id])
authorize map
valid_event = false
if params[:event] == 'conversation'
Events::ConversationStartedOnMap.publish!(map, current_user)
valid_event = true
elsif params[:event] == 'user_presence'
Events::UserPresentOnMap.publish!(map, current_user)
valid_event = true
end end
# POST maps respond_to do |format|
def create format.json do
@user = current_user head :ok if valid_event
@map = Map.new() head :bad_request unless valid_event
@map.name = params[:name] end
@map.desc = params[:desc] end
@map.permission = params[:permission] end
@map.user = @user
@map.arranged = false
if params[:topicsToMap] # GET maps/:id/contains
@all = params[:topicsToMap] def contains
@all = @all.split(',') @map = Map.find(params[:id])
@all.each do |topic| authorize @map
topic = topic.split('/')
mapping = Mapping.new
mapping.map = @map
mapping.user = @user
mapping.mappable = Topic.find(topic[0])
mapping.xloc = topic[1]
mapping.yloc = topic[2]
authorize mapping, :create?
mapping.save
end
if params[:synapsesToMap] @allmappers = @map.contributors
@synAll = params[:synapsesToMap] @allcollaborators = @map.editors
@synAll = @synAll.split(',') @alltopics = @map.topics.to_a.delete_if { |t| !policy(t).show? }
@synAll.each do |synapse_id| @allsynapses = @map.synapses.to_a.delete_if { |s| !policy(s).show? }
mapping = Mapping.new @allmappings = @map.mappings.to_a.delete_if { |m| !policy(m).show? }
mapping.map = @map
mapping.user = @user
mapping.mappable = Synapse.find(synapse_id)
authorize mapping, :create?
mapping.save
end
end
@map.arranged = true @json = {}
@json['map'] = @map
@json['topics'] = @alltopics
@json['synapses'] = @allsynapses
@json['mappings'] = @allmappings
@json['mappers'] = @allmappers
@json['collaborators'] = @allcollaborators
@json['messages'] = @map.messages.sort_by(&:created_at)
respond_to do |format|
format.json { render json: @json }
end
end
# POST maps
def create
@user = current_user
@map = Map.new
@map.name = params[:name]
@map.desc = params[:desc]
@map.permission = params[:permission]
@map.user = @user
@map.arranged = false
if params[:topicsToMap]
@all = params[:topicsToMap]
@all = @all.split(',')
@all.each do |topic|
topic = topic.split('/')
mapping = Mapping.new
mapping.map = @map
mapping.user = @user
mapping.mappable = Topic.find(topic[0])
mapping.xloc = topic[1]
mapping.yloc = topic[2]
authorize mapping, :create?
mapping.save
end
if params[:synapsesToMap]
@synAll = params[:synapsesToMap]
@synAll = @synAll.split(',')
@synAll.each do |synapse_id|
mapping = Mapping.new
mapping.map = @map
mapping.user = @user
mapping.mappable = Synapse.find(synapse_id)
authorize mapping, :create?
mapping.save
end end
end
authorize @map @map.arranged = true
if @map.save
respond_to do |format|
format.json { render :json => @map }
end
else
respond_to do |format|
format.json { render :json => "invalid params" }
end
end
end end
# PUT maps/:id authorize @map
def update
@map = Map.find(params[:id])
authorize @map
respond_to do |format|
if @map.update_attributes(map_params)
format.json { head :no_content }
else
format.json { render json: @map.errors, status: :unprocessable_entity }
end
end
end
# POST maps/:id/access
def access
@map = Map.find(params[:id])
authorize @map
userIds = params[:access] || []
added = userIds.select { |uid|
user = User.find(uid)
if user.nil? || (current_user && user == current_user)
false
else
not @map.collaborators.include?(user)
end
}
removed = @map.collaborators.select { |user| not userIds.include?(user.id.to_s) }.map(&:id)
added.each { |uid|
um = UserMap.create({ user_id: uid.to_i, map_id: @map.id })
user = User.find(uid.to_i)
MapMailer.invite_to_edit_email(@map, current_user, user).deliver_later
}
removed.each { |uid|
@map.user_maps.select{ |um| um.user_id == uid }.each{ |um| um.destroy }
}
if @map.save
respond_to do |format| respond_to do |format|
format.json do format.json { render json: @map }
render :json => { :message => "Successfully altered edit permissions" } end
end else
respond_to do |format|
format.json { render json: 'invalid params' }
end end
end end
end
# POST maps/:id/upload_screenshot
def screenshot
@map = Map.find(params[:id])
authorize @map
png = Base64.decode64(params[:encoded_image]['data:image/png;base64,'.length .. -1]) # PUT maps/:id
StringIO.open(png) do |data| def update
data.class.class_eval { attr_accessor :original_filename, :content_type } @map = Map.find(params[:id])
data.original_filename = "map-" + @map.id.to_s + "-screenshot.png" authorize @map
data.content_type = "image/png"
@map.screenshot = data respond_to do |format|
end if @map.update_attributes(map_params)
format.json { head :no_content }
if @map.save
render :json => {:message => "Successfully uploaded the map screenshot."}
else else
render :json => {:message => "Failed to upload image."} format.json { render json: @map.errors, status: :unprocessable_entity }
end end
end end
end
# DELETE maps/:id # POST maps/:id/access
def destroy def access
@map = Map.find(params[:id]) @map = Map.find(params[:id])
authorize @map authorize @map
userIds = params[:access] || []
@map.delete added = userIds.select do |uid|
user = User.find(uid)
respond_to do |format| if user.nil? || (current_user && user == current_user)
format.json do false
head :no_content else
end !@map.collaborators.include?(user)
end end
end end
removed = @map.collaborators.select { |user| !userIds.include?(user.id.to_s) }.map(&:id)
private added.each do |uid|
UserMap.create(user_id: uid.to_i, map_id: @map.id)
# Never trust parameters from the scary internet, only allow the white list through. user = User.find(uid.to_i)
def map_params MapMailer.invite_to_edit_email(@map, current_user, user).deliver_later
params.require(:map).permit(:id, :name, :arranged, :desc, :permission)
end end
removed.each do |uid|
@map.user_maps.select { |um| um.user_id == uid }.each(&:destroy)
end
respond_to do |format|
format.json do
render json: { message: 'Successfully altered edit permissions' }
end
end
end
# POST maps/:id/upload_screenshot
def screenshot
@map = Map.find(params[:id])
authorize @map
png = Base64.decode64(params[:encoded_image]['data:image/png;base64,'.length..-1])
StringIO.open(png) do |data|
data.class.class_eval { attr_accessor :original_filename, :content_type }
data.original_filename = 'map-' + @map.id.to_s + '-screenshot.png'
data.content_type = 'image/png'
@map.screenshot = data
end
if @map.save
render json: { message: 'Successfully uploaded the map screenshot.' }
else
render json: { message: 'Failed to upload image.' }
end
end
# DELETE maps/:id
def destroy
@map = Map.find(params[:id])
authorize @map
@map.delete
respond_to do |format|
format.json do
head :no_content
end
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def map_params
params.require(:map).permit(:id, :name, :arranged, :desc, :permission)
end
end end

View file

@ -1,5 +1,4 @@
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
@ -59,9 +58,9 @@ class MessagesController < ApplicationController
private private
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def message_params def message_params
#params.require(:message).permit(:id, :resource_id, :message) # params.require(:message).permit(:id, :resource_id, :message)
params.permit(:id, :resource_id, :resource_type, :message) params.permit(:id, :resource_id, :resource_type, :message)
end end
end end

View file

@ -1,11 +1,10 @@
class MetacodeSetsController < ApplicationController class MetacodeSetsController < ApplicationController
before_action :require_admin before_action :require_admin
# GET /metacode_sets # GET /metacode_sets
# GET /metacode_sets.json # GET /metacode_sets.json
def index def index
@metacode_sets = MetacodeSet.order("name").all @metacode_sets = MetacodeSet.order('name').all
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
@ -16,14 +15,14 @@ class MetacodeSetsController < ApplicationController
### SHOW IS NOT CURRENTLY IN USE ### SHOW IS NOT CURRENTLY IN USE
# GET /metacode_sets/1 # GET /metacode_sets/1
# GET /metacode_sets/1.json # GET /metacode_sets/1.json
# def show # def show
# @metacode_set = MetacodeSet.find(params[:id]) # @metacode_set = MetacodeSet.find(params[:id])
# #
# respond_to do |format| # respond_to do |format|
# format.html # show.html.erb # format.html # show.html.erb
# format.json { render json: @metacode_set } # format.json { render json: @metacode_set }
# end # end
# end # end
# GET /metacode_sets/new # GET /metacode_sets/new
# GET /metacode_sets/new.json # GET /metacode_sets/new.json
@ -53,12 +52,12 @@ class MetacodeSetsController < ApplicationController
# create the InMetacodeSet for all the metacodes that were selected for the set # create the InMetacodeSet for all the metacodes that were selected for the set
@metacodes = params[:metacodes][:value].split(',') @metacodes = params[:metacodes][:value].split(',')
@metacodes.each do |m| @metacodes.each do |m|
InMetacodeSet.create(:metacode_id => m, :metacode_set_id => @metacode_set.id) InMetacodeSet.create(metacode_id: m, metacode_set_id: @metacode_set.id)
end end
format.html { redirect_to metacode_sets_url, notice: 'Metacode set was successfully created.' } format.html { redirect_to metacode_sets_url, notice: 'Metacode set was successfully created.' }
format.json { render json: @metacode_set, status: :created, location: metacode_sets_url } format.json { render json: @metacode_set, status: :created, location: metacode_sets_url }
else else
format.html { render action: "new" } format.html { render action: 'new' }
format.json { render json: @metacode_set.errors, status: :unprocessable_entity } format.json { render json: @metacode_set.errors, status: :unprocessable_entity }
end end
end end
@ -71,29 +70,29 @@ class MetacodeSetsController < ApplicationController
respond_to do |format| respond_to do |format|
if @metacode_set.update_attributes(metacode_set_params) if @metacode_set.update_attributes(metacode_set_params)
# build an array of the IDs of the metacodes currently in the set # build an array of the IDs of the metacodes currently in the set
@currentMetacodes = @metacode_set.metacodes.map{ |m| m.id.to_s } @currentMetacodes = @metacode_set.metacodes.map { |m| m.id.to_s }
# get the list of desired metacodes for the set from the user input and build an array out of it # get the list of desired metacodes for the set from the user input and build an array out of it
@newMetacodes = params[:metacodes][:value].split(',') @newMetacodes = params[:metacodes][:value].split(',')
#remove the metacodes that were in it, but now aren't # remove the metacodes that were in it, but now aren't
@removedMetacodes = @currentMetacodes - @newMetacodes @removedMetacodes = @currentMetacodes - @newMetacodes
@removedMetacodes.each do |m| @removedMetacodes.each do |m|
@inmetacodeset = InMetacodeSet.find_by_metacode_id_and_metacode_set_id(m, @metacode_set.id) @inmetacodeset = InMetacodeSet.find_by_metacode_id_and_metacode_set_id(m, @metacode_set.id)
@inmetacodeset.destroy @inmetacodeset.destroy
end end
# add the new metacodes # add the new metacodes
@addedMetacodes = @newMetacodes - @currentMetacodes @addedMetacodes = @newMetacodes - @currentMetacodes
@addedMetacodes.each do |m| @addedMetacodes.each do |m|
InMetacodeSet.create(:metacode_id => m, :metacode_set_id => @metacode_set.id) InMetacodeSet.create(metacode_id: m, metacode_set_id: @metacode_set.id)
end end
format.html { redirect_to metacode_sets_url, notice: 'Metacode set was successfully updated.' } format.html { redirect_to metacode_sets_url, notice: 'Metacode set was successfully updated.' }
format.json { head :no_content } format.json { head :no_content }
else else
format.html { render action: "edit" } format.html { render action: 'edit' }
format.json { render json: @metacode_set.errors, status: :unprocessable_entity } format.json { render json: @metacode_set.errors, status: :unprocessable_entity }
end end
end end
@ -103,12 +102,10 @@ class MetacodeSetsController < ApplicationController
# DELETE /metacode_sets/1.json # DELETE /metacode_sets/1.json
def destroy def destroy
@metacode_set = MetacodeSet.find(params[:id]) @metacode_set = MetacodeSet.find(params[:id])
#delete everything that tracks what's in the set # delete everything that tracks what's in the set
@metacode_set.in_metacode_sets.each do |m| @metacode_set.in_metacode_sets.each(&:destroy)
m.destroy
end
@metacode_set.destroy @metacode_set.destroy
respond_to do |format| respond_to do |format|
@ -122,5 +119,4 @@ class MetacodeSetsController < ApplicationController
def metacode_set_params def metacode_set_params
params.require(:metacode_set).permit(:desc, :mapperContributed, :name) params.require(:metacode_set).permit(:desc, :mapperContributed, :name)
end end
end end

View file

@ -1,19 +1,19 @@
class MetacodesController < ApplicationController class MetacodesController < ApplicationController
before_action :require_admin, except: [:index, :show] before_action :require_admin, except: [:index, :show]
# GET /metacodes # GET /metacodes
# GET /metacodes.json # GET /metacodes.json
def index def index
@metacodes = Metacode.order("name").all @metacodes = Metacode.order('name').all
respond_to do |format| respond_to do |format|
format.html { format.html do
unless authenticated? && user.admin unless authenticated? && user.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 return false
end end
render :index render :index
} end
format.json { render json: @metacodes } format.json { render json: @metacodes }
end end
end end

View file

@ -4,9 +4,9 @@ class SynapsesController < 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
after_action :verify_policy_scoped, only: :index after_action :verify_policy_scoped, only: :index
respond_to :json respond_to :json
# GET /synapses/1.json # GET /synapses/1.json
def show def show
@synapse = Synapse.find(params[:id]) @synapse = Synapse.find(params[:id])
@ -14,12 +14,12 @@ class SynapsesController < ApplicationController
render json: @synapse render json: @synapse
end end
# POST /synapses # POST /synapses
# POST /synapses.json # POST /synapses.json
def create def create
@synapse = Synapse.new(synapse_params) @synapse = Synapse.new(synapse_params)
@synapse.desc = "" if @synapse.desc.nil? @synapse.desc = '' if @synapse.desc.nil?
authorize @synapse authorize @synapse
respond_to do |format| respond_to do |format|
@ -30,12 +30,12 @@ class SynapsesController < ApplicationController
end end
end end
end end
# PUT /synapses/1 # PUT /synapses/1
# PUT /synapses/1.json # PUT /synapses/1.json
def update def update
@synapse = Synapse.find(params[:id]) @synapse = Synapse.find(params[:id])
@synapse.desc = "" if @synapse.desc.nil? @synapse.desc = '' if @synapse.desc.nil?
authorize @synapse authorize @synapse
respond_to do |format| respond_to do |format|
@ -46,13 +46,13 @@ class SynapsesController < ApplicationController
end end
end end
end end
# DELETE synapses/:id # DELETE synapses/:id
def destroy def destroy
@synapse = Synapse.find(params[:id]) @synapse = Synapse.find(params[:id])
authorize @synapse authorize @synapse
@synapse.destroy @synapse.destroy
respond_to do |format| respond_to do |format|
format.json { head :no_content } format.json { head :no_content }
end end

View file

@ -1,119 +1,119 @@
class TopicsController < ApplicationController class TopicsController < ApplicationController
include TopicsHelper include TopicsHelper
before_action :require_user, only: [:create, :update, :destroy] before_action :require_user, only: [:create, :update, :destroy]
after_action :verify_authorized, except: :autocomplete_topic after_action :verify_authorized, except: :autocomplete_topic
respond_to :html, :js, :json
# GET /topics/autocomplete_topic respond_to :html, :js, :json
def autocomplete_topic
term = params[:term]
if term && !term.empty?
@topics = policy_scope(Topic.where('LOWER("name") like ?', term.downcase + '%')).order('"name"')
else
@topics = []
end
render json: autocomplete_array_json(@topics)
end
# GET topics/:id # GET /topics/autocomplete_topic
def show def autocomplete_topic
@topic = Topic.find(params[:id]) term = params[:term]
authorize @topic @topics = if term && !term.empty?
policy_scope(Topic.where('LOWER("name") like ?', term.downcase + '%')).order('"name"')
else
[]
end
render json: autocomplete_array_json(@topics)
end
respond_to do |format| # GET topics/:id
format.html { def show
@alltopics = [@topic].concat(policy_scope(Topic.relatives1(@topic.id)).to_a).concat(policy_scope(Topic.relatives2(@topic.id)).to_a) @topic = Topic.find(params[:id])
@allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a authorize @topic
puts @alltopics.length
puts @allsynapses.length
@allcreators = @alltopics.map(&:user).uniq
@allcreators += @allsynapses.map(&:user).uniq
respond_with(@allsynapses, @alltopics, @allcreators, @topic)
}
format.json { render json: @topic }
end
end
# GET topics/:id/network
def network
@topic = Topic.find(params[:id])
authorize @topic
respond_to do |format|
format.html do
@alltopics = [@topic].concat(policy_scope(Topic.relatives1(@topic.id)).to_a).concat(policy_scope(Topic.relatives2(@topic.id)).to_a) @alltopics = [@topic].concat(policy_scope(Topic.relatives1(@topic.id)).to_a).concat(policy_scope(Topic.relatives2(@topic.id)).to_a)
@allsynapses = policy_scope(Synapse.for_topic(@topic.id)) @allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a
puts @alltopics.length
puts @allsynapses.length
@allcreators = @alltopics.map(&:user).uniq @allcreators = @alltopics.map(&:user).uniq
@allcreators += @allsynapses.map(&:user).uniq @allcreators += @allsynapses.map(&:user).uniq
@json = Hash.new() respond_with(@allsynapses, @alltopics, @allcreators, @topic)
@json['topic'] = @topic end
@json['creators'] = @allcreators format.json { render json: @topic }
@json['relatives'] = @alltopics end
@json['synapses'] = @allsynapses end
respond_to do |format| # GET topics/:id/network
format.json { render json: @json } def network
end @topic = Topic.find(params[:id])
authorize @topic
@alltopics = [@topic].concat(policy_scope(Topic.relatives1(@topic.id)).to_a).concat(policy_scope(Topic.relatives2(@topic.id)).to_a)
@allsynapses = policy_scope(Synapse.for_topic(@topic.id))
@allcreators = @alltopics.map(&:user).uniq
@allcreators += @allsynapses.map(&:user).uniq
@json = {}
@json['topic'] = @topic
@json['creators'] = @allcreators
@json['relatives'] = @alltopics
@json['synapses'] = @allsynapses
respond_to do |format|
format.json { render json: @json }
end
end
# GET topics/:id/relative_numbers
def relative_numbers
@topic = Topic.find(params[:id])
authorize @topic
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
@alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq
@alltopics.delete_if do |topic|
!topicsAlreadyHas.index(topic.id).nil?
end end
# GET topics/:id/relative_numbers @json = Hash.new(0)
def relative_numbers @alltopics.each do |t|
@topic = Topic.find(params[:id]) @json[t.metacode.id] += 1
authorize @topic
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
@alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq
@alltopics.delete_if do |topic|
topicsAlreadyHas.index(topic.id) != nil
end
@json = Hash.new(0)
@alltopics.each do |t|
@json[t.metacode.id] += 1
end
respond_to do |format|
format.json { render json: @json }
end
end end
# GET topics/:id/relatives respond_to do |format|
def relatives format.json { render json: @json }
@topic = Topic.find(params[:id])
authorize @topic
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq
alltopics.delete_if do |topic|
topicsAlreadyHas.index(topic.id.to_s) != nil
end
#find synapses between topics in alltopics array
allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a
synapse_ids = (allsynapses.map(&:node1_id) + allsynapses.map(&:node2_id)).uniq
allsynapses.delete_if do |synapse|
synapse_ids.index(synapse.id) != nil
end
creatorsAlreadyHas = params[:creators] ? params[:creators].split(',').map(&:to_i) : []
allcreators = (alltopics.map(&:user) + allsynapses.map(&:user)).uniq.delete_if do |user|
creatorsAlreadyHas.index(user.id) != nil
end
@json = Hash.new()
@json['topics'] = alltopics
@json['synapses'] = allsynapses
@json['creators'] = allcreators
respond_to do |format|
format.json { render json: @json }
end
end end
end
# GET topics/:id/relatives
def relatives
@topic = Topic.find(params[:id])
authorize @topic
topicsAlreadyHas = params[:network] ? params[:network].split(',').map(&:to_i) : []
alltopics = policy_scope(Topic.relatives1(@topic.id)).to_a.concat(policy_scope(Topic.relatives2(@topic.id)).to_a).uniq
alltopics.delete_if do |topic|
!topicsAlreadyHas.index(topic.id.to_s).nil?
end
# find synapses between topics in alltopics array
allsynapses = policy_scope(Synapse.for_topic(@topic.id)).to_a
synapse_ids = (allsynapses.map(&:node1_id) + allsynapses.map(&:node2_id)).uniq
allsynapses.delete_if do |synapse|
!synapse_ids.index(synapse.id).nil?
end
creatorsAlreadyHas = params[:creators] ? params[:creators].split(',').map(&:to_i) : []
allcreators = (alltopics.map(&:user) + allsynapses.map(&:user)).uniq.delete_if do |user|
!creatorsAlreadyHas.index(user.id).nil?
end
@json = {}
@json['topics'] = alltopics
@json['synapses'] = allsynapses
@json['creators'] = allcreators
respond_to do |format|
format.json { render json: @json }
end
end
# POST /topics # POST /topics
# POST /topics.json # POST /topics.json

View file

@ -1,5 +1,6 @@
class Users::PasswordsController < Devise::PasswordsController class Users::PasswordsController < Devise::PasswordsController
protected protected
def after_resetting_password_path_for(resource) def after_resetting_password_path_for(resource)
signed_in_root_path(resource) signed_in_root_path(resource)
end end

View file

@ -3,21 +3,23 @@ class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_account_update_params, only: [:update] before_action :configure_account_update_params, only: [:update]
protected protected
def after_sign_up_path_for(resource)
signed_in_root_path(resource)
end
def after_update_path_for(resource) def after_sign_up_path_for(resource)
signed_in_root_path(resource) signed_in_root_path(resource)
end end
def after_update_path_for(resource)
signed_in_root_path(resource)
end
private private
def configure_sign_up_params
devise_parameter_sanitizer.for(:sign_up) << [:name, :joinedwithcode]
end
def configure_account_update_params def configure_sign_up_params
puts devise_parameter_sanitizer_for(:account_update) devise_parameter_sanitizer.for(:sign_up) << [:name, :joinedwithcode]
devise_parameter_sanitizer.for(:account_update) << [:image] end
end
def configure_account_update_params
puts devise_parameter_sanitizer_for(:account_update)
devise_parameter_sanitizer.for(:account_update) << [:image]
end
end end

View file

@ -1,38 +1,36 @@
class UsersController < ApplicationController class UsersController < ApplicationController
before_action :require_user, only: [:edit, :update, :updatemetacodes] before_action :require_user, only: [:edit, :update, :updatemetacodes]
respond_to :html, :json respond_to :html, :json
# GET /users/1.json # GET /users/1.json
def show def show
@user = User.find(params[:id]) @user = User.find(params[:id])
render json: @user render json: @user
end end
# GET /users/:id/edit # GET /users/:id/edit
def edit def edit
@user = current_user @user = current_user
respond_with(@user) respond_with(@user)
end end
# PUT /users/:id # PUT /users/:id
def update def update
@user = current_user @user = current_user
if user_params[:password] == "" && user_params[:password_confirmation] == "" if user_params[:password] == '' && user_params[:password_confirmation] == ''
# not trying to change the password # not trying to change the password
if @user.update_attributes(user_params.except(:password, :password_confirmation)) if @user.update_attributes(user_params.except(:password, :password_confirmation))
if params[:remove_image] == "1" @user.image = nil if params[:remove_image] == '1'
@user.image = nil
end
@user.save @user.save
sign_in(@user, :bypass => true) sign_in(@user, bypass: true)
respond_to do |format| respond_to do |format|
format.html { redirect_to root_url, notice: "Account updated!" } format.html { redirect_to root_url, notice: 'Account updated!' }
end end
else else
sign_in(@user, :bypass => true) sign_in(@user, bypass: true)
respond_to do |format| respond_to do |format|
format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] } format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] }
end end
@ -42,53 +40,51 @@ class UsersController < ApplicationController
correct_pass = @user.valid_password?(params[:current_password]) correct_pass = @user.valid_password?(params[:current_password])
if correct_pass && @user.update_attributes(user_params) if correct_pass && @user.update_attributes(user_params)
if params[:remove_image] == "1" @user.image = nil if params[:remove_image] == '1'
@user.image = nil
end
@user.save @user.save
sign_in(@user, :bypass => true) sign_in(@user, bypass: true)
respond_to do |format| respond_to do |format|
format.html { redirect_to root_url, notice: "Account updated!" } format.html { redirect_to root_url, notice: 'Account updated!' }
end end
else else
respond_to do |format| respond_to do |format|
if correct_pass if correct_pass
u = User.find(@user.id) u = User.find(@user.id)
sign_in(u, :bypass => true) sign_in(u, bypass: true)
format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] } format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] }
else else
sign_in(@user, :bypass => true) sign_in(@user, bypass: true)
format.html { redirect_to edit_user_path(@user), notice: "Incorrect current password" } format.html { redirect_to edit_user_path(@user), notice: 'Incorrect current password' }
end end
end end
end end
end end
end end
# GET /users/:id/details [.json] # GET /users/:id/details [.json]
def details def details
@user = User.find(params[:id]) @user = User.find(params[:id])
@details = Hash.new @details = {}
@details['name'] = @user.name @details['name'] = @user.name
@details['created_at'] = @user.created_at.strftime("%m/%d/%Y") @details['created_at'] = @user.created_at.strftime('%m/%d/%Y')
@details['image'] = @user.image.url(:ninetysix) @details['image'] = @user.image.url(:ninetysix)
@details['generation'] = @user.generation @details['generation'] = @user.generation
@details['numSynapses'] = @user.synapses.count @details['numSynapses'] = @user.synapses.count
@details['numTopics'] = @user.topics.count @details['numTopics'] = @user.topics.count
@details['numMaps'] = @user.maps.count @details['numMaps'] = @user.maps.count
render json: @details render json: @details
end end
# PUT /user/updatemetacodes # PUT /user/updatemetacodes
def updatemetacodes def updatemetacodes
@user = current_user @user = current_user
@m = params[:metacodes][:value] @m = params[:metacodes][:value]
@user.settings.metacodes=@m.split(',') @user.settings.metacodes = @m.split(',')
@user.save @user.save
respond_to do |format| respond_to do |format|

View file

@ -1,22 +1,22 @@
module ApplicationHelper module ApplicationHelper
def get_metacodeset def get_metacodeset
@m = current_user.settings.metacodes @m = current_user.settings.metacodes
set = @m[0].include?("metacodeset") ? MetacodeSet.find(@m[0].sub("metacodeset-","").to_i) : false set = @m[0].include?('metacodeset') ? MetacodeSet.find(@m[0].sub('metacodeset-', '').to_i) : false
return set set
end end
def user_metacodes def user_metacodes
@m = current_user.settings.metacodes @m = current_user.settings.metacodes
set = get_metacodeset set = get_metacodeset
if set @metacodes = if set
@metacodes = set.metacodes.to_a set.metacodes.to_a
else else
@metacodes = Metacode.where(id: @m).to_a Metacode.where(id: @m).to_a
end end
@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 determine_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,26 +1,9 @@
module DeviseHelper module DeviseHelper
def devise_error_messages! def devise_error_messages!
resource.errors.to_a[0]
message = resource.errors.to_a[0]
#return "" if resource.errors.empty?
#messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
#sentence = I18n.t("errors.messages.not_saved",
# :count => resource.errors.count,
# :resource => resource.class.model_name.human.downcase)
#html = <<-HTML
#<div id="error_explanation">
# <h2>#{sentence}</h2>
# <ul>#{messages}</ul>
#</div>
#HTML
#html.html_safe
end end
def devise_error_messages? def devise_error_messages?
resource.errors.empty? ? false : true resource.errors.empty? ? false : true
end end
end
end

View file

@ -1,5 +1,4 @@
module MapsHelper module MapsHelper
## 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_map_array_json(maps) def autocomplete_map_array_json(maps)
temp = [] temp = []
@ -13,16 +12,16 @@ module MapsHelper
map['topicCount'] = m.topics.count map['topicCount'] = m.topics.count
map['synapseCount'] = m.synapses.count map['synapseCount'] = m.synapses.count
map['contributorCount'] = m.contributors.count map['contributorCount'] = m.contributors.count
map['rtype'] = "map" map['rtype'] = 'map'
contributorTip = '' contributorTip = ''
firstContributorImage = 'https://s3.amazonaws.com/metamaps-assets/site/user.png' firstContributorImage = 'https://s3.amazonaws.com/metamaps-assets/site/user.png'
if m.contributors.count > 0 if m.contributors.count > 0
firstContributorImage = m.contributors[0].image.url(:thirtytwo) firstContributorImage = m.contributors[0].image.url(:thirtytwo)
m.contributors.each_with_index do |c, index| m.contributors.each_with_index do |c, _index|
userImage = c.image.url(:thirtytwo) userImage = c.image.url(:thirtytwo)
name = c.name name = c.name
contributorTip += '<li> <img class="tipUserImage" width="25" height="25" src=' + userImage + ' />' + '<span>' + name + '</span> </li>' contributorTip += '<li> <img class="tipUserImage" width="25" height="25" src=' + userImage + ' />' + '<span>' + name + '</span> </li>'
end end
end end
map['contributorTip'] = contributorTip map['contributorTip'] = contributorTip
@ -30,7 +29,6 @@ module MapsHelper
temp.push map temp.push map
end end
return temp temp
end end
end end

View file

@ -1,6 +1,4 @@
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 = [] temp = []
@ -8,29 +6,28 @@ module SynapsesHelper
synapse = {} synapse = {}
synapse['label'] = s.desc synapse['label'] = s.desc
synapse['value'] = s.desc synapse['value'] = s.desc
temp.push synapse temp.push synapse
end end
return temp 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 = [] temp = []
synapses.each do |s| synapses.each do |s|
synapse = {} synapse = {}
synapse['id'] = s.id synapse['id'] = s.id
synapse['label'] = s.desc == nil || s.desc == "" ? "(no description)" : s.desc synapse['label'] = s.desc.nil? || s.desc == '' ? '(no description)' : s.desc
synapse['value'] = s.desc synapse['value'] = s.desc
synapse['permission'] = s.permission synapse['permission'] = s.permission
synapse['mapCount'] = s.maps.count synapse['mapCount'] = s.maps.count
synapse['originator'] = s.user.name synapse['originator'] = s.user.name
synapse['originatorImage'] = s.user.image.url(:thirtytwo) synapse['originatorImage'] = s.user.image.url(:thirtytwo)
synapse['rtype'] = "synapse" synapse['rtype'] = 'synapse'
temp.push synapse temp.push synapse
end end
return temp temp
end end
end end

View file

@ -1,5 +1,4 @@
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 = [] temp = []
@ -16,46 +15,42 @@ module TopicsHelper
topic['synapseCount'] = t.synapses.count topic['synapseCount'] = t.synapses.count
topic['originator'] = t.user.name topic['originator'] = t.user.name
topic['originatorImage'] = t.user.image.url(:thirtytwo) topic['originatorImage'] = t.user.image.url(:thirtytwo)
topic['rtype'] = "topic" topic['rtype'] = 'topic'
topic['inmaps'] = t.inmaps topic['inmaps'] = t.inmaps
topic['inmapsLinks'] = t.inmapsLinks topic['inmapsLinks'] = t.inmapsLinks
temp.push topic temp.push topic
end end
return temp temp
end end
#find all nodes in any given nodes network # 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 # 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 # if the array of nodes is empty initialize it
if array.nil? array = [] if array.nil?
array = Array.new
end
# add the node to the array # add the node to the array
array.push(node) array.push(node)
if count == 0 return array if count == 0
return array
end
count = count - 1 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 not node.relatives.empty? if !node.relatives.empty?
if (node.relatives-array).empty? if (node.relatives - array).empty?
return array return array
else else
(node.relatives-array).each do |relative| (node.relatives - array).each do |relative|
array = (array | network(relative, array, count)) array = (array | network(relative, array, count))
end end
return array return array
end end
elsif node.relatives.empty? elsif node.relatives.empty?
return array return array
end end
end end
end end

View file

@ -3,7 +3,7 @@ module UsersHelper
def autocomplete_user_array_json(users) def autocomplete_user_array_json(users)
json_users = [] json_users = []
users.each do |user| users.each do |user|
json_users.push user.as_json_for_autocomplete json_users.push user.as_json_for_autocomplete
end end
json_users json_users
end end

View file

@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base class ApplicationMailer < ActionMailer::Base
default from: "team@metamaps.cc" default from: 'team@metamaps.cc'
layout 'mailer' layout 'mailer'
end end

View file

@ -1,5 +1,5 @@
class MapMailer < ApplicationMailer class MapMailer < ApplicationMailer
default from: "team@metamaps.cc" default from: 'team@metamaps.cc'
def invite_to_edit_email(map, inviter, invitee) def invite_to_edit_email(map, inviter, invitee)
@inviter = inviter @inviter = inviter

View file

@ -1,7 +1,7 @@
class Event < ActiveRecord::Base class Event < ActiveRecord::Base
KINDS = %w[user_present_on_map conversation_started_on_map topic_added_to_map synapse_added_to_map] KINDS = %w(user_present_on_map conversation_started_on_map topic_added_to_map synapse_added_to_map).freeze
#has_many :notifications, dependent: :destroy # has_many :notifications, dependent: :destroy
belongs_to :eventable, polymorphic: true belongs_to :eventable, polymorphic: true
belongs_to :map belongs_to :map
belongs_to :user belongs_to :user
@ -10,22 +10,21 @@ class Event < ActiveRecord::Base
after_create :notify_webhooks!, if: :map after_create :notify_webhooks!, if: :map
validates_inclusion_of :kind, :in => KINDS validates :kind, inclusion: { in: KINDS }
validates_presence_of :eventable validates :eventable, presence: true
#def notify!(user) # def notify!(user)
# notifications.create!(user: user) # notifications.create!(user: user)
#end # end
def belongs_to?(this_user) def belongs_to?(this_user)
self.user_id == this_user.id user_id == this_user.id
end end
def notify_webhooks! def notify_webhooks!
#group = self.discussion.group # group = self.discussion.group
self.map.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self } map.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self }
#group.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self } # group.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self }
end end
handle_asynchronously :notify_webhooks! handle_asynchronously :notify_webhooks!
end end

View file

@ -1,18 +1,10 @@
class Events::ConversationStartedOnMap < Event class Events::ConversationStartedOnMap < Event
#after_create :notify_users! # after_create :notify_users!
def self.publish!(map, user) def self.publish!(map, user)
create!(kind: "conversation_started_on_map", create!(kind: 'conversation_started_on_map',
eventable: map, eventable: map,
map: map, map: map,
user: user) user: user)
end end
private
#def notify_users!
# unless comment_vote.user == comment_vote.comment_user
# notify!(comment_vote.comment_user)
# end
#end
end end

View file

@ -1,18 +1,10 @@
class Events::NewMapping < Event class Events::NewMapping < Event
#after_create :notify_users! # after_create :notify_users!
def self.publish!(mapping, user) def self.publish!(mapping, user)
create!(kind: mapping.mappable_type == "Topic" ? "topic_added_to_map" : "synapse_added_to_map", create!(kind: mapping.mappable_type == 'Topic' ? 'topic_added_to_map' : 'synapse_added_to_map',
eventable: mapping, eventable: mapping,
map: mapping.map, map: mapping.map,
user: user) user: user)
end end
private
#def notify_users!
# unless comment_vote.user == comment_vote.comment_user
# notify!(comment_vote.comment_user)
# end
#end
end end

View file

@ -1,18 +1,10 @@
class Events::UserPresentOnMap < Event class Events::UserPresentOnMap < Event
#after_create :notify_users! # after_create :notify_users!
def self.publish!(map, user) def self.publish!(map, user)
create!(kind: "user_present_on_map", create!(kind: 'user_present_on_map',
eventable: map, eventable: map,
map: map, map: map,
user: user) user: user)
end end
private
#def notify_users!
# unless comment_vote.user == comment_vote.comment_user
# notify!(comment_vote.comment_user)
# end
#end
end end

View file

@ -1,4 +1,4 @@
class InMetacodeSet < ActiveRecord::Base class InMetacodeSet < ActiveRecord::Base
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'
end end

View file

@ -1,11 +1,10 @@
class Map < ActiveRecord::Base class Map < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping, dependent: :destroy has_many :topicmappings, -> { Mapping.topicmapping }, class_name: :Mapping, dependent: :destroy
has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping, dependent: :destroy has_many :synapsemappings, -> { Mapping.synapsemapping }, class_name: :Mapping, dependent: :destroy
has_many :topics, through: :topicmappings, source: :mappable, source_type: "Topic" has_many :topics, through: :topicmappings, source: :mappable, source_type: 'Topic'
has_many :synapses, through: :synapsemappings, source: :mappable, source_type: "Synapse" has_many :synapses, through: :synapsemappings, source: :mappable, source_type: 'Synapse'
has_many :messages, as: :resource, dependent: :destroy has_many :messages, as: :resource, dependent: :destroy
has_many :user_maps, dependent: :destroy has_many :user_maps, dependent: :destroy
@ -15,11 +14,11 @@ class Map < ActiveRecord::Base
has_many :events, -> { includes :user }, as: :eventable, dependent: :destroy has_many :events, -> { includes :user }, as: :eventable, dependent: :destroy
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :screenshot, :styles => { has_attached_file :screenshot, styles: {
:thumb => ['188x126#', :png] thumb: ['188x126#', :png]
#:full => ['940x630#', :png] #:full => ['940x630#', :png]
}, },
:default_url => 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png' default_url: 'https://s3.amazonaws.com/metamaps-assets/site/missing-map.png'
validates :name, presence: true validates :name, presence: true
validates :arranged, inclusion: { in: [true, false] } validates :arranged, inclusion: { in: [true, false] }
@ -27,29 +26,29 @@ class Map < ActiveRecord::Base
validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) }
# Validate the attached image is image/jpg, image/png, etc # Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :screenshot, :content_type => /\Aimage\/.*\Z/ validates_attachment_content_type :screenshot, content_type: /\Aimage\/.*\Z/
def mappings def mappings
topicmappings + synapsemappings topicmappings + synapsemappings
end end
def mk_permission def mk_permission
Perm.short(permission) Perm.short(permission)
end end
#return an array of the contributors to the map # return an array of the contributors to the map
def contributors def contributors
contributors = [] contributors = []
self.mappings.each do |m| mappings.each do |m|
contributors.push(m.user) if !contributors.include?(m.user) contributors.push(m.user) unless contributors.include?(m.user)
end end
return contributors contributors
end end
def editors def editors
collaborators + [self.user] collaborators + [user]
end end
def topic_count def topic_count
@ -60,15 +59,13 @@ class Map < ActiveRecord::Base
synapses.length synapses.length
end end
def user_name delegate :name, to: :user, prefix: true
user.name
end
def user_image def user_image
user.image.url user.image.url
end end
def contributor_count def contributor_count
contributors.length contributors.length
end end
@ -81,15 +78,15 @@ class Map < ActiveRecord::Base
end end
def created_at_str def created_at_str
created_at.strftime("%m/%d/%Y") created_at.strftime('%m/%d/%Y')
end end
def updated_at_str def updated_at_str
updated_at.strftime("%m/%d/%Y") updated_at.strftime('%m/%d/%Y')
end end
def as_json(options={}) def as_json(_options = {})
json = super(:methods =>[:user_name, :user_image, :topic_count, :synapse_count, :contributor_count, :collaborator_ids, :screenshot_url], :except => [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, :screenshot_updated_at]) json = super(methods: [:user_name, :user_image, :topic_count, :synapse_count, :contributor_count, :collaborator_ids, :screenshot_url], except: [:screenshot_content_type, :screenshot_file_size, :screenshot_file_name, :screenshot_updated_at])
json[:created_at_clean] = created_at_str json[:created_at_clean] = created_at_str
json[:updated_at_clean] = updated_at_str json[:updated_at_clean] = updated_at_str
json json
@ -103,11 +100,10 @@ class Map < ActiveRecord::Base
attr_accessor :content_type, :original_filename attr_accessor :content_type, :original_filename
end end
data.content_type = "image/png" data.content_type = 'image/png'
data.original_filename = File.basename('map-' + self.id.to_s + '-screenshot.png') data.original_filename = File.basename('map-' + id.to_s + '-screenshot.png')
self.screenshot = data self.screenshot = data
self.save save
end end
end end

View file

@ -1,29 +1,25 @@
class Mapping < ActiveRecord::Base class Mapping < ActiveRecord::Base
scope :topicmapping, -> { where(mappable_type: :Topic) } scope :topicmapping, -> { where(mappable_type: :Topic) }
scope :synapsemapping, -> { where(mappable_type: :Synapse) } scope :synapsemapping, -> { where(mappable_type: :Synapse) }
belongs_to :mappable, polymorphic: true belongs_to :mappable, polymorphic: true
belongs_to :map, :class_name => "Map", :foreign_key => "map_id", touch: true belongs_to :map, class_name: 'Map', foreign_key: 'map_id', touch: true
belongs_to :user belongs_to :user
validates :xloc, presence: true, validates :xloc, presence: true,
unless: Proc.new { |m| m.mappable_type == 'Synapse' } unless: proc { |m| m.mappable_type == 'Synapse' }
validates :yloc, presence: true, validates :yloc, presence: true,
unless: Proc.new { |m| m.mappable_type == 'Synapse' } unless: proc { |m| m.mappable_type == 'Synapse' }
validates :map, presence: true validates :map, presence: true
validates :mappable, presence: true validates :mappable, presence: true
def user_name delegate :name, to: :user, prefix: true
self.user.name
end
def user_image def user_image
self.user.image.url user.image.url
end end
def as_json(options={}) def as_json(_options = {})
super(:methods =>[:user_name, :user_image]) super(methods: [:user_name, :user_image])
end end
end end

View file

@ -1,19 +1,15 @@
class Message < ActiveRecord::Base class Message < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :resource, polymorphic: true belongs_to :resource, polymorphic: true
def user_name delegate :name, to: :user, prefix: true
self.user.name
end
def user_image def user_image
self.user.image.url user.image.url
end end
def as_json(options={}) def as_json(_options = {})
json = super(:methods =>[:user_name, :user_image]) json = super(methods: [:user_name, :user_image])
json json
end end
end end

View file

@ -1,21 +1,21 @@
class Metacode < ActiveRecord::Base class Metacode < ActiveRecord::Base
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
has_many :topics has_many :topics
# This method associates the attribute ":aws_icon" with a file attachment # This method associates the attribute ":aws_icon" with a file attachment
has_attached_file :aws_icon, :styles => { has_attached_file :aws_icon, styles: {
:ninetysix => ['96x96#', :png], ninetysix: ['96x96#', :png]
}, },
:default_url => 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png' default_url: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png'
# Validate the attached icon is image/jpg, image/png, etc # Validate the attached icon is image/jpg, image/png, etc
validates_attachment_content_type :aws_icon, :content_type => /\Aimage\/.*\Z/ validates_attachment_content_type :aws_icon, content_type: /\Aimage\/.*\Z/
validate :aws_xor_manual_icon validate :aws_xor_manual_icon
validate :manual_icon_https validate :manual_icon_https
before_create do before_create do
self.manual_icon = nil if self.manual_icon == "" self.manual_icon = nil if manual_icon == ''
end end
def icon(*args) def icon(*args)
@ -26,37 +26,37 @@ class Metacode < ActiveRecord::Base
end end
end end
def as_json(options={}) def as_json(options = {})
default = super(options) default = super(options)
default[:icon] = icon default[:icon] = icon
default.except('aws_icon_file_name', 'aws_icon_content_type', 'aws_icon_file_size', 'aws_icon_updated_at', 'manual_icon') default.except('aws_icon_file_name', 'aws_icon_content_type', 'aws_icon_file_size', 'aws_icon_updated_at', 'manual_icon')
end end
def hasSelected(user) def hasSelected(user)
return true if user.settings.metacodes.include? self.id.to_s return true if user.settings.metacodes.include? id.to_s
return false false
end end
def inMetacodeSet(metacode_set) def inMetacodeSet(metacode_set)
return true if self.metacode_sets.include? metacode_set return true if metacode_sets.include? metacode_set
return false false
end end
private private
def aws_xor_manual_icon def aws_xor_manual_icon
if aws_icon.blank? && manual_icon.blank? if aws_icon.blank? && manual_icon.blank?
errors.add(:base, "Either aws_icon or manual_icon is required") errors.add(:base, 'Either aws_icon or manual_icon is required')
end end
if aws_icon.present? && manual_icon.present? if aws_icon.present? && manual_icon.present?
errors.add(:base, "Specify aws_icon or manual_icon, not both") errors.add(:base, 'Specify aws_icon or manual_icon, not both')
end end
end end
def manual_icon_https def manual_icon_https
if manual_icon.present? if manual_icon.present?
unless manual_icon.starts_with? 'https' unless manual_icon.starts_with? 'https'
errors.add(:base, "Manual icon must begin with https") errors.add(:base, 'Manual icon must begin with https')
end end
end end
end end

View file

@ -1,5 +1,5 @@
class MetacodeSet < ActiveRecord::Base class MetacodeSet < ActiveRecord::Base
belongs_to :user belongs_to :user
has_many :in_metacode_sets has_many :in_metacode_sets
has_many :metacodes, :through => :in_metacode_sets has_many :metacodes, through: :in_metacode_sets
end end

View file

@ -1,23 +1,22 @@
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
permitted_attributes = self.send("#{kind}_attributes") permitted_attributes = send("#{kind}_attributes")
params.require(kind).permit(*permitted_attributes) params.require(kind).permit(*permitted_attributes)
end end
alias_method :"api_#{kind}", kind.to_sym alias_method :"api_#{kind}", kind.to_sym
end end
alias :read_attribute_for_serialization :send alias read_attribute_for_serialization send
def token_attributes def token_attributes
[:description] [:description]
end end
def map_attributes def map_attributes
[:name, :desc, :permission, :arranged] [:name, :desc, :permission, :arranged]
end end
def synapse_attributes def synapse_attributes
[:desc, :category, :weight, :permission, :node1_id, :node2_id] [:desc, :category, :weight, :permission, :node1_id, :node2_id]
end end
@ -29,5 +28,4 @@ class PermittedParams < Struct.new(:params)
def mapping_attributes def mapping_attributes
[:xloc, :yloc, :map_id, :mappable_type, :mappable_id] [:xloc, :yloc, :map_id, :mappable_type, :mappable_id]
end end
end end

View file

@ -1,12 +1,12 @@
class Synapse < ActiveRecord::Base class Synapse < ActiveRecord::Base
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'
belongs_to :topic1, :class_name => "Topic", :foreign_key => "node1_id" belongs_to :topic1, class_name: 'Topic', foreign_key: 'node1_id'
belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id" belongs_to :topic2, class_name: 'Topic', foreign_key: 'node2_id'
has_many :mappings, as: :mappable, dependent: :destroy has_many :mappings, as: :mappable, dependent: :destroy
has_many :maps, :through => :mappings has_many :maps, through: :mappings
validates :desc, length: { minimum: 0, allow_nil: false } validates :desc, length: { minimum: 0, allow_nil: false }
@ -17,14 +17,12 @@ class Synapse < ActiveRecord::Base
validates :category, inclusion: { in: ['from-to', 'both'], allow_nil: true } validates :category, inclusion: { in: ['from-to', 'both'], allow_nil: true }
scope :for_topic, ->(topic_id = nil) { scope :for_topic, ->(topic_id = nil) {
where("node1_id = ? OR node2_id = ?", topic_id, topic_id) where('node1_id = ? OR node2_id = ?', topic_id, topic_id)
} }
# :nocov: # :nocov:
def user_name delegate :name, to: :user, prefix: true
user.name
end
# :nocov: # :nocov:
# :nocov: # :nocov:
@ -36,14 +34,14 @@ class Synapse < ActiveRecord::Base
# :nocov: # :nocov:
def collaborator_ids def collaborator_ids
if defer_to_map if defer_to_map
defer_to_map.editors.select{|mapper| not mapper == self.user }.map(&:id) defer_to_map.editors.select { |mapper| mapper != user }.map(&:id)
else else
[] []
end end
end end
# :nocov: # :nocov:
# :nocov: # :nocov:
def calculated_permission def calculated_permission
if defer_to_map if defer_to_map
defer_to_map.permission defer_to_map.permission
@ -52,11 +50,10 @@ class Synapse < ActiveRecord::Base
end end
end end
# :nocov: # :nocov:
# :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: # :nocov:
end end

View file

@ -6,6 +6,7 @@ class Token < ActiveRecord::Base
CHARS = 32 CHARS = 32
private private
def assign_token def assign_token
self.token = generate_token self.token = generate_token
end end
@ -13,10 +14,7 @@ class Token < ActiveRecord::Base
def generate_token def generate_token
loop do loop do
candidate = SecureRandom.base64(CHARS).gsub(/\W/, '') candidate = SecureRandom.base64(CHARS).gsub(/\W/, '')
if candidate.size >= CHARS return candidate[0...CHARS] if candidate.size >= CHARS
return candidate[0...CHARS]
end
end end
end end
end end

View file

@ -2,61 +2,59 @@ class Topic < ActiveRecord::Base
include TopicsHelper include TopicsHelper
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'
has_many :synapses1, :class_name => 'Synapse', :foreign_key => 'node1_id', dependent: :destroy has_many :synapses1, class_name: 'Synapse', foreign_key: 'node1_id', dependent: :destroy
has_many :synapses2, :class_name => 'Synapse', :foreign_key => 'node2_id', dependent: :destroy has_many :synapses2, class_name: 'Synapse', foreign_key: 'node2_id', dependent: :destroy
has_many :topics1, :through => :synapses2, source: :topic1 has_many :topics1, through: :synapses2, source: :topic1
has_many :topics2, :through => :synapses1, source: :topic2 has_many :topics2, through: :synapses1, source: :topic2
has_many :mappings, as: :mappable, dependent: :destroy has_many :mappings, as: :mappable, dependent: :destroy
has_many :maps, :through => :mappings has_many :maps, through: :mappings
belongs_to :metacode belongs_to :metacode
validates :permission, presence: true validates :permission, presence: true
validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) }
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :image has_attached_file :image
#, styles: { # , styles: {
# thumb: '100x100>', # thumb: '100x100>',
# square: '200x200#', # square: '200x200#',
# medium: '300x300>' # medium: '300x300>'
#} # }
# 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 => /\Aimage\/.*\Z/ validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :audio has_attached_file :audio
# Validate the attached audio is audio/wav, audio/mp3, etc # Validate the attached audio is audio/wav, audio/mp3, etc
validates_attachment_content_type :audio, :content_type => /\Aaudio\/.*\Z/ validates_attachment_content_type :audio, content_type: /\Aaudio\/.*\Z/
def synapses def synapses
synapses1 + synapses2 synapses1 + synapses2
end
def relatives
topics1 + topics2
end end
scope :relatives1, ->(topic_id = nil) { def relatives
topics1 + topics2
end
scope :relatives1, ->(topic_id = nil) {
includes(:topics1) includes(:topics1)
.where('synapses.node1_id = ?', topic_id) .where('synapses.node1_id = ?', topic_id)
.references(:synapses) .references(:synapses)
} }
scope :relatives2, ->(topic_id = nil) { scope :relatives2, ->(topic_id = nil) {
includes(:topics2) includes(:topics2)
.where('synapses.node2_id = ?', topic_id) .where('synapses.node2_id = ?', topic_id)
.references(:synapses) .references(:synapses)
} }
def user_name delegate :name, to: :user, prefix: true
user.name
end
def user_image def user_image
user.image.url user.image.url
@ -86,19 +84,19 @@ class Topic < ActiveRecord::Base
end end
end end
def as_json(options={}) def as_json(_options = {})
super(:methods =>[:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks, :calculated_permission, :collaborator_ids]) super(methods: [:user_name, :user_image, :map_count, :synapse_count, :inmaps, :inmapsLinks, :calculated_permission, :collaborator_ids])
end end
def collaborator_ids def collaborator_ids
if defer_to_map if defer_to_map
defer_to_map.editors.select{|mapper| not mapper == self.user }.map(&:id) defer_to_map.editors.select { |mapper| mapper != user }.map(&:id)
else else
[] []
end end
end end
# TODO move to a decorator? # TODO: move to a decorator?
def synapses_csv(output_format = 'array') def synapses_csv(output_format = 'array')
output = [] output = []
synapses.each do |synapse| synapses.each do |synapse|
@ -108,7 +106,7 @@ class Topic < ActiveRecord::Base
elsif synapse.node2_id == id elsif synapse.node2_id == id
output << synapse.node2_id.to_s + '<-' + synapse.node1_id.to_s output << synapse.node2_id.to_s + '<-' + synapse.node1_id.to_s
else else
fail 'invalid synapse on topic in synapse_csv' raise 'invalid synapse on topic in synapse_csv'
end end
elsif synapse.category == 'both' elsif synapse.category == 'both'
if synapse.node1_id == id if synapse.node1_id == id
@ -116,7 +114,7 @@ class Topic < ActiveRecord::Base
elsif synapse.node2_id == id elsif synapse.node2_id == id
output << synapse.node2_id.to_s + '<->' + synapse.node1_id.to_s output << synapse.node2_id.to_s + '<->' + synapse.node1_id.to_s
else else
fail 'invalid synapse on topic in synapse_csv' raise 'invalid synapse on topic in synapse_csv'
end end
end end
end end
@ -125,15 +123,15 @@ class Topic < ActiveRecord::Base
elsif output_format == 'text' elsif output_format == 'text'
return output.join('; ') return output.join('; ')
else else
fail 'invalid argument to synapses_csv' raise 'invalid argument to synapses_csv'
end end
output output
end end
def topic_autocomplete_method def topic_autocomplete_method
"Get: #{self.name}" "Get: #{name}"
end end
def mk_permission def mk_permission
Perm.short(permission) Perm.short(permission)
end end

View file

@ -1,7 +1,6 @@
require 'open-uri' require 'open-uri'
class User < ActiveRecord::Base class User < ActiveRecord::Base
has_many :topics has_many :topics
has_many :synapses has_many :synapses
has_many :maps has_many :maps
@ -9,47 +8,46 @@ class User < ActiveRecord::Base
has_many :tokens has_many :tokens
has_many :user_maps, dependent: :destroy has_many :user_maps, dependent: :destroy
has_many :shared_maps, through: :user_maps, source: :map has_many :shared_maps, through: :user_maps, source: :map
after_create :generate_code after_create :generate_code
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable
serialize :settings, UserPreference serialize :settings, UserPreference
validates :password, :presence => true, validates :password, presence: true,
:length => { :within => 8..40 }, length: { within: 8..40 },
:on => :create on: :create
validates :password, :length => { :within => 8..40 }, validates :password, length: { within: 8..40 },
:allow_blank => true, allow_blank: true,
:on => :update on: :update
validates_confirmation_of :password validates :password, confirmation: true
validates_presence_of :name # done by devise validates :name, presence: true # done by devise
validates_presence_of :email # done by devise validates :email, presence: true # done by devise
validates_uniqueness_of :name # done by devise validates :name, uniqueness: true # done by devise
validates_uniqueness_of :email # done by devise validates :email, uniqueness: true # done by devise
validates :joinedwithcode, :presence => true, :inclusion => { :in => $codes, :message => "%{value} is not valid" }, :on => :create validates :joinedwithcode, presence: true, inclusion: { in: $codes, message: '%{value} is not valid' }, on: :create
# This method associates the attribute ":image" with a file attachment # This method associates the attribute ":image" with a file attachment
has_attached_file :image, :styles => { has_attached_file :image, styles: {
:thirtytwo => ['32x32#', :png], thirtytwo: ['32x32#', :png],
:sixtyfour => ['64x64#', :png], sixtyfour: ['64x64#', :png],
:ninetysix => ['96x96#', :png], ninetysix: ['96x96#', :png],
:onetwentyeight => ['128x128#', :png] onetwentyeight: ['128x128#', :png]
}, },
: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 => /\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 = {})
{ :id => self.id, { id: id,
:name => self.name, name: name,
:image => self.image.url(:sixtyfour), image: image.url(:sixtyfour),
:admin => self.admin admin: admin }
}
end end
def as_json_for_autocomplete def as_json_for_autocomplete
@ -60,14 +58,14 @@ class User < ActiveRecord::Base
json['profile'] = image.url(:sixtyfour) json['profile'] = image.url(:sixtyfour)
json['mapCount'] = maps.count json['mapCount'] = maps.count
json['generation'] = generation json['generation'] = generation
json['created_at'] = created_at.strftime("%m/%d/%Y") json['created_at'] = created_at.strftime('%m/%d/%Y')
json['rtype'] = "mapper" json['rtype'] = 'mapper'
json json
end end
#generate a random 8 letter/digit code that they can use to invite people # generate a random 8 letter/digit code that they can use to invite people
def generate_code def generate_code
self.code ||= rand(36**8).to_s(36) self.code ||= rand(36**8).to_s(36)
$codes.push(self.code) $codes.push(self.code)
self.generation = get_generation! self.generation = get_generation!
end end
@ -82,14 +80,11 @@ class User < ActiveRecord::Base
def settings def settings
# make sure we always return a UserPreference instance # make sure we always return a UserPreference instance
if read_attribute(:settings).nil? self[:settings] = UserPreference.new if self[:settings].nil?
write_attribute :settings, UserPreference.new self[:settings]
end
read_attribute :settings
end end
def settings=(val) def settings=(val)
write_attribute :settings, val self[:settings] = val
end end
end end

View file

@ -1,11 +1,11 @@
class UserPreference class UserPreference
attr_accessor :metacodes attr_accessor :metacodes
def initialize def initialize
array = [] array = []
Metacode.all.each do |m| Metacode.all.find_each do |m|
array.push(m.id.to_s) array.push(m.id.to_s)
end end
@metacodes = array @metacodes = array
end end
end end

View file

@ -3,11 +3,10 @@ class Webhook < ActiveRecord::Base
validates :uri, presence: true validates :uri, presence: true
validates :hookable, presence: true validates :hookable, presence: true
validates_inclusion_of :kind, in: %w[slack] validates :kind, inclusion: { in: %w(slack) }
validates :event_types, length: { minimum: 1 } validates :event_types, length: { minimum: 1 }
def headers def headers
{} {}
end end
end end

View file

@ -2,15 +2,15 @@ Webhooks::Slack::Base = Struct.new(:event) do
include Routing include Routing
def username def username
"Metamaps Bot" 'Metamaps Bot'
end end
def icon_url def icon_url
"https://pbs.twimg.com/profile_images/539300245029392385/dJ1bwnw7.jpeg" 'https://pbs.twimg.com/profile_images/539300245029392385/dJ1bwnw7.jpeg'
end end
def text def text
"something" 'something'
end end
def attachments def attachments
@ -22,11 +22,11 @@ Webhooks::Slack::Base = Struct.new(:event) do
}] }]
end end
alias :read_attribute_for_serialization :send alias_method :read_attribute_for_serialization, :send
private private
#def motion_vote_field # def motion_vote_field
# { # {
# title: "Vote on this proposal", # title: "Vote on this proposal",
# value: "#{proposal_link(eventable, "yes")} · " + # value: "#{proposal_link(eventable, "yes")} · " +
@ -34,23 +34,23 @@ Webhooks::Slack::Base = Struct.new(:event) do
# "#{proposal_link(eventable, "no")} · " + # "#{proposal_link(eventable, "no")} · " +
# "#{proposal_link(eventable, "block")}" # "#{proposal_link(eventable, "block")}"
# } # }
#end # end
def view_map_on_metamaps(text = nil) def view_map_on_metamaps(text = nil)
"<#{map_url(event.map)}|#{text || event.map.name}>" "<#{map_url(event.map)}|#{text || event.map.name}>"
end end
#def view_discussion_on_loomio(params = {}) # def view_discussion_on_loomio(params = {})
# { value: discussion_link(I18n.t(:"webhooks.slack.view_it_on_loomio"), params) } # { value: discussion_link(I18n.t(:"webhooks.slack.view_it_on_loomio"), params) }
#end # end
#def proposal_link(proposal, position = nil) # def proposal_link(proposal, position = nil)
# discussion_link position || proposal.name, { proposal: proposal.key, position: position } # discussion_link position || proposal.name, { proposal: proposal.key, position: position }
#end # end
#def discussion_link(text = nil, params = {}) # def discussion_link(text = nil, params = {})
# "<#{discussion_url(eventable.map, params)}|#{text || eventable.discussion.title}>" # "<#{discussion_url(eventable.map, params)}|#{text || eventable.discussion.title}>"
#end # end
def eventable def eventable
@eventable ||= event.eventable @eventable ||= event.eventable
@ -59,10 +59,9 @@ Webhooks::Slack::Base = Struct.new(:event) do
def author def author
@author ||= eventable.author @author ||= eventable.author
end end
end end
#webhooks: # webhooks:
# slack: # slack:
# motion_closed: "*%{name}* has closed" # motion_closed: "*%{name}* has closed"
# motion_closing_soon: "*%{name}* has a proposal closing in 24 hours" # motion_closing_soon: "*%{name}* has a proposal closing in 24 hours"

View file

@ -1,27 +1,25 @@
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!')}"
end end
# todo: it would be sweet if it sends it with the metacode as the icon_url # TODO: it would be sweet if it sends it with the metacode as the icon_url
def attachment_fallback def attachment_fallback
"" #{}"*#{eventable.name}*\n#{eventable.description}\n" '' # {}"*#{eventable.name}*\n#{eventable.description}\n"
end end
def attachment_title def attachment_title
"" #proposal_link(eventable) '' # proposal_link(eventable)
end end
def attachment_text def attachment_text
"" # "#{eventable.description}\n" '' # "#{eventable.description}\n"
end end
def attachment_fields def attachment_fields
[{ [{
title: "nothing", title: 'nothing',
value: "nothing" value: 'nothing'
}] #[motion_vote_field] }] # [motion_vote_field]
end end
end end

View file

@ -1,26 +1,24 @@
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}*"
end end
def attachment_fallback def attachment_fallback
"" #{}"*#{eventable.name}*\n#{eventable.description}\n" '' # {}"*#{eventable.name}*\n#{eventable.description}\n"
end end
def attachment_title def attachment_title
"" #proposal_link(eventable) '' # proposal_link(eventable)
end end
def attachment_text def attachment_text
"" # "#{eventable.description}\n" '' # "#{eventable.description}\n"
end end
def attachment_fields def attachment_fields
[{ [{
title: "nothing", title: 'nothing',
value: "nothing" value: 'nothing'
}] #[motion_vote_field] }] # [motion_vote_field]
end end
end end

View file

@ -1,27 +1,25 @@
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}*"
end end
# todo: it would be sweet if it sends it with the metacode as the icon_url # TODO: it would be sweet if it sends it with the metacode as the icon_url
def attachment_fallback def attachment_fallback
"" #{}"*#{eventable.name}*\n#{eventable.description}\n" '' # {}"*#{eventable.name}*\n#{eventable.description}\n"
end end
def attachment_title def attachment_title
"" #proposal_link(eventable) '' # proposal_link(eventable)
end end
def attachment_text def attachment_text
"" # "#{eventable.description}\n" '' # "#{eventable.description}\n"
end end
def attachment_fields def attachment_fields
[{ [{
title: "nothing", title: 'nothing',
value: "nothing" value: 'nothing'
}] #[motion_vote_field] }] # [motion_vote_field]
end end
end end

View file

@ -1,27 +1,25 @@
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')}"
end end
# todo: it would be sweet if it sends it with the metacode as the icon_url # TODO: it would be sweet if it sends it with the metacode as the icon_url
def attachment_fallback def attachment_fallback
"" #{}"*#{eventable.name}*\n#{eventable.description}\n" '' # {}"*#{eventable.name}*\n#{eventable.description}\n"
end end
def attachment_title def attachment_title
"" #proposal_link(eventable) '' # proposal_link(eventable)
end end
def attachment_text def attachment_text
"" # "#{eventable.description}\n" '' # "#{eventable.description}\n"
end end
def attachment_fields def attachment_fields
[{ [{
title: "nothing", title: 'nothing',
value: "nothing" value: 'nothing'
}] #[motion_vote_field] }] # [motion_vote_field]
end end
end end

View file

@ -11,7 +11,7 @@ class ApplicationPolicy
end end
def show? def show?
scope.where(:id => record.id).exists? scope.where(id: record.id).exists?
end end
def create? def create?
@ -34,7 +34,7 @@ class ApplicationPolicy
false false
end end
# TODO update this function to enable some flag in the interface # TODO: update this function to enable some flag in the interface
# so that admins usually can't do super admin stuff unless they # so that admins usually can't do super admin stuff unless they
# 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)

View file

@ -1,5 +1,5 @@
class MainPolicy < ApplicationPolicy class MainPolicy < ApplicationPolicy
def initialize(user, record) def initialize(user, _record)
@user = user @user = user
@record = nil @record = nil
end end

View file

@ -1,7 +1,7 @@
class MapPolicy < ApplicationPolicy class MapPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'maps.permission IN (?)' permission = 'maps.permission IN (?)'
if user if user
shared_maps = user.shared_maps.map(&:id) shared_maps = user.shared_maps.map(&:id)

View file

@ -1,17 +1,17 @@
class MappingPolicy < ApplicationPolicy class MappingPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
# TODO base this on the map policy # TODO: base this on the map policy
# it would be nice if we could also base this on the mappable, but that # it would be nice if we could also base this on the mappable, but that
# gets really complicated. Devin thinks it's OK to SHOW a mapping for # gets really complicated. Devin thinks it's OK to SHOW a mapping for
# a private topic, since you can't see the private topic anyways # a private topic, since you can't see the private topic anyways
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'maps.permission IN (?)' permission = 'maps.permission IN (?)'
if user if user
scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id) scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id)
else else
scope.where(permission, visible) scope.where(permission, visible)
end end
end end
end end

View file

@ -1,19 +1,17 @@
class MessagePolicy < ApplicationPolicy class MessagePolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'maps.permission IN (?)' permission = 'maps.permission IN (?)'
if user if user
scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id) scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id)
else else
scope.where(permission, visible) scope.where(permission, visible)
end end
end end
end end
def show? delegate :show?, to: :resource_policy
resource_policy.show?
end
def create? def create?
record.resource.present? && resource_policy.update? record.resource.present? && resource_policy.update?
@ -32,5 +30,4 @@ class MessagePolicy < ApplicationPolicy
def resource_policy def resource_policy
@resource_policy ||= Pundit.policy(user, record.resource) @resource_policy ||= Pundit.policy(user, record.resource)
end end
end end

View file

@ -1,7 +1,7 @@
class SynapsePolicy < ApplicationPolicy class SynapsePolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'synapses.permission IN (?)' permission = 'synapses.permission IN (?)'
if user if user
scope.where(permission + ' OR synapses.defer_to_map_id IN (?) OR synapses.user_id = ?', visible, user.shared_maps.map(&:id), user.id) scope.where(permission + ' OR synapses.defer_to_map_id IN (?) OR synapses.user_id = ?', visible, user.shared_maps.map(&:id), user.id)
@ -13,7 +13,7 @@ class SynapsePolicy < ApplicationPolicy
def create? def create?
user.present? user.present?
# todo add validation against whether you can see both topics # TODO: add validation against whether you can see both topics
end end
def show? def show?
@ -25,11 +25,11 @@ class SynapsePolicy < ApplicationPolicy
end end
def update? def update?
if not user.present? if !user.present?
false false
elsif 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
end end
end end

View file

@ -4,13 +4,13 @@ class TokenPolicy < ApplicationPolicy
if user if user
scope.where('tokens.user_id = ?', user.id) scope.where('tokens.user_id = ?', user.id)
else else
scope.where(:id => nil).where("id IS NOT ?", nil) # to just return none scope.where(id: nil).where('id IS NOT ?', nil) # to just return none
end end
end end
end end
def create? def create?
user.present? user.present?
end end
def my_tokens? def my_tokens?
@ -20,5 +20,4 @@ class TokenPolicy < ApplicationPolicy
def destroy? def destroy?
user.present? && record.user == user user.present? && record.user == user
end end
end end

View file

@ -1,7 +1,7 @@
class TopicPolicy < ApplicationPolicy class TopicPolicy < ApplicationPolicy
class Scope < Scope class Scope < Scope
def resolve def resolve
visible = ['public', 'commons'] visible = %w(public commons)
permission = 'topics.permission IN (?)' permission = 'topics.permission IN (?)'
if 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 + ' OR topics.defer_to_map_id IN (?) OR topics.user_id = ?', visible, user.shared_maps.map(&:id), user.id)
@ -24,11 +24,11 @@ class TopicPolicy < ApplicationPolicy
end end
def update? def update?
if not user.present? if !user.present?
false false
elsif 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
end end
end end

View file

@ -13,5 +13,4 @@ class NewMapSerializer < ActiveModel::Serializer
has_many :mappings, serializer: NewMappingSerializer has_many :mappings, serializer: NewMappingSerializer
has_many :contributors, root: :users, serializer: NewUserSerializer has_many :contributors, root: :users, serializer: NewUserSerializer
has_many :collaborators, root: :users, serializer: NewUserSerializer has_many :collaborators, root: :users, serializer: NewUserSerializer
end end

View file

@ -12,8 +12,8 @@ class NewMappingSerializer < ActiveModel::Serializer
has_one :map, serializer: NewMapSerializer has_one :map, serializer: NewMapSerializer
def filter(keys) def filter(keys)
keys.delete(:xloc) unless object.mappable_type == "Topic" keys.delete(:xloc) unless object.mappable_type == 'Topic'
keys.delete(:yloc) unless object.mappable_type == "Topic" keys.delete(:yloc) unless object.mappable_type == 'Topic'
keys keys
end end
end end

View file

@ -4,4 +4,4 @@ class NewMetacodeSerializer < ActiveModel::Serializer
:manual_icon, :manual_icon,
:color, :color,
:aws_icon :aws_icon
end end

View file

@ -11,5 +11,4 @@ class NewSynapseSerializer < ActiveModel::Serializer
has_one :topic1, root: :topics, serializer: NewTopicSerializer has_one :topic1, root: :topics, serializer: NewTopicSerializer
has_one :topic2, root: :topics, serializer: NewTopicSerializer has_one :topic2, root: :topics, serializer: NewTopicSerializer
has_one :user, serializer: NewUserSerializer has_one :user, serializer: NewUserSerializer
end end

View file

@ -10,5 +10,4 @@ class NewTopicSerializer < ActiveModel::Serializer
has_one :user, serializer: NewUserSerializer has_one :user, serializer: NewUserSerializer
has_one :metacode, serializer: NewMetacodeSerializer has_one :metacode, serializer: NewMetacodeSerializer
end end

View file

@ -12,4 +12,4 @@ class NewUserSerializer < ActiveModel::Serializer
def is_admin def is_admin
object.admin object.admin
end end
end end

View file

@ -4,5 +4,4 @@ class TokenSerializer < ActiveModel::Serializer
:description, :description,
:created_at, :created_at,
:updated_at :updated_at
end end

View file

@ -1,3 +1,3 @@
class WebhookSerializer < ActiveModel::Serializer class WebhookSerializer < ActiveModel::Serializer
attributes :text, :username, :icon_url #, :attachments attributes :text, :username, :icon_url # , :attachments
end end

View file

@ -24,6 +24,7 @@ class MapExportService < Struct.new(:user, :map)
def topic_headings def topic_headings
[:id, :name, :metacode, :x, :y, :description, :link, :user, :permission] [:id, :name, :metacode, :x, :y, :description, :link, :user, :permission]
end end
def synapse_headings def synapse_headings
[:topic1, :topic2, :category, :description, :user, :permission] [:topic1, :topic2, :category, :description, :user, :permission]
end end
@ -64,7 +65,7 @@ class MapExportService < Struct.new(:user, :map)
def to_spreadsheet def to_spreadsheet
spreadsheet = [] spreadsheet = []
spreadsheet << ["Topics"] spreadsheet << ['Topics']
spreadsheet << topic_headings.map(&:capitalize) spreadsheet << topic_headings.map(&:capitalize)
exportable_topics.each do |topics| exportable_topics.each do |topics|
# convert exportable_topics into an array of arrays # convert exportable_topics into an array of arrays
@ -72,7 +73,7 @@ class MapExportService < Struct.new(:user, :map)
end end
spreadsheet << [] spreadsheet << []
spreadsheet << ["Synapses"] spreadsheet << ['Synapses']
spreadsheet << synapse_headings.map(&:capitalize) spreadsheet << synapse_headings.map(&:capitalize)
exportable_synapses.each do |synapse| exportable_synapses.each do |synapse|
# convert exportable_synapses into an array of arrays # convert exportable_synapses into an array of arrays

View file

@ -1,35 +1,34 @@
class Perm class Perm
# e.g. Perm::ISSIONS # e.g. Perm::ISSIONS
ISSIONS = [:commons, :public, :private] ISSIONS = [:commons, :public, :private].freeze
class << self class << self
def short(permission) def short(permission)
case permission case permission
when :commons when :commons
"co" 'co'
when :public when :public
"pu" 'pu'
when :private when :private
"pr" 'pr'
else else
fail "Invalid permission" raise 'Invalid permission'
end end
end end
def long(perm) def long(perm)
case perm case perm
when "co" when 'co'
:commons :commons
when "pu" when 'pu'
:public :public
when "pr" when 'pr'
:private :private
else else
fail "Invalid short permission" raise 'Invalid short permission'
end end
end end
def valid?(permission) def valid?(permission)
ISSIONS.include? permission ISSIONS.include? permission
end end

View file

@ -1,18 +1,16 @@
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
HTTParty.post webhook.uri, body: payload_for(webhook, event), headers: webhook.headers HTTParty.post webhook.uri, body: payload_for(webhook, event), headers: webhook.headers
end end
private class << self
def payload_for(webhook, event)
WebhookSerializer.new(webhook_object_for(webhook, event), root: false).to_json
end
def self.payload_for(webhook, event) def webhook_object_for(webhook, event)
WebhookSerializer.new(webhook_object_for(webhook, event), root: false).to_json "Webhooks::#{webhook.kind.classify}::#{event.kind.classify}".constantize.new(event)
end
end end
def self.webhook_object_for(webhook, event)
"Webhooks::#{webhook.kind.classify}::#{event.kind.classify}".constantize.new(event)
end
end end

View file

@ -1,4 +1,4 @@
# 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__)
run Metamaps::Application run Metamaps::Application

View file

@ -7,7 +7,7 @@ Bundler.require(*Rails.groups)
module Metamaps module Metamaps
class Application < Rails::Application class Application < Rails::Application
config.active_job.queue_adapter = :delayed_job config.active_job.queue_adapter = :delayed_job
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded.
@ -31,12 +31,12 @@ module Metamaps
# config.i18n.default_locale = :de # config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9. # Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8" config.encoding = 'utf-8'
config.to_prepare do config.to_prepare do
Doorkeeper::ApplicationsController.layout "doorkeeper" Doorkeeper::ApplicationsController.layout 'doorkeeper'
Doorkeeper::AuthorizationsController.layout "doorkeeper" Doorkeeper::AuthorizationsController.layout 'doorkeeper'
Doorkeeper::AuthorizedApplicationsController.layout "doorkeeper" Doorkeeper::AuthorizedApplicationsController.layout 'doorkeeper'
Doorkeeper::ApplicationController.helper ApplicationHelper Doorkeeper::ApplicationController.helper ApplicationHelper
end end
@ -50,7 +50,7 @@ module Metamaps
# Enable the asset pipeline # Enable the asset pipeline
config.assets.initialize_on_precompile = false config.assets.initialize_on_precompile = false
# Version of your assets, change this if you want to expire all your assets # Version of your assets, change this if you want to expire all your assets
config.assets.version = '2.0' config.assets.version = '2.0'
@ -60,6 +60,6 @@ module Metamaps
config.active_record.raise_in_transactional_callbacks = true config.active_record.raise_in_transactional_callbacks = true
# pundit errors return 403 FORBIDDEN # pundit errors return 403 FORBIDDEN
config.action_dispatch.rescue_responses["Pundit::NotAuthorizedError"] = :forbidden config.action_dispatch.rescue_responses['Pundit::NotAuthorizedError'] = :forbidden
end end
end end

View file

@ -11,4 +11,4 @@ end
# Set up gems listed in the Gemfile. # Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

View file

@ -12,7 +12,7 @@ Metamaps::Application.configure do
# Show full error reports and disable caching # Show full error reports and disable caching
config.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
# S3 file storage # S3 file storage
config.paperclip_defaults = { config.paperclip_defaults = {
storage: :s3, storage: :s3,
@ -23,7 +23,7 @@ Metamaps::Application.configure do
}, },
s3_protocol: 'https' s3_protocol: 'https'
} }
config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
address: ENV['SMTP_SERVER'], address: ENV['SMTP_SERVER'],
@ -33,8 +33,9 @@ Metamaps::Application.configure do
domain: ENV['SMTP_DOMAIN'], domain: ENV['SMTP_DOMAIN'],
authentication: 'plain', authentication: 'plain',
enable_starttls_auto: true, enable_starttls_auto: true,
openssl_verify_mode: 'none' } openssl_verify_mode: 'none'
config.action_mailer.default_url_options = { :host => 'localhost:3000' } }
config.action_mailer.default_url_options = { host: 'localhost:3000' }
# Don't care if the mailer can't send # Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true

View file

@ -19,11 +19,10 @@ Metamaps::Application.configure do
# Compress JavaScripts and CSS # Compress JavaScripts and CSS
config.assets.compress = true config.assets.compress = true
# S3 file storage # S3 file storage
config.paperclip_defaults = { config.paperclip_defaults = {
:storage => :s3, storage: :s3,
s3_credentials: { s3_credentials: {
bucket: ENV['S3_BUCKET_NAME'], bucket: ENV['S3_BUCKET_NAME'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'], access_key_id: ENV['AWS_ACCESS_KEY_ID'],
@ -31,18 +30,19 @@ Metamaps::Application.configure do
}, },
s3_protocol: 'https' s3_protocol: 'https'
} }
config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
address: ENV['SMTP_SERVER'], address: ENV['SMTP_SERVER'],
port: ENV['SMTP_PORT'], port: ENV['SMTP_PORT'],
user_name: ENV['SMTP_USERNAME'], user_name: ENV['SMTP_USERNAME'],
password: ENV['SMTP_PASSWORD'], password: ENV['SMTP_PASSWORD'],
#domain: ENV['SMTP_DOMAIN'] # domain: ENV['SMTP_DOMAIN']
authentication: 'plain', authentication: 'plain',
enable_starttls_auto: true, enable_starttls_auto: true,
openssl_verify_mode: 'none' } openssl_verify_mode: 'none'
config.action_mailer.default_url_options = { :host => ENV['MAILER_DEFAULT_URL'] } }
config.action_mailer.default_url_options = { host: ENV['MAILER_DEFAULT_URL'] }
# Don't care if the mailer can't send # Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true
@ -78,7 +78,7 @@ Metamaps::Application.configure do
# config.action_controller.asset_host = "http://assets.example.com" # config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
#config.assets.precompile += %w( ) # config.assets.precompile += %w( )
# Disable delivery errors, bad email addresses will be ignored # Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false # config.action_mailer.raise_delivery_errors = false

View file

@ -11,7 +11,7 @@ Metamaps::Application.configure do
# Configure static asset server for tests with Cache-Control for performance # Configure static asset server for tests with Cache-Control for performance
config.serve_static_files = true config.serve_static_files = true
config.static_cache_control = "public, max-age=3600" config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching # Show full error reports and disable caching
config.consider_all_requests_local = true config.consider_all_requests_local = true
@ -21,7 +21,7 @@ Metamaps::Application.configure do
config.action_dispatch.show_exceptions = false config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment # Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world. # Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the # The :test delivery method accumulates sent emails in the
@ -31,7 +31,7 @@ Metamaps::Application.configure do
# Print deprecation notices to the stderr # Print deprecation notices to the stderr
config.active_support.deprecation = :stderr config.active_support.deprecation = :stderr
#assets config # assets config
config.assets.compile = true config.assets.compile = true
config.assets.compress = false config.assets.compress = false
config.assets.debug = false config.assets.debug = false

View file

@ -1,4 +1,4 @@
$codes = [] $codes = []
if ActiveRecord::Base.connection.table_exists? 'users' if ActiveRecord::Base.connection.table_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

@ -2,7 +2,7 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do allow do
origins '*' origins '*'
resource '/api/*', resource '/api/*',
headers: :any, headers: :any,
methods: [:get, :post, :put, :delete, :options, :head] methods: [:get, :post, :put, :delete, :options, :head]
end end
end end

View file

@ -15,10 +15,9 @@ Devise.setup do |config|
# Configure the class responsible to send e-mails. # Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer" # config.mailer = "Devise::Mailer"
config.secret_key = ENV['DEVISE_SECRET_KEY'] config.secret_key = ENV['DEVISE_SECRET_KEY']
# ==> ORM configuration # ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and # Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be # :mongoid (bson_ext recommended) by default. Other ORMs may be
@ -45,12 +44,12 @@ Devise.setup do |config|
# Configure which authentication keys should be case-insensitive. # Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used # These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email. # to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [ :email ] config.case_insensitive_keys = [:email]
# Configure which authentication keys should have whitespace stripped. # Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or # These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email. # modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [ :email ] config.strip_whitespace_keys = [:email]
# Tell if authentication through request.params is enabled. True by default. # Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the # It can be set to an array that will enable params authentication only for the

View file

@ -4,4 +4,4 @@
# Mime::Type.register "text/richtext", :rtf # Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone # Mime::Type.register_alias "text/html", :iphone
Mime::Type.register "application/xls", :xls Mime::Type.register 'application/xls', :xls

View file

@ -1,2 +1,2 @@
Paperclip::Attachment.default_options[:url] = ':s3_domain_url' Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'

View file

@ -1,7 +1,7 @@
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('metamapscc', ENV['SSO_KEY'], {
:email => current_user.email email: current_user.email
}, 300) # Default expiry time is 5 minutes = 300 seconds }, 300) # Default expiry time is 5 minutes = 300 seconds
end end

View file

@ -1 +1 @@
METAMAPS_VERSION = '2.8.5' METAMAPS_VERSION = '2.8.5'.freeze

View file

@ -1,56 +1,55 @@
Metamaps::Application.routes.draw do Metamaps::Application.routes.draw do
use_doorkeeper use_doorkeeper
root to: 'main#home', via: :get root to: 'main#home', via: :get
get 'request', to: 'main#requestinvite', as: :request get 'request', to: 'main#requestinvite', as: :request
get 'search/topics', to: 'main#searchtopics', as: :searchtopics get 'search/topics', to: 'main#searchtopics', as: :searchtopics
get 'search/maps', to: 'main#searchmaps', as: :searchmaps get 'search/maps', to: 'main#searchmaps', as: :searchmaps
get 'search/mappers', to: 'main#searchmappers', as: :searchmappers get 'search/mappers', to: 'main#searchmappers', as: :searchmappers
get 'search/synapses', to: 'main#searchsynapses', as: :searchsynapses get 'search/synapses', to: 'main#searchsynapses', as: :searchsynapses
namespace :api, path: '/api/v1', defaults: {format: :json} do namespace :api, path: '/api/v1', defaults: { format: :json } do
resources :maps, only: [:create, :show, :update, :destroy] resources :maps, only: [:create, :show, :update, :destroy]
resources :synapses, only: [:create, :show, :update, :destroy] resources :synapses, only: [:create, :show, :update, :destroy]
resources :topics, only: [:create, :show, :update, :destroy] resources :topics, only: [:create, :show, :update, :destroy]
resources :mappings, only: [:create, :show, :update, :destroy] resources :mappings, only: [:create, :show, :update, :destroy]
resources :tokens, only: [ :create, :destroy] do resources :tokens, only: [:create, :destroy] do
get :my_tokens, on: :collection get :my_tokens, on: :collection
end end
end end
resources :messages, only: [:show, :create, :update, :destroy] resources :messages, only: [:show, :create, :update, :destroy]
resources :mappings, except: [:index, :new, :edit] resources :mappings, except: [:index, :new, :edit]
resources :metacode_sets, :except => [:show] resources :metacode_sets, except: [:show]
resources :metacodes, :except => [:destroy] resources :metacodes, except: [:destroy]
get 'metacodes/:name', to: 'metacodes#show' get 'metacodes/:name', to: 'metacodes#show'
resources :synapses, except: [:index, :new, :edit] resources :synapses, except: [:index, :new, :edit]
resources :topics, except: [:index, :new, :edit] do resources :topics, except: [:index, :new, :edit] do
get :autocomplete_topic, :on => :collection get :autocomplete_topic, on: :collection
end end
get 'topics/:id/network', to: 'topics#network', as: :network get 'topics/:id/network', to: 'topics#network', as: :network
get 'topics/:id/relative_numbers', to: 'topics#relative_numbers', as: :relative_numbers get 'topics/:id/relative_numbers', to: 'topics#relative_numbers', as: :relative_numbers
get 'topics/:id/relatives', to: 'topics#relatives', as: :relatives get 'topics/:id/relatives', to: 'topics#relatives', as: :relatives
resources :maps, except: [:index, :new, :edit] resources :maps, except: [:index, :new, :edit]
get 'maps/:id/export', to: 'maps#export' get 'maps/:id/export', to: 'maps#export'
post 'maps/:id/events/:event', to: 'maps#events' post 'maps/:id/events/:event', to: 'maps#events'
get 'maps/:id/contains', to: 'maps#contains', as: :contains get 'maps/:id/contains', to: 'maps#contains', as: :contains
post 'maps/:id/upload_screenshot', to: 'maps#screenshot', as: :screenshot post 'maps/:id/upload_screenshot', to: 'maps#screenshot', as: :screenshot
post 'maps/:id/access', to: 'maps#access', as: :access, defaults: {format: :json} post 'maps/:id/access', to: 'maps#access', as: :access, defaults: { format: :json }
get 'explore/active', to: 'maps#activemaps' get 'explore/active', to: 'maps#activemaps'
get 'explore/featured', to: 'maps#featuredmaps' get 'explore/featured', to: 'maps#featuredmaps'
get 'explore/mine', to: 'maps#mymaps' get 'explore/mine', to: 'maps#mymaps'
get 'explore/shared', to: 'maps#sharedmaps' get 'explore/shared', to: 'maps#sharedmaps'
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_scope :user do devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, skip: :sessions
devise_scope :user do
get 'login' => 'devise/sessions#new', :as => :new_user_session get 'login' => 'devise/sessions#new', :as => :new_user_session
post 'login' => 'devise/sessions#create', :as => :user_session post 'login' => 'devise/sessions#create', :as => :user_session
get 'logout' => 'devise/sessions#destroy', :as => :destroy_user_session get 'logout' => 'devise/sessions#destroy', :as => :destroy_user_session

View file

@ -1,5 +1,5 @@
class AddGenerationToUsers < ActiveRecord::Migration class AddGenerationToUsers < ActiveRecord::Migration
def change def change
add_column :users, :generation, :integer add_column :users, :generation, :integer
end end
end end

View file

@ -5,21 +5,21 @@ class MappingPolymorphism < ActiveRecord::Migration
add_index :mappings, [:mappable_id, :mappable_type] add_index :mappings, [:mappable_id, :mappable_type]
Mapping.find_each do |mapping| Mapping.find_each do |mapping|
if mapping.synapse_id.nil? and mapping.topic_id.nil? if mapping.synapse_id.nil? && mapping.topic_id.nil?
puts "Mapping id=#{mapping.id} has no valid id, skipping!" puts "Mapping id=#{mapping.id} has no valid id, skipping!"
next next
end end
if not mapping.synapse_id.nil? and not mapping.topic_id.nil? if !mapping.synapse_id.nil? && !mapping.topic_id.nil?
puts "Mapping id=#{mapping.id} has both topic and synapse ids, skipping!" puts "Mapping id=#{mapping.id} has both topic and synapse ids, skipping!"
next next
end end
unless mapping.synapse_id.nil? if mapping.synapse_id.nil?
mapping.mappable = Synapse.find_by(id: mapping.synapse_id)
else
mapping.mappable = Topic.find_by(id: mapping.topic_id) mapping.mappable = Topic.find_by(id: mapping.topic_id)
else
mapping.mappable = Synapse.find_by(id: mapping.synapse_id)
end end
if mapping.mappable.nil? if mapping.mappable.nil?
mapping.delete mapping.delete
else else

View file

@ -1,6 +1,6 @@
class Messages < ActiveRecord::Migration class Messages < ActiveRecord::Migration
def change def change
create_table :messages do |t| create_table :messages do |t|
t.text :message t.text :message
t.references :user t.references :user
t.integer :resource_id t.integer :resource_id

View file

@ -4,12 +4,11 @@ end
class MetacodeAssetPathUpdate < ActiveRecord::Migration class MetacodeAssetPathUpdate < ActiveRecord::Migration
def change def change
Metacode.first(50).each do |metacode| Metacode.first(50).each do |metacode|
if metacode.icon.start_with?("/assets/icons/") next unless metacode.icon.start_with?('/assets/icons/')
metacode.icon = metacode.icon.sub(/^\/assets\/icons/, "https://s3.amazonaws.com/metamaps-assets/metacodes") metacode.icon = metacode.icon.sub(/^\/assets\/icons/, 'https://s3.amazonaws.com/metamaps-assets/metacodes')
metacode.icon = metacode.icon.sub('blueprint_96px', 'blueprint/96px') metacode.icon = metacode.icon.sub('blueprint_96px', 'blueprint/96px')
metacode.icon = metacode.icon.sub('generics_96px', 'generics/96px') metacode.icon = metacode.icon.sub('generics_96px', 'generics/96px')
metacode.save metacode.save
end
end end
end end
end end

View file

@ -13,7 +13,7 @@ class CreateDelayedJobs < ActiveRecord::Migration
table.timestamps null: true table.timestamps null: true
end end
add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority" add_index :delayed_jobs, [:priority, :run_at], name: 'delayed_jobs_priority'
end end
def self.down def self.down

View file

@ -34,12 +34,12 @@ class CreateDoorkeeperTables < ActiveRecord::Migration
# https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
# #
# t.text :token, null: false # t.text :token, null: false
t.string :token, null: false t.string :token, null: false
t.string :refresh_token t.string :refresh_token
t.integer :expires_in t.integer :expires_in
t.datetime :revoked_at t.datetime :revoked_at
t.datetime :created_at, null: false t.datetime :created_at, null: false
t.string :scopes t.string :scopes
end end

View file

@ -11,270 +11,269 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160401133937) do ActiveRecord::Schema.define(version: 20_160_401_133_937) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension 'plpgsql'
create_table "delayed_jobs", force: :cascade do |t| create_table 'delayed_jobs', force: :cascade do |t|
t.integer "priority", default: 0, null: false t.integer 'priority', default: 0, null: false
t.integer "attempts", default: 0, null: false t.integer 'attempts', default: 0, null: false
t.text "handler", null: false t.text 'handler', null: false
t.text "last_error" t.text 'last_error'
t.datetime "run_at" t.datetime 'run_at'
t.datetime "locked_at" t.datetime 'locked_at'
t.datetime "failed_at" t.datetime 'failed_at'
t.string "locked_by" t.string 'locked_by'
t.string "queue" t.string 'queue'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree add_index 'delayed_jobs', %w(priority run_at), name: 'delayed_jobs_priority', using: :btree
create_table "events", force: :cascade do |t| create_table 'events', force: :cascade do |t|
t.string "kind", limit: 255 t.string 'kind', limit: 255
t.integer "eventable_id" t.integer 'eventable_id'
t.string "eventable_type" t.string 'eventable_type'
t.integer "user_id" t.integer 'user_id'
t.integer "map_id" t.integer 'map_id'
t.integer "sequence_id" t.integer 'sequence_id'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "events", ["eventable_type", "eventable_id"], name: "index_events_on_eventable_type_and_eventable_id", using: :btree add_index 'events', %w(eventable_type eventable_id), name: 'index_events_on_eventable_type_and_eventable_id', using: :btree
add_index "events", ["map_id", "sequence_id"], name: "index_events_on_map_id_and_sequence_id", unique: true, using: :btree add_index 'events', %w(map_id sequence_id), name: 'index_events_on_map_id_and_sequence_id', unique: true, using: :btree
add_index "events", ["map_id"], name: "index_events_on_map_id", using: :btree add_index 'events', ['map_id'], name: 'index_events_on_map_id', using: :btree
add_index "events", ["sequence_id"], name: "index_events_on_sequence_id", using: :btree add_index 'events', ['sequence_id'], name: 'index_events_on_sequence_id', using: :btree
add_index "events", ["user_id"], name: "index_events_on_user_id", using: :btree add_index 'events', ['user_id'], name: 'index_events_on_user_id', using: :btree
create_table "in_metacode_sets", force: :cascade do |t| create_table 'in_metacode_sets', force: :cascade do |t|
t.integer "metacode_id" t.integer 'metacode_id'
t.integer "metacode_set_id" t.integer 'metacode_set_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
end end
add_index "in_metacode_sets", ["metacode_id"], name: "index_in_metacode_sets_on_metacode_id", using: :btree add_index 'in_metacode_sets', ['metacode_id'], name: 'index_in_metacode_sets_on_metacode_id', using: :btree
add_index "in_metacode_sets", ["metacode_set_id"], name: "index_in_metacode_sets_on_metacode_set_id", using: :btree add_index 'in_metacode_sets', ['metacode_set_id'], name: 'index_in_metacode_sets_on_metacode_set_id', using: :btree
create_table "mappings", force: :cascade do |t| create_table 'mappings', force: :cascade do |t|
t.text "category" t.text 'category'
t.integer "xloc" t.integer 'xloc'
t.integer "yloc" t.integer 'yloc'
t.integer "topic_id" t.integer 'topic_id'
t.integer "synapse_id" t.integer 'synapse_id'
t.integer "map_id" t.integer 'map_id'
t.integer "user_id" t.integer 'user_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.integer "mappable_id" t.integer 'mappable_id'
t.string "mappable_type" t.string 'mappable_type'
end end
add_index "mappings", ["map_id", "synapse_id"], name: "index_mappings_on_map_id_and_synapse_id", using: :btree add_index 'mappings', %w(map_id synapse_id), name: 'index_mappings_on_map_id_and_synapse_id', using: :btree
add_index "mappings", ["map_id", "topic_id"], name: "index_mappings_on_map_id_and_topic_id", using: :btree add_index 'mappings', %w(map_id topic_id), name: 'index_mappings_on_map_id_and_topic_id', using: :btree
add_index "mappings", ["map_id"], name: "index_mappings_on_map_id", using: :btree add_index 'mappings', ['map_id'], name: 'index_mappings_on_map_id', using: :btree
add_index "mappings", ["mappable_id", "mappable_type"], name: "index_mappings_on_mappable_id_and_mappable_type", using: :btree add_index 'mappings', %w(mappable_id mappable_type), name: 'index_mappings_on_mappable_id_and_mappable_type', using: :btree
add_index "mappings", ["user_id"], name: "index_mappings_on_user_id", using: :btree add_index 'mappings', ['user_id'], name: 'index_mappings_on_user_id', using: :btree
create_table "maps", force: :cascade do |t| create_table 'maps', force: :cascade do |t|
t.text "name" t.text 'name'
t.boolean "arranged" t.boolean 'arranged'
t.text "desc" t.text 'desc'
t.text "permission" t.text 'permission'
t.integer "user_id" t.integer 'user_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.boolean "featured" t.boolean 'featured'
t.string "screenshot_file_name" t.string 'screenshot_file_name'
t.string "screenshot_content_type" t.string 'screenshot_content_type'
t.integer "screenshot_file_size" t.integer 'screenshot_file_size'
t.datetime "screenshot_updated_at" t.datetime 'screenshot_updated_at'
end end
add_index "maps", ["user_id"], name: "index_maps_on_user_id", using: :btree add_index 'maps', ['user_id'], name: 'index_maps_on_user_id', using: :btree
create_table "messages", force: :cascade do |t| create_table 'messages', force: :cascade do |t|
t.text "message" t.text 'message'
t.integer "user_id" t.integer 'user_id'
t.integer "resource_id" t.integer 'resource_id'
t.string "resource_type" t.string 'resource_type'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "messages", ["resource_id"], name: "index_messages_on_resource_id", using: :btree add_index 'messages', ['resource_id'], name: 'index_messages_on_resource_id', using: :btree
add_index "messages", ["resource_type"], name: "index_messages_on_resource_type", using: :btree add_index 'messages', ['resource_type'], name: 'index_messages_on_resource_type', using: :btree
add_index "messages", ["user_id"], name: "index_messages_on_user_id", using: :btree add_index 'messages', ['user_id'], name: 'index_messages_on_user_id', using: :btree
create_table "metacode_sets", force: :cascade do |t| create_table 'metacode_sets', force: :cascade do |t|
t.string "name" t.string 'name'
t.text "desc" t.text 'desc'
t.integer "user_id" t.integer 'user_id'
t.boolean "mapperContributed" t.boolean 'mapperContributed'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
end end
add_index "metacode_sets", ["user_id"], name: "index_metacode_sets_on_user_id", using: :btree add_index 'metacode_sets', ['user_id'], name: 'index_metacode_sets_on_user_id', using: :btree
create_table "metacodes", force: :cascade do |t| create_table 'metacodes', force: :cascade do |t|
t.text "name" t.text 'name'
t.string "manual_icon" t.string 'manual_icon'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.string "color" t.string 'color'
t.string "aws_icon_file_name" t.string 'aws_icon_file_name'
t.string "aws_icon_content_type" t.string 'aws_icon_content_type'
t.integer "aws_icon_file_size" t.integer 'aws_icon_file_size'
t.datetime "aws_icon_updated_at" t.datetime 'aws_icon_updated_at'
end end
create_table "oauth_access_grants", force: :cascade do |t| create_table 'oauth_access_grants', force: :cascade do |t|
t.integer "resource_owner_id", null: false t.integer 'resource_owner_id', null: false
t.integer "application_id", null: false t.integer 'application_id', null: false
t.string "token", null: false t.string 'token', null: false
t.integer "expires_in", null: false t.integer 'expires_in', null: false
t.text "redirect_uri", null: false t.text 'redirect_uri', null: false
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "revoked_at" t.datetime 'revoked_at'
t.string "scopes" t.string 'scopes'
end end
add_index "oauth_access_grants", ["token"], name: "index_oauth_access_grants_on_token", unique: true, using: :btree add_index 'oauth_access_grants', ['token'], name: 'index_oauth_access_grants_on_token', unique: true, using: :btree
create_table "oauth_access_tokens", force: :cascade do |t| create_table 'oauth_access_tokens', force: :cascade do |t|
t.integer "resource_owner_id" t.integer 'resource_owner_id'
t.integer "application_id" t.integer 'application_id'
t.string "token", null: false t.string 'token', null: false
t.string "refresh_token" t.string 'refresh_token'
t.integer "expires_in" t.integer 'expires_in'
t.datetime "revoked_at" t.datetime 'revoked_at'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.string "scopes" t.string 'scopes'
end end
add_index "oauth_access_tokens", ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true, using: :btree add_index 'oauth_access_tokens', ['refresh_token'], name: 'index_oauth_access_tokens_on_refresh_token', unique: true, using: :btree
add_index "oauth_access_tokens", ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id", using: :btree add_index 'oauth_access_tokens', ['resource_owner_id'], name: 'index_oauth_access_tokens_on_resource_owner_id', using: :btree
add_index "oauth_access_tokens", ["token"], name: "index_oauth_access_tokens_on_token", unique: true, using: :btree add_index 'oauth_access_tokens', ['token'], name: 'index_oauth_access_tokens_on_token', unique: true, using: :btree
create_table "oauth_applications", force: :cascade do |t| create_table 'oauth_applications', force: :cascade do |t|
t.string "name", null: false t.string 'name', null: false
t.string "uid", null: false t.string 'uid', null: false
t.string "secret", null: false t.string 'secret', null: false
t.text "redirect_uri", null: false t.text 'redirect_uri', null: false
t.string "scopes", default: "", null: false t.string 'scopes', default: '', null: false
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true, using: :btree add_index 'oauth_applications', ['uid'], name: 'index_oauth_applications_on_uid', unique: true, using: :btree
create_table "synapses", force: :cascade do |t| create_table 'synapses', force: :cascade do |t|
t.text "desc" t.text 'desc'
t.text "category" t.text 'category'
t.text "weight" t.text 'weight'
t.text "permission" t.text 'permission'
t.integer "node1_id" t.integer 'node1_id'
t.integer "node2_id" t.integer 'node2_id'
t.integer "user_id" t.integer 'user_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.integer "defer_to_map_id" t.integer 'defer_to_map_id'
end end
add_index "synapses", ["node1_id", "node1_id"], name: "index_synapses_on_node1_id_and_node1_id", using: :btree add_index 'synapses', %w(node1_id node1_id), name: 'index_synapses_on_node1_id_and_node1_id', using: :btree
add_index "synapses", ["node1_id"], name: "index_synapses_on_node1_id", using: :btree add_index 'synapses', ['node1_id'], name: 'index_synapses_on_node1_id', using: :btree
add_index "synapses", ["node2_id", "node2_id"], name: "index_synapses_on_node2_id_and_node2_id", using: :btree add_index 'synapses', %w(node2_id node2_id), name: 'index_synapses_on_node2_id_and_node2_id', using: :btree
add_index "synapses", ["node2_id"], name: "index_synapses_on_node2_id", using: :btree add_index 'synapses', ['node2_id'], name: 'index_synapses_on_node2_id', using: :btree
add_index "synapses", ["user_id"], name: "index_synapses_on_user_id", using: :btree add_index 'synapses', ['user_id'], name: 'index_synapses_on_user_id', using: :btree
create_table "tokens", force: :cascade do |t| create_table 'tokens', force: :cascade do |t|
t.string "token" t.string 'token'
t.string "description" t.string 'description'
t.integer "user_id" t.integer 'user_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
end end
add_index "tokens", ["user_id"], name: "index_tokens_on_user_id", using: :btree add_index 'tokens', ['user_id'], name: 'index_tokens_on_user_id', using: :btree
create_table "topics", force: :cascade do |t| create_table 'topics', force: :cascade do |t|
t.text "name" t.text 'name'
t.text "desc" t.text 'desc'
t.text "link" t.text 'link'
t.text "permission" t.text 'permission'
t.integer "user_id" t.integer 'user_id'
t.integer "metacode_id" t.integer 'metacode_id'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.string "image_file_name" t.string 'image_file_name'
t.string "image_content_type" t.string 'image_content_type'
t.integer "image_file_size" t.integer 'image_file_size'
t.datetime "image_updated_at" t.datetime 'image_updated_at'
t.string "audio_file_name" t.string 'audio_file_name'
t.string "audio_content_type" t.string 'audio_content_type'
t.integer "audio_file_size" t.integer 'audio_file_size'
t.datetime "audio_updated_at" t.datetime 'audio_updated_at'
t.integer "defer_to_map_id" t.integer 'defer_to_map_id'
end end
add_index "topics", ["metacode_id"], name: "index_topics_on_metacode_id", using: :btree add_index 'topics', ['metacode_id'], name: 'index_topics_on_metacode_id', using: :btree
add_index "topics", ["user_id"], name: "index_topics_on_user_id", using: :btree add_index 'topics', ['user_id'], name: 'index_topics_on_user_id', using: :btree
create_table "user_maps", force: :cascade do |t| create_table 'user_maps', force: :cascade do |t|
t.integer "user_id" t.integer 'user_id'
t.integer "map_id" t.integer 'map_id'
t.datetime "created_at" t.datetime 'created_at'
t.datetime "updated_at" t.datetime 'updated_at'
end end
add_index "user_maps", ["map_id"], name: "index_user_maps_on_map_id", using: :btree add_index 'user_maps', ['map_id'], name: 'index_user_maps_on_map_id', using: :btree
add_index "user_maps", ["user_id"], name: "index_user_maps_on_user_id", using: :btree add_index 'user_maps', ['user_id'], name: 'index_user_maps_on_user_id', using: :btree
create_table "users", force: :cascade do |t| create_table 'users', force: :cascade do |t|
t.string "name" t.string 'name'
t.string "email" t.string 'email'
t.text "settings" t.text 'settings'
t.string "code", limit: 8 t.string 'code', limit: 8
t.string "joinedwithcode", limit: 8 t.string 'joinedwithcode', limit: 8
t.string "crypted_password" t.string 'crypted_password'
t.string "password_salt" t.string 'password_salt'
t.string "persistence_token" t.string 'persistence_token'
t.string "perishable_token" t.string 'perishable_token'
t.datetime "created_at", null: false t.datetime 'created_at', null: false
t.datetime "updated_at", null: false t.datetime 'updated_at', null: false
t.string "encrypted_password", limit: 128, default: "" t.string 'encrypted_password', limit: 128, default: ''
t.string "remember_token" t.string 'remember_token'
t.datetime "remember_created_at" t.datetime 'remember_created_at'
t.string "reset_password_token" t.string 'reset_password_token'
t.datetime "last_sign_in_at" t.datetime 'last_sign_in_at'
t.string "last_sign_in_ip" t.string 'last_sign_in_ip'
t.integer "sign_in_count", default: 0 t.integer 'sign_in_count', default: 0
t.datetime "current_sign_in_at" t.datetime 'current_sign_in_at'
t.string "current_sign_in_ip" t.string 'current_sign_in_ip'
t.datetime "reset_password_sent_at" t.datetime 'reset_password_sent_at'
t.boolean "admin" t.boolean 'admin'
t.string "image_file_name" t.string 'image_file_name'
t.string "image_content_type" t.string 'image_content_type'
t.integer "image_file_size" t.integer 'image_file_size'
t.datetime "image_updated_at" t.datetime 'image_updated_at'
t.integer "generation" t.integer 'generation'
end end
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree add_index 'users', ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true, using: :btree
create_table "webhooks", force: :cascade do |t| create_table 'webhooks', force: :cascade do |t|
t.integer "hookable_id" t.integer 'hookable_id'
t.string "hookable_type" t.string 'hookable_type'
t.string "kind", null: false t.string 'kind', null: false
t.string "uri", null: false t.string 'uri', null: false
t.text "event_types", default: [], array: true t.text 'event_types', default: [], array: true
end end
add_index "webhooks", ["hookable_type", "hookable_id"], name: "index_webhooks_on_hookable_type_and_hookable_id", using: :btree add_index 'webhooks', %w(hookable_type hookable_id), name: 'index_webhooks_on_hookable_type_and_hookable_id', using: :btree
add_foreign_key "tokens", "users" add_foreign_key 'tokens', 'users'
end end

View file

@ -2,305 +2,207 @@
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
## USERS ## USERS
User.new({ User.new(name: 'user',
name: 'user', email: 'user@user.com',
email: 'user@user.com', password: 'toolsplusconsciousness',
password: 'toolsplusconsciousness', code: 'qwertyui',
code: 'qwertyui', joinedwithcode: 'qwertyui',
joinedwithcode: 'qwertyui', admin: 'false').save(validate: false)
admin: 'false'
}).save(validate: false)
User.new({ User.new(name: 'admin',
name: 'admin', email: 'admin@admin.com',
email: 'admin@admin.com', password: 'toolsplusconsciousness',
password: 'toolsplusconsciousness', code: 'iuytrewq',
code: 'iuytrewq', joinedwithcode: 'iuytrewq',
joinedwithcode: 'iuytrewq', admin: 'true').save(validate: false)
admin: 'true'
}).save(validate: false)
## END USERS ## END USERS
## METACODES ## METACODES
Metacode.create({ Metacode.create(name: 'Action',
name: 'Action', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_action.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_action.png', color: '#BD6C85')
color: '#BD6C85'
})
Metacode.create({ Metacode.create(name: 'Activity',
name: 'Activity', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_activity.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_activity.png', color: '#6EBF65')
color: '#6EBF65'
})
Metacode.create({ Metacode.create(name: 'Catalyst',
name: 'Catalyst', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_catalyst.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_catalyst.png', color: '#EF8964')
color: '#EF8964',
})
Metacode.create({ Metacode.create(name: 'Closed',
name: 'Closed', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_closedissue.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_closedissue.png', color: '#ABB49F')
color: '#ABB49F',
})
Metacode.create({ Metacode.create(name: 'Process',
name: 'Process', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_process.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_process.png', color: '#BDB25E')
color: '#BDB25E',
})
Metacode.create({ Metacode.create(name: 'Future',
name: 'Future', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_futuredev.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_futuredev.png', color: '#25A17F')
color: '#25A17F',
})
Metacode.create({ Metacode.create(name: 'Group',
name: 'Group', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_group.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_group.png', color: '#7076BC')
color: '#7076BC',
})
Metacode.create({ Metacode.create(name: 'Implication',
name: 'Implication', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_implication.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_implication.png', color: '#83DECA')
color: '#83DECA',
})
Metacode.create({ Metacode.create(name: 'Insight',
name: 'Insight', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_insight.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_insight.png', color: '#B074AD')
color: '#B074AD',
})
Metacode.create({ Metacode.create(name: 'Intention',
name: 'Intention', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_intention.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_intention.png', color: '#BAEAFF')
color: '#BAEAFF',
})
Metacode.create({ Metacode.create(name: 'Knowledge',
name: 'Knowledge', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_knowledge.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_knowledge.png', color: '#60ACF7')
color: '#60ACF7',
})
Metacode.create({ Metacode.create(name: 'Location',
name: 'Location', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_location.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_location.png', color: '#ABD9A7')
color: '#ABD9A7',
})
Metacode.create({ Metacode.create(name: 'Need',
name: 'Need', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_need.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_need.png', color: '#D2A7D4')
color: '#D2A7D4',
})
Metacode.create({ Metacode.create(name: 'Open',
name: 'Open', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_openissue.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_openissue.png', color: '#9BBF71')
color: '#9BBF71',
})
Metacode.create({ Metacode.create(name: 'Opportunity',
name: 'Opportunity', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_opportunity.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_opportunity.png', color: '#889F64')
color: '#889F64',
})
Metacode.create({ Metacode.create(name: 'Person',
name: 'Person', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_person.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_person.png', color: '#DE925F')
color: '#DE925F',
})
Metacode.create({ Metacode.create(name: 'Platform',
name: 'Platform', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_platform.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_platform.png', color: '#21C8FE')
color: '#21C8FE',
})
Metacode.create({ Metacode.create(name: 'Problem',
name: 'Problem', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_problem.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_problem.png', color: '#99CFC4')
color: '#99CFC4',
})
Metacode.create({ Metacode.create(name: 'Resource',
name: 'Resource', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_resource.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_resource.png', color: '#C98C63')
color: '#C98C63',
})
Metacode.create({ Metacode.create(name: 'Role',
name: 'Role', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_role.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_role.png', color: '#A8595D')
color: '#A8595D',
})
Metacode.create({ Metacode.create(name: 'Task',
name: 'Task', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_task.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_task.png', color: '#3397C4')
color: '#3397C4',
})
Metacode.create({ Metacode.create(name: 'Trajectory',
name: 'Trajectory', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_trajectory.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/blueprint/96px/bp_trajectory.png', color: '#D3AA4C')
color: '#D3AA4C',
})
Metacode.create({ Metacode.create(name: 'Argument',
name: 'Argument', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_argument.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_argument.png', color: '#7FAEFD')
color: '#7FAEFD',
})
Metacode.create({ Metacode.create(name: 'Con',
name: 'Con', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_con.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_con.png', color: '#CF7C74')
color: '#CF7C74',
})
Metacode.create({ Metacode.create(name: 'Subject',
name: 'Subject', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_subject.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_subject.png', color: '#8293D8')
color: '#8293D8',
})
Metacode.create({ Metacode.create(name: 'Decision',
name: 'Decision', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_decision.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_decision.png', color: '#CCA866')
color: '#CCA866',
})
Metacode.create({ Metacode.create(name: 'Event',
name: 'Event', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_event.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_event.png', color: '#F5854B')
color: '#F5854B',
})
Metacode.create({ Metacode.create(name: 'Example',
name: 'Example', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_example.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_example.png', color: '#618C61')
color: '#618C61',
})
Metacode.create({ Metacode.create(name: 'Experience',
name: 'Experience', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_experience.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_experience.png', color: '#BE995F')
color: '#BE995F',
})
Metacode.create({ Metacode.create(name: 'Feedback',
name: 'Feedback', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_feedback.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_feedback.png', color: '#54A19D')
color: '#54A19D',
})
Metacode.create({ Metacode.create(name: 'Aim',
name: 'Aim', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_aim.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_aim.png', color: '#B0B0B0')
color: '#B0B0B0',
})
Metacode.create({ Metacode.create(name: 'Good',
name: 'Good', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_goodpractice.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_goodpractice.png', color: '#BD9E86')
color: '#BD9E86',
})
Metacode.create({ Metacode.create(name: 'Idea',
name: 'Idea', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_idea.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_idea.png', color: '#C4BC5E')
color: '#C4BC5E',
})
Metacode.create({ Metacode.create(name: 'List',
name: 'List', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_list.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_list.png', color: '#B7A499')
color: '#B7A499',
})
Metacode.create({ Metacode.create(name: 'Media',
name: 'Media', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_media.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_media.png', color: '#6D94CC')
color: '#6D94CC',
})
Metacode.create({ Metacode.create(name: 'Metamap',
name: 'Metamap', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_metamap.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_metamap.png', color: '#AEA9FD')
color: '#AEA9FD',
})
Metacode.create({ Metacode.create(name: 'Model',
name: 'Model', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_model.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_model.png', color: '#B385BA')
color: '#B385BA',
})
Metacode.create({ Metacode.create(name: 'Note',
name: 'Note', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_note.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_note.png', color: '#A389A1')
color: '#A389A1',
})
Metacode.create({ Metacode.create(name: 'Perspective',
name: 'Perspective', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_perspective.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_perspective.png', color: '#2EB6CC')
color: '#2EB6CC',
})
Metacode.create({ Metacode.create(name: 'Pro',
name: 'Pro', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_pro.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_pro.png', color: '#89B879')
color: '#89B879',
})
Metacode.create({ Metacode.create(name: 'Project',
name: 'Project', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_project.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_project.png', color: '#85A050')
color: '#85A050',
})
Metacode.create({ Metacode.create(name: 'Question',
name: 'Question', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_question.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_question.png', color: '#5CB3B3')
color: '#5CB3B3',
})
Metacode.create({ Metacode.create(name: 'Reference',
name: 'Reference', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_reference.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_reference.png', color: '#A7A7A7')
color: '#A7A7A7',
})
Metacode.create({ Metacode.create(name: 'Research',
name: 'Research', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_research.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_research.png', color: '#CD8E89')
color: '#CD8E89',
})
Metacode.create({ Metacode.create(name: 'Status',
name: 'Status', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_status.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_status.png', color: '#EFA7C0')
color: '#EFA7C0',
})
Metacode.create({ Metacode.create(name: 'Tool',
name: 'Tool', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_tool.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_tool.png', color: '#828282')
color: '#828282',
})
Metacode.create({ Metacode.create(name: 'Wildcard',
name: 'Wildcard', manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png',
manual_icon: 'https://s3.amazonaws.com/metamaps-assets/metacodes/generics/96px/gen_wildcard.png', color: '#73C7DE')
color: '#73C7DE',
})
## END METACODES ## END METACODES

View file

@ -1,15 +1,15 @@
require 'dotenv/tasks' require 'dotenv/tasks'
namespace :heroku do namespace :heroku do
desc "Generate the Heroku gems manifest from gem dependencies" desc 'Generate the Heroku gems manifest from gem dependencies'
task :gems => :dotenv do task gems: :dotenv do
RAILS_ENV='production' RAILS_ENV = 'production'.freeze
Rake::Task[:environment].invoke Rake::Task[:environment].invoke
list = Rails.configuration.gems.collect do |g| list = Rails.configuration.gems.collect do |g|
command, *options = g.send(:install_command) _command, *options = g.send(:install_command)
options.join(" ") + "\n" options.join(' ') + "\n"
end end
File.open(File.join(RAILS_ROOT, '.gems'), 'w') do |f| File.open(File.join(RAILS_ROOT, '.gems'), 'w') do |f|
f.write(list) f.write(list)
end end

View file

@ -1,8 +1,8 @@
require 'dotenv/tasks' require 'dotenv/tasks'
namespace :perms do namespace :perms do
desc "Update the Unix permissions on the public directory" desc 'Update the Unix permissions on the public directory'
task :fix => :environment do task fix: :environment do
# e.g. rake perms:fix user=mmstaging group=mmstaging # e.g. rake perms:fix user=mmstaging group=mmstaging
# e.g. rake perms:fix group=www-data #probably don't need this one # e.g. rake perms:fix group=www-data #probably don't need this one
# e.g. rake perms:fix # e.g. rake perms:fix

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby.exe #!/usr/bin/env ruby.exe
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. # 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__)
require 'rails/commands' require 'rails/commands'

View file

@ -10,7 +10,7 @@ RSpec.describe MappingsController, type: :controller do
describe 'GET #show' do describe 'GET #show' do
it 'assigns the requested mapping as @mapping' do it 'assigns the requested mapping as @mapping' do
get :show, { id: mapping.to_param } get :show, id: mapping.to_param
expect(assigns(:mapping)).to eq(mapping) expect(assigns(:mapping)).to eq(mapping)
end end
end end
@ -19,12 +19,12 @@ RSpec.describe MappingsController, type: :controller do
context 'with valid params' do context 'with valid params' do
it 'creates a new Mapping' do it 'creates a new Mapping' do
expect do expect do
post :create, { mapping: valid_attributes } post :create, mapping: valid_attributes
end.to change(Mapping, :count).by(1) end.to change(Mapping, :count).by(1)
end end
it 'assigns a newly created mapping as @mapping' do it 'assigns a newly created mapping as @mapping' do
post :create, { mapping: valid_attributes } post :create, mapping: valid_attributes
expect(assigns(:mapping)).to be_a(Mapping) expect(assigns(:mapping)).to be_a(Mapping)
expect(assigns(:mapping)).to be_persisted expect(assigns(:mapping)).to be_persisted
end end
@ -32,7 +32,7 @@ RSpec.describe MappingsController, type: :controller do
context 'with invalid params' do context 'with invalid params' do
it 'assigns a newly created but unsaved mapping as @mapping' do it 'assigns a newly created but unsaved mapping as @mapping' do
post :create, { mapping: invalid_attributes } post :create, mapping: invalid_attributes
expect(assigns(:mapping)).to be_a_new(Mapping) expect(assigns(:mapping)).to be_a_new(Mapping)
end end
end end
@ -44,13 +44,13 @@ RSpec.describe MappingsController, type: :controller do
it 'updates the requested mapping' do it 'updates the requested mapping' do
put :update, put :update,
{ id: mapping.to_param, mapping: new_attributes } id: mapping.to_param, mapping: new_attributes
mapping.reload mapping.reload
end end
it 'assigns the requested mapping as @mapping' do it 'assigns the requested mapping as @mapping' do
put :update, put :update,
{ id: mapping.to_param, mapping: valid_attributes } id: mapping.to_param, mapping: valid_attributes
expect(assigns(:mapping)).to eq(mapping) expect(assigns(:mapping)).to eq(mapping)
end end
end end
@ -58,7 +58,7 @@ RSpec.describe MappingsController, type: :controller do
context 'with invalid params' do context 'with invalid params' do
it 'assigns the mapping as @mapping' do it 'assigns the mapping as @mapping' do
put :update, put :update,
{ id: mapping.to_param, mapping: invalid_attributes } id: mapping.to_param, mapping: invalid_attributes
expect(assigns(:mapping)).to eq(mapping) expect(assigns(:mapping)).to eq(mapping)
end end
end end
@ -67,7 +67,7 @@ RSpec.describe MappingsController, type: :controller do
describe 'DELETE #destroy' do describe 'DELETE #destroy' do
it 'destroys the requested mapping' do it 'destroys the requested mapping' do
expect do expect do
delete :destroy, { id: mapping.to_param } delete :destroy, id: mapping.to_param
end.to change(Mapping, :count).by(-1) end.to change(Mapping, :count).by(-1)
end end
end end

View file

@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe MapsController, type: :controller do RSpec.describe MapsController, type: :controller do
let(:map) { create(:map) } let(:map) { create(:map) }
let(:valid_attributes) { map.attributes.except(:id) } let(:valid_attributes) { map.attributes.except(:id) }
let(:invalid_attributes) { { permission: :commons } } let(:invalid_attributes) { { permission: :commons } }
before :each do before :each do
sign_in sign_in
end end
@ -17,14 +17,14 @@ RSpec.describe MapsController, type: :controller do
describe 'GET #contains' do describe 'GET #contains' do
it 'returns json matching schema' do it 'returns json matching schema' do
get :contains, { id: map.to_param, format: :json } get :contains, id: map.to_param, format: :json
expect(response.body).to match_json_schema(:map_contains) expect(response.body).to match_json_schema(:map_contains)
end end
end end
describe 'GET #show' do describe 'GET #show' do
it 'assigns the requested map as @map' do it 'assigns the requested map as @map' do
get :show, { id: map.to_param } get :show, id: map.to_param
expect(assigns(:map)).to eq(map) expect(assigns(:map)).to eq(map)
end end
end end
@ -55,18 +55,18 @@ RSpec.describe MapsController, type: :controller do
describe 'PUT #update' do describe 'PUT #update' do
context 'with valid params' do context 'with valid params' do
let(:new_attributes) { { name: "Uncool map", permission: :private } } let(:new_attributes) { { name: 'Uncool map', permission: :private } }
it 'updates the requested map' do it 'updates the requested map' do
put :update, put :update,
{ id: map.to_param, map: new_attributes, format: :json } id: map.to_param, map: new_attributes, format: :json
expect(assigns(:map).name).to eq "Uncool map" expect(assigns(:map).name).to eq 'Uncool map'
expect(assigns(:map).permission).to eq 'private' expect(assigns(:map).permission).to eq 'private'
end end
it 'assigns the requested map as @map' do it 'assigns the requested map as @map' do
put :update, put :update,
{ id: map.to_param, map: valid_attributes, format: :json } id: map.to_param, map: valid_attributes, format: :json
expect(assigns(:map)).to eq(map) expect(assigns(:map)).to eq(map)
end end
end end
@ -74,7 +74,7 @@ RSpec.describe MapsController, type: :controller do
context 'with invalid params' do context 'with invalid params' do
it 'assigns the map as @map' do it 'assigns the map as @map' do
put :update, put :update,
{ id: map.to_param, map: invalid_attributes, format: :json } id: map.to_param, map: invalid_attributes, format: :json
expect(assigns(:map)).to eq(map) expect(assigns(:map)).to eq(map)
end end
end end
@ -87,7 +87,7 @@ RSpec.describe MapsController, type: :controller do
it 'prevents deletion by non-owners' do it 'prevents deletion by non-owners' do
unowned_map.reload unowned_map.reload
expect do expect do
delete :destroy, { id: unowned_map.to_param, format: :json } delete :destroy, id: unowned_map.to_param, format: :json
end.to change(Map, :count).by(0) end.to change(Map, :count).by(0)
expect(response.body).to eq '' expect(response.body).to eq ''
expect(response.status).to eq 403 expect(response.status).to eq 403
@ -96,7 +96,7 @@ RSpec.describe MapsController, type: :controller do
it 'deletes owned map' do it 'deletes owned map' do
owned_map.reload # ensure it's in the database owned_map.reload # ensure it's in the database
expect do expect do
delete :destroy, { id: owned_map.to_param, format: :json } delete :destroy, id: owned_map.to_param, format: :json
end.to change(Map, :count).by(-1) end.to change(Map, :count).by(-1)
expect(response.body).to eq '' expect(response.body).to eq ''
expect(response.status).to eq 204 expect(response.status).to eq 204

View file

@ -17,14 +17,14 @@ RSpec.describe MetacodesController, type: :controller do
describe 'GET #new' do describe 'GET #new' do
it 'assigns a new metacode as @metacode' do it 'assigns a new metacode as @metacode' do
get :new, { format: :json } get :new, format: :json
expect(assigns(:metacode)).to be_a_new(Metacode) expect(assigns(:metacode)).to be_a_new(Metacode)
end end
end end
describe 'GET #edit' do describe 'GET #edit' do
it 'assigns the requested metacode as @metacode' do it 'assigns the requested metacode as @metacode' do
get :edit, { id: metacode.to_param } get :edit, id: metacode.to_param
expect(assigns(:metacode)).to eq(metacode) expect(assigns(:metacode)).to eq(metacode)
end end
end end
@ -34,19 +34,19 @@ RSpec.describe MetacodesController, type: :controller do
it 'creates a new Metacode' do it 'creates a new Metacode' do
metacode.reload # ensure it's present to start metacode.reload # ensure it's present to start
expect do expect do
post :create, { metacode: valid_attributes } post :create, metacode: valid_attributes
end.to change(Metacode, :count).by(1) end.to change(Metacode, :count).by(1)
end end
it 'has the correct attributes' do it 'has the correct attributes' do
post :create, { metacode: valid_attributes } post :create, metacode: valid_attributes
# expect(Metacode.last.attributes.expect(:id)).to eq(metacode.attributes.except(:id)) # expect(Metacode.last.attributes.expect(:id)).to eq(metacode.attributes.except(:id))
expect(assigns(:metacode)).to be_a(Metacode) expect(assigns(:metacode)).to be_a(Metacode)
expect(assigns(:metacode)).to be_persisted expect(assigns(:metacode)).to be_persisted
end end
it 'redirects to the metacode index' do it 'redirects to the metacode index' do
post :create, { metacode: valid_attributes } post :create, metacode: valid_attributes
expect(response).to redirect_to(metacodes_url) expect(response).to redirect_to(metacodes_url)
end end
end end
@ -63,7 +63,7 @@ RSpec.describe MetacodesController, type: :controller do
it 'updates the requested metacode' do it 'updates the requested metacode' do
put :update, put :update,
{ id: metacode.to_param, metacode: new_attributes } id: metacode.to_param, metacode: new_attributes
metacode.reload metacode.reload
expect(metacode.icon).to eq 'https://newimages.ca/cool-image.jpg' expect(metacode.icon).to eq 'https://newimages.ca/cool-image.jpg'
expect(metacode.color).to eq '#ffffff' expect(metacode.color).to eq '#ffffff'
@ -75,13 +75,13 @@ RSpec.describe MetacodesController, type: :controller do
context 'not admin' do context 'not admin' do
it 'denies access to create' do it 'denies access to create' do
sign_in create(:user, admin: false) sign_in create(:user, admin: false)
post :create, { metacode: valid_attributes } post :create, metacode: valid_attributes
expect(response).to redirect_to root_url expect(response).to redirect_to root_url
end end
it 'denies access to update' do it 'denies access to update' do
sign_in create(:user, admin: false) sign_in create(:user, admin: false)
post :update, { id: metacode.to_param, metacode: valid_attributes } post :update, id: metacode.to_param, metacode: valid_attributes
expect(response).to redirect_to root_url expect(response).to redirect_to root_url
end end
end end

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