Commit 90aff383 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '294048-fj-show-wiki-page-delete-button-to-developers' into 'master'

Show 'Delete' button to developers in Wiki

See merge request gitlab-org/gitlab!65420
parents fe8c8d70 8babca59
......@@ -14,8 +14,7 @@ module WikiActions
before_action { respond_to :html }
before_action :authorize_read_wiki!
before_action :authorize_create_wiki!, only: [:edit, :create]
before_action :authorize_admin_wiki!, only: :destroy
before_action :authorize_create_wiki!, only: [:edit, :create, :destroy]
before_action :wiki
before_action :page, only: [:show, :edit, :update, :history, :destroy, :diff]
......
......@@ -18,7 +18,7 @@
.nav-controls.pb-md-3.pb-lg-0
- if @page.persisted?
- if can?(current_user, :admin_wiki, @wiki.container)
- if can?(current_user, :create_wiki, @wiki.container)
#delete-wiki-modal-wrapper{ data: { delete_wiki_url: wiki_page_path(@wiki, @page), page_title: @page.human_title } }
= render 'shared/wikis/form', uploads_path: wiki_attachment_upload_url
......
# frozen_string_literal: true
RSpec.shared_examples 'wiki controller actions' do
let_it_be(:user) { create(:user) }
let_it_be(:other_user) { create(:user) }
let(:container) { raise NotImplementedError }
let(:routing_params) { raise NotImplementedError }
let_it_be(:user) { create(:user) }
let(:wiki) { Wiki.for_container(container, user) }
let(:wiki_title) { 'page title test' }
......@@ -458,6 +459,7 @@ RSpec.shared_examples 'wiki controller actions' do
describe 'DELETE #destroy' do
let(:id_param) { wiki_title }
let(:delete_user) { user }
subject(:request) do
delete(:destroy,
......@@ -466,13 +468,21 @@ RSpec.shared_examples 'wiki controller actions' do
))
end
before do
sign_in(delete_user)
end
context 'when page exists' do
it 'deletes the page' do
expect do
request
end.to change { wiki.list_pages.size }.by(-1)
shared_examples 'deletes the page' do
specify do
expect do
request
end.to change { wiki.list_pages.size }.by(-1)
end
end
it_behaves_like 'deletes the page'
context 'but page cannot be deleted' do
before do
allow_next_instance_of(WikiPage) do |page|
......@@ -489,6 +499,28 @@ RSpec.shared_examples 'wiki controller actions' do
expect(assigns(:error)).to eq('Could not delete wiki page')
end
end
context 'when user is a developer' do
let(:delete_user) { other_user }
before do
container.add_developer(other_user)
end
it_behaves_like 'deletes the page'
end
context 'when user is a reporter' do
let(:delete_user) { other_user }
before do
container.add_reporter(other_user)
end
it 'returns 404' do
is_expected.to have_gitlab_http_status(:not_found)
end
end
end
context 'when page does not exist' do
......
......@@ -7,18 +7,34 @@
RSpec.shared_examples 'User deletes wiki page' do
include WikiHelpers
let_it_be(:developer) { create(:user) }
let(:wiki_page) { create(:wiki_page, wiki: wiki) }
before do
wiki.container.add_developer(developer)
sign_in(user)
visit wiki_page_path(wiki, wiki_page)
end
it 'deletes a page', :js do
click_on('Edit')
click_on('Delete')
find('[data-testid="confirm_deletion_button"]').click
shared_examples 'deletes a wiki page' do
specify 'deletes a page', :js do
click_on('Edit')
click_on('Delete')
find('[data-testid="confirm_deletion_button"]').click
expect(page).to have_content('Wiki page was successfully deleted.')
end
end
context 'when user is the owner or maintainer' do
it_behaves_like 'deletes a wiki page'
end
context 'when user is a developer' do
let(:user) { developer }
expect(page).to have_content('Wiki page was successfully deleted.')
it_behaves_like 'deletes a wiki page'
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