Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/publiclab/plots2 into iss…
Browse files Browse the repository at this point in the history
…ue5725-chrome-driver
  • Loading branch information
alaxalves committed May 21, 2019
2 parents a741140 + 439d3ce commit 5422549
Show file tree
Hide file tree
Showing 52 changed files with 430 additions and 302 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ install:
- docker-compose build
- docker-compose up -d
- docker-compose exec web sleep 5
- docker-compose logs db
- docker-compose logs
- netstat -ltpn
- docker-compose exec web bash -c "rake db:setup"
- docker-compose exec web bash -c "rake db:migrate"
Expand Down
21 changes: 8 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,29 @@ FROM ruby:2.4.4-stretch
LABEL description="This image deploys Plots2."

# Set correct environment variables.
RUN mkdir -p /app
ENV HOME /root
ENV PHANTOMJS_VERSION 2.1.1

RUN echo \
'deb http://ftp.ca.debian.org/debian/ stretch main\n \
deb http://ftp.ca.debian.org/debian/ stretch-updates main\n \
deb http://security.debian.org stretch/updates main\n' \
deb http://security.debian.org stretch/updates main\n \
deb http://deb.nodesource.com/node_8.x stretch main\n' \
> /etc/apt/sources.list

# Install dependencies
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get update -qq && apt-get install -y build-essential bundler libmariadbclient-dev ruby-rmagick libfreeimage3 wget curl procps cron make nodejs
RUN wget https://github.com/Medium/phantomjs/releases/download/v$PHANTOMJS_VERSION/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -O /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2; tar -xvf /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -C /opt ; cp /opt/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/bin/* /usr/local/bin/

# Install yarn
RUN npm config set strict-ssl false
RUN npm install -g yarn

RUN rm -r /usr/local/bundle
ADD nodesource.gpg.key /tmp/nodesource.gpg.key
RUN apt-key add /tmp/nodesource.gpg.key && apt-get update -qq \
&& apt-get install --no-install-recommends -y build-essential libmariadbclient-dev \
wget curl procps cron make nodejs unzip \
apt-transport-https libfreeimage3 \
&& npm install -g yarn

# Install bundle of gems
WORKDIR /tmp
ADD Gemfile /tmp/Gemfile
ADD Gemfile.lock /tmp/Gemfile.lock
RUN bundle install --jobs=4

ADD . /app
WORKDIR /app

