Commit 022fa8d5 authored by Peter Hegman's avatar Peter Hegman

Merge branch '353853-hide-new-epic-button-for-guest-users' into 'master'

Hide New Epic button on Epic Boards for guest users

See merge request gitlab-org/gitlab!84583
parents 76df8c7d 589d436f
...@@ -57,6 +57,9 @@ export default { ...@@ -57,6 +57,9 @@ export default {
currentUserId: { currentUserId: {
default: null, default: null,
}, },
canCreateEpic: {
default: false,
},
}, },
props: { props: {
list: { list: {
...@@ -129,7 +132,7 @@ export default { ...@@ -129,7 +132,7 @@ export default {
return (this.listType === ListType.backlog || this.showListHeaderButton) && !this.isEpicBoard; return (this.listType === ListType.backlog || this.showListHeaderButton) && !this.isEpicBoard;
}, },
isNewEpicShown() { isNewEpicShown() {
return this.isEpicBoard && this.listType !== ListType.closed; return this.isEpicBoard && this.canCreateEpic && this.listType !== ListType.closed;
}, },
isSettingsShown() { isSettingsShown() {
return ( return (
......
...@@ -72,6 +72,7 @@ function mountBoardApp(el) { ...@@ -72,6 +72,7 @@ function mountBoardApp(el) {
canUpdate: parseBoolean(el.dataset.canUpdate), canUpdate: parseBoolean(el.dataset.canUpdate),
canAdminList: parseBoolean(el.dataset.canAdminList), canAdminList: parseBoolean(el.dataset.canAdminList),
canAdminBoard: parseBoolean(el.dataset.canAdminBoard), canAdminBoard: parseBoolean(el.dataset.canAdminBoard),
canCreateEpic: parseBoolean(el.dataset.canCreateEpic),
allowLabelCreate: parseBoolean(el.dataset.canUpdate), allowLabelCreate: parseBoolean(el.dataset.canUpdate),
allowLabelEdit: parseBoolean(el.dataset.canUpdate), allowLabelEdit: parseBoolean(el.dataset.canUpdate),
allowScopedLabels: parseBoolean(el.dataset.scopedLabels), allowScopedLabels: parseBoolean(el.dataset.scopedLabels),
......
...@@ -22,7 +22,8 @@ module EE ...@@ -22,7 +22,8 @@ module EE
board_weight: board.weight, board_weight: board.weight,
show_promotion: show_feature_promotion, show_promotion: show_feature_promotion,
emails_disabled: current_board_parent.emails_disabled?.to_s, emails_disabled: current_board_parent.emails_disabled?.to_s,
weights: ::Issue.weight_options weights: ::Issue.weight_options,
can_create_epic: can_create_epic?
} }
super.merge(data).merge(licensed_features).merge(group_level_features) super.merge(data).merge(licensed_features).merge(group_level_features)
...@@ -50,6 +51,10 @@ module EE ...@@ -50,6 +51,10 @@ module EE
end end
# rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/AbcSize
def can_create_epic?
return can?(current_user, :create_epic, current_board_namespace).to_s if board.is_a?(::Boards::EpicBoard)
end
override :can_update? override :can_update?
def can_update? def can_update?
return can?(current_user, :admin_epic, board) if board.is_a?(::Boards::EpicBoard) return can?(current_user, :admin_epic, board) if board.is_a?(::Boards::EpicBoard)
......
...@@ -50,6 +50,7 @@ describe('Board List Header Component', () => { ...@@ -50,6 +50,7 @@ describe('Board List Header Component', () => {
withLocalStorage = true, withLocalStorage = true,
isSwimlanesHeader = false, isSwimlanesHeader = false,
weightFeatureAvailable = false, weightFeatureAvailable = false,
canCreateEpic = true,
listQueryHandler = jest.fn().mockResolvedValue(boardListQueryResponse()), listQueryHandler = jest.fn().mockResolvedValue(boardListQueryResponse()),
currentUserId = 1, currentUserId = 1,
state = { activeId: inactiveId }, state = { activeId: inactiveId },
...@@ -93,6 +94,7 @@ describe('Board List Header Component', () => { ...@@ -93,6 +94,7 @@ describe('Board List Header Component', () => {
boardId, boardId,
weightFeatureAvailable, weightFeatureAvailable,
currentUserId, currentUserId,
canCreateEpic,
}, },
}); });
}; };
...@@ -128,6 +130,19 @@ describe('Board List Header Component', () => { ...@@ -128,6 +130,19 @@ describe('Board List Header Component', () => {
}); });
}); });
it('does not render New epic button when canCreateEpic is false', () => {
createComponent({
canCreateEpic: false,
getters: {
isIssueBoard: () => false,
isEpicBoard: () => true,
isGroupBoard: () => true,
},
});
expect(wrapper.findComponent(GlButtonGroup).exists()).toBe(false);
});
it('emits `toggle-epic-form` event on Sidebar eventHub when clicked', async () => { it('emits `toggle-epic-form` event on Sidebar eventHub when clicked', async () => {
await newEpicButton.vm.$emit('click'); await newEpicButton.vm.$emit('click');
......
...@@ -137,6 +137,7 @@ RSpec.describe BoardsHelper do ...@@ -137,6 +137,7 @@ RSpec.describe BoardsHelper do
assign(:group, group) assign(:group, group)
allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, epic_board).and_return(false) allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, epic_board).and_return(false)
allow(helper).to receive(:can?).with(user, :create_epic, group).and_return(true)
allow(helper).to receive(:can?).with(user, :admin_epic, epic_board).and_return(true) allow(helper).to receive(:can?).with(user, :admin_epic, epic_board).and_return(true)
allow(helper).to receive(:can?).with(user, :admin_epic_board_list, group).and_return(true) allow(helper).to receive(:can?).with(user, :admin_epic_board_list, group).and_return(true)
allow(helper).to receive(:can?).with(user, :admin_epic_board, group).and_return(true) allow(helper).to receive(:can?).with(user, :admin_epic_board, group).and_return(true)
...@@ -146,6 +147,10 @@ RSpec.describe BoardsHelper do ...@@ -146,6 +147,10 @@ RSpec.describe BoardsHelper do
allow(helper).to receive(:can?).with(user, :admin_issue_board, group).and_return(false) allow(helper).to receive(:can?).with(user, :admin_issue_board, group).and_return(false)
end end
it 'returns the correct permission for creating an epic from board' do
expect(board_data[:can_create_epic]).to eq "true"
end
it 'returns the correct permission for updating the board' do it 'returns the correct permission for updating the board' do
expect(board_data[:can_update]).to eq "true" expect(board_data[:can_update]).to eq "true"
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