Commit 032a5a20 authored by Florie Guibert's avatar Florie Guibert

Fix ability for non project member to subscribe to an issue

parent 77f229f2
...@@ -24,7 +24,6 @@ export default { ...@@ -24,7 +24,6 @@ export default {
GlToggle, GlToggle,
SidebarEditableItem, SidebarEditableItem,
}, },
inject: ['canUpdate'],
props: { props: {
iid: { iid: {
type: String, type: String,
...@@ -102,6 +101,9 @@ export default { ...@@ -102,6 +101,9 @@ export default {
parent: this.parentIsGroup ? 'group' : 'project', parent: this.parentIsGroup ? 'group' : 'project',
}); });
}, },
isLoggedIn() {
return Boolean(gon.current_user_id);
},
}, },
methods: { methods: {
setSubscribed(subscribed) { setSubscribed(subscribed) {
...@@ -174,7 +176,7 @@ export default { ...@@ -174,7 +176,7 @@ export default {
<gl-toggle <gl-toggle
:value="subscribed" :value="subscribed"
:is-loading="isLoading" :is-loading="isLoading"
:disabled="emailsDisabled || !canUpdate" :disabled="emailsDisabled || !isLoggedIn"
class="hide-collapsed gl-ml-auto" class="hide-collapsed gl-ml-auto"
data-testid="subscription-toggle" data-testid="subscription-toggle"
:label="$options.i18n.notifications" :label="$options.i18n.notifications"
......
...@@ -5,8 +5,20 @@ require "spec_helper" ...@@ -5,8 +5,20 @@ require "spec_helper"
RSpec.describe "User toggles subscription", :js do RSpec.describe "User toggles subscription", :js do
let(:project) { create(:project_empty_repo, :public) } let(:project) { create(:project_empty_repo, :public) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:issue) { create(:issue, project: project, author: user) } let(:issue) { create(:issue, project: project, author: user) }
context 'user is not logged in' do
before do
visit(project_issue_path(project, issue))
end
it 'toggle does not display' do
expect(page).not_to have_button('Notifications')
end
end
context 'user is logged in' do
before do before do
project.add_developer(user) project.add_developer(user)
sign_in(user) sign_in(user)
...@@ -14,7 +26,7 @@ RSpec.describe "User toggles subscription", :js do ...@@ -14,7 +26,7 @@ RSpec.describe "User toggles subscription", :js do
visit(project_issue_path(project, issue)) visit(project_issue_path(project, issue))
end end
it "unsubscribes from issue" do it 'unsubscribes from issue' do
subscription_button = find('[data-testid="subscription-toggle"]') subscription_button = find('[data-testid="subscription-toggle"]')
# Check we're subscribed. # Check we're subscribed.
...@@ -36,4 +48,27 @@ RSpec.describe "User toggles subscription", :js do ...@@ -36,4 +48,27 @@ RSpec.describe "User toggles subscription", :js do
expect(page).to have_button('Notifications', class: 'is-disabled') expect(page).to have_button('Notifications', class: 'is-disabled')
end end
end end
end
context 'user is logged in without edit permission' do
before do
sign_in(user2)
visit(project_issue_path(project, issue))
end
it 'subscribes to issue' do
subscription_button = find('[data-testid="subscription-toggle"]')
# Check we're not subscribed.
expect(subscription_button).to have_css("button:not(.is-checked)")
# Toggle subscription.
find('[data-testid="subscription-toggle"]').click
wait_for_requests
# Check we're subscribed.
expect(subscription_button).to have_css("button.is-checked")
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment