Commit 52190b05 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '24190-archived-project-warning-message-on-discussion-thread' into 'master'

Display login or register widget only if user is not logged in

Closes #24190

See merge request gitlab-org/gitlab!22211
parents df0d8f2c e0d2437f
...@@ -89,6 +89,9 @@ export default { ...@@ -89,6 +89,9 @@ export default {
currentUser() { currentUser() {
return this.getUserData; return this.getUserData;
}, },
isLoggedIn() {
return Boolean(gon.current_user_id);
},
autosaveKey() { autosaveKey() {
return getDiscussionReplyKey(this.firstNote.noteable_type, this.discussion.id); return getDiscussionReplyKey(this.firstNote.noteable_type, this.discussion.id);
}, },
...@@ -314,7 +317,7 @@ export default { ...@@ -314,7 +317,7 @@ export default {
@cancelForm="cancelReplyForm" @cancelForm="cancelReplyForm"
/> />
</div> </div>
<note-signed-out-widget v-if="!userCanReply" /> <note-signed-out-widget v-if="!isLoggedIn" />
</div> </div>
</template> </template>
</discussion-notes> </discussion-notes>
......
---
title: Display login or register widget only if user is not logged in
merge_request: 22211
author:
type: fixed
...@@ -5,8 +5,15 @@ import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vu ...@@ -5,8 +5,15 @@ import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vu
import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue'; import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue';
import NoteForm from '~/notes/components/note_form.vue'; import NoteForm from '~/notes/components/note_form.vue';
import '~/behaviors/markdown/render_gfm'; import '~/behaviors/markdown/render_gfm';
import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data'; import {
noteableDataMock,
discussionMock,
notesDataMock,
loggedOutnoteableData,
userDataMock,
} from '../mock_data';
import mockDiffFile from '../../diffs/mock_data/diff_file'; import mockDiffFile from '../../diffs/mock_data/diff_file';
import { trimText } from '../../helpers/text_helper';
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json'; const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
...@@ -15,6 +22,7 @@ const localVue = createLocalVue(); ...@@ -15,6 +22,7 @@ const localVue = createLocalVue();
describe('noteable_discussion component', () => { describe('noteable_discussion component', () => {
let store; let store;
let wrapper; let wrapper;
let originalGon;
preloadFixtures(discussionWithTwoUnresolvedNotes); preloadFixtures(discussionWithTwoUnresolvedNotes);
...@@ -167,4 +175,55 @@ describe('noteable_discussion component', () => { ...@@ -167,4 +175,55 @@ describe('noteable_discussion component', () => {
expect(button.exists()).toBe(true); expect(button.exists()).toBe(true);
}); });
}); });
describe('signout widget', () => {
beforeEach(() => {
originalGon = Object.assign({}, window.gon);
window.gon = window.gon || {};
});
afterEach(() => {
wrapper.destroy();
window.gon = originalGon;
});
describe('user is logged in', () => {
beforeEach(() => {
window.gon.current_user_id = userDataMock.id;
store.dispatch('setUserData', userDataMock);
wrapper = mount(localVue.extend(noteableDiscussion), {
store,
propsData: { discussion: discussionMock },
localVue,
sync: false,
});
});
it('should not render signed out widget', () => {
expect(Boolean(wrapper.vm.isLoggedIn)).toBe(true);
expect(trimText(wrapper.text())).not.toContain('Please register or sign in to reply');
});
});
describe('user is not logged in', () => {
beforeEach(() => {
window.gon.current_user_id = null;
store.dispatch('setNoteableData', loggedOutnoteableData);
store.dispatch('setNotesData', notesDataMock);
wrapper = mount(localVue.extend(noteableDiscussion), {
store,
propsData: { discussion: discussionMock },
localVue,
sync: false,
});
});
it('should render signed out widget', () => {
expect(Boolean(wrapper.vm.isLoggedIn)).toBe(false);
expect(trimText(wrapper.text())).toContain('Please register or sign in to reply');
});
});
});
}); });
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