Skip to content

Commit

Permalink
Merge branch 'master' into issue_4168
Browse files Browse the repository at this point in the history
  • Loading branch information
sarken committed Jul 14, 2015
2 parents 6350a3f + 171e299 commit 58a8c13
Show file tree
Hide file tree
Showing 57 changed files with 431 additions and 347 deletions.
1 change: 1 addition & 0 deletions .ruby_version
@@ -0,0 +1 @@
ruby-2.0.0-p598
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -16,7 +16,7 @@ env:
- TEST_GROUP="cucumber -f progress -r features features/users"
- TEST_GROUP="cucumber -f progress -r features features/works"
rvm:
- "1.9.3"
- "2.0.0"
services:
- elasticsearch
- redis-server
Expand Down
7 changes: 4 additions & 3 deletions Gemfile
@@ -1,6 +1,6 @@
source 'http://rubygems.org'

ruby '1.9.3'
ruby '2.0.0'

gem 'bundler'

Expand All @@ -12,6 +12,8 @@ gem 'rails', '3.2.21'
# Database
# gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'mysql2'
#https://github.com/qertoip/transaction_retry
gem 'transaction_retry'

# Version of redis-rb gem
# We are currently running Redis 2.6.4 (12/6/2012)
Expand All @@ -30,12 +32,11 @@ gem "lograge" # https://github.com/roidrage/lograge
gem 'will_paginate', '>=3.0.2'
gem 'acts_as_list'
gem 'akismetor'
gem 'psych' , '1.3.4'

gem 'httparty'
gem 'htmlentities'
gem 'whenever', '~>0.6.2', :require => false
gem 'nokogiri', '>=1.4.2'
gem 'nokogiri', '>=1.6.6.2'
gem 'mechanize'
gem 'sanitize'
gem 'rest-client', :require => 'rest_client'
Expand Down
10 changes: 7 additions & 3 deletions Gemfile.lock
Expand Up @@ -217,7 +217,6 @@ GEM
method_source (~> 0.8)
slop (~> 3.4)
win32console (~> 1.3)
psych (1.3.4)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
Expand Down Expand Up @@ -330,6 +329,11 @@ GEM
multi_json (~> 1.3)
rake
rest-client (~> 1.6)
transaction_isolation (1.0.3)
activerecord (>= 3.0.11)
transaction_retry (1.0.2)
activerecord (>= 3.0.11)
transaction_isolation (>= 1.0.2)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
Expand Down Expand Up @@ -408,13 +412,12 @@ DEPENDENCIES
mysql2
newrelic-redis
newrelic_rpm (= 3.9.3.241)
nokogiri (>= 1.4.2)
nokogiri (>= 1.6.6.2)
paperclip
permit_yo
phrase
pickle
pry
psych (= 1.3.4)
rack-dev-mark
rails (= 3.2.21)
redis (>= 3.0)
Expand All @@ -432,6 +435,7 @@ DEPENDENCIES
simplecov
timeliness
tire
transaction_retry
unicode
unicorn
unidecoder
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin_posts_controller.rb
Expand Up @@ -19,6 +19,7 @@ def index
@tags = AdminPostTag.order(:name)
end
@admin_posts = @admin_posts.order('created_at DESC').page(params[:page])
@news_languages = Language.where(id: Locale.all.map(&:language_id)).default_order
end

# GET /admin_posts/1
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/works_controller.rb
Expand Up @@ -46,7 +46,7 @@ def work_url_from_external(original_url)
if original_url.blank?
error = "Please provide the original URL for the work."
else
work = Work.find_by_url(original_url)
work = Work.where(imported_from_url: original_url).first
if !work
error = "No work has been imported from \"" + original_url + "\"."
end
Expand Down
14 changes: 6 additions & 8 deletions app/controllers/application_controller.rb
Expand Up @@ -50,6 +50,10 @@ def set_flash_cookie(key=nil, msg=nil)
# def setflash (this is here in case someone is grepping for the definition of the method)
alias :setflash :set_flash_cookie

def current_user
@current_user ||= current_user_session && current_user_session.record
end

protected

def record_not_found (exception)
Expand All @@ -64,13 +68,6 @@ def current_user_session
@current_user_session = UserSession.find
end

def current_user
@current_user = current_user_session && current_user_session.record
# if Rails.env.development? && params[:force_current_user].present?
# @current_user = User.find_by_login(params[:force_current_user])
# end
end

