Skip to content

Commit

Permalink
Merge e72d489 into 577686c
Browse files Browse the repository at this point in the history
  • Loading branch information
thatandromeda committed Aug 20, 2018
2 parents 577686c + e72d489 commit 333ede3
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 93 deletions.
86 changes: 43 additions & 43 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
source 'https://rubygems.org'

gem 'stackprof'
gem 'skylight'
gem 'active_model_serializers', '~> 0.8.3'
gem 'activerecord-import'
gem 'acts-as-taggable-on'
gem 'ancestry'
gem 'bootstrap-datepicker-rails'
gem 'bourbon'
gem 'neat'
gem 'cancancan'
gem 'country_select'
gem 'coveralls', require: false
gem 'date_validator'
gem 'devise'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'flutie'
gem 'high_voltage'
gem 'rails', '~> 4.2.10'
gem 'recipient_interceptor'
gem 'html2md'
gem 'jquery-placeholder-rails'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'pg', '0.20.0'
gem 'simple_form'
gem 'mime-types', '2.99.3'
gem 'paperclip', '3.5.4'
gem 'active_model_serializers', '~> 0.8.3'
gem 'acts-as-taggable-on'
gem 'ancestry'
gem 'devise'
gem 'rails_admin'
# kaminari is locked because we've monkeypatched it to work around
# slow postgres table counts on large tables.
gem 'kaminari', '0.14.1'
gem 'lograge'
gem 'mime-types', '2.99.3'
gem 'minitest'
gem 'neat'
gem 'paperclip', '3.5.4'
gem 'pg', '0.20.0'
gem 'rack-attack'
gem 'rack-test', require: 'rack/test'
gem 'rails', '~> 4.2.10'
gem 'rails_admin'
gem 'rails_admin_tag_list'
gem 'recipient_interceptor'
gem 'redcarpet', '~>2.3.0'
gem 'country_select'
gem 'select2-rails', '~> 4.0', '>= 4.0.3'
gem 'bootstrap-datepicker-rails'
#gem 'cancan', '~>1.6.10'
gem 'cancancan'
gem 'jquery-placeholder-rails'
gem 'activerecord-import'
gem 'html2md'
gem 'ruby-progressbar'
gem 'select2-rails', '~> 4.0', '>= 4.0.3'
gem 'simple_form'
gem 'skylight'
gem 'spork-rails', git: 'https://github.com/sporkrb/spork-rails'
gem 'stackprof'
gem 'turnout'
gem 'date_validator'
gem 'twitter'
gem 'twitter-text'
gem 'rails_admin_tag_list'
gem 'rack-attack'
gem 'rack-test', require: 'rack/test'
gem 'minitest'
gem 'spork-rails', git: 'https://github.com/sporkrb/spork-rails'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'coveralls', require: false

group :assets do
gem 'coffee-rails'
gem 'sass-rails'
gem 'uglifier'
gem 'therubyracer'
gem 'uglifier'
end

group :development do
gem 'foreman'
gem 'binding_of_caller'
gem 'foreman'
end

group :development, :test do
gem 'phantomjs'
gem 'dotenv-rails'
gem 'factory_girl_rails'
gem 'rspec-rails'
gem 'sham_rack'
gem 'phantomjs'
gem 'pry', '~> 0.10.4'
gem 'pry-byebug'
gem 'pry-rails'
gem 'ruby-prof'
gem 'rspec-collection_matchers', '~> 1.1', '>= 1.1.2'
gem 'pry-byebug'
gem 'pry', '~> 0.10.4'
gem 'rspec-rails'
gem 'ruby-prof'
gem 'sham_rack'
end