RUN yarn install && yarn upgrade
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gem 'grape-swagger-ui'
gem 'http_accept_language'
gem "i18n-js", ">= 3.0.0.rc11"
gem 'impressionist'
gem 'jbuilder', '~> 2.8'
gem 'jbuilder', '~> 2.9'
gem 'jquery-rails'
gem 'less-rails', '~> 4.0'
gem 'mocha', '~> 1.8'
Expand All @@ -51,7 +51,7 @@ gem 'rb-readline'
gem 'rdiscount', '~> 2.2', '>= 2.2.0.1'
gem "recaptcha", require: "recaptcha/rails"
gem 'responders', '~> 2.4'
gem 'rubocop', '~> 0.68.1', require: false
gem 'rubocop', '~> 0.69.0', require: false
gem "ruby-openid", :require => "openid"
gem 'sanitize'
gem 'sentry-raven'
Expand Down Expand Up @@ -113,7 +113,7 @@ group :test, :development do
gem 'rake', '~> 12.3.2'
gem 'rest-client'
gem 'rspec'
gem 'selenium-webdriver', '~> 3.142.1'
gem 'selenium-webdriver', '~> 3.142.2'
gem 'test-unit'
gem 'teaspoon-mocha'
gem 'timecop'
Expand Down
30 changes: 15 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ GEM
buftok (0.2.0)
builder (3.2.3)
byebug (11.0.1)
capybara (3.18.0)
capybara (3.20.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.2)
uglifier
xpath (~> 3.2)
childprocess (1.0.1)
rake (< 13.0)
Expand Down Expand Up @@ -184,9 +185,8 @@ GEM
phantomjs (>= 1.9)
railties (>= 3.2.0)
sprockets-rails
jbuilder (2.8.0)
jbuilder (2.9.1)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jquery-atwho-rails (1.5.4)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
Expand Down Expand Up @@ -394,13 +394,13 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.68.1)
rubocop (0.69.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
parser (>= 2.6)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.6)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-openid (2.7.0)
ruby-progressbar (1.10.0)
ruby_dep (1.5.0)
Expand All @@ -420,7 +420,7 @@ GEM
tilt
scrypt (3.0.6)
ffi-compiler (>= 1.0, < 2.0)
selenium-webdriver (3.142.1)
selenium-webdriver (3.142.2)
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
sentry-raven (2.9.0)
Expand All @@ -436,9 +436,9 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
skylight (4.0.0)
skylight-core (= 4.0.0)
skylight-core (4.0.0)
skylight (4.0.1)
skylight-core (= 4.0.1)
skylight-core (4.0.1)
activesupport (>= 4.2.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
Expand All @@ -456,7 +456,7 @@ GEM
tins (~> 1.0)
terrapin (0.6.0)
climate_control (>= 0.0.3, < 1.0)
test-unit (3.3.2)
test-unit (3.3.3)
power_assert
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
Expand Down Expand Up @@ -487,7 +487,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.5.0)
unicode-display_width (1.6.0)
unicode-emoji (2.1.0)
virtus (1.0.5)
axiom-types (~> 0.1)
Expand Down Expand Up @@ -542,7 +542,7 @@ DEPENDENCIES
impressionist
jasmine-jquery-rails
jasmine-rails
jbuilder (~> 2.8)
jbuilder (~> 2.9)
jquery-atwho-rails
jquery-rails
json_expressions
Expand Down Expand Up @@ -586,12 +586,12 @@ DEPENDENCIES
rest-client
reverse_markdown
rspec
rubocop (~> 0.68.1)
rubocop (~> 0.69.0)
ruby-openid
sanitize
sassc-rails
scrypt (~> 3)
selenium-webdriver (~> 3.142.1)
selenium-webdriver (~> 3.142.2)
sentry-raven
sidekiq
skylight
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ $E = {

// wraps currently selected text in textarea with strings a and b
wrap: function(a,b,args) {
this.refresh();
var isWiki = (window.location + '').includes('wiki');
if (!isWiki) this.refresh();
var len = $E.textarea.val().length;
var start = $E.textarea[0].selectionStart;
var end = $E.textarea[0].selectionEnd;
Expand Down
7 changes: 6 additions & 1 deletion app/assets/javascripts/restful_typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ $(function() {
source: debounce(function (query, process) {
var encoded_query = encodeURIComponent(query);
var qryType = $(el).attr('qryType');
return $.getJSON('/api/srch/' + qryType + '?query=' + encoded_query, function (data) {
var queryUrl = 'api/srch/' + qryType + '?query=' + encoded_query;
if (window.hasOwnProperty('ga')) {
tracker = ga.getAll()[0];
tracker.send("pageview", queryUrl + '&typeahead=true');
}
return $.getJSON('/' + queryUrl, function (data) {
return process(data.items);
},'json');
}, 350),
Expand Down
6 changes: 5 additions & 1 deletion app/assets/stylesheets/comments.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
font-family: "Helvetica Neue";
border-left: 5px solid #736f6f;
background-color: #f3f1ef;
}
}

#comments-list .comment p img {
max-width: 100%;
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@
#side-progress {
margin:3px 10px 10px;
width:30%;
}
}
2 changes: 1 addition & 1 deletion app/controllers/answer_like_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def likes
else
AnswerSelection.set_likes(current_user.uid, @answer.id, true)
user = User.find(current_user.uid)
AnswerMailer.notify_answer_like(user, @answer).deliver_now
AnswerMailer.notify_answer_like(user, @answer).deliver_later
end
@answer.reload
respond_to do |format|
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ def set_sidebar(type = :generic, data = :all, args = {})
@maps = Tag.find_nodes_by_type(data, 'map', 20)
else # type is generic
# remove "classroom" postings; also switch to an EXCEPT operator in sql, see https://github.com/publiclab/plots2/issues/375
hidden_nids = Node.joins(:node_tag)
.joins('LEFT OUTER JOIN term_data ON term_data.tid = community_tags.tid')
.select('node.*, term_data.*, community_tags.*')
.where(type: 'note', status: 1)
.where('term_data.name = (?)', 'hidden:response')
.collect(&:nid)
hidden_nids = Node.where(type: :note, status: 1).select { |n| n.has_a_tag('hidden:response') }.collect(&:nid)
@notes = if params[:controller] == 'questions'
Node.questions
.joins(:revision)
Expand Down
9 changes: 2 additions & 7 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ def research
def activity
blog = Tag.find_nodes_by_type('blog', 'note', 1).first
# remove "classroom" postings; also switch to an EXCEPT operator in sql, see https://github.com/publiclab/plots2/issues/375
hidden_nids = Node.joins(:node_tag)
.joins('LEFT OUTER JOIN term_data ON term_data.tid = community_tags.tid')
.select('node.*, term_data.*, community_tags.*')
.where(type: 'note', status: 1)
.where('term_data.name = (?)', 'hidden:response')
.collect(&:nid)
hidden_nids = Node.where(type: :note, status: 1).select { |n| n.has_a_tag('hidden:response') }.collect(&:nid)
notes = Node.where(type: 'note')
.where('node.nid NOT IN (?)', hidden_nids + [0]) # in case hidden_nids is empty
.order('nid DESC')
Expand All @@ -89,7 +84,7 @@ def activity
notes = notes.where('(node.status = 1 OR node.status = 4 OR node.status = 3)')
comments = comments.where('comments.status = 1 OR comments.status = 4')
elsif current_user
coauthor_nids = Node.joins(:node_tag).joins('LEFT OUTER JOIN term_data ON term_data.tid = community_tags.tid').select('node.*, term_data.*, community_tags.*').where(type: 'note', status: 3).where('term_data.name = (?)', "with:#{current_user.username}").collect(&:nid)
coauthor_nids = Node.where(type: :note, status: 3).select { |n| n.has_a_tag("with:#{current_user.username}") }.collect(&:nid)
notes = notes.where('(node.nid IN (?) OR node.status = 1 OR ((node.status = 3 OR node.status = 4) AND node.uid = ?))', coauthor_nids, current_user.uid)
comments = comments.where('comments.status = 1 OR (comments.status = 4 AND comments.uid = ?)', current_user.uid)
else
Expand Down
14 changes: 5 additions & 9 deletions app/controllers/openid_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,9 @@ def index

if oidreq

if current_user && !requested_username.casecmp(current_user.username.downcase).zero?
flash[:error] = "You are requesting access to an account that's not yours. Please <a href='/logout'>log out</a> and use the correct account, or <a href='" + oidreq.trust_root + "'>try to login with the correct username</a>"
redirect_to '/dashboard'
else
oidresp = nil
if oidreq.is_a?(CheckIDRequest)

oidresp = nil
if oidreq.is_a?(CheckIDRequest)

identity = oidreq.identity

Expand Down Expand Up @@ -139,12 +136,11 @@ def index
return
end

else
else
oidresp = server.handle_request(oidreq)
end

render_response(oidresp)
end
render_response(oidresp)
else
session[:openid_return_to] = request.env['ORIGINAL_FULLPATH']
if provider
Expand Down
38 changes: 19 additions & 19 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ def range
@end = fin
@notes = Node.published.select(%i(created type))
.where(type: 'note', created: @start.to_i..@end.to_i)
.count(:all)
@wikis = Revision.select(:timestamp)
.size
@wikis = Revision.published.select(:timestamp)
.where(timestamp: @start.to_i..@end.to_i)
.count - @notes # because notes each have one revision
.size - @notes # because notes each have one revision
@people = User.where(created_at: @start..@end).where(status: 1)
.count
.size
@answers = Answer.where(created_at: @start..@end)
.count
@comments = Comment.select(:timestamp)
.where(timestamp: @start.to_i..@end.to_i)
.count
.size
@comments = Comment.select(:status, :timestamp)
.where(status: 1, timestamp: @start.to_i..@end.to_i)
.size
@questions = Node.published.questions.where(created: @start.to_i..@end.to_i)
.count
.size
@contributors = User.contributor_count_for(@start, @end)
@popular_tags = Tag.nodes_frequency(@start, @end)
end
Expand All @@ -41,16 +41,16 @@ def index
end
@title = 'Stats'

@weekly_notes = Node.past_week.select(:type).where(type: 'note').count(:all)
@weekly_wikis = Revision.past_week.count
@weekly_questions = Node.questions.past_week.count(:all).count
@weekly_answers = Answer.past_week.count
@weekly_members = User.past_week.where(status: 1).count
@monthly_notes = Node.past_month.select(:type).where(type: 'note').count(:all)
@monthly_wikis = Revision.past_month.count
@monthly_members = User.past_month.where(status: 1).count
@monthly_questions = Node.questions.past_month.count(:all).count
@monthly_answers = Answer.past_month.count
@weekly_notes = Node.past_week.select(:type).where(type: 'note').size
@weekly_wikis = Revision.past_week.size
@weekly_questions = Node.questions.past_week.size
@weekly_answers = Answer.past_week.size
@weekly_members = User.past_week.where(status: 1).size
@monthly_notes = Node.past_month.select(:type).where(type: 'note').size
@monthly_wikis = Revision.past_month.size
@monthly_members = User.past_month.where(status: 1).size
@monthly_questions = Node.questions.past_month.size
@monthly_answers = Answer.past_month.size

@notes_per_week_period = Node.frequency('note', @start, @end).round(2)
@edits_per_week_period = Revision.frequency(@start, @end).round(2)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/user_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def handle_social_login_flow(auth)
if session[:openid_return_to] # for openid login, redirects back to openid auth process
return_to = session[:openid_return_to]
session[:openid_return_to] = nil
redirect_to return_to + hash_params
else
redirect_to return_to + hash_params, notice: "Signed in!"
end
redirect_to return_to + hash_params, notice: "Signed in!"
else # identity does not exist so we need to either create a user with identity OR link identity to existing user
if User.where(email: auth["info"]["email"]).empty?
# Create a new user as email provided is not present in PL database
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create
flash[:notice] += " " + I18n.t('users_controller.continue_where_you_left_off', url1: params[:return_to].to_s)
end
flash[:notice] = flash[:notice].html_safe
flash[:warning] = I18n.t('users_controller.spectralworkbench_or_mapknitter', url1: "'#{session[:openid_return_to]}'").html_safe if session[:openid_return_to]
flash[:warning] = I18n.t('users_controller.spectralworkbench_or_mapknitter', url1: "#{session[:openid_return_to]}'").html_safe if session[:openid_return_to]
session[:openid_return_to] = nil
redirect_to "/dashboard"
end
Expand Down
Loading

0 comments on commit 5422549

Please sign in to comment.