def current_admin_session
return @current_admin_session if defined?(@current_admin_session)
@current_admin_session = AdminSession.find
Expand Down Expand Up @@ -371,7 +368,8 @@ def check_ownership_or_admin
# includes a special case for restricted works and series, since we want to encourage people to sign up to read them
def check_visibility
if @check_visibility_of.respond_to?(:restricted) && @check_visibility_of.restricted && User.current_user.nil?
redirect_to login_path(:restricted => true)
store_location
redirect_to login_path(restricted: true)
elsif @check_visibility_of.is_a? Skin
access_denied unless logged_in_as_admin? || current_user_owns?(@check_visibility_of) || @check_visibility_of.official?
else
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/challenge/gift_exchange_controller.rb
Expand Up @@ -69,8 +69,8 @@ def destroy
def initializing_tag_sets?
# uuughly :P but check params to see if we're initializing
!params[:gift_exchange][:offer_restriction_attributes].keys.
select {|k| k=~ /init_(less|greater)/}.
select {|k| params[:gift_exchange][:offer_restriction_attributes][k] == "1"}.
select { |k| k =~ /init_(less|greater)/ }.
select { |k| params[:gift_exchange][:offer_restriction_attributes][k] == '1' }.
empty?
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/challenges_controller.rb
Expand Up @@ -32,7 +32,7 @@ class ChallengesController < ApplicationController
#

before_filter :load_collection

def no_collection
flash[:error] = t('challenge.no_collection', :default => "What collection did you want to work with?")
redirect_to(request.env["HTTP_REFERER"] || root_path)
Expand Down
32 changes: 16 additions & 16 deletions app/mailers/admin_mailer.rb
Expand Up @@ -3,16 +3,16 @@ class AdminMailer < ActionMailer::Base

layout 'mailer'
helper :mailer
default :from => "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"
default from: "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"

def abuse_report(abuse_report_id)
abuse_report = AbuseReport.find(abuse_report_id)
@email = abuse_report.email
@url = abuse_report.url
@comment = abuse_report.comment
mail(
:to => ArchiveConfig.ABUSE_ADDRESS,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Admin Abuse Report"
to: ArchiveConfig.ABUSE_ADDRESS,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Admin Abuse Report"
)
end

Expand All @@ -21,8 +21,8 @@ def created_faq(archive_faq_id, admin)
@archive_faq = ArchiveFaq.find(archive_faq_id)
@email = "translation@transformativeworks.org"
mail(
:to => @email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] FAQ Creation",
to: @email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] FAQ Creation",
)
end

Expand All @@ -31,8 +31,8 @@ def edited_faq(archive_faq_id, admin)
@archive_faq = ArchiveFaq.find(archive_faq_id)
@email = "translation@transformativeworks.org"
mail(
:to => @email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] FAQ Edit",
to: @email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] FAQ Edit",
)
end

Expand All @@ -41,9 +41,9 @@ def feedback(feedback_id)
@summary = feedback.summary
@comment = feedback.comment
mail(
:from => feedback.email.blank? ? ArchiveConfig.RETURN_ADDRESS : feedback.email,
:to => ArchiveConfig.FEEDBACK_ADDRESS,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Support - " + feedback.summary,
from: feedback.email.blank? ? ArchiveConfig.RETURN_ADDRESS : feedback.email,
to: ArchiveConfig.FEEDBACK_ADDRESS,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Support - " + feedback.summary,
)
end

Expand All @@ -57,8 +57,8 @@ def archive_notification(admin_login, user_ids, subject, message)
user_ids.size.to_s + " users, including: " + User.limit(20).find(user_ids).map(&:login).join(", ")
end
mail(
:to => ArchiveConfig.WEBMASTER_ADDRESS,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Admin Archive Notification Sent - #{subject}"
to: ArchiveConfig.WEBMASTER_ADDRESS,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Admin Archive Notification Sent - #{subject}"
)
end

Expand All @@ -67,8 +67,8 @@ def comment_notification(comment_id)
# admin = Admin.find(admin_id)
@comment = Comment.find(comment_id)
mail(
:to => ArchiveConfig.ADMIN_ADDRESS,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name
to: ArchiveConfig.ADMIN_ADDRESS,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name
)
end

Expand All @@ -77,8 +77,8 @@ def edited_comment_notification(comment_id)
# admin = Admin.find(admin_id)
@comment = Comment.find(comment_id)
mail(
:to => ArchiveConfig.ADMIN_ADDRESS,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Edited comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name
to: ArchiveConfig.ADMIN_ADDRESS,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Edited comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name
)
end

Expand Down
6 changes: 3 additions & 3 deletions app/mailers/collection_mailer.rb
Expand Up @@ -8,15 +8,15 @@ class CollectionMailer < ActionMailer::Base
helper :series

layout 'mailer'
default :from => "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"
default from: "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"

def item_added_notification(creation_id, collection_id, item_type)
@item_type = item_type
@item_type == "Work" ? @creation = Work.find(creation_id) : @creation = Bookmark.find(creation_id)
@collection = Collection.find(collection_id)
mail(
:to => @collection.email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] #{@item_type.capitalize} added to " + @collection.title.gsub("&gt;", ">").gsub("&lt;", "<")
to: @collection.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] #{@item_type.capitalize} added to " + @collection.title.gsub("&gt;", ">").gsub("&lt;", "<")
)
end
end
2 changes: 1 addition & 1 deletion app/mailers/comment_mailer.rb
Expand Up @@ -3,7 +3,7 @@ class CommentMailer < ActionMailer::Base

