Skip to content

Commit

Permalink
Merge branch 'master' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
elzj committed Nov 8, 2012
2 parents 4c6e6ab + 070c336 commit 4c2f1a2
Show file tree
Hide file tree
Showing 311 changed files with 4,133 additions and 2,053 deletions.
11 changes: 5 additions & 6 deletions Gemfile
@@ -1,6 +1,6 @@
source 'http://rubygems.org'

gem 'bundler', '~>1.0.0'
gem 'bundler'

gem 'rails', '3.0.4'

Expand Down Expand Up @@ -28,11 +28,8 @@ gem 'sanitize'
gem 'rest-client', :require => 'rest_client'
gem 'resque', '>=1.14.0'
gem 'resque_mailer'
gem 'thinking-sphinx',
:git => 'git://github.com/freelancing-god/thinking-sphinx.git',
:branch => 'rails3',
:require => 'thinking_sphinx'
#gem 'daemon-spawn', :require => 'daemon_spawn'
gem 'tire'
gem 'aws-s3', :require => 'aws/s3'
gem 'mocha'
gem 'css_parser'
Expand Down Expand Up @@ -70,7 +67,9 @@ gem 'best_in_place'

gem 'timeliness'

gem 'newrelic_rpm'
gem 'rpm_contrib'
gem 'newrelic_rpm', ">= 3.5.0"
gem 'newrelic-redis'

# for generating graphs
gem "google_visualr", ">= 2.1"
Expand Down
42 changes: 24 additions & 18 deletions Gemfile.lock
Expand Up @@ -7,15 +7,6 @@ GIT
will_paginate (~> 3.0.pre2)
ya2yaml (~> 0.26)

GIT
remote: git://github.com/freelancing-god/thinking-sphinx.git
revision: 506db5cb1b11d4c09d3d6fcccb87a40b1b839ba0
branch: rails3
specs:
thinking-sphinx (2.0.0)
activerecord (>= 3.0.2)
riddle (>= 1.2.1)

GIT
remote: git://github.com/odorcicd/authlogic.git
revision: a087ad0cba3c165ba22fcf176c28b6f7517931e8
Expand Down Expand Up @@ -113,9 +104,10 @@ GEM
gherkin (2.3.3)
json (~> 1.4.6)
google_visualr (2.1.2)
hashr (0.0.21)
highline (1.6.2)
htmlentities (4.2.1)
i18n (0.5.0)
i18n (0.6.0)
jquery-rails (0.2.7)
rails (~> 3.0)
thor (~> 0.14.4)
Expand All @@ -135,9 +127,10 @@ GEM
mechanize (1.0.0)
nokogiri (>= 1.2.1)
memcache-client (1.8.5)
mime-types (1.16)
mime-types (1.19)
mocha (0.9.9)
rake
multi_json (1.3.6)
mysql2 (0.2.6)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
Expand All @@ -146,7 +139,10 @@ GEM
net-ssh (2.2.1)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
newrelic_rpm (3.3.1)
newrelic-redis (1.4.0)
newrelic_rpm (~> 3.0)
redis (< 4.0)
newrelic_rpm (3.5.0.1)
nokogiri (1.5.0)
paperclip (2.3.16)
activerecord (>= 2.3.0)
Expand Down Expand Up @@ -182,7 +178,7 @@ GEM
rake (>= 0.8.7)
thor (~> 0.14.4)
raindrops (0.7.0)
rake (0.9.2)
rake (0.9.2.2)
redis (2.1.1)
redis-namespace (0.10.0)
redis (< 3.0.0)
Expand All @@ -192,9 +188,11 @@ GEM
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
resque_mailer (1.0.1)
rest-client (1.6.1)
rest-client (1.6.7)
mime-types (>= 1.16)
riddle (1.2.1)
rpm_contrib (2.1.11)
newrelic_rpm (>= 3.1.1)
newrelic_rpm (>= 3.1.1)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
Expand Down Expand Up @@ -236,6 +234,12 @@ GEM
thor (0.14.6)
tilt (1.2.2)
timeliness (0.3.4)
tire (0.4.2)
activemodel (>= 3.0)
hashr (~> 0.0.19)
multi_json (~> 1.0)
rake
rest-client (~> 1.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.24)
Expand Down Expand Up @@ -264,7 +268,7 @@ DEPENDENCIES
authlogic!
aws-s3
best_in_place
bundler (~> 1.0.0)
bundler
capistrano-gitflow_version (>= 0.0.3)
capybara (= 0.3.9)
css_parser
Expand All @@ -283,7 +287,8 @@ DEPENDENCIES
memcache-client
mocha
mysql2
newrelic_rpm
newrelic-redis
newrelic_rpm (>= 3.5.0)
nokogiri (>= 1.4.2)
paperclip (>= 2.3.16)
permit_yo
Expand All @@ -293,12 +298,13 @@ DEPENDENCIES
resque (>= 1.14.0)
resque_mailer
rest-client
rpm_contrib
rspec-rails (>= 2.5.0)
ruby-debug19
sanitize
shoulda
thinking-sphinx!
timeliness
tire
tolk!
unicorn
valium
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin_posts_controller.rb
Expand Up @@ -29,6 +29,7 @@ def show
@admin_post = AdminPost.find(params[:id])
@commentable = @admin_post
@comments = @admin_post.comments
@page_subtitle = @admin_post.title
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @admin_post }
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -292,6 +292,10 @@ def see_adult?
return true if current_user.preference && current_user.preference.adult
return false
end

