Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
c61a54f7
Commit
c61a54f7
authored
Sep 16, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix initial implementation to actually render the unsubscribe page
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
b3357308
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
13 deletions
+54
-13
app/controllers/sent_notifications_controller.rb
app/controllers/sent_notifications_controller.rb
+5
-2
app/views/sent_notifications/unsubscribe.html.haml
app/views/sent_notifications/unsubscribe.html.haml
+14
-3
spec/controllers/sent_notifications_controller_spec.rb
spec/controllers/sent_notifications_controller_spec.rb
+10
-4
spec/features/unsubscribe_links_spec.rb
spec/features/unsubscribe_links_spec.rb
+25
-4
No files found.
app/controllers/sent_notifications_controller.rb
View file @
c61a54f7
...
...
@@ -2,12 +2,15 @@ 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?
return
unsubscribe_and_redirect
if
current_user
||
params
[
:force
]
end
private
def
unsubscribe_and_redirect
noteable
=
@sent_notification
.
noteable
noteable
.
unsubscribe
(
@sent_notification
.
recipient
)
...
...
app/views/sent_notifications/unsubscribe.html.haml
View file @
c61a54f7
%h3
.page-title
Are you sure you want to unsubscribe from this thread?
-
noteable
=
@sent_notification
.
noteable
-
noteable_type
=
@sent_notification
.
noteable_type
.
humanize
(
capitalize:
false
)
-
noteable_text
=
%(#{noteable_type} "#{noteable.title}" (#{noteable.to_reference}))
-
title
=
"Unsubscribe from
#{
noteable_text
}
"
=
link_to
"Unsubscribe"
,
unsubscribe_sent_notification_path
(
@sent_notification
,
force:
true
),
class:
'btn btn-primary wide'
-
page_title
title
%h3
.page-title
=
title
%p
=
"Are you sure you want to unsubscribe from
#{
noteable_text
}
?"
%p
=
link_to
'Unsubscribe'
,
unsubscribe_sent_notification_path
(
@sent_notification
,
force:
true
),
class:
'btn btn-primary append-right-10'
=
link_to
'Cancel'
,
new_user_session_path
,
class:
'btn append-right-10'
spec/controllers/sent_notifications_controller_spec.rb
View file @
c61a54f7
...
...
@@ -41,7 +41,7 @@ describe SentNotificationsController, type: :controller do
end
it
'redirects to the login page'
do
expect
(
response
).
to
re
direct_to
(
new_user_session_path
)
expect
(
response
).
to
re
nder_template
:unsubscribe
end
end
end
...
...
@@ -83,19 +83,25 @@ describe SentNotificationsController, type: :controller do
end
context
'when the force param is not passed'
do
let
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
project
,
author:
user
)
do
|
merge_request
|
merge_request
.
subscriptions
.
create
(
user:
user
,
subscribed:
true
)
end
end
let
(
:sent_notification
)
{
create
(
:sent_notification
,
noteable:
merge_request
,
recipient:
user
)
}
before
{
get
(
:unsubscribe
,
id:
sent_notification
.
reply_key
)
}
it
'unsubscribes the user'
do
expect
(
issue
.
subscribed?
(
user
)).
to
be_falsey
expect
(
merge_request
.
subscribed?
(
user
)).
to
be_falsey
end
it
'sets the flash message'
do
expect
(
controller
).
to
set_flash
[
:notice
].
to
(
/unsubscribed/
).
now
end
it
'redirects to the
issue
page'
do
it
'redirects to the
merge request
page'
do
expect
(
response
).
to
redirect_to
(
namespace_project_
issue_path
(
project
.
namespace
,
project
,
issue
))
to
redirect_to
(
namespace_project_
merge_request_path
(
project
.
namespace
,
project
,
merge_request
))
end
end
end
...
...
spec/features/unsubscribe_links_spec.rb
View file @
c61a54f7
...
...
@@ -19,11 +19,32 @@ describe 'Unsubscribe links', feature: true do
end
context
'when logged out'
do
it
'redirects to the login page when visiting the link from the body'
do
visit
body_link
context
'when visiting the link from the body'
do
it
'shows the unsubscribe confirmation page and redirects to root path when confirming'
do
visit
body_link
expect
(
current_path
).
to
eq
unsubscribe_sent_notification_path
(
SentNotification
.
last
)
expect
(
page
).
to
have_text
(
%(Unsubscribe from issue "#{issue.title}" (#{issue.to_reference}))
)
expect
(
page
).
to
have_text
(
%(Are you sure you want to unsubscribe from issue "#{issue.title}" (#{issue.to_reference})?)
)
expect
(
issue
.
subscribed?
(
recipient
)).
to
be_truthy
click_link
'Unsubscribe'
expect
(
issue
.
subscribed?
(
recipient
)).
to
be_falsey
expect
(
current_path
).
to
eq
new_user_session_path
end
it
'shows the unsubscribe confirmation page and redirects to root path when canceling'
do
visit
body_link
expect
(
current_path
).
to
eq
unsubscribe_sent_notification_path
(
SentNotification
.
last
)
expect
(
issue
.
subscribed?
(
recipient
)).
to
be_truthy
click_link
'Cancel'
expect
(
current_path
).
to
eq
new_user_session_path
expect
(
issue
.
subscribed?
(
recipient
)).
to
be_truthy
expect
(
issue
.
subscribed?
(
recipient
)).
to
be_truthy
expect
(
current_path
).
to
eq
new_user_session_path
end
end
it
'unsubscribes from the issue when visiting the link from the header'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment