Skip to content

Commit

Permalink
Pull latest changes from documentcloud/documentcloud:master
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLemayian committed Dec 31, 2018
2 parents d77f05a + ef48fd1 commit d4c8064
Show file tree
Hide file tree
Showing 40 changed files with 2,064 additions and 113 deletions.
5 changes: 4 additions & 1 deletion app/actions/document_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def process_text
document.id
end


private

def queue_page_text(text, page_number)
Expand Down Expand Up @@ -190,6 +189,10 @@ def save_page_text!
def save_page_aspect_ratios!
ids = document.pages.order(:page_number).pluck(:id)

# This is a query which will take a list of pages and aspect ratios
# and update all of the pages in a single query.
#
# Note, the page objects need to all exist for this to work.
query_template = <<-QUERY
UPDATE pages
SET aspect_ratio = input.aspect_ratio
Expand Down
2 changes: 1 addition & 1 deletion app/actions/reindex_everything.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def process
counter += 1
(sleep(0.25 * counter) and retry) if counter < 5
LifecycleMailer.exception_notification(e,options).deliver_now
outcomes[:failed].push(:id=>doc.id)
outcomes[:failed].push(:id=>document.id)
end
end
Sunspot.commit
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def organization
top_data = @documents.group(:account_id).count.sort_by{|k,v| -v}.first(@top_count).map do |arr|
m = @memberships.where(account_id: arr.first).first
fake_account = Struct.new(:full_name, :email, :slug)
accountish = m.blank? ? fake_account.new("Deleted User", nil, nil) : m.account
accountish = (m.blank? or m.account.nil?) ? fake_account.new("Deleted User", nil, nil) : m.account
[accountish, arr.last]
end
@top_uploaders = Hash[top_data]
Expand Down Expand Up @@ -378,7 +378,7 @@ def login_as

# notify when an Admin logs in as a user.
hook_url = DC::SECRETS['slack_webhook']
text = "#{@current_account.full_name} has logged in as #{acc.full_name} (#{acc.email} on #{Rails.env})."
text = "#{@current_account.full_name} (#{@current_account.email}) has logged in as #{acc.full_name} (#{acc.email} on #{Rails.env})."
data = {:payload => {:text => text, :username => "docbot", :icon_emoji => ":doccloud:"}.to_json}
RestClient.post(hook_url, data)

Expand Down
1 change: 1 addition & 0 deletions app/controllers/annotations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def show
@exclude_analytics = true
render template: 'annotations/show_embedded', layout: 'new'
else
@include_analytics = true
make_oembeddable(current_annotation) unless current_annotation.section_note?
set_minimal_nav text: 'Read the full document',
xs_text: 'Full document',
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def terms
return not_found unless @version_numbers.include? @version

@canonical_url = terms_url if @version == @current_terms['version']
@include_analytics = true
render layout: 'new', template: "home/terms/show"
end

Expand All @@ -48,18 +49,22 @@ def api_terms
return not_found unless @version_numbers.include? @version

@canonical_url = api_terms_url if @version == @current_terms['version']
@include_analytics = true
render layout: 'new', template: "home/api_terms/show"
end

def status
@include_analytics = true
not_found
end

def privacy
@include_analytics = true
render layout: 'new'
end

def faq
@include_analytics = true
render layout: 'new'
end

Expand Down Expand Up @@ -98,6 +103,7 @@ def quackbot

end

@include_analytics = true
render layout: 'new'
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def show
@exclude_analytics = true
render template: 'pages/show_embedded'
else
@include_analytics = true
make_oembeddable(current_page)
set_minimal_nav text: 'Read the full document',
xs_text: 'Full document',
Expand Down
49 changes: 45 additions & 4 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
class ProjectsController < ApplicationController

before_action :login_required
before_action :login_required, except: :show

READONLY_ACTIONS = [
:index, :documents
:index, :documents, :show
]
before_action :read_only_error, :except => READONLY_ACTIONS if read_only?

def show
# PLEASE BE CAREFUL WITH THIS ACTION
#
# It was intentionally authored in spite of ProjectsController#current_project
# in order to hack around the notion that projects can be public objects
# and not merely objects viewable if you have edit permissions for them.
@project = Project.where(hidden:false).find(params[:id])
return not_found unless @project

