Permalink
Browse files

Merge branch 'dc-master'

# Conflicts:
#	app/controllers/workspace_controller.rb
#	app/views/authentication/signup_info.html.erb
#	app/views/home/_sidebar.html.erb
#	app/views/workspace/upgrade.html.erb
#	config/routes.rb
#	config/server/files/nginx/documentcloud/env/development.conf
#	config/server/files/nginx/documentcloud/env/production.conf
#	config/server/files/nginx/documentcloud/env/staging.conf
#	config/server/scripts/setup_webserver.sh
  • Loading branch information...
DavidLemayian committed Oct 14, 2016
2 parents 895418a + fbdc427 commit 64fd68ffb0263bd37feca1655712d86a3795f759
Showing with 198 additions and 184 deletions.
  1. +43 −41 Gemfile.lock
  2. +17 −11 app/controllers/accounts_controller.rb
  3. +1 −6 app/controllers/authentication_controller.rb
  4. +2 −0 app/controllers/home_controller.rb
  5. +61 −1 app/controllers/import_controller.rb
  6. +7 −12 app/controllers/workspace_controller.rb
  7. +2 −2 app/models/processing_job.rb
  8. +8 −0 app/models/upload_mailbox.rb
  9. +0 −8 app/views/accounts/index.html.erb
  10. +2 −1 app/views/annotations/oembed_loader.js.erb
  11. +0 −12 app/views/authentication/signup_info.html.erb
  12. +1 −1 app/views/home/_sidebar.html.erb
  13. +1 −1 app/views/home/terms/changelog.yml
  14. +1 −0 app/views/layouts/home.html.erb
  15. +0 −3 app/views/layouts/workspace.html.erb
  16. +5 −61 app/views/workspace/upgrade.html.erb
  17. +1 −1 bower.json
  18. +4 −5 config/routes.rb
  19. +1 −0 config/server/files/nginx/documentcloud/env/development.conf
  20. +1 −1 config/server/files/nginx/documentcloud/env/production.conf
  21. +1 −0 config/server/files/nginx/documentcloud/env/staging.conf
  22. +0 −1 config/server/files/nginx/passenger.conf
  23. +1 −1 config/server/scripts/setup_common_dependencies.sh
  24. +5 −2 config/server/scripts/setup_webserver.sh
  25. +11 −0 db/migrate/20160929174005_create_upload_mailboxes.rb
  26. BIN public/images/home/browsers/chrome.gif
  27. BIN public/images/home/browsers/firefox.gif
  28. BIN public/images/home/browsers/safari.gif
  29. +4 −4 public/javascripts/app/searcher.js
  30. +1 −0 public/javascripts/ui/common/form.js
  31. +4 −1 public/stylesheets/common/lt_ie_9.css
  32. +1 −1 public/stylesheets/ui/ui.css
  33. +0 −7 test/controllers/authentication_controller_test.rb
  34. +5 −0 test/factories/upload_mailboxes.rb
  35. +7 −0 test/models/upload_mailbox_test.rb