group :test do
gem 'bourne', require: false
gem 'poltergeist', '~> 1.10'
gem 'curb'
gem 'database_cleaner'
gem 'elasticsearch-extensions'
gem 'fakeweb'
gem 'launchy'
gem 'poltergeist', '~> 1.10'
gem 'shoulda-matchers', '~> 3.1', '>= 3.1.1'
gem 'simplecov', require: false
gem 'timecop'
gem 'fakeweb'
gem 'curb'
gem 'elasticsearch-extensions'
end
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ GEM
launchy (2.3.0)
addressable (~> 2.3)
libv8 (3.16.14.19)
lograge (0.10.0)
actionpack (>= 4)
activesupport (>= 4)
railties (>= 4)
request_store (~> 1.0)
loofah (2.1.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -281,6 +286,8 @@ GEM
redcarpet (2.3.0)
ref (2.0.0)
remotipart (1.3.1)
request_store (1.4.1)
rack (>= 1.4)
responders (2.2.0)
railties (>= 4.2.0, < 5.1)
rest-client (2.0.2)
Expand Down Expand Up @@ -418,6 +425,7 @@ DEPENDENCIES
jquery-ui-rails
kaminari (= 0.14.1)
launchy
lograge
mime-types (= 2.99.3)
minitest
neat
Expand Down
24 changes: 11 additions & 13 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class ApplicationController < ActionController::Base
private

def meta_hash_for(results)
%i(
%i[
current_page next_page offset per_page
previous_page total_entries total_pages
).each_with_object(query_meta(results)) do |attribute, memo|
].each_with_object(query_meta(results)) do |attribute, memo|
begin
memo[attribute] = results.send(attribute)
rescue
Expand All @@ -39,26 +39,25 @@ def query_meta(results)

def facet_query_meta(results)
results.response.aggregations && results.response.aggregations.keys.each_with_object({}) do |facet, memo|
if params[facet.to_sym].present?
memo[facet.to_sym] = params[facet.to_sym]
end
memo[facet.to_sym] = params[facet.to_sym] if params[facet.to_sym].present?
end
end

def layout_by_resource
if devise_controller?
"sessions"
'sessions'
else
"application"
'application'
end
end

def authenticate_user_from_token!
user = authentication_token && User.find_by_authentication_token(authentication_token.to_s)
Rails.logger.info "Attempted login from token #{authentication_token.to_s}"
user = authentication_token &&
User.find_by_authentication_token(authentication_token.to_s)

if user
sign_in user, store: false
end
return unless user
sign_in user, store: false
end

def authentication_token
Expand All @@ -68,7 +67,6 @@ def authentication_token
end

def include_auth_cookie
cookies[:lumen_authenticated] = ( current_user.present? ? 1 : 0 )
cookies[:lumen_authenticated] = (current_user.present? ? 1 : 0)
end

end
6 changes: 3 additions & 3 deletions app/controllers/entities/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ def index
results = searcher.instances

respond_to do |format|
format.json {
format.json do
render(
json: results,
each_serializer: EntitySerializer,
serializer: ActiveModel::ArraySerializer,
root: 'entities',
meta: meta_hash_for(raw_results)
)
}
end
format.html { redirect_to root_path }
end
end
Expand All @@ -26,7 +26,7 @@ def entity_searcher
if can?(:search, Entity)
searcher.register TermSearch.new(:term, :_all)
else
searcher.register TermSearch.new(:term, [:name, :country_code, :url])
searcher.register TermSearch.new(:term, %i[name country_code url])
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/notices/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def notice_searcher
searcher.register filtered_field
end

if params[:sort_by]
searcher.sort_by = sort_by(params[:sort_by])
end
searcher.sort_by = sort_by(params[:sort_by]) if params[:sort_by]
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize(user)
if user.has_role?(Role.super_admin)
can :manage, :all
end

if user.has_role?(Role.researcher)
can :read, Notice
end
Expand Down
40 changes: 18 additions & 22 deletions app/models/submit_notice.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class SubmitNotice

delegate :errors, to: :notice

def initialize(model_class, parameters)
Expand All @@ -8,22 +7,15 @@ def initialize(model_class, parameters)
end

def submit(user = nil)
if user && (entity = user.entity)
entity_present?('submitter') or set_entity('submitter', entity)
entity_present?('recipient') or set_entity('recipient', entity)
end

unless notice.title.present?
notice.title = generic_title
end

set_all_entities(user)
notice.title = generic_title unless notice.title.present?
notice.auto_redact

if notice.save
notice.mark_for_review
notice.copy_id_to_submission_id
true
end
return unless notice.save

notice.mark_for_review
notice.copy_id_to_submission_id
true
end

def notice
Expand All @@ -48,6 +40,12 @@ def set_entity(role_name, entity)
}
end

def set_all_entities(user)
return unless user && (entity = user.entity)
set_entity('submitter', entity) unless entity_present?('submitter')
set_entity('recipient', entity) unless entity_present?('recipient')
end

def recipient_name
entity_name('recipient')
end
Expand All @@ -63,12 +61,11 @@ def generic_title
def entity_name(role_name)
role = entity_notice_role(role_name)

if role.present?
if role.has_key?(:entity_attributes)
role[:entity_attributes][:name]
elsif role.has_key?(:entity_id)
Entity.find(role[:entity_id]).name
end
return unless role.present?
if role.key?(:entity_attributes)
role[:entity_attributes][:name]
elsif role.key?(:entity_id)
Entity.find(role[:entity_id]).name
end
end

Expand Down Expand Up @@ -98,5 +95,4 @@ def flatten_param(param)
else []
end
end

end
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,11 @@ class Application < Rails::Application
# propagate in later versions of AR. Setting this to true allows the error
# to propagate, so that we can find it.
config.active_record.raise_in_transactional_callbacks = true

config.log_formatter = proc do |severity, datetime, progname, msg|
timestamp = datetime.strftime '%Y-%m-%d %H:%M:%S (%Z)'
"#{timestamp} #{severity}: #{progname} #{msg}\n"
end

end
end
3 changes: 3 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 @@
config.action_mailer.default_url_options = {
host: (ENV['EMAIL_DOMAIN'] || 'chillingeffects.org')
}
config.action_mailer.default_url_options = { host: (ENV['EMAIL_DOMAIN'] || 'chillingeffects.org') }

config.lograge.enabled = true
end
4 changes: 2 additions & 2 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
require 'devise/orm/active_record'

config.secret_key = Rails.application.secrets.devise_secret
config.mailer_sender = "admin@chillingeffects.org"
config.mailer_sender = 'admin@chillingeffects.org'
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 10
config.password_length = 8..128
config.email_regexp = /\A[^@]+@[^@]+\z/
config.reset_password_within = 6.hours
config.sign_out_via = :get
config.sign_out_via = :get
end
Loading

0 comments on commit 333ede3

Please sign in to comment.