From 97086a8a9a8e14243b67b5638d17765bc704290f Mon Sep 17 00:00:00 2001 From: Andreas N Date: Fri, 2 Jan 2015 01:09:04 +0100 Subject: [PATCH 01/24] add privacy tab --- app/views/user/_settings_tabs.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/user/_settings_tabs.html.haml b/app/views/user/_settings_tabs.html.haml index a58d3517..85aa90d5 100644 --- a/app/views/user/_settings_tabs.html.haml +++ b/app/views/user/_settings_tabs.html.haml @@ -4,6 +4,8 @@ %ul.nav.nav-pills.nav-stacked = nav_entry "Account", edit_user_registration_path = nav_entry "Profile", edit_user_profile_path + = nav_entry "Privacy", "#" = nav_entry "Sharing", services_path + .hidden-xs= render "shared/links" \ No newline at end of file From 74ece9d971d186f1de6f0222afd236c92a69c7da Mon Sep 17 00:00:00 2001 From: nilsding Date: Fri, 2 Jan 2015 21:34:56 +0100 Subject: [PATCH 02/24] added privacy setting routes this took me longer than it should have taken --- app/controllers/user_controller.rb | 6 +++++- app/views/user/_settings_tabs.html.haml | 2 +- app/views/user/privacy.html.haml | 6 ++++++ config/routes.rb | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 app/views/user/privacy.html.haml diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 8124e1e8..ee51b783 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,5 +1,5 @@ class UserController < ApplicationController - before_filter :authenticate_user!, only: %w(edit update) + before_filter :authenticate_user!, only: %w(edit update privacy) def show @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! @@ -26,6 +26,10 @@ class UserController < ApplicationController redirect_to edit_user_profile_path end + def privacy + + end + def followers @title = 'Followers' @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! diff --git a/app/views/user/_settings_tabs.html.haml b/app/views/user/_settings_tabs.html.haml index 85aa90d5..05450613 100644 --- a/app/views/user/_settings_tabs.html.haml +++ b/app/views/user/_settings_tabs.html.haml @@ -4,7 +4,7 @@ %ul.nav.nav-pills.nav-stacked = nav_entry "Account", edit_user_registration_path = nav_entry "Profile", edit_user_profile_path - = nav_entry "Privacy", "#" + = nav_entry "Privacy", privacy_settings_path = nav_entry "Sharing", services_path diff --git a/app/views/user/privacy.html.haml b/app/views/user/privacy.html.haml new file mode 100644 index 00000000..4ae256cc --- /dev/null +++ b/app/views/user/privacy.html.haml @@ -0,0 +1,6 @@ +.container.j2-page + = render 'settings_tabs' + .col-md-9.col-xs-12.col-sm-9 + = render 'layouts/messages' + .panel.panel-default + .panel-body \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 49f115f0..df5ef086 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,6 +57,8 @@ Rails.application.routes.draw do end end + match '/settings/privacy', to: 'user#privacy', via: :get, as: :privacy_settings + namespace :ajax do match '/ask', to: 'question#create', via: :post, as: :ask match '/answer', to: 'inbox#destroy', via: :post, as: :answer From 4fc98d598029693bc3034a98be39cccf05fd8ae1 Mon Sep 17 00:00:00 2001 From: Andreas N Date: Sat, 3 Jan 2015 16:51:00 +0100 Subject: [PATCH 03/24] added sweetalert-rails --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index e4a65239..ecfc613b 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem 'bcrypt', '~> 3.1.7' gem 'haml' gem 'bootstrap-sass', '~> 3.2.0.1' gem 'bootswatch-rails' +gem 'sweetalert-rails' gem 'will_paginate' gem 'will_paginate-bootstrap' gem 'http_accept_language' From c6e7170e7b7c47d342d52354d8e4301001748ef0 Mon Sep 17 00:00:00 2001 From: Andreas N Date: Sat, 3 Jan 2015 16:51:57 +0100 Subject: [PATCH 04/24] added sweetalert styles --- app/assets/stylesheets/application.css.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index e88e57cc..ef3390d7 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -3,6 +3,8 @@ *= require growl *= require jquery.guillotine *= require_self + *= require sweet-alert + *= require_tree . */ @import url(https://fonts.googleapis.com/css?family=Exo+2:400,700); From ac9738d058957042bb76b208963f7554648ca18f Mon Sep 17 00:00:00 2001 From: Andreas N Date: Sat, 3 Jan 2015 16:54:10 +0100 Subject: [PATCH 05/24] added sweetalert scripts --- app/assets/javascripts/application.js.erb.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/application.js.erb.coffee b/app/assets/javascripts/application.js.erb.coffee index ef98ffe4..0b74905a 100644 --- a/app/assets/javascripts/application.js.erb.coffee +++ b/app/assets/javascripts/application.js.erb.coffee @@ -8,6 +8,7 @@ #= require growl #= require cheet #= require jquery.guillotine +#= require sweet-alert #= require_tree . NProgress.configure From 9d3b8cced414091ce0b153de4171d443c8a5c916 Mon Sep 17 00:00:00 2001 From: Andreas N Date: Sat, 3 Jan 2015 17:36:55 +0100 Subject: [PATCH 06/24] replaced alerts with sweetAlert --- Gemfile.lock | 3 +++ .../answerbox/comment/destroy.coffee | 9 +++++++++ .../answerbox/comment/report.coffee | 10 +++++++++- .../javascripts/answerbox/destroy.coffee | 10 +++++++++- .../javascripts/answerbox/report.coffee | 10 +++++++++- app/assets/javascripts/inbox.coffee | 20 +++++++++++++++++-- .../javascripts/moderation/comment.coffee | 10 +++++++++- .../javascripts/moderation/destroy.coffee | 10 +++++++++- 8 files changed, 75 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 165fe918..9e09452c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -298,6 +298,8 @@ GEM colorize (>= 0.7.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) + sweetalert-rails (0.3.3) + railties (>= 3.1.0) thin (1.6.3) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0) @@ -387,6 +389,7 @@ DEPENDENCIES simplecov sinatra spring + sweetalert-rails thin turbolinks twitter diff --git a/app/assets/javascripts/answerbox/comment/destroy.coffee b/app/assets/javascripts/answerbox/comment/destroy.coffee index 19de53e5..ac89bef3 100644 --- a/app/assets/javascripts/answerbox/comment/destroy.coffee +++ b/app/assets/javascripts/answerbox/comment/destroy.coffee @@ -1,5 +1,14 @@ $(document).on "click", "a[data-action=ab-comment-destroy]", (ev) -> ev.preventDefault() + swal + title: "Are you sure?" + text: "You will not be able to recover this!" + type: "warning" + showCancelButton: true + confirmButtonColor: "#DD6B55" + confirmButtonText: "Yes, delete it!" + closeOnConfirm: false + , -> if confirm 'Are you sure?' btn = $(this) cid = btn[0].dataset.cId diff --git a/app/assets/javascripts/answerbox/comment/report.coffee b/app/assets/javascripts/answerbox/comment/report.coffee index 3f407a69..e21e7071 100644 --- a/app/assets/javascripts/answerbox/comment/report.coffee +++ b/app/assets/javascripts/answerbox/comment/report.coffee @@ -1,6 +1,14 @@ $(document).on "click", "a[data-action=ab-comment-report]", (ev) -> ev.preventDefault() - if confirm 'Are you sure you want to report this comment?' + swal + title: "Report?" + text: "A moderator will check this and decide what happens!" + type: "warning" + showCancelButton: true + confirmButtonColor: "#DD6B55" + confirmButtonText: "Report!" + closeOnConfirm: false + , -> btn = $(this) cid = btn[0].dataset.cId $.ajax diff --git a/app/assets/javascripts/answerbox/destroy.coffee b/app/assets/javascripts/answerbox/destroy.coffee index a26214a1..4ec5e38e 100644 --- a/app/assets/javascripts/answerbox/destroy.coffee +++ b/app/assets/javascripts/answerbox/destroy.coffee @@ -1,6 +1,14 @@ $(document).on "click", "a[data-action=ab-destroy]", (ev) -> ev.preventDefault() - if confirm 'Are you sure?' + swal + title: "Are you sure?" + text: "You will not be able to recover this!" + type: "warning" + showCancelButton: true + confirmButtonColor: "#DD6B55" + confirmButtonText: "Yes, delete it!" + closeOnConfirm: false + , -> btn = $(this) aid = btn[0].dataset.aId $.ajax diff --git a/app/assets/javascripts/answerbox/report.coffee b/app/assets/javascripts/answerbox/report.coffee index bacf29c1..804aa1bd 100644 --- a/app/assets/javascripts/answerbox/report.coffee +++ b/app/assets/javascripts/answerbox/report.coffee @@ -1,6 +1,14 @@ $(document).on "click", "a[data-action=ab-report]", (ev) -> ev.preventDefault() - if confirm 'Are you sure you want to report this answer?' + swal + title: "Report?" + text: "A moderator will check this and decide what happens!" + type: "warning" + showCancelButton: true + confirmButtonColor: "#DD6B55" + confirmButtonText: "Report!" + closeOnConfirm: false + , -> btn = $(this) aid = btn[0].dataset.aId $.ajax diff --git a/app/assets/javascripts/inbox.coffee b/app/assets/javascripts/inbox.coffee index 14c835e2..9347891e 100644 --- a/app/assets/javascripts/inbox.coffee +++ b/app/assets/javascripts/inbox.coffee @@ -22,7 +22,15 @@ ($ document).on "click", "button#ib-delete-all", -> btn = ($ this) count = btn[0].dataset.ibCount - if confirm "Really delete #{count} questions?" + swal + title: "Really delete #{count} questions??" + text: "You will not be able to recover them!" + type: "warning" + showCancelButton: true + confirmButtonColor: "#DD6B55" + confirmButtonText: "Yes, delete all!" + closeOnConfirm: false + , -> btn.button "loading" succ = no $.ajax @@ -84,7 +92,15 @@ $(document).on "click", "button[name=ib-answer]", -> $(document).on "click", "button[name=ib-destroy]", -> - if confirm 'Are you sure?' + swal + title: "Are you sure?" + text: "You will not be able to recover this question!" + type: "warning" + showCancelButton: true + confirmButtonColor: "#DD6B55" + confirmButtonText: "Yes, delete it!" + closeOnConfirm: false + , -> btn = $(this) btn.button "loading" iid = btn[0].dataset.ibId diff --git a/app/assets/javascripts/moderation/comment.coffee b/app/assets/javascripts/moderation/comment.coffee index 27d7544c..dd8647b8 100644 --- a/app/assets/javascripts/moderation/comment.coffee +++ b/app/assets/javascripts/moderation/comment.coffee @@ -68,7 +68,15 @@ $(document).on "input", "input[name=mod-comment-new]", (evt) -> # destroy $(document).on "click", "a[data-action=mod-comment-destroy]", (ev) -> ev.preventDefault() - if confirm 'Are you sure?' + swal + title: "Are you sure?" + text: "You will not be able to recover this comment!" + type: "warning" + showCancelButton: true + confirmButtonColor: "#DD6B55" + confirmButtonText: "Yes, delete it!" + closeOnConfirm: false + , -> btn = $(this) cid = btn[0].dataset.id $.ajax diff --git a/app/assets/javascripts/moderation/destroy.coffee b/app/assets/javascripts/moderation/destroy.coffee index 728b36f3..75feabc5 100644 --- a/app/assets/javascripts/moderation/destroy.coffee +++ b/app/assets/javascripts/moderation/destroy.coffee @@ -1,5 +1,13 @@ $(document).on "click", "button[name=mod-delete-report]", -> - if confirm 'Are you sure?' + swal + title: "Are you sure?" + text: "You will not be able to recover this!" + type: "warning" + showCancelButton: true + confirmButtonColor: "#DD6B55" + confirmButtonText: "Yes, delete it!" + closeOnConfirm: false + , -> btn = $(this) id = btn[0].dataset.id $.ajax From f5a469bafa6a453736d75cea99b194be9ed7a2c8 Mon Sep 17 00:00:00 2001 From: Andreas N Date: Sat, 3 Jan 2015 18:40:56 +0100 Subject: [PATCH 07/24] fix alert text for destroying answers --- app/assets/javascripts/answerbox/destroy.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/answerbox/destroy.coffee b/app/assets/javascripts/answerbox/destroy.coffee index 4ec5e38e..afe379d2 100644 --- a/app/assets/javascripts/answerbox/destroy.coffee +++ b/app/assets/javascripts/answerbox/destroy.coffee @@ -2,7 +2,7 @@ $(document).on "click", "a[data-action=ab-destroy]", (ev) -> ev.preventDefault() swal title: "Are you sure?" - text: "You will not be able to recover this!" + text: "If you delete this answer it will be moved back to your inbox!" type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" From 72140be316cda22ccaca1a7748f870ad3de5799d Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 19:02:06 +0100 Subject: [PATCH 08/24] moved answer thing to the bottom --- app/views/question/show.html.haml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/views/question/show.html.haml b/app/views/question/show.html.haml index 4c360262..92ade27f 100644 --- a/app/views/question/show.html.haml +++ b/app/views/question/show.html.haml @@ -14,6 +14,9 @@ ago %p.answerbox--question-text= @question.content + - @answers.each do |a| + = render 'shared/answerbox', a: a, show_question: false + - if user_signed_in? and !current_user.answered? @question .panel.panel-default#q-answer-box .panel-heading @@ -27,8 +30,4 @@ %label %input{type: 'checkbox', name: 'share', checked: :checked, data: { q_id: @question.id, service: service.provider }} Post to - = service.provider.capitalize - - - @answers.each do |a| - = render 'shared/answerbox', a: a, show_question: false - + = service.provider.capitalize \ No newline at end of file From aec3e1c8004b534692b9be37a55da946ade16bd1 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 19:02:56 +0100 Subject: [PATCH 09/24] if a question was answered, all occurrences of it in the inbox are now gone --- app/models/answer.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/answer.rb b/app/models/answer.rb index 917476bd..e346853b 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -5,6 +5,8 @@ class Answer < ActiveRecord::Base has_many :smiles, dependent: :destroy after_create do + Inbox.where(user: self.user, question: self.question).destroy_all + Notification.notify self.question.user, self unless self.question.author_is_anonymous self.user.increment! :answered_count self.question.increment! :answer_count From 9dc98a3e4eb148382cb66cffd3d3ebcf3478ef08 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 19:08:09 +0100 Subject: [PATCH 10/24] users may not not answer their own question --- app/views/question/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/question/show.html.haml b/app/views/question/show.html.haml index 92ade27f..eede0c3e 100644 --- a/app/views/question/show.html.haml +++ b/app/views/question/show.html.haml @@ -17,7 +17,7 @@ - @answers.each do |a| = render 'shared/answerbox', a: a, show_question: false - - if user_signed_in? and !current_user.answered? @question + - if user_signed_in? and !current_user.answered? @question and current_user != @question.user .panel.panel-default#q-answer-box .panel-heading %h3.panel-title This question was not in your inbox? Answer it here! From f53ca1b449300310add53c85b2b0ab170d5e066c Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 19:14:26 +0100 Subject: [PATCH 11/24] the new answer is now shown --- app/assets/javascripts/question.coffee | 3 +-- app/controllers/ajax/answer_controller.rb | 6 +++++- app/views/question/show.html.haml | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/question.coffee b/app/assets/javascripts/question.coffee index 888815db..9cfa2f76 100644 --- a/app/assets/javascripts/question.coffee +++ b/app/assets/javascripts/question.coffee @@ -27,8 +27,7 @@ $(document).on "click", "button#q-answer", -> success: (data, status, jqxhr) -> if data.success $("div#q-answer-box").slideUp() - # TODO: - # ($ "div#q-answer-box").prepend data.render + ($ "div#answers").prepend data.render showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index 45c43ba3..768ba97f 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -38,10 +38,14 @@ class Ajax::AnswerController < ApplicationController services = JSON.parse params[:share] ShareWorker.perform_async(current_user.id, answer.id, services) + @status = :okay @message = "Successfully answered question." @success = true - @render = render_to_string(partial: 'shared/answerbox', locals: { a: answer, show_question: false }) unless inbox + unless inbox + @question = 1 + @render = render_to_string(partial: 'shared/answerbox', locals: { a: answer, show_question: false }) + end end def destroy diff --git a/app/views/question/show.html.haml b/app/views/question/show.html.haml index eede0c3e..e0b681e3 100644 --- a/app/views/question/show.html.haml +++ b/app/views/question/show.html.haml @@ -14,8 +14,9 @@ ago %p.answerbox--question-text= @question.content - - @answers.each do |a| - = render 'shared/answerbox', a: a, show_question: false + #answers + - @answers.each do |a| + = render 'shared/answerbox', a: a, show_question: false - if user_signed_in? and !current_user.answered? @question and current_user != @question.user .panel.panel-default#q-answer-box From 81becddbd56ffa791ed0d955aa738fe3dbb24c06 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 19:24:51 +0100 Subject: [PATCH 12/24] added pagination to answers --- app/controllers/question_controller.rb | 6 +++++- app/views/question/show.html.haml | 6 ++++++ app/views/question/show.js.erb | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 app/views/question/show.js.erb diff --git a/app/controllers/question_controller.rb b/app/controllers/question_controller.rb index 4789a8d2..54fac76c 100644 --- a/app/controllers/question_controller.rb +++ b/app/controllers/question_controller.rb @@ -1,6 +1,10 @@ class QuestionController < ApplicationController def show @question = Question.find(params[:id]) - @answers = @question.answers.reverse_order + @answers = @question.answers.reverse_order.paginate(page: params[:page]) + respond_to do |format| + format.html + format.js + end end end diff --git a/app/views/question/show.html.haml b/app/views/question/show.html.haml index e0b681e3..fe74986c 100644 --- a/app/views/question/show.html.haml +++ b/app/views/question/show.html.haml @@ -18,6 +18,12 @@ - @answers.each do |a| = render 'shared/answerbox', a: a, show_question: false + #pagination= will_paginate @answers, renderer: BootstrapPagination::Rails, page_links: false + + - if @answers.next_page + %button#load-more-btn.btn.btn-default{type: :button, data: { current_page: @answers.current_page }} + Load more + - if user_signed_in? and !current_user.answered? @question and current_user != @question.user .panel.panel-default#q-answer-box .panel-heading diff --git a/app/views/question/show.js.erb b/app/views/question/show.js.erb new file mode 100644 index 00000000..bcaf826e --- /dev/null +++ b/app/views/question/show.js.erb @@ -0,0 +1,8 @@ +$('#answers').append('<% @answers.each do |answer| + %><%= j render 'shared/answerbox', a: answer, show_question: false +%><% end %>'); +<% if @answers.next_page %> + $('#pagination').html('<%= j will_paginate @answers, renderer: BootstrapPagination::Rails, page_links: false %>'); +<% else %> + $('#pagination, #load-more-btn').remove(); +<% end %> \ No newline at end of file From d183a79493409a23ae32aa6d0f210dd41ae50029 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 19:43:51 +0100 Subject: [PATCH 13/24] fixed sweetalert for use with Turbolinks, changed wording --- .../javascripts/answerbox/comment/destroy.coffee | 7 +++---- .../javascripts/answerbox/comment/report.coffee | 6 +++--- app/assets/javascripts/answerbox/destroy.coffee | 6 +++--- app/assets/javascripts/answerbox/report.coffee | 6 +++--- app/assets/javascripts/application.js.erb.coffee | 6 ++++++ app/assets/javascripts/inbox.coffee | 12 ++++++------ app/assets/javascripts/moderation/comment.coffee | 6 +++--- app/assets/javascripts/moderation/destroy.coffee | 6 +++--- app/assets/stylesheets/application.css.scss | 3 +-- 9 files changed, 31 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/answerbox/comment/destroy.coffee b/app/assets/javascripts/answerbox/comment/destroy.coffee index ac89bef3..02cdbea8 100644 --- a/app/assets/javascripts/answerbox/comment/destroy.coffee +++ b/app/assets/javascripts/answerbox/comment/destroy.coffee @@ -1,15 +1,14 @@ $(document).on "click", "a[data-action=ab-comment-destroy]", (ev) -> ev.preventDefault() swal - title: "Are you sure?" - text: "You will not be able to recover this!" + title: "Really delete?" + text: "You will not be able to recover this comment." type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" - confirmButtonText: "Yes, delete it!" + confirmButtonText: "Delete" closeOnConfirm: false , -> - if confirm 'Are you sure?' btn = $(this) cid = btn[0].dataset.cId $.ajax diff --git a/app/assets/javascripts/answerbox/comment/report.coffee b/app/assets/javascripts/answerbox/comment/report.coffee index e21e7071..6aa245d4 100644 --- a/app/assets/javascripts/answerbox/comment/report.coffee +++ b/app/assets/javascripts/answerbox/comment/report.coffee @@ -1,12 +1,12 @@ $(document).on "click", "a[data-action=ab-comment-report]", (ev) -> ev.preventDefault() swal - title: "Report?" - text: "A moderator will check this and decide what happens!" + title: "Really report?" + text: "A moderator will review this comment and decide what happens." type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" - confirmButtonText: "Report!" + confirmButtonText: "Report" closeOnConfirm: false , -> btn = $(this) diff --git a/app/assets/javascripts/answerbox/destroy.coffee b/app/assets/javascripts/answerbox/destroy.coffee index afe379d2..ac3ad680 100644 --- a/app/assets/javascripts/answerbox/destroy.coffee +++ b/app/assets/javascripts/answerbox/destroy.coffee @@ -1,12 +1,12 @@ $(document).on "click", "a[data-action=ab-destroy]", (ev) -> ev.preventDefault() swal - title: "Are you sure?" - text: "If you delete this answer it will be moved back to your inbox!" + title: "Really delete?" + text: "The question will be moved back to your inbox." type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" - confirmButtonText: "Yes, delete it!" + confirmButtonText: "Delete" closeOnConfirm: false , -> btn = $(this) diff --git a/app/assets/javascripts/answerbox/report.coffee b/app/assets/javascripts/answerbox/report.coffee index 804aa1bd..6fd0fa6a 100644 --- a/app/assets/javascripts/answerbox/report.coffee +++ b/app/assets/javascripts/answerbox/report.coffee @@ -1,12 +1,12 @@ $(document).on "click", "a[data-action=ab-report]", (ev) -> ev.preventDefault() swal - title: "Report?" - text: "A moderator will check this and decide what happens!" + title: "Really report?" + text: "A moderator will review this comment and decide what happens." type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" - confirmButtonText: "Report!" + confirmButtonText: "Report" closeOnConfirm: false , -> btn = $(this) diff --git a/app/assets/javascripts/application.js.erb.coffee b/app/assets/javascripts/application.js.erb.coffee index 0b74905a..8a479028 100644 --- a/app/assets/javascripts/application.js.erb.coffee +++ b/app/assets/javascripts/application.js.erb.coffee @@ -25,3 +25,9 @@ window.showNotification = (text, success=true) -> $(document).on "click", "button#create-account", -> Turbolinks.visit "/sign_up" + +_ready = -> + sweetAlertInitialize() + +$(document).ready _ready +$(document).on 'page:load', _ready \ No newline at end of file diff --git a/app/assets/javascripts/inbox.coffee b/app/assets/javascripts/inbox.coffee index 9347891e..0e26742c 100644 --- a/app/assets/javascripts/inbox.coffee +++ b/app/assets/javascripts/inbox.coffee @@ -23,12 +23,12 @@ btn = ($ this) count = btn[0].dataset.ibCount swal - title: "Really delete #{count} questions??" - text: "You will not be able to recover them!" + title: "Really delete #{count} questions?" + text: "They will be gone forever." type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" - confirmButtonText: "Yes, delete all!" + confirmButtonText: "Delete" closeOnConfirm: false , -> btn.button "loading" @@ -93,12 +93,12 @@ $(document).on "click", "button[name=ib-answer]", -> $(document).on "click", "button[name=ib-destroy]", -> swal - title: "Are you sure?" - text: "You will not be able to recover this question!" + title: "Really delete?" + text: "This question will be gone forever." type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" - confirmButtonText: "Yes, delete it!" + confirmButtonText: "Delete" closeOnConfirm: false , -> btn = $(this) diff --git a/app/assets/javascripts/moderation/comment.coffee b/app/assets/javascripts/moderation/comment.coffee index dd8647b8..23134c18 100644 --- a/app/assets/javascripts/moderation/comment.coffee +++ b/app/assets/javascripts/moderation/comment.coffee @@ -69,12 +69,12 @@ $(document).on "input", "input[name=mod-comment-new]", (evt) -> $(document).on "click", "a[data-action=mod-comment-destroy]", (ev) -> ev.preventDefault() swal - title: "Are you sure?" - text: "You will not be able to recover this comment!" + title: "Really delete?" + text: "You will not be able to recover this comment." type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" - confirmButtonText: "Yes, delete it!" + confirmButtonText: "Delete" closeOnConfirm: false , -> btn = $(this) diff --git a/app/assets/javascripts/moderation/destroy.coffee b/app/assets/javascripts/moderation/destroy.coffee index 75feabc5..5eae4ef5 100644 --- a/app/assets/javascripts/moderation/destroy.coffee +++ b/app/assets/javascripts/moderation/destroy.coffee @@ -1,11 +1,11 @@ $(document).on "click", "button[name=mod-delete-report]", -> swal - title: "Are you sure?" - text: "You will not be able to recover this!" + title: "Really delete?" + text: "You will not be able to recover this report." type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" - confirmButtonText: "Yes, delete it!" + confirmButtonText: "Delete" closeOnConfirm: false , -> btn = $(this) diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index ef3390d7..e43fa907 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -2,9 +2,8 @@ *= require rails_bootstrap_forms *= require growl *= require jquery.guillotine - *= require_self *= require sweet-alert - *= require_tree . + *= require_self */ @import url(https://fonts.googleapis.com/css?family=Exo+2:400,700); From 0485be8eb9fc6b91f7cd6ba31029222ad4dcb16f Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 19:45:14 +0100 Subject: [PATCH 14/24] report user also now has sweetalert --- app/assets/javascripts/answerbox/report.coffee | 2 +- app/assets/javascripts/user.coffee | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/answerbox/report.coffee b/app/assets/javascripts/answerbox/report.coffee index 6fd0fa6a..b3fec65c 100644 --- a/app/assets/javascripts/answerbox/report.coffee +++ b/app/assets/javascripts/answerbox/report.coffee @@ -2,7 +2,7 @@ $(document).on "click", "a[data-action=ab-report]", (ev) -> ev.preventDefault() swal title: "Really report?" - text: "A moderator will review this comment and decide what happens." + text: "A moderator will review this answer and decide what happens." type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" diff --git a/app/assets/javascripts/user.coffee b/app/assets/javascripts/user.coffee index 589c517b..1a13f8ec 100644 --- a/app/assets/javascripts/user.coffee +++ b/app/assets/javascripts/user.coffee @@ -50,7 +50,16 @@ $(document).on "click", "a[data-action=report-user]", (ev) -> ev.preventDefault() btn = $(this) target = btn[0].dataset.target - if confirm "Are you sure you want to report #{target}?" + + swal + title: "Really report #{target}?" + text: "A moderator will review this user and decide what happens." + type: "warning" + showCancelButton: true + confirmButtonColor: "#DD6B55" + confirmButtonText: "Report" + closeOnConfirm: false + , -> $.ajax url: '/ajax/report' type: 'POST' From 7d9a0b720d4941de362897139e1ac2801eb59bd5 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 19:49:47 +0100 Subject: [PATCH 15/24] even more fixes --- app/assets/javascripts/answerbox/comment/destroy.coffee | 6 +++--- app/assets/javascripts/answerbox/comment/report.coffee | 6 +++--- app/assets/javascripts/answerbox/destroy.coffee | 6 +++--- app/assets/javascripts/answerbox/report.coffee | 6 +++--- app/assets/javascripts/inbox.coffee | 6 +++--- app/assets/javascripts/moderation/comment.coffee | 6 +++--- app/assets/javascripts/moderation/destroy.coffee | 6 +++--- app/assets/javascripts/user.coffee | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/answerbox/comment/destroy.coffee b/app/assets/javascripts/answerbox/comment/destroy.coffee index 02cdbea8..36505fa8 100644 --- a/app/assets/javascripts/answerbox/comment/destroy.coffee +++ b/app/assets/javascripts/answerbox/comment/destroy.coffee @@ -1,5 +1,7 @@ $(document).on "click", "a[data-action=ab-comment-destroy]", (ev) -> ev.preventDefault() + btn = $(this) + cid = btn[0].dataset.cId swal title: "Really delete?" text: "You will not be able to recover this comment." @@ -7,10 +9,8 @@ $(document).on "click", "a[data-action=ab-comment-destroy]", (ev) -> showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: "Delete" - closeOnConfirm: false + closeOnConfirm: true , -> - btn = $(this) - cid = btn[0].dataset.cId $.ajax url: '/ajax/destroy_comment' type: 'POST' diff --git a/app/assets/javascripts/answerbox/comment/report.coffee b/app/assets/javascripts/answerbox/comment/report.coffee index 6aa245d4..559552fa 100644 --- a/app/assets/javascripts/answerbox/comment/report.coffee +++ b/app/assets/javascripts/answerbox/comment/report.coffee @@ -1,5 +1,7 @@ $(document).on "click", "a[data-action=ab-comment-report]", (ev) -> ev.preventDefault() + btn = $(this) + cid = btn[0].dataset.cId swal title: "Really report?" text: "A moderator will review this comment and decide what happens." @@ -7,10 +9,8 @@ $(document).on "click", "a[data-action=ab-comment-report]", (ev) -> showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: "Report" - closeOnConfirm: false + closeOnConfirm: true , -> - btn = $(this) - cid = btn[0].dataset.cId $.ajax url: '/ajax/report' type: 'POST' diff --git a/app/assets/javascripts/answerbox/destroy.coffee b/app/assets/javascripts/answerbox/destroy.coffee index ac3ad680..2a343bb6 100644 --- a/app/assets/javascripts/answerbox/destroy.coffee +++ b/app/assets/javascripts/answerbox/destroy.coffee @@ -1,5 +1,7 @@ $(document).on "click", "a[data-action=ab-destroy]", (ev) -> ev.preventDefault() + btn = $(this) + aid = btn[0].dataset.aId swal title: "Really delete?" text: "The question will be moved back to your inbox." @@ -7,10 +9,8 @@ $(document).on "click", "a[data-action=ab-destroy]", (ev) -> showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: "Delete" - closeOnConfirm: false + closeOnConfirm: true , -> - btn = $(this) - aid = btn[0].dataset.aId $.ajax url: '/ajax/destroy_answer' # TODO: find a way to use rake routes instead of hardcoding them here type: 'POST' diff --git a/app/assets/javascripts/answerbox/report.coffee b/app/assets/javascripts/answerbox/report.coffee index b3fec65c..266755b5 100644 --- a/app/assets/javascripts/answerbox/report.coffee +++ b/app/assets/javascripts/answerbox/report.coffee @@ -1,5 +1,7 @@ $(document).on "click", "a[data-action=ab-report]", (ev) -> ev.preventDefault() + btn = $(this) + aid = btn[0].dataset.aId swal title: "Really report?" text: "A moderator will review this answer and decide what happens." @@ -7,10 +9,8 @@ $(document).on "click", "a[data-action=ab-report]", (ev) -> showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: "Report" - closeOnConfirm: false + closeOnConfirm: true , -> - btn = $(this) - aid = btn[0].dataset.aId $.ajax url: '/ajax/report' # TODO: find a way to use rake routes instead of hardcoding them here type: 'POST' diff --git a/app/assets/javascripts/inbox.coffee b/app/assets/javascripts/inbox.coffee index 0e26742c..da9f9a0e 100644 --- a/app/assets/javascripts/inbox.coffee +++ b/app/assets/javascripts/inbox.coffee @@ -29,7 +29,7 @@ showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: "Delete" - closeOnConfirm: false + closeOnConfirm: true , -> btn.button "loading" succ = no @@ -92,6 +92,7 @@ $(document).on "click", "button[name=ib-answer]", -> $(document).on "click", "button[name=ib-destroy]", -> + btn = $(this) swal title: "Really delete?" text: "This question will be gone forever." @@ -99,9 +100,8 @@ $(document).on "click", "button[name=ib-destroy]", -> showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: "Delete" - closeOnConfirm: false + closeOnConfirm: true , -> - btn = $(this) btn.button "loading" iid = btn[0].dataset.ibId $("textarea[name=ib-answer][data-id=#{iid}]").attr "readonly", "readonly" diff --git a/app/assets/javascripts/moderation/comment.coffee b/app/assets/javascripts/moderation/comment.coffee index 23134c18..5fe965c0 100644 --- a/app/assets/javascripts/moderation/comment.coffee +++ b/app/assets/javascripts/moderation/comment.coffee @@ -68,6 +68,8 @@ $(document).on "input", "input[name=mod-comment-new]", (evt) -> # destroy $(document).on "click", "a[data-action=mod-comment-destroy]", (ev) -> ev.preventDefault() + btn = $(this) + cid = btn[0].dataset.id swal title: "Really delete?" text: "You will not be able to recover this comment." @@ -75,10 +77,8 @@ $(document).on "click", "a[data-action=mod-comment-destroy]", (ev) -> showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: "Delete" - closeOnConfirm: false + closeOnConfirm: true , -> - btn = $(this) - cid = btn[0].dataset.id $.ajax url: '/ajax/mod/destroy_comment' type: 'POST' diff --git a/app/assets/javascripts/moderation/destroy.coffee b/app/assets/javascripts/moderation/destroy.coffee index 5eae4ef5..cd52437e 100644 --- a/app/assets/javascripts/moderation/destroy.coffee +++ b/app/assets/javascripts/moderation/destroy.coffee @@ -1,4 +1,6 @@ $(document).on "click", "button[name=mod-delete-report]", -> + btn = $(this) + id = btn[0].dataset.id swal title: "Really delete?" text: "You will not be able to recover this report." @@ -6,10 +8,8 @@ $(document).on "click", "button[name=mod-delete-report]", -> showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: "Delete" - closeOnConfirm: false + closeOnConfirm: true , -> - btn = $(this) - id = btn[0].dataset.id $.ajax url: '/ajax/mod/destroy_report' type: 'POST' diff --git a/app/assets/javascripts/user.coffee b/app/assets/javascripts/user.coffee index 1a13f8ec..7ab8fd4d 100644 --- a/app/assets/javascripts/user.coffee +++ b/app/assets/javascripts/user.coffee @@ -58,7 +58,7 @@ $(document).on "click", "a[data-action=report-user]", (ev) -> showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: "Report" - closeOnConfirm: false + closeOnConfirm: true , -> $.ajax url: '/ajax/report' From 30189ae6b8ad8a63056ab77b893b4d2f3e770d16 Mon Sep 17 00:00:00 2001 From: Andreas N Date: Sat, 3 Jan 2015 19:53:22 +0100 Subject: [PATCH 16/24] fixed overlay z-index --- app/assets/stylesheets/base.css.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/stylesheets/base.css.scss b/app/assets/stylesheets/base.css.scss index 0dcc15d4..5edb08d0 100644 --- a/app/assets/stylesheets/base.css.scss +++ b/app/assets/stylesheets/base.css.scss @@ -69,4 +69,8 @@ body { .j2-up { text-transform: uppercase; +} + +.sweet-overlay { + z-index: 1031; } \ No newline at end of file From b3348dbfff08b1f612bc31ea940e107963c9e604 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 21:43:19 +0100 Subject: [PATCH 17/24] added a few privacy options to users --- ...0103200732_add_privacy_options_to_users.rb | 12 ++++++ db/schema.rb | 38 ++++++++++--------- 2 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20150103200732_add_privacy_options_to_users.rb diff --git a/db/migrate/20150103200732_add_privacy_options_to_users.rb b/db/migrate/20150103200732_add_privacy_options_to_users.rb new file mode 100644 index 00000000..464589ae --- /dev/null +++ b/db/migrate/20150103200732_add_privacy_options_to_users.rb @@ -0,0 +1,12 @@ +class AddPrivacyOptionsToUsers < ActiveRecord::Migration + def change + %i{ + privacy_allow_anonymous_questions + privacy_allow_public_timeline + privacy_allow_stranger_answers + privacy_show_in_search + }.each do |sym| + add_column :users, sym, :boolean, default: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a71209be..f7c86d6d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150102231343) do +ActiveRecord::Schema.define(version: 20150103200732) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -133,12 +133,12 @@ ActiveRecord::Schema.define(version: 20150102231343) do add_index "smiles", ["user_id"], name: "index_smiles_on_user_id", using: :btree create_table "users", force: true do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" @@ -146,19 +146,19 @@ ActiveRecord::Schema.define(version: 20150102231343) do t.datetime "created_at" t.datetime "updated_at" t.string "screen_name" - t.integer "friend_count", default: 0, null: false - t.integer "follower_count", default: 0, null: false - t.integer "asked_count", default: 0, null: false - t.integer "answered_count", default: 0, null: false - t.integer "commented_count", default: 0, null: false + t.integer "friend_count", default: 0, null: false + t.integer "follower_count", default: 0, null: false + t.integer "asked_count", default: 0, null: false + t.integer "answered_count", default: 0, null: false + t.integer "commented_count", default: 0, null: false t.string "display_name" - t.integer "smiled_count", default: 0, null: false - t.boolean "admin", default: false, null: false - t.string "motivation_header", default: "", null: false - t.string "website", default: "", null: false - t.string "location", default: "", null: false - t.text "bio", default: "", null: false - t.boolean "moderator", default: false, null: false + t.integer "smiled_count", default: 0, null: false + t.boolean "admin", default: false, null: false + t.string "motivation_header", default: "", null: false + t.string "website", default: "", null: false + t.string "location", default: "", null: false + t.text "bio", default: "", null: false + t.boolean "moderator", default: false, null: false t.string "profile_picture_file_name" t.string "profile_picture_content_type" t.integer "profile_picture_file_size" @@ -168,7 +168,11 @@ ActiveRecord::Schema.define(version: 20150102231343) do t.integer "crop_y" t.integer "crop_w" t.integer "crop_h" - t.boolean "supporter", default: false + t.boolean "supporter", default: false + t.boolean "privacy_allow_anonymous_questions", default: true + t.boolean "privacy_allow_public_timeline", default: true + t.boolean "privacy_allow_stranger_answers", default: true + t.boolean "privacy_show_in_search", default: true end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree From bc94a729a65687fb08513b4df2bad7ff78184fb3 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 21:58:56 +0100 Subject: [PATCH 18/24] users now can enable/disable some privacy settings --- app/controllers/user_controller.rb | 20 ++++++++++++++++++-- app/views/user/_settings_tabs.html.haml | 2 +- app/views/user/edit_privacy.html.haml | 13 +++++++++++++ app/views/user/privacy.html.haml | 6 ------ config/routes.rb | 3 ++- 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 app/views/user/edit_privacy.html.haml delete mode 100644 app/views/user/privacy.html.haml diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index ee51b783..57e784d0 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -10,6 +10,7 @@ class UserController < ApplicationController end end + # region Account settings def edit end @@ -25,11 +26,26 @@ class UserController < ApplicationController end redirect_to edit_user_profile_path end + # endregion - def privacy - + # region Privacy settings + def edit_privacy end + def update_privacy + user_attributes = params.require(:user).permit(:privacy_allow_anonymous_questions, + :privacy_allow_public_timeline, + :privacy_allow_stranger_answers, + :privacy_show_in_search) + if current_user.update_attributes(user_attributes) + flash[:success] = 'Your privacy settings have been updated!' + else + flash[:error] = 'An error occurred. ;_;' + end + redirect_to edit_user_privacy_path + end + # endregion + def followers @title = 'Followers' @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! diff --git a/app/views/user/_settings_tabs.html.haml b/app/views/user/_settings_tabs.html.haml index 05450613..8bfe3c00 100644 --- a/app/views/user/_settings_tabs.html.haml +++ b/app/views/user/_settings_tabs.html.haml @@ -4,7 +4,7 @@ %ul.nav.nav-pills.nav-stacked = nav_entry "Account", edit_user_registration_path = nav_entry "Profile", edit_user_profile_path - = nav_entry "Privacy", privacy_settings_path + = nav_entry "Privacy", edit_user_privacy_path = nav_entry "Sharing", services_path diff --git a/app/views/user/edit_privacy.html.haml b/app/views/user/edit_privacy.html.haml new file mode 100644 index 00000000..eb151105 --- /dev/null +++ b/app/views/user/edit_privacy.html.haml @@ -0,0 +1,13 @@ +.container.j2-page + = render 'settings_tabs' + .col-md-9.col-xs-12.col-sm-9 + = render 'layouts/messages' + .panel.panel-default + .panel-body + = bootstrap_form_for(current_user, url: {action: "edit_privacy"}, method: "patch") do |f| + + = f.check_box :privacy_allow_anonymous_questions, label: "Allow anonymous questions" + = f.check_box :privacy_allow_public_timeline, label: "Show your answers in the public timeline" + = f.check_box :privacy_allow_stranger_answers, label: "Allow other people to answer your questions" + + = f.submit "Save settings", class: 'btn btn-primary' \ No newline at end of file diff --git a/app/views/user/privacy.html.haml b/app/views/user/privacy.html.haml deleted file mode 100644 index 4ae256cc..00000000 --- a/app/views/user/privacy.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -.container.j2-page - = render 'settings_tabs' - .col-md-9.col-xs-12.col-sm-9 - = render 'layouts/messages' - .panel.panel-default - .panel-body \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c2cac785..95be833a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,7 +57,8 @@ Rails.application.routes.draw do end end - match '/settings/privacy', to: 'user#privacy', via: :get, as: :privacy_settings + match '/settings/privacy', to: 'user#edit_privacy', via: :get, as: :edit_user_privacy + match '/settings/privacy', to: 'user#update_privacy', via: :patch, as: :update_user_privacy namespace :ajax do match '/ask', to: 'question#create', via: :post, as: :ask From 175e113af1fdd08818c700336160a51803579b1a Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 22:06:23 +0100 Subject: [PATCH 19/24] an error is now raised if the user does not want to receive anonymous questions --- app/models/question.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/question.rb b/app/models/question.rb index 5f8289e4..a7d553dd 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -5,6 +5,10 @@ class Question < ActiveRecord::Base validates :content, length: { maximum: 255 } + before_create do + raise "User does not want to receive anonymous questions" if self.author_is_anonymous and !self.user.privacy_allow_anonymous_questions? + end + before_destroy do user.decrement! :asked_count unless self.author_is_anonymous end From 09b6a6bc102e6e3a5546de0f7bc301d543e3cc1d Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 22:27:14 +0100 Subject: [PATCH 20/24] made that stuff work --- app/models/inbox.rb | 4 ++ app/models/question.rb | 4 -- app/views/shared/_questionbox.html.haml | 80 +++++++++++++------------ 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/app/models/inbox.rb b/app/models/inbox.rb index 57debac5..161e8c7c 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -2,6 +2,10 @@ class Inbox < ActiveRecord::Base belongs_to :user belongs_to :question + before_create do + raise "User does not want to receive anonymous questions" if self.question.author_is_anonymous and !self.user.privacy_allow_anonymous_questions? + end + def answer(answer_content, user) answer = user.answer(self.question, answer_content) self.destroy diff --git a/app/models/question.rb b/app/models/question.rb index a7d553dd..5f8289e4 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -5,10 +5,6 @@ class Question < ActiveRecord::Base validates :content, length: { maximum: 255 } - before_create do - raise "User does not want to receive anonymous questions" if self.author_is_anonymous and !self.user.privacy_allow_anonymous_questions? - end - before_destroy do user.decrement! :asked_count unless self.author_is_anonymous end diff --git a/app/views/shared/_questionbox.html.haml b/app/views/shared/_questionbox.html.haml index e9d066b7..89bceb2d 100644 --- a/app/views/shared/_questionbox.html.haml +++ b/app/views/shared/_questionbox.html.haml @@ -6,41 +6,47 @@ - else = @user.motivation_header .panel-body - #question-box - .row - .col-xs-12 - %textarea.form-control{:name => "qb-question", :placeholder => "Type your question here…"} - .row{:style => "padding-top: 5px; padding-left: 5px; padding-right: 5px;"} - .col-xs-6 - - if user_signed_in? # and @user.allow_anonymous - %input{:name => "qb-anonymous", :type => "checkbox"}/ - Hide your name - %br/ - .col-xs-6 - %p.pull-right - %input{name: 'qb-to', type: 'hidden', :value => @user.id}/ - %button.btn.btn-primary{name: 'qb-ask', :type => "button", data: {loading_text: 'Asking...', promote: user_signed_in? ? "false" : "true" }} Ask + - if user_signed_in? or @user.privacy_allow_anonymous_questions? + #question-box + .row + .col-xs-12 + %textarea.form-control{:name => "qb-question", :placeholder => "Type your question here…"} + .row{:style => "padding-top: 5px; padding-left: 5px; padding-right: 5px;"} + .col-xs-6 + - if user_signed_in? + - if @user.privacy_allow_anonymous_questions? + %input{:name => "qb-anonymous", :type => "checkbox"}/ + Hide your name + %br/ + - else + %input{:name => "qb-anonymous", :type => "hidden", :value => "false"}/ + .col-xs-6 + %p.pull-right + %input{name: 'qb-to', type: 'hidden', :value => @user.id}/ + %button.btn.btn-primary{name: 'qb-ask', :type => "button", data: {loading_text: 'Asking...', promote: user_signed_in? ? "false" : "true" }} Ask - unless user_signed_in? - #question-box-promote.row{:style => "display: none;"} - .row - .col-xs-12.text-center - %strong Your question has been sent. - .row - .col-sm-1 - .col-sm-5 - %button#create-account.btn.btn-block.btn-primary Create an account - .col-sm-5 - %button#new-question.btn.btn-block.btn-default Ask another question - .col-sm-1 - .row - .col-sm-1 - .col-xs-12.col-sm-10 - %small - Join - = APP_CONFIG['site_name'] - today! You'll be able to follow and ask people you know and a lot more. - .col-sm-1 -/ %p -/ This user does not want to get asked by strangers. Why don't you -/ = succeed "?" do -/ %a{:href => "{{ url_for('register') }}"} sign up + - if @user.privacy_allow_anonymous_questions? + #question-box-promote.row{:style => "display: none;"} + .row + .col-xs-12.text-center + %strong Your question has been sent. + .row + .col-sm-1 + .col-sm-5 + %button#create-account.btn.btn-block.btn-primary Create an account + .col-sm-5 + %button#new-question.btn.btn-block.btn-default Ask another question + .col-sm-1 + .row + .col-sm-1 + .col-xs-12.col-sm-10 + %small + Join + = APP_CONFIG['site_name'] + today! You'll be able to follow and ask people you know and a lot more. + .col-sm-1 + - else + %p + This user does not want to get asked by strangers. Why don't you + = succeed "?" do + %a{:href => "{{ url_for('register') }}"} sign up \ No newline at end of file From 997430f909d30f7bd28740525124f0f6f8a309e8 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 22:30:40 +0100 Subject: [PATCH 21/24] opting-out of the public timeline works now --- app/controllers/public_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb index 753542b4..9ea76e76 100644 --- a/app/controllers/public_controller.rb +++ b/app/controllers/public_controller.rb @@ -2,7 +2,7 @@ class PublicController < ApplicationController before_filter :authenticate_user! def index - @timeline = Answer.all.reverse_order.paginate(page: params[:page]) + @timeline = Answer.joins(:user).where(users: { privacy_allow_public_timeline: true }).all.reverse_order.paginate(page: params[:page]) respond_to do |format| format.html format.js From cdfe5564d64529cbac5bd6f88edf366aabce23e5 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 22:36:51 +0100 Subject: [PATCH 22/24] made C-RET work again --- app/assets/javascripts/question.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/question.coffee b/app/assets/javascripts/question.coffee index 9cfa2f76..09c26ecb 100644 --- a/app/assets/javascripts/question.coffee +++ b/app/assets/javascripts/question.coffee @@ -2,14 +2,14 @@ $(document).on "keydown", "textarea#q-answer", (evt) -> qid = $(this)[0].dataset.id if evt.keyCode == 13 and evt.ctrlKey # trigger warning: - $("button#q-answer[data-q-id=#{qid}]").trigger 'click' + $("button#q-answer").trigger 'click' $(document).on "click", "button#q-answer", -> btn = $(this) btn.button "loading" qid = btn[0].dataset.qId - $("textarea#q-answer[data-q=#{qid}]").attr "readonly", "readonly" + $("textarea#q-answer").attr "readonly", "readonly" shareTo = [] ($ "input[type=checkbox][name=share][data-q-id=#{qid}]:checked").each (i, share) -> @@ -34,4 +34,4 @@ $(document).on "click", "button#q-answer", -> showNotification "An error occurred, a developer should check the console for details", false complete: (jqxhr, status) -> btn.button "reset" - $("textarea#q-answer[data-id=#{qid}]").removeAttr "readonly" + $("textarea#q-answer").removeAttr "readonly" From 59b431513bffa3bdc492f1003973cf825f2b234e Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 22:37:10 +0100 Subject: [PATCH 23/24] made privacy_allow_stranger_answers work --- app/controllers/ajax/answer_controller.rb | 7 +++++++ app/views/question/show.html.haml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index 768ba97f..f15fe671 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -18,6 +18,13 @@ class Ajax::AnswerController < ApplicationController end else question = Question.find(params[:id]) + + unless question.user.privacy_allow_stranger_answers + @status = :privacy_stronk + @message = "This user does not want other users to answer their question." + @success = false + return + end end answer = nil diff --git a/app/views/question/show.html.haml b/app/views/question/show.html.haml index fe74986c..b259bfa5 100644 --- a/app/views/question/show.html.haml +++ b/app/views/question/show.html.haml @@ -24,7 +24,7 @@ %button#load-more-btn.btn.btn-default{type: :button, data: { current_page: @answers.current_page }} Load more - - if user_signed_in? and !current_user.answered? @question and current_user != @question.user + - if user_signed_in? and !current_user.answered? @question and current_user != @question.user and @question.user.privacy_allow_stranger_answers .panel.panel-default#q-answer-box .panel-heading %h3.panel-title This question was not in your inbox? Answer it here! From 9e0abc342a2304096ded8223755767e91250f926 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sat, 3 Jan 2015 22:48:59 +0100 Subject: [PATCH 24/24] redirect to login page --- app/controllers/user_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 57e784d0..f4913875 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,5 +1,5 @@ class UserController < ApplicationController - before_filter :authenticate_user!, only: %w(edit update privacy) + before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy) def show @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!