Permalink
Browse files

Merge branch 'dev' into fixes-for-search-as-new-question

Conflicts:
	app/controllers/searches_controller.rb
	app/stylesheets/themes/plain/_base.sass
  • Loading branch information...
2 parents e3f8c75 + e1a5292 commit 51b8ec57d29788b6c7f0193f76d30f29f469a12e @mpereira mpereira committed Nov 17, 2011
Showing with 945 additions and 308 deletions.
  1. +2 −1 Gemfile
  2. +11 −4 Gemfile.lock
  3. +4 −0 app/controllers/answers_controller.rb
  4. +8 −2 app/controllers/application_controller.rb
  5. +107 −0 app/controllers/auth_callback_controller.rb
  6. +17 −1 app/controllers/comments_controller.rb
  7. +8 −6 app/controllers/questions_controller.rb
  8. +1 −4 app/controllers/search_results_controller.rb
  9. +8 −1 app/controllers/searches_controller.rb
  10. +0 −40 app/controllers/settings/external_accounts_controller.rb
  11. +1 −0 app/controllers/signup_wizard_controller.rb
  12. +13 −2 app/controllers/topics_controller.rb
  13. +1 −0 app/controllers/url_invitations_controller.rb
  14. +2 −1 app/controllers/users_controller.rb
  15. +2 −0 app/controllers/votes_controller.rb
  16. +30 −16 app/models/answer.rb
  17. +0 −2 app/models/comment.rb
  18. +1 −3 app/models/news_item.rb
  19. +0 −1 app/models/question.rb
  20. +5 −9 app/models/search_result.rb
  21. +21 −1 app/models/user.rb
  22. +2 −5 app/stylesheets/_base.sass
  23. +8 −5 app/stylesheets/application.sass
  24. +1 −1 app/stylesheets/inline_edition.sass
  25. +25 −4 app/stylesheets/landing.sass
  26. +33 −0 app/stylesheets/partials/_facebook.scss
  27. +6 −0 app/stylesheets/themes/plain/_base.sass
  28. +26 −0 app/stylesheets/themes/plain/_questions.sass
  29. +2 −1 app/stylesheets/themes/plain/_sidebar.sass
  30. +3 −0 app/stylesheets/themes/plain/_users.sass
  31. +4 −0 app/views/answers/show.html.haml
  32. +15 −0 app/views/auth_callback/signup_with_provider.html.haml
  33. +0 −14 app/views/comments/_comment.html.haml
  34. +11 −2 app/views/comments/_count.html.haml
  35. +8 −5 app/views/comments/_form.html.haml
  36. +21 −0 app/views/comments/_inline_form.html.haml
  37. +1 −0 app/views/layouts/application.html.haml
  38. +1 −0 app/views/layouts/welcome.html.haml
  39. +1 −1 app/views/questions/_answer.html.haml
  40. +43 −27 app/views/questions/_answer_with_form.html.haml
  41. +5 −0 app/views/questions/_form.html.haml
  42. +1 −5 app/views/questions/_new_follow_up_question.text.erb
  43. +1 −1 app/views/questions/edit.html.haml
  44. +12 −14 app/views/questions/show.html.haml
  45. +22 −6 app/views/search_results/_form.html.haml
  46. +7 −5 app/views/search_results/_search_result.html.haml
  47. +5 −4 app/views/searches/search_as_new_question.html.haml
  48. +4 −12 app/views/shared/_analytics.haml
  49. +23 −2 app/views/shared/_comments.html.haml
  50. +3 −6 app/views/shared/_other_actions.html.haml
  51. +4 −0 app/views/signup_wizard/wizard.html.haml
  52. +2 −6 app/views/topics/_common.html.haml
  53. +4 −0 app/views/topics/show.html.haml
  54. +3 −0 app/views/users/_form_signup.html.haml
  55. +1 −1 app/views/users/_news_update.html.haml
  56. +2 −1 app/views/users/_profile_common.html.haml
  57. +6 −3 app/views/users/_signup.html.haml
  58. +4 −4 app/views/users/_user_bar.html.haml
  59. +2 −2 app/views/welcome/_news_item.html.haml
  60. +9 −0 app/views/welcome/landing.html.haml
  61. +4 −0 config/initializers/04_airbrake.rb
  62. +0 −4 config/initializers/04_hoptoad.rb
  63. +2 −2 config/initializers/delayed_job_config.rb
  64. +2 −1 config/locales/answers/en.yml
  65. +2 −1 config/locales/answers/pt-BR.yml
  66. +4 −0 config/locales/auth_callback/en.yml
  67. +4 −0 config/locales/auth_callback/pt-BR.yml
  68. +5 −1 config/locales/comments/en.yml
  69. +4 −0 config/locales/comments/pt-BR.yml
  70. +2 −2 config/locales/devise/devise.en.yml
  71. +1 −1 config/locales/global/en.yml
  72. +4 −4 config/locales/layouts/en.yml
  73. +1 −1 config/locales/questions/en.yml
  74. +2 −0 config/locales/search_results/en.yml
  75. +2 −0 config/locales/search_results/pt-BR.yml
  76. +6 −6 config/locales/sessions/en.yml
  77. +1 −1 config/locales/shared/en.yml
  78. +1 −1 config/locales/url_invitations/en.yml
  79. +1 −1 config/locales/url_invitations/pt-BR.yml
  80. +1 −0 config/locales/users/en.yml
  81. +3 −0 config/locales/users/pt-BR.yml
  82. +1 −0 config/locales/welcome/en.yml
  83. +1 −0 config/locales/welcome/pt-BR.yml
  84. +5 −3 config/routes.rb
  85. +0 −5 experiments/answer_with_form_position.rb
  86. +4 −0 experiments/inline_comment_helpers.rb
  87. +5 −0 experiments/link_only_answer_form.rb
  88. +3 −0 experiments/metrics/clicked_search_result.rb
  89. +3 −0 experiments/metrics/commented.rb
  90. +0 −3 experiments/metrics/search_results_news_items.rb
  91. +3 −0 experiments/metrics/signed_up_action.rb
  92. +0 −3 experiments/metrics/signup_method.rb
  93. +3 −0 experiments/metrics/used_today.rb
  94. +3 −0 experiments/metrics/voted.rb
  95. +1 −1 experiments/new_question_as_search.rb
  96. +1 −1 experiments/news_items_search_results_helpers.rb
  97. +1 −0 experiments/question_responding_helpers.rb
  98. +6 −0 experiments/sign_in_with_facebook.rb
  99. +0 −5 experiments/signup_method_helpers.rb
  100. +27 −0 lib/support/embedly.rb
  101. +6 −4 lib/support/response_fetcher.rb
  102. +1 −17 lib/tasks/data_migrations.rake
  103. +12 −1 lib/tasks/deploy.rake
  104. +20 −0 lib/tasks/news_items.rake
  105. +42 −0 lib/tasks/search_results.rake
  106. +109 −0 lib/tasks/topics.rake
  107. +3 −1 lib/umamao.rb
  108. +5 −2 public/javascripts/i18n/en.js
  109. +4 −1 public/javascripts/i18n/pt-BR.js
  110. +3 −3 public/javascripts/modules/inline_edition.js
  111. +48 −1 public/javascripts/modules/show_question.js