View
@@ -23,7 +23,7 @@ GIT
GIT
remote: git@github.com:documentcloud/bull_proof_china_shop
revision: 97b3721e2ec2840028c2a8434a1e7c88a4282075
revision: 0460788877a7a0b6c8ba3eea9eace96f2083e4ad
branch: master
specs:
bull_proof_china_shop (0.0.1)
@@ -35,40 +35,40 @@ GIT
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
actionmailer (4.2.7.1)
actionpack (= 4.2.7.1)
actionview (= 4.2.7.1)
activejob (= 4.2.7.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.6)
actionview (= 4.2.6)
activesupport (= 4.2.6)
actionpack (4.2.7.1)
actionview (= 4.2.7.1)
activesupport (= 4.2.7.1)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionpack-page_caching (1.0.2)
actionpack (>= 4.0.0, < 5)
actionview (4.2.6)
activesupport (= 4.2.6)
actionview (4.2.7.1)
activesupport (= 4.2.7.1)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
active_model_serializers (0.9.4)
activemodel (>= 3.2)
activejob (4.2.6)
activesupport (= 4.2.6)
activejob (4.2.7.1)
activesupport (= 4.2.7.1)
globalid (>= 0.3.0)
activemodel (4.2.6)
activesupport (= 4.2.6)
activemodel (4.2.7.1)
activesupport (= 4.2.7.1)
builder (~> 3.1)
activerecord (4.2.6)
activemodel (= 4.2.6)
activesupport (= 4.2.6)
activerecord (4.2.7.1)
activemodel (= 4.2.7.1)
activesupport (= 4.2.7.1)
arel (~> 6.0)
activesupport (4.2.6)
activesupport (4.2.7.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
@@ -98,7 +98,7 @@ GEM
sinatra
thin (>= 1.2.4)
coderay (1.1.1)
concurrent-ruby (1.0.1)
concurrent-ruby (1.0.2)
countries (0.11.5)
currencies (~> 0.4.2)
i18n_data (~> 0.7.0)
@@ -112,7 +112,7 @@ GEM
currencies (0.4.2)
daemons (1.2.3)
docsplit (0.8.0.alpha1)
domain_name (0.5.20160310)
domain_name (0.5.20160826)
unf (>= 0.0.5, < 1.0.0)
erubis (2.7.0)
eventmachine (1.0.9.1)
@@ -129,7 +129,7 @@ GEM
faraday (>= 0.7.4, < 0.10)
ffi (1.9.10)
formatador (0.2.5)
globalid (0.3.6)
globalid (0.3.7)
activesupport (>= 4.1.0)
google-api-client (0.8.6)
activesupport (>= 3.2)
@@ -202,9 +202,9 @@ GEM
mime-types (>= 1.16, < 4)
memoist (0.14.0)
method_source (0.8.2)
mime-types (2.99.1)
mini_portile2 (2.0.0)
minitest (5.8.4)
mime-types (2.99.3)
mini_portile2 (2.1.0)
minitest (5.9.0)
minitest-spec-rails (5.3.0)
minitest (~> 5.0)
rails (>= 4.1)
@@ -216,8 +216,9 @@ GEM
net-ssh-shell (0.2.0)
net-ssh (~> 2.1.0)
netrc (0.11.0)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
notiffany (0.0.8)
nenv (~> 0.1)
shellany (~> 0.0)
@@ -255,6 +256,7 @@ GEM
pdfshaver (0.0.3)
pdftailor (0.0.5)
pg (0.18.4)
pkg-config (1.1.7)
pr_geohash (1.0.0)
progress_bar (1.0.5)
highline (~> 1.6)
@@ -268,16 +270,16 @@ GEM
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.6)
actionmailer (= 4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
activemodel (= 4.2.6)
activerecord (= 4.2.6)
activesupport (= 4.2.6)
rails (4.2.7.1)
actionmailer (= 4.2.7.1)
actionpack (= 4.2.7.1)
actionview (= 4.2.7.1)
activejob (= 4.2.7.1)
activemodel (= 4.2.7.1)
activerecord (= 4.2.7.1)
activesupport (= 4.2.7.1)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.6)
railties (= 4.2.7.1)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
@@ -287,12 +289,12 @@ GEM
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.6)
actionpack (= 4.2.6)
activesupport (= 4.2.6)
railties (4.2.7.1)
actionpack (= 4.2.7.1)
activesupport (= 4.2.7.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (11.1.1)
rake (11.2.2)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
@@ -323,10 +325,10 @@ GEM
sort_alphabetical (1.0.2)
unicode_utils (>= 1.2.2)
spring (1.6.3)
sprockets (3.5.2)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.0.4)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
@@ -43,18 +43,14 @@ def reset
def index
respond_to do |format|
format.html do
if logged_in?
if current_account.real?
@projects = Project.load_for(current_account)
@current_organization = current_account.organization
@organizations = Organization.all_slugs
@has_documents = Document.owned_by(current_account).count(:limit => 1) > 0
return render
else
return redirect_to '/public/search'
end
if logged_in? and current_account.real?
@projects = Project.load_for(current_account)
@current_organization = current_account.organization
@organizations = Organization.all_slugs
@has_documents = Document.owned_by(current_account).exists?
return render :template => 'workspace/index'
end
redirect_to '/home'
redirect_to home_path
end
format.json do
json current_organization.accounts.active
@@ -136,6 +132,16 @@ def resend_welcome
LifecycleMailer.login_instructions( account, current_organization, current_account ).deliver_now
json nil
end
def mailboxes
# code goes here.
end
def create_mailbox
end
def destroy_mailbox
end
# Removing an account only changes their role so that they cannot
# login. Ther documents, projects, and name remain.
@@ -8,15 +8,10 @@ class AuthenticationController < ApplicationController
before_action :secure_only, :only => [:login, :logout]
READONLY_ACTIONS = [
:signup_info, :login, :logout, :blank, :remote_data
:login, :logout, :blank, :remote_data
]
before_action :read_only_error, :except => READONLY_ACTIONS if read_only?
# Display the signup information page.
def signup_info
render :layout => 'workspace'
end
# /login handles both the login form and the login request.
def login
return redirect_to '/' if current_account && current_account.refresh_credentials(cookies) && !current_account.reviewer? && current_account.active?
@@ -9,6 +9,8 @@ class HomeController < ApplicationController
before_action :bouncer if exclusive_access?
def index
@canonical_url = homepage_url
redirect_to search_url if logged_in? and env["PATH_INFO"].slice(0,5) != "/home"
@document = Rails.cache.fetch( "homepage/featured_document" ) do
time = Rails.env.production? ? 2.weeks.ago : nil
Document.unrestricted.published.popular.random.since(time).first
@@ -21,9 +21,58 @@ def upload_document
# Render the HTML/script...
end
end
def upload_from_email
return forbidden unless correct_email_upload_secret?(params[:secret])
# take JSON blob
email = JSON.parse(params[:email])
uploader = email[:from]
uploader_recipient = email[:to]
# fetch message metadata
s3 = AWS::S3.new
bucket = s3.buckets['dc-email-uploads']
email_metadata_path = "emails/processed/#{email['id']}/#{email['id']}.json"
metadata = JSON.parse(bucket.objects[email_metadata_path].read)
recipients = metadata["to"]
sender = metadata["from"]
# check for shenanigans and if someone is trying to send in json blobs for someone else's email
return forbidden unless sender == uploader
# verify recipient email address
address_key = recipients.find do |address|
address == uploader_recipient and address.split('@').last == 'upload.documentcloud.org'
end
return forbidden unless address_key
# verify key against sender
key, domain = address_key.split('@')
mailbox = UploadMailbox.lookup(sender, key)
return forbidden unless mailbox and mailbox.recipient == key and mailbox.sender == sender
membership = mailbox.membership
account, organization = membership.account, membership.organization
# Okay! We're in the clear! PROCEED WITH UPLOADS
(metadata[:file_paths] || []).each do |file_path|
attributes = {
# Assume that CloudCrowd will get to the email before 24 hours are through.
url: bucket.objects[file_path].url_for(:read, {secure: Thread.current[:ssl], expires: 24.hours}).to_s,
email_me: metadata[:file_paths].size
}
Document.upload(attributes, account, organization)
end
# get list of files
file_paths = email[:files]
end
# Returning a "201 Created" ack tells CloudCrowd to clean up the job.
def cloud_crowd
return forbidden unless correct_cloud_crowd_secret?(params[:secret])
cloud_crowd_job = JSON.parse(params[:job])
if processing_job = ProcessingJob.lookup_by_remote(cloud_crowd_job)
processing_job.resolve(cloud_crowd_job) do |pj|
@@ -38,6 +87,7 @@ def cloud_crowd
# CloudCrowd is done changing the document's asset access levels.
# 201 created cleans up the job.
def update_access
return forbidden unless correct_cloud_crowd_secret?(params[:secret])
cloud_crowd_job = JSON.parse(params[:job])
if processing_job = ProcessingJob.lookup_by_remote(cloud_crowd_job)
processing_job.resolve(cloud_crowd_job) do |pj|
@@ -47,6 +97,16 @@ def update_access
render :plain => '201 Created', :status => 201
end
private
def correct_email_upload_secret?(secret)
secret.kind_of? String and secret == DC::SECRETS['email_upload_secret']
end
def correct_cloud_crowd_secret?(secret)
secret.kind_of? String and secret == DC::SECRETS['cloud_crowd_secret']
end
def expire_document_cache(document)
if document
@@ -13,19 +13,14 @@ class WorkspaceController < ApplicationController
# Main documentcloud.org page. Renders the workspace if logged in or
# searching, the home page otherwise.
def index
if logged_in?
if current_account.real?
@projects = Project.load_for(current_account)
@current_organization = current_account.organization
@organizations = Organization.all_slugs
@has_documents = Document.owned_by(current_account).exists?
@include_analytics = true
return render :template => 'workspace/index'
else
return redirect_to '/public/search'
end
if logged_in? and current_account.real?
@projects = Project.load_for(current_account)
@current_organization = current_account.organization
@organizations = Organization.all_slugs
@has_documents = Document.owned_by(current_account).exists?
return render :template => 'workspace/index'
end
redirect_to '/home'
redirect_to public_search_url(query: params[:query])
end
# Render a help page as regular HTML, including correctly re-directed links.
@@ -36,9 +36,9 @@ def inputs; [object.document_id]; end
def callback_url
case object.action
when "update_access"
"#{DC.server_root(:ssl => false)}/import/update_access"
"#{DC.server_root(:ssl => false)}/import/update_access?secret=#{DC::SECRETS['cloud_crowd_secret']}"
else
"#{DC.server_root(:ssl => false)}/import/cloud_crowd"
"#{DC.server_root(:ssl => false)}/import/cloud_crowd?secret=#{DC::SECRETS['cloud_crowd_secret']}"
end
end
end
@@ -0,0 +1,8 @@
class UploadMailbox < ActiveRecord::Base
before_validation :ensure_recipient
def ensure_recipient
self.recipient ||= "#{membership.organization.slug}-#{SecureRandom(4)}"
end
end

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 64fd68f

Please sign in to comment.