respond_to do |format|
format.html do
@organization_id = @project.account.organization_id
render(layout: 'new')
end
format.json do
documents = @project.documents.accessible(current_account, current_organization).select(:id,:slug)
json({
id: @project.slug,
title: @project.title,
documents: documents.first(10000).map{ |document| document.canonical_url(:html) }
}.as_json)
end
end
end

def index
json Project.visible.accessible(current_account)
end
Expand Down Expand Up @@ -45,11 +70,27 @@ def remove_documents
end

private

=begin
Okay i want to add a notion of publicness.
The notions that a project has are:
- projects you own
- projects shared with you
The current project is a project you can edit (which you own or have had shared w/ you)
There should be public projects.
Having a list of public projects and integer ids means that folks can enumerate projects
(they already can via search tho) and find groupings of public documents which may reveal
investigations underway.
Need a mechanism to indicate the privacy/publicness of a project.
Really need to overhaul the search index.
=end
def current_project(only_owner=false)
return @current_project if @current_project
base = only_owner ? current_account.projects : Project.accessible(current_account)
@current_project = base.find(params[:id])
end

end
9 changes: 5 additions & 4 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ def self.upload_statistics(type, id)

# Ensure that titles are stripped of trailing whitespace.
def title=(title="Untitled Document")
self[:title] = self.strip title.strip
# Clean the stripped title
self[:title] = CGI.unescape_html(self.strip title.strip)
end