View
@@ -14,6 +14,7 @@ group :development do
gem 'yaml_waml', '0.3.0'
end
+gem 'airbrake', '3.0.5'
gem 'bitly'
gem 'bson_ext', :require => 'bson'
gem 'carrierwave' # file upload manager
@@ -30,11 +31,11 @@ gem 'faker'
gem 'fog' # connect to storage services such as cloudfiles
gem 'goalie'
gem 'haml', '~> 3.1.1'
-gem 'hoptoad_notifier'
gem 'jammit', '~>0.6.0'
gem 'jnunemaker-validatable', :require => 'validatable', :git => "git://github.com/umamao/validatable.git"
gem 'jquery-rails'
gem 'koala', '~> 0.10.0'
+gem 'language_detector', '0.1.2', :git => 'https://github.com/feedbackmine/language_detector.git'
gem 'mechanize', :require => false
gem 'mongo'
gem 'mongo_mapper', :git => 'git://github.com/umamao/mongomapper.git'
View
@@ -97,6 +97,12 @@ GIT
jnunemaker-validatable (1.8.4)
activesupport (>= 2.3.4)
+GIT
+ remote: https://github.com/feedbackmine/language_detector.git
+ revision: 89102790194150b3a8110ce691f9989b8ce70f8d
+ specs:
+ language_detector (0.1.2)
+
GEM
remote: http://gemcutter.org/
specs:
@@ -108,6 +114,9 @@ GEM
ZenTest (4.5.0)
abstract (1.0.0)
addressable (2.2.4)
+ airbrake (3.0.5)
+ activesupport
+ builder
arel (2.0.9)
autotest-rails (4.1.0)
ZenTest
@@ -209,9 +218,6 @@ GEM
mime-types (~> 1.15)
haml (3.1.1)
hashie (1.0.0)
- hoptoad_notifier (2.4.9)
- activesupport
- builder
httparty (0.7.4)
crack (= 0.1.8)
i18n (0.5.0)
@@ -388,6 +394,7 @@ PLATFORMS
DEPENDENCIES
RedCloth (~> 4.1.1)
+ airbrake (= 3.0.5)
autotest-rails
bitly
bson_ext
@@ -416,11 +423,11 @@ DEPENDENCIES
goalie
grit
haml (~> 3.1.1)
- hoptoad_notifier
jammit (~> 0.6.0)
jnunemaker-validatable!
jquery-rails
koala (~> 0.10.0)
+ language_detector (= 0.1.2)!
launchy
mechanize
mongo
@@ -143,6 +143,10 @@ def create
def edit
@question = @answer.question
+ unless current_user.can_modify?(@answer)
+ redirect_to [@question, @answer]
+ return
+ end
end
def update
@@ -40,9 +40,14 @@ def _vanity_identity
# This identifier recognizes untracked users' identities via cookies even if
# they're not logged in. It's used in our vanity experiment files.
- def identify_vanity
- if identity = _vanity_identity
+ #
+ # Options:
+ # exclude_guests: don't track non-logged visitors _at all_.
+ def identify_vanity(options = {})
+ if (identity = _vanity_identity) && !options[:preserve_identity]
identity.id
+ elsif options[:exclude_guests]
+ Umamao::UntrackedUser.instance.id
else
set_vanity_cookie(SecureRandom.hex(16)) unless cookies[:vanity_id]
cookies[:vanity_id]
@@ -189,6 +194,7 @@ def track_user
handle_event_tracking = lambda do |event|
Rails.cache.write(key, Date.today.to_s)
track_event(:used_today)
+ track_bingo(:used_today)
end
if last_day_used_at = Rails.cache.read(key)
if last_day_used_at != Date.today.to_s
@@ -0,0 +1,107 @@
+class AuthCallbackController < ApplicationController
+ respond_to :html
+ before_filter :login_required, :only => :create_external_account
+
+ def callback
+ auth_hash = request.env['omniauth.auth']
+ if not user_signed_in? && auth_hash['provider'] == 'facebook'
+ signup_with_provider
+ else
+ create_external_account
+ end
+ end
+
+ def failure
+ respond_to do |format|
+ format.html { redirect_to session["omniauth_return_url"] }
+ end
+ end
+
+ def create_external_account
+ auth_hash = request.env['omniauth.auth']
+
+ if session["umamao.topic_id"].present? &&
+ auth_hash.present? && auth_hash["provider"] == "twitter"
+ # Associate this Twitter account with a Topic.
+ topic = Topic.find_by_slug_or_id(session.delete("umamao.topic_id"))
+ raise Goalie::NotFound if topic.blank?
+ TopicExternalAccount.create(auth_hash.merge(:topic => topic))
+ redirect_to topic_path(topic)
+ return
+ end
+
+ if request.env['omniauth.error.type'].present?
+ respond_to do |format|
+ flash[:error] = I18n.t("external_accounts.connection_error")
+ format.html { redirect_to session["omniauth_return_url"] }
+ end
+ return
+ end
+
+ unless @external_account = UserExternalAccount.find_from_hash(auth_hash)
+ @external_account =
+ UserExternalAccount.create(auth_hash.merge(:user => current_user))
+ end
+
+ if @external_account && @external_account.user.id == current_user.id
+ respond_with(@external_account, :status => :created) do |format|
+ track_event("connected_#{@external_account.provider}".to_sym)
+ flash[:connected_to] = @external_account.provider
+ format.html { redirect_to session["omniauth_return_url"] }
+ end
+ else
+ flash[:error] = I18n.t("external_accounts.connection_error")
+ redirect_to session["omniauth_return_url"]
+ end
+ end
+
+ def signup_with_provider
+ auth_hash = request.env['omniauth.auth']
+
+ user_info = auth_hash["user_info"]
+ email = user_info["email"]
+ user = User.find_by_email(email)
+
+ if user
+ if user.external_accounts.first(:provider => auth_hash['provider'])
+ sign_in user
+ redirect_to root_path
+ else
+ session["omniauth-hash"] = auth_hash
+ @email = auth_hash["user_info"]["email"]
+ @user = User.new
+ render :signup_with_provider
+ end
+ else
+ if session['sign_up_allowed']
+ if user = User.create_with_provider(auth_hash)
+ track_bingo(:signed_up_action)
+
+ sign_in user
+ redirect_to wizard_path("follow")
+ else
+ head(:unprocessable_entity)
+ end
+ else
+ flash[:error] = I18n.t("welcome.landing.invitation_only")
+ redirect_to root_path
+ end
+ end
+ end
+
+ def sign_in_and_associate_provider
+ auth_hash = session['omniauth-hash']
+ user = User.find_by_email(auth_hash["user_info"]["email"])
+ if user.valid_password?(params[:user][:password])
+ session.delete('omniauth-hash')
+ sign_in user
+ UserExternalAccount.create(auth_hash.merge(:user => user))
+ redirect_to root_url
+ else
+ flash[:error] = I18n.t('auth_callback.invalid_password')
+ @email = auth_hash["user_info"]["email"]
+ @user = User.new
+ render :signup_with_provider
+ end
+ end
+end
@@ -4,6 +4,8 @@ class CommentsController < ApplicationController
before_filter :check_permissions, :except => [:create]
def create
+ track_bingo(:commented)
+
@comment = Comment.new
@comment.body = params[:body]
@comment.commentable = scope
@@ -42,7 +44,9 @@ def create
}),
:count => render_to_string(:partial => "comments/count",
:locals => {
- :commentable => @comment.commentable
+ :commentable => @comment.commentable,
+ :inline => @comment.commentable.is_a?(SearchResult) &&
+ ab_test(:inline_comment_helpers) == :inline
})
}.to_json)
end
@@ -64,6 +68,18 @@ def create
def edit
@comment = current_scope.find(params[:id])
+ unless current_user.can_modify?(@comment)
+ format.html do
+ redirect_to [@comment.commentable, @comment]
+ end
+ format.js do
+ render :json => {:status => :error,
+ :message => t("global.permission_denied")
+ }
+ end
+ return
+ end
+
raise Goalie::NotFound unless @comment
respond_to do |format|
@@ -149,10 +149,6 @@ def show
return
end
- if params[:r].present?
- track_bingo(:search_results_news_items)
- end
-
if params[:group_invitation]
session[:group_invitation] = params[:group_invitation]
end
@@ -190,8 +186,9 @@ def show
# GET /questions/new.xml
def new
if ab_test(:new_question_as_search) == :new_search_scheme
- if params[:question] && params[:question][:title].present?
- redirect_to search_path(:q => params[:question][:title])
+ if params[:question].present?
+ redirect_to search_path(:q => params[:question].delete(:title),
+ :question => params[:question])
else
redirect_to root_path
end
@@ -210,6 +207,11 @@ def new
# GET /questions/1/edit
def edit
+ @question = Question.find_by_slug_or_id(params[:id])
+ unless current_user.can_modify?(@question)
+ redirect_to @question
+ return
+ end
end
# POST /questions
@@ -2,14 +2,11 @@ class SearchResultsController < ApplicationController
before_filter :login_required, :only => [:create, :destroy, :flag]
def show
- if params[:r].present?
- track_bingo(:search_results_news_items)
- end
-
@search_result = SearchResult.find_by_id(params[:search_result_id])
track_event(:clicked_search_result,
:search_result_id => @search_result.id,
:url => @search_result.url)
+ track_bingo(:clicked_search_result)
redirect_to(@search_result.url)
end
@@ -1,7 +1,7 @@
class SearchesController < ApplicationController
def index
- if params[:q].blank?
+ if params[:q].blank? && params[:question].blank?
redirect_to root_path
return
end
@@ -10,6 +10,13 @@ def index
if ab_test(:new_question_as_search) == :new_search_scheme
@question = Question.new(params[:q] ? { :title => params[:q] } : {})
+ # FIXME: rearrange logic.
+ if params[:question].present?
+ @question.safe_update(%w[body parent_question_id], params[:question])
+ end
+ if @question.parent_question_id
+ @question.topics = Question.find_by_id(@question.parent_question_id).topics
+ end
@bing_results = Support::Bing.search(@question.title, :max_results => 10)
end
@@ -7,51 +7,11 @@ class Settings::ExternalAccountsController < ApplicationController
def index
end
- def create
- auth_hash = request.env['omniauth.auth']
-
- if session["umamao.topic_id"].present? &&
- auth_hash.present? && auth_hash["provider"] == "twitter"
- # Associate this Twitter account with a Topic.
- topic = Topic.find_by_slug_or_id(session.delete("umamao.topic_id"))
- raise Goalie::NotFound if topic.blank?
- TopicExternalAccount.create(auth_hash.merge(:topic => topic))
- redirect_to topic_path(topic)
- return
- end
-
- if request.env['omniauth.error.type'].present?
- respond_to do |format|
- flash[:error] = I18n.t("external_accounts.connection_error")
- format.html { redirect_to session["omniauth_return_url"] }
- end
- return
- end
-
- unless @external_account = UserExternalAccount.find_from_hash(auth_hash)
- @external_account =
- UserExternalAccount.create(auth_hash.merge(:user => current_user))
- end
-
- respond_with(@external_account, :status => :created) do |format|
- track_event("connected_#{@external_account.provider}".to_sym)
- flash[:connected_to] = @external_account.provider
- format.html { redirect_to session["omniauth_return_url"] }
- end
- end
-
- def failure
- respond_to do |format|
- format.html { redirect_to session["omniauth_return_url"] }
- end
- end
-
def destroy
@external_account = ExternalAccount.find(params[:id])
@external_account.destroy
respond_with(@external_account, :status => :ok) do |format|
format.html { redirect_to session["omniauth_return_url"] }
end
end
-
end
@@ -8,6 +8,7 @@ def wizard
current_user.save!
redirect_to root_path
else
+ @current_step = params[:current_step]
render :layout => "welcome"
end
end
Oops, something went wrong.

0 comments on commit 51b8ec5

Please sign in to comment.