Commit 8dbd99bd authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'kp-hide-create-issue-boards-unauthorized' into 'master'

Hide board list actions for unauthorized users

See merge request gitlab-org/gitlab!63426
parents 1d599b61 265680f7
...@@ -24,11 +24,6 @@ export default { ...@@ -24,11 +24,6 @@ export default {
type: Boolean, type: Boolean,
required: true, required: true,
}, },
canAdminList: {
type: Boolean,
required: false,
default: false,
},
}, },
computed: { computed: {
...mapState(['filterParams', 'highlightedLists']), ...mapState(['filterParams', 'highlightedLists']),
...@@ -92,14 +87,8 @@ export default { ...@@ -92,14 +87,8 @@ export default {
class="board-inner gl-display-flex gl-flex-direction-column gl-relative gl-h-full gl-rounded-base" class="board-inner gl-display-flex gl-flex-direction-column gl-relative gl-h-full gl-rounded-base"
:class="{ 'board-column-highlighted': highlighted }" :class="{ 'board-column-highlighted': highlighted }"
> >
<board-list-header :can-admin-list="canAdminList" :list="list" :disabled="disabled" /> <board-list-header :list="list" :disabled="disabled" />
<board-list <board-list ref="board-list" :disabled="disabled" :board-items="listItems" :list="list" />
ref="board-list"
:disabled="disabled"
:board-items="listItems"
:list="list"
:can-admin-list="canAdminList"
/>
</div> </div>
</div> </div>
</template> </template>
...@@ -26,11 +26,6 @@ export default { ...@@ -26,11 +26,6 @@ export default {
type: Boolean, type: Boolean,
required: true, required: true,
}, },
canAdminList: {
type: Boolean,
required: false,
default: false,
},
}, },
data() { data() {
return { return {
...@@ -110,7 +105,7 @@ export default { ...@@ -110,7 +105,7 @@ export default {
class="board-inner gl-display-flex gl-flex-direction-column gl-relative gl-h-full gl-rounded-base" class="board-inner gl-display-flex gl-flex-direction-column gl-relative gl-h-full gl-rounded-base"
:class="{ 'board-column-highlighted': list.highlighted }" :class="{ 'board-column-highlighted': list.highlighted }"
> >
<board-list-header :can-admin-list="canAdminList" :list="list" :disabled="disabled" /> <board-list-header :list="list" :disabled="disabled" />
<board-list ref="board-list" :disabled="disabled" :issues="listIssues" :list="list" /> <board-list ref="board-list" :disabled="disabled" :issues="listIssues" :list="list" />
</div> </div>
</div> </div>
......
...@@ -106,7 +106,6 @@ export default { ...@@ -106,7 +106,6 @@ export default {
v-for="(list, index) in boardListsToUse" v-for="(list, index) in boardListsToUse"
:key="index" :key="index"
ref="board" ref="board"
:can-admin-list="canAdminList"
:list="list" :list="list"
:disabled="disabled" :disabled="disabled"
/> />
......
...@@ -23,6 +23,11 @@ export default { ...@@ -23,6 +23,11 @@ export default {
GlLoadingIcon, GlLoadingIcon,
GlIntersectionObserver, GlIntersectionObserver,
}, },
inject: {
canAdminList: {
default: false,
},
},
props: { props: {
disabled: { disabled: {
type: Boolean, type: Boolean,
...@@ -36,11 +41,6 @@ export default { ...@@ -36,11 +41,6 @@ export default {
type: Array, type: Array,
required: true, required: true,
}, },
canAdminList: {
type: Boolean,
required: false,
default: false,
},
}, },
data() { data() {
return { return {
......
...@@ -98,6 +98,12 @@ export default { ...@@ -98,6 +98,12 @@ export default {
showListDetails() { showListDetails() {
return !this.list.collapsed || !this.isSwimlanesHeader; return !this.list.collapsed || !this.isSwimlanesHeader;
}, },
showListHeaderActions() {
if (this.isLoggedIn) {
return this.isNewIssueShown || this.isSettingsShown;
}
return false;
},
itemsCount() { itemsCount() {
return this.list.issuesCount; return this.list.issuesCount;
}, },
...@@ -351,10 +357,7 @@ export default { ...@@ -351,10 +357,7 @@ export default {
<!-- EE end --> <!-- EE end -->
</span> </span>
</div> </div>
<gl-button-group <gl-button-group v-if="showListHeaderActions" class="board-list-button-group gl-pl-2">
v-if="isNewIssueShown || isSettingsShown"
class="board-list-button-group pl-2"
>
<gl-button <gl-button
v-if="isNewIssueShown" v-if="isNewIssueShown"
v-show="!list.collapsed" v-show="!list.collapsed"
......
...@@ -35,6 +35,9 @@ export default { ...@@ -35,6 +35,9 @@ export default {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
}, },
inject: { inject: {
currentUserId: {
default: null,
},
boardId: { boardId: {
default: '', default: '',
}, },
...@@ -63,7 +66,7 @@ export default { ...@@ -63,7 +66,7 @@ export default {
computed: { computed: {
...mapState(['activeId']), ...mapState(['activeId']),
isLoggedIn() { isLoggedIn() {
return Boolean(gon.current_user_id); return Boolean(this.currentUserId);
}, },
listType() { listType() {
return this.list.type; return this.list.type;
...@@ -89,6 +92,12 @@ export default { ...@@ -89,6 +92,12 @@ export default {
showListDetails() { showListDetails() {
return this.list.isExpanded || !this.isSwimlanesHeader; return this.list.isExpanded || !this.isSwimlanesHeader;
}, },
showListHeaderActions() {
if (this.isLoggedIn) {
return this.isNewIssueShown || this.isSettingsShown;
}
return false;
},
issuesCount() { issuesCount() {
return this.list.issuesSize; return this.list.issuesSize;
}, },
...@@ -320,10 +329,7 @@ export default { ...@@ -320,10 +329,7 @@ export default {
</template> </template>
</span> </span>
</div> </div>
<gl-button-group <gl-button-group v-if="showListHeaderActions" class="board-list-button-group pl-2">
v-if="isNewIssueShown || isSettingsShown"
class="board-list-button-group pl-2"
>
<gl-button <gl-button
v-if="isNewIssueShown" v-if="isNewIssueShown"
ref="newIssueBtn" ref="newIssueBtn"
......
...@@ -41,6 +41,7 @@ describe('Board List Header Component', () => { ...@@ -41,6 +41,7 @@ describe('Board List Header Component', () => {
listType = ListType.backlog, listType = ListType.backlog,
collapsed = false, collapsed = false,
withLocalStorage = true, withLocalStorage = true,
currentUserId = 1,
} = {}) => { } = {}) => {
const boardId = '1'; const boardId = '1';
...@@ -73,6 +74,7 @@ describe('Board List Header Component', () => { ...@@ -73,6 +74,7 @@ describe('Board List Header Component', () => {
list, list,
}, },
provide: { provide: {
currentUserId,
boardId, boardId,
}, },
}); });
......
...@@ -33,6 +33,7 @@ describe('Board List Header Component', () => { ...@@ -33,6 +33,7 @@ describe('Board List Header Component', () => {
withLocalStorage = true, withLocalStorage = true,
isSwimlanesHeader = false, isSwimlanesHeader = false,
weightFeatureAvailable = false, weightFeatureAvailable = false,
currentUserId = 1,
} = {}) => { } = {}) => {
const boardId = '1'; const boardId = '1';
...@@ -65,6 +66,7 @@ describe('Board List Header Component', () => { ...@@ -65,6 +66,7 @@ describe('Board List Header Component', () => {
provide: { provide: {
boardId, boardId,
weightFeatureAvailable, weightFeatureAvailable,
currentUserId,
}, },
}); });
}; };
......
...@@ -154,8 +154,8 @@ RSpec.describe 'Issue Boards new issue', :js do ...@@ -154,8 +154,8 @@ RSpec.describe 'Issue Boards new issue', :js do
wait_for_requests wait_for_requests
end end
it 'displays new issue button in open list' do it 'does not display new issue button in open list' do
expect(first('.board')).to have_button('New issue', count: 1) expect(first('.board')).not_to have_button('New issue')
end end
it 'does not display new issue button in label list' do it 'does not display new issue button in label list' do
...@@ -192,8 +192,8 @@ RSpec.describe 'Issue Boards new issue', :js do ...@@ -192,8 +192,8 @@ RSpec.describe 'Issue Boards new issue', :js do
context 'when backlog list already exists' do context 'when backlog list already exists' do
let_it_be(:backlog_list) { create(:backlog_list, board: group_board) } let_it_be(:backlog_list) { create(:backlog_list, board: group_board) }
it 'displays new issue button in open list' do it 'does not display new issue button in open list' do
expect(first('.board')).to have_button('New issue', count: 1) expect(first('.board')).not_to have_button('New issue')
end end
it 'does not display new issue button in label list' do it 'does not display new issue button in label list' do
......
...@@ -80,6 +80,7 @@ const createComponent = ({ ...@@ -80,6 +80,7 @@ const createComponent = ({
rootPath: '/', rootPath: '/',
weightFeatureAvailable: false, weightFeatureAvailable: false,
boardWeight: null, boardWeight: null,
canAdminList: true,
}, },
stubs: { stubs: {
BoardCard, BoardCard,
......
...@@ -31,6 +31,7 @@ describe('Board List Header Component', () => { ...@@ -31,6 +31,7 @@ describe('Board List Header Component', () => {
listType = ListType.backlog, listType = ListType.backlog,
collapsed = false, collapsed = false,
withLocalStorage = true, withLocalStorage = true,
currentUserId = 1,
} = {}) => { } = {}) => {
const boardId = '1'; const boardId = '1';
...@@ -62,6 +63,7 @@ describe('Board List Header Component', () => { ...@@ -62,6 +63,7 @@ describe('Board List Header Component', () => {
}, },
provide: { provide: {
boardId, boardId,
currentUserId,
}, },
}); });
}; };
...@@ -100,10 +102,12 @@ describe('Board List Header Component', () => { ...@@ -100,10 +102,12 @@ describe('Board List Header Component', () => {
}); });
}); });
it('does render when logged out', () => { it('does not render when logged out', () => {
createComponent(); createComponent({
currentUserId: null,
});
expect(findAddIssueButton().exists()).toBe(true); expect(findAddIssueButton().exists()).toBe(false);
}); });
}); });
...@@ -143,7 +147,6 @@ describe('Board List Header Component', () => { ...@@ -143,7 +147,6 @@ describe('Board List Header Component', () => {
it("when logged in it calls list update and doesn't set localStorage", () => { it("when logged in it calls list update and doesn't set localStorage", () => {
jest.spyOn(List.prototype, 'update'); jest.spyOn(List.prototype, 'update');
window.gon.current_user_id = 1;
createComponent({ withLocalStorage: false }); createComponent({ withLocalStorage: false });
...@@ -158,7 +161,7 @@ describe('Board List Header Component', () => { ...@@ -158,7 +161,7 @@ describe('Board List Header Component', () => {
it("when logged out it doesn't call list update and sets localStorage", () => { it("when logged out it doesn't call list update and sets localStorage", () => {
jest.spyOn(List.prototype, 'update'); jest.spyOn(List.prototype, 'update');
createComponent(); createComponent({ currentUserId: null });
findCaret().vm.$emit('click'); findCaret().vm.$emit('click');
......
...@@ -28,7 +28,7 @@ describe('Board List Header Component', () => { ...@@ -28,7 +28,7 @@ describe('Board List Header Component', () => {
listType = ListType.backlog, listType = ListType.backlog,
collapsed = false, collapsed = false,
withLocalStorage = true, withLocalStorage = true,
currentUserId = null, currentUserId = 1,
} = {}) => { } = {}) => {
const boardId = '1'; const boardId = '1';
...@@ -109,10 +109,12 @@ describe('Board List Header Component', () => { ...@@ -109,10 +109,12 @@ describe('Board List Header Component', () => {
}); });
}); });
it('does render when logged out', () => { it('does not render when logged out', () => {
createComponent(); createComponent({
currentUserId: null,
});
expect(findAddIssueButton().exists()).toBe(true); expect(findAddIssueButton().exists()).toBe(false);
}); });
}); });
...@@ -153,7 +155,9 @@ describe('Board List Header Component', () => { ...@@ -153,7 +155,9 @@ describe('Board List Header Component', () => {
}); });
it("when logged out it doesn't call list update and sets localStorage", async () => { it("when logged out it doesn't call list update and sets localStorage", async () => {
createComponent(); createComponent({
currentUserId: null,
});
findCaret().vm.$emit('click'); findCaret().vm.$emit('click');
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
......
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