diff options
author | Maximiliano Perez Coto <maxi@assembla.com> | 2016-07-13 20:56:54 -0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-20 09:52:57 +0200 |
commit | b335730817e096bb4c68e5e4a4a2a3ec29b25243 (patch) | |
tree | 58e66bb4c97f139d68def7183fb7089166c5670f /app | |
parent | 95b9421ad3b2678da6e0af0131eafd52cdd0b2a5 (diff) | |
download | gitlab-ce-b335730817e096bb4c68e5e4a4a2a3ec29b25243.tar.gz |
Fix "Unsubscribe" link in notification emails that is triggered by anti-virus
* Created a force=true param that will continue with the previous
behaviour of the unsubscribe method
* Created a filter for not-logged users so they see a unsubsribe
confirmation page
* Added the List-Unsubscribe header on emails so the email client can
display it on top
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/sent_notifications_controller.rb | 4 | ||||
-rw-r--r-- | app/mailers/notify.rb | 6 | ||||
-rw-r--r-- | app/views/layouts/notify.html.haml | 4 | ||||
-rw-r--r-- | app/views/sent_notifications/unsubscribe.html.haml | 4 |
4 files changed, 16 insertions, 2 deletions
diff --git a/app/controllers/sent_notifications_controller.rb b/app/controllers/sent_notifications_controller.rb index 7271c933b9b..c4abc597cf1 100644 --- a/app/controllers/sent_notifications_controller.rb +++ b/app/controllers/sent_notifications_controller.rb @@ -2,13 +2,17 @@ class SentNotificationsController < ApplicationController skip_before_action :authenticate_user! def unsubscribe + return redirect_to new_user_session_path unless current_user || params[:force] + @sent_notification = SentNotification.for(params[:id]) + return render_404 unless @sent_notification && @sent_notification.unsubscribable? noteable = @sent_notification.noteable noteable.unsubscribe(@sent_notification.recipient) flash[:notice] = "You have been unsubscribed from this thread." + if current_user case noteable when Issue diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 0cc709f68e4..9799f1dc886 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -108,6 +108,12 @@ class Notify < BaseMailer headers["X-GitLab-#{model.class.name}-ID"] = model.id headers['X-GitLab-Reply-Key'] = reply_key + if !@labels_url && @sent_notification && @sent_notification.unsubscribable? + headers['List-Unsubscribe'] = unsubscribe_sent_notification_url(@sent_notification, force: true) + + @sent_notification_url = unsubscribe_sent_notification_url(@sent_notification) + end + if Gitlab::IncomingEmail.enabled? address = Mail::Address.new(Gitlab::IncomingEmail.reply_address(reply_key)) address.display_name = @project.name_with_namespace diff --git a/app/views/layouts/notify.html.haml b/app/views/layouts/notify.html.haml index dde2e2889dc..1ec4c3f0c67 100644 --- a/app/views/layouts/notify.html.haml +++ b/app/views/layouts/notify.html.haml @@ -25,8 +25,8 @@ - if @labels_url adjust your #{link_to 'label subscriptions', @labels_url}. - else - - if @sent_notification && @sent_notification.unsubscribable? - = link_to "unsubscribe", unsubscribe_sent_notification_url(@sent_notification) + - if @sent_notification_url + = link_to "unsubscribe", @sent_notification_url from this thread or adjust your notification settings. diff --git a/app/views/sent_notifications/unsubscribe.html.haml b/app/views/sent_notifications/unsubscribe.html.haml new file mode 100644 index 00000000000..568d2ac3af1 --- /dev/null +++ b/app/views/sent_notifications/unsubscribe.html.haml @@ -0,0 +1,4 @@ +%h3.page-title + Are you sure you want to unsubscribe from this thread? + + = link_to "Unsubscribe", unsubscribe_sent_notification_path(@sent_notification, force: true), class: 'btn btn-primary wide' |