def use_caching?
%w(staging production).include?(Rails.env) && @admin_settings.enable_test_caching?
end

protected

Expand Down Expand Up @@ -364,7 +368,7 @@ def valid_sort_column(param, model='work')
elsif model.to_s.downcase == 'tag'
allowed = ['name', 'created_at', 'suggested_fandoms', 'taggings_count']
elsif model.to_s.downcase == 'collection'
allowed = ['collections.title', 'collections.created_at', 'item_count']
allowed = ['collections.title', 'collections.created_at']
elsif model.to_s.downcase == 'prompt'
allowed = %w(fandom created_at prompter)
elsif model.to_s.downcase == 'claim'
Expand Down
158 changes: 76 additions & 82 deletions app/controllers/bookmarks_controller.rb
@@ -1,5 +1,6 @@
class BookmarksController < ApplicationController
before_filter :load_collection
before_filter :load_owner, :only => [ :index ]
before_filter :load_bookmarkable, :only => [ :index, :new, :create, :fetch_recent, :hide_recent ]
before_filter :users_only, :only => [:new, :create, :edit, :update]
before_filter :check_user_status, :only => [:new, :create, :edit, :update]
Expand Down Expand Up @@ -27,103 +28,56 @@ def load_bookmark
end

def search
@query = {}
if params[:query]
@query = Query.standardize(params[:query])
begin
page = params[:page] || 1
errors, @bookmarks = Query.search_with_sphinx(Bookmark, @query, page)
setflash; flash.now[:error] = errors.join(" ") unless errors.blank?
rescue Riddle::ConnectionError
setflash; flash.now[:error] = ts("The search engine seems to be down at the moment, sorry!")
@languages = Language.default_order
options = params[:bookmark_search] || {}
options.merge!(page: params[:page]) if params[:page].present?
options[:show_private] = false
options[:show_restricted] = current_user.present?
@search = BookmarkSearch.new(options)
@page_subtitle = ts("Search Bookmarks")
if params[:bookmark_search].present? && params[:edit_search].blank?
if @search.query.present?
@page_subtitle = ts("Bookmarks Matching '%{query}'", query: @search.query)
end
@bookmarks = @search.search_results
render 'search_results'
end
end
end


# aggregates bookmarks for the same bookmarkable
# note, these do not show private bookmarks
# GET /bookmarks
# GET /tags/:tag_id/bookmarks
# non aggregates - show all bookmarks, even duplicates and private
# GET /collections/:collection_id/bookmarks
# GET /users/:user_id/pseuds/:pseud_id/bookmarks
# GET /users/:user_id/bookmarks
# GET /works/:work_id/bookmarks
# GET /external_works/:external_work_id/bookmarks
# GET /series/:series/bookmarks
# TODO needs a complete overhaul. using reject is a performance killer
def index
if @bookmarkable
access_denied unless is_admin? || @bookmarkable.visible
end
if params[:user_id]
# @user is needed in the sidebar
owner = @user = User.find_by_login(params[:user_id])
@page_subtitle = ts("by ") + @user.login if @user
if params[:pseud_id] && @user
# @author is needed in the sidebar
owner = @author = @user.pseuds.find_by_name(params[:pseud_id])
@page_subtitle = ts("by ") + @author.byline if @author
end
elsif params[:tag_id]
owner ||= Tag.find_by_name(params[:tag_id])
@page_subtitle = owner.name if owner
elsif @collection
@page_subtitle = @collection.title
owner ||= @collection # insufficient to filter out unapproved bookmarks, see below
@bookmarks = @bookmarkable.bookmarks.is_public.paginate(:page => params[:page], :per_page => ArchiveConfig.ITEMS_PER_PAGE)
else
owner ||= @bookmarkable
end
if params[:user_id] || params[:work_id] || params[:external_work_id] || params[:series_id] || params[:collection_id]
unless owner
# we have to manually trigger a 404 when we're using find_by_name
# otherwise the user gets a 500 error
raise ActiveRecord::RecordNotFound
end

# Do not aggregate bookmarks on these pages
if params[:collection_id] && @collection
@bookmarks = Bookmark.in_collection(@collection)
if params[:bookmark_search].present?
options = params[:bookmark_search].dup
else
@bookmarks= owner.bookmarks
options = {}
end