layout 'mailer'
helper :mailer
default :from => "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"
default from: "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"

# Sends email to an owner of the top-level commentable when a new comment is created
def comment_notification(user_id, comment_id)
Expand Down
60 changes: 35 additions & 25 deletions app/mailers/kudo_mailer.rb
Expand Up @@ -3,46 +3,56 @@ class KudoMailer < ActionMailer::Base

layout 'mailer'
helper :mailer
default :from => "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"
default from: "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"

def kudo_notification(user_id, kudo_id)
user = User.find(user_id)
kudo = Kudo.find(kudo_id)
@pseud = kudo.pseud
@commentable = kudo.commentable
I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Kudos on " + @commentable.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
end
ensure
I18n.locale = I18n.default_locale
end

# send a batched-up notification
# user_kudos is a hash of arrays converted to JSON string format
# [commentable_type]_[commentable_id] => [array of users who left kudos with the last entry being "# guests" if any]
# [commentable_type]_[commentable_id] =>
# names: [array of users who left kudos with the last entry being "# guests" if any]
# guest_count: number of guest kudos
def batch_kudo_notification(user_id, user_kudos)
@commentables = []
@kudo_givers = {}
user = User.find(user_id)
kudos_hash = JSON.parse(user_kudos)
kudos_hash.each_pair do |commentable_info, kudo_givers|
commentable_type, commentable_id = commentable_info.split("_")
commentable = commentable_type.constantize.find_by_id(commentable_id)
next unless commentable
@commentables << commentable
@kudo_givers[commentable_info] = kudo_givers
end

I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
kudos_hash.each_pair do |commentable_info, kudo_givers_hash|
# Parse the key to extract the type and id of the commentable - skip if no commentable
commentable_type, commentable_id = commentable_info.split('_')
commentable = commentable_type.constantize.find_by_id(commentable_id)
next unless commentable

# If we have a commentable, extract names and process guest kudos text - skip if no kudos givers
names = kudo_givers_hash['names']
guest_count = kudo_givers_hash['guest_count']
kudo_givers = []

if !names.nil? && names.size > 0
kudo_givers = names
kudo_givers << guest_kudos(guest_count) unless guest_count == 0
else
kudo_givers << guest_kudos(guest_count).capitalize unless guest_count == 0
end
next if kudo_givers.empty?

@commentables << commentable
@kudo_givers[commentable_info] = kudo_givers
end
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] You've got kudos!"
subject: t('mailer.kudos.you_have', app_name: ArchiveConfig.APP_SHORT_NAME)
)
end
ensure
I18n.locale = I18n.default_locale
end

def guest_kudos(guest_count)
if guest_count.to_i == 1
"#{t 'mailer.kudos.guest'}"
else
"#{guest_count} #{t 'mailer.kudos.guests'}"
end
end
end
18 changes: 1 addition & 17 deletions app/mailers/user_mailer.rb
Expand Up @@ -18,7 +18,7 @@ class UserMailer < BulletproofMailer::Base
helper :series
include HtmlCleaner

default :from => "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"
default from: "Archive of Our Own " + "<#{ArchiveConfig.RETURN_ADDRESS}>"

# Sends an invitation to join the archive
# Must be sent synchronously as it is rescued
Expand Down Expand Up @@ -296,22 +296,6 @@ def prompter_notification(work_id, collection_id=nil)
I18n.locale = I18n.default_locale
end

# Sends email to coauthors when a work is edited
# NOTE: this must be sent synchronously! otherwise the new version will be sent.
# TODO refactor to make it asynchronous by passing the content in the method
def edit_work_notification(user, work)
@user = user
@work = work
I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Your story has been updated"
)
end
ensure
I18n.locale = I18n.default_locale
end

# Sends email to authors when a creation is deleted
# NOTE: this must be sent synchronously! otherwise the work will no longer be there to send
# TODO refactor to make it asynchronous by passing the content in the method
Expand Down
3 changes: 3 additions & 0 deletions app/models/challenge_models/gift_exchange.rb
Expand Up @@ -52,6 +52,9 @@ def update_allowed_values

#FIXME hack because time zones are being html encoded. couldn't figure out why.
before_save :fix_time_zone

# When Challenges are deleted, there are two references left behind that need to be reset to nil
before_destroy :clear_challenge_references

after_save :copy_tag_set_from_offer_to_request
def copy_tag_set_from_offer_to_request
Expand Down

0 comments on commit 58a8c13

Please sign in to comment.