# Save all text assets, including the `combined_page_text`, and the text of
Expand Down Expand Up @@ -899,7 +900,7 @@ def self.duplicate(document_ids, account, options={})
def duplicate!(recipient=nil, options={})
Document.transaction do
# Clone the document.
newattrs = attributes.merge({
newattrs = attributes.dup.merge({
:access => PENDING,
:created_at => Time.now,
:updated_at => Time.now
Expand All @@ -912,7 +913,7 @@ def duplicate!(recipient=nil, options={})

# Clone the docdata.
if docdata and options['include_docdata']
Docdata.create! document_id: copy_id, data: docdata.data
Docdata.create! document_id: copy_id, data: docdata.data.dup
end

# Clone the associations.
Expand All @@ -925,7 +926,7 @@ def duplicate!(recipient=nil, options={})
associations.push project_memberships if options['include_project']
associations.each do |association|
association.each do |model|
model_attrs = model.attributes.merge newattrs
model_attrs = model.attributes.dup.merge newattrs
model_attrs.delete('id')
model.class.create! model_attrs
end
Expand Down
4 changes: 0 additions & 4 deletions app/views/documents/preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,5 @@

<%= render(:partial => 'viewer_editing') if @edits_enabled %>

<% if @current_document %>
<%= render partial: 'common/google', locals: { pageview_url: '/documents/show' } %>
<% end %>

</body>
</html>
27 changes: 5 additions & 22 deletions app/views/donate/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<header id="donation-page-header" class="container-md">
<h1>
Support open and truthful journalism.
<mark>Donate to sourceAFRICA.</mark>
<mark>Donate to DocumentCloud.</mark>
</h1>
</header>

Expand All @@ -18,31 +18,14 @@
<div class="container-sm">
<% end %>

<%= bootstrap_form_tag url: donate_charge_path, html: {id: 'donation-form'} do |f| %>
<%= hidden_field_tag(:stripe_token) %>
<%= hidden_field_tag(:stripe_email) %>
<%= hidden_field_tag(:donation_amount_cents) %>
<%= hidden_field_tag(:suggested_donation, @suggested_donation) %>
<div id="donation_amounts" class="btn-group" data-toggle="buttons">
<% @donation_levels.each do |amount| %>
<label class="btn btn-secondary">
<input name="donation_amount" id="donation-amount-<%= amount %>" value="<%= amount %>" type="radio" autocomplete="off"> $<%= amount %>
</label>
<% end %>
<label class="sr-only" for="donation_amount">Amount (USD)</label>
<input name="donation_amount_other" id="donation-amount-other" type="tel" class="form-control" placeholder="Other">
</div>
<p><%= f.submit 'Donate!', class: 'btn btn-block btn-success' %></p>
<div id="error_explanation"></div>
<p class="note">You’re making a tax-deductible donation on behalf of sourceAFRICA to our parent non-profit <%= external_link_to 'Code for Africa', 'https://codeforafrica.org/' %>, a <nobr>non profit</nobr> organization.</p>
<% end %>
<iframe src="https://www.muckrock.com/crowdfund/185/embed/" width="100%" height="530px" style="border: none; box-shadow: 2px 2px 2px #00000024; margin: -1em 0 4em 0;"></iframe>

<% if params[:prolix] %>
</div>
<div id="donation-pitch" class="col-12 pull-md-5 col-md-7">
<p class="lead">Journalism starts with the facts. What happened? Can you prove it? Getting to the truth can be hard, and convincing others even harder.</p>
<p>Investigative journalists use sourceAFRICA to sort through piles of primary source documents, find the story, and then publish that evidence for the public. It's been used in some of the most important reporting of the decade, like Oxpecker's <%= external_link_to 'SA\'s Tigers Going Home To China', 'http://oxpeckers.org/2014/01/sas-tigers-going-home-to-china/' %>.</p>
<p>More than <strong><%= link_to "#{ActiveSupport::NumberHelper.number_to_human Document.unrestricted.count, precision: 2} documents", public_search_url, target: '_blank' %></strong> constituting <strong><%= "#{ActiveSupport::NumberHelper.number_to_human Document.unrestricted.sum(:page_count) } pages" %></strong> have been released to the public through sourceAFRICA.</p>
<p>Investigative journalists use DocumentCloud to sort through piles of primary source documents, find the story, and then publish that evidence for the public. It's been used in some of the most important reporting of the decade, like Oxpecker's <%= external_link_to 'SA\'s Tigers Going Home To China', 'http://oxpeckers.org/2014/01/sas-tigers-going-home-to-china/' %>.</p>
<p>More than <strong><%= link_to "#{ActiveSupport::NumberHelper.number_to_human Document.unrestricted.count, precision: 2} documents", public_search_url, target: '_blank' %></strong> constituting <strong><%= "#{ActiveSupport::NumberHelper.number_to_human Document.unrestricted.sum(:page_count) } pages" %></strong> have been released to the public through DocumentCloud.</p>
<p>If you want to support us in our mission to make good, evidence-backed reporting better and easier, <a class="cast-spotlight-link" href="#donation-page-header">please donate</a>! We run lean on grants and donations, and every dollar helps.</p>
</div>
<% end %>
Expand Down Expand Up @@ -102,7 +85,7 @@
</div>

<div class="text-center">
<a class="cast-spotlight-link btn btn-success btn-link" href="#donation-page-header">&uarr; Donate to sourceAFRICA!</a>
<a class="cast-spotlight-link btn btn-success btn-link" href="#donation-page-header">&uarr; Donate to DocumentCloud!</a>
</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/donate/thanks.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>

<section class="container-md text-center mt-5">
<p class="lead">Please encourage others to donated to sourceAFRICA!</p>
<p class="lead">Please encourage others to donated to DocumentCloud!</p>
<p>
<a href="https://twitter.com/share" class="twitter-share-button" data-size="large" data-text="Support open and truthful journalism. Donate to #sourceAFRICA. I just did!" data-url="https://dc.sourceafrica.net/donate" data-dnt="true" data-show-count="false">Tweet</a>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
Expand Down
7 changes: 1 addition & 6 deletions app/views/home/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,7 @@
Show your support for great journalism with a donation to sourceAFRICA.<br>
<%= link_to "Read more about donating", donate_path %>
</p>
<div class="text_input first light">
<div class="inner">
<input type="tel" placeholder="Amount ($)" name="amount" id="donation-amount-other" />
</div>
</div>
<p><button type="submit" class="minibutton default">Donate</button></p>
<a href="/donate"><span class="minibutton default">Donate</span></a>
<div id="error_explanation" style="color:red"></div>
<% end %>
</div>
Expand Down
Loading

0 comments on commit d4c8064

Please sign in to comment.