if @user && @user == current_user
# can see all own bookmarks
elsif logged_in_as_admin?
@bookmarks = @bookmarks.visible_to_admin
elsif logged_in?
@bookmarks = @bookmarks.visible_to_registered_user
else
@bookmarks = @bookmarks.visible_to_all
end
else
setflash; flash.now[:notice] = ts("Bookmark pages are currently being reworked. Apologies for the inconvenience!")
if params[:tag_id] # tag page
unless owner
raise ActiveRecord::RecordNotFound, "Couldn't find tag named '#{params[:tag_id]}'"
options[:show_private] = (@user.present? && @user == current_user)
options[:show_restricted] = current_user.present?

options.merge!(page: params[:page])
@page_subtitle = index_page_title

if @owner.present?
if @admin_settings.disable_filtering?
@bookmarks = Bookmark.list_without_filters(@owner, options)
else
@search = BookmarkSearch.new(options.merge(faceted: true, bookmarks_parent: @owner))
results = @search.search_results
@bookmarks = @search.search_results
@facets = @bookmarks.facets
end
@bookmarks = owner.bookmarks
else # main page
@most_recent_bookmarks = true
@bookmarks = Bookmark.recent.visible_to_user(current_user)
if params[:recs_only]
@page_subtitle = ts("recs")
elsif use_caching?
@bookmarks = Rails.cache.fetch("bookmarks/index/latest/v1", :expires_in => 10.minutes) do
Bookmark.latest.to_a
end
end
if logged_in_as_admin?
@bookmarks = @bookmarks.visible_to_admin
elsif logged_in?
@bookmarks = @bookmarks.visible_to_registered_user
else
@bookmarks = @bookmarks.visible_to_all
@bookmarks = Bookmark.latest.to_a
end
end
if params[:recs_only]
@bookmarks = @bookmarks.recs
end
@bookmarks = @bookmarks.paginate(:page => params[:page])
end

# GET /:locale/bookmark/:id
Expand Down Expand Up @@ -216,4 +170,44 @@ def hide_recent
@bookmarkable = @bookmark.bookmarkable
end

protected

def load_owner
if params[:user_id].present?
@user = User.find_by_login(params[:user_id])
if params[:pseud_id].present?
@pseud = @user.pseuds.find_by_name(params[:pseud_id])
end
end
if params[:tag_id]
@tag = Tag.find_by_name(params[:tag_id])
unless @tag.canonical?
if @tag.merger.present?
redirect_to tag_bookmarks_path(@tag.merger) and return
else
redirect_to tag_path(@tag) and return
end
end
end
@owner = @bookmarkable || @pseud || @user || @collection || @tag
end

def index_page_title
if @owner.present?
owner_name = case @owner.class.to_s
when 'Pseud'
@owner.name
when 'User'
@owner.login
when 'Collection'
@owner.title
else
@owner.try(:name)
end
"#{owner_name} - Bookmarks".html_safe
else
"Latest Bookmarks"
end
end

end
2 changes: 1 addition & 1 deletion app/controllers/invite_requests_controller.rb
Expand Up @@ -26,7 +26,7 @@ def show
def create
@invite_request = InviteRequest.new(params[:invite_request])
if @invite_request.save
setflash; flash[:notice] = "You've been added to our queue! Yay! We estimate that you'll receive an invitation around #{@invite_request.proposed_fill_date}."
setflash; flash[:notice] = "You've been added to our queue! Yay! We estimate that you'll receive an invitation around #{@invite_request.proposed_fill_date}. We strongly recommend that you add do-not-reply@archiveofourown.org to your address book to prevent the invitation email from getting blocked as spam by your email provider."
redirect_to invite_requests_path
else
render :action => :index
Expand Down
1 change: 1 addition & 0 deletions app/controllers/media_controller.rb
Expand Up @@ -16,6 +16,7 @@ def index
Fandom.public_top(5).find(:all, :joins => :common_taggings, :conditions => {:canonical => true, :common_taggings => {:filterable_id => medium.id, :filterable_type => 'Tag'}})
end
end
@page_subtitle = ts("Fandoms")
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/orphans_controller.rb
Expand Up @@ -15,7 +15,7 @@ def load_orphans
@pseuds = (current_user.pseuds & work.pseuds)
@orphans = [work]
elsif params[:work_ids]
@orphans = Work.joins(:pseuds => :user).where("users.id = ?", current_user.id).where(:id => params[:work_ids])
@orphans = Work.joins(:pseuds => :user).where("users.id = ?", current_user.id).where(:id => params[:work_ids]).readonly(false)
@pseuds = current_user.pseuds & (@orphans.collect(&:pseuds).flatten)
elsif params[:series_id]
series = Series.find(params[:series_id])
Expand Down

0 comments on commit 4c2f1a2

Please sign in to comment.