Commit fdd5177a authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'ce-8631-archiving-a-project-should-create-an-audit-event' into 'master'

CE: Archiving a project should create an audit event

See merge request gitlab-org/gitlab-ce!32039
parents c1d315d4 a07efbdf
...@@ -29,6 +29,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -29,6 +29,7 @@ class ProjectsController < Projects::ApplicationController
# Authorize # Authorize
before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export, :remove_export, :generate_new_export] before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export, :remove_export, :generate_new_export]
before_action :authorize_archive_project!, only: [:archive, :unarchive]
before_action :event_filter, only: [:show, :activity] before_action :event_filter, only: [:show, :activity]
layout :determine_layout layout :determine_layout
...@@ -164,8 +165,6 @@ class ProjectsController < Projects::ApplicationController ...@@ -164,8 +165,6 @@ class ProjectsController < Projects::ApplicationController
end end
def archive def archive
return access_denied! unless can?(current_user, :archive_project, @project)
::Projects::UpdateService.new(@project, current_user, archived: true).execute ::Projects::UpdateService.new(@project, current_user, archived: true).execute
respond_to do |format| respond_to do |format|
...@@ -174,8 +173,6 @@ class ProjectsController < Projects::ApplicationController ...@@ -174,8 +173,6 @@ class ProjectsController < Projects::ApplicationController
end end
def unarchive def unarchive
return access_denied! unless can?(current_user, :archive_project, @project)
::Projects::UpdateService.new(@project, current_user, archived: false).execute ::Projects::UpdateService.new(@project, current_user, archived: false).execute
respond_to do |format| respond_to do |format|
......
...@@ -75,6 +75,8 @@ From there, you can see the following actions: ...@@ -75,6 +75,8 @@ From there, you can see the following actions:
- User was removed from project - User was removed from project
- Project export was downloaded - Project export was downloaded
- Project repository was downloaded - Project repository was downloaded
- Project was archived
- Project was unarchived
### Instance events **(PREMIUM ONLY)** ### Instance events **(PREMIUM ONLY)**
......
...@@ -318,6 +318,102 @@ describe ProjectsController do ...@@ -318,6 +318,102 @@ describe ProjectsController do
end end
end end
describe 'POST #archive' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
before do
sign_in(user)
end
context 'for a user with the ability to archive a project' do
before do
group.add_owner(user)
post :archive, params: {
namespace_id: project.namespace.path,
id: project.path
}
end
it 'archives the project' do
expect(project.reload.archived?).to be_truthy
end
it 'redirects to projects path' do
expect(response).to have_gitlab_http_status(302)
expect(response).to redirect_to(project_path(project))
end
end
context 'for a user that does not have the ability to archive a project' do
before do
project.add_maintainer(user)
post :archive, params: {
namespace_id: project.namespace.path,
id: project.path
}
end
it 'does not archive the project' do
expect(project.reload.archived?).to be_falsey
end
it 'returns 404' do
expect(response).to have_gitlab_http_status(404)
end
end
end
describe 'POST #unarchive' do
let(:group) { create(:group) }
let(:project) { create(:project, :archived, group: group) }
before do
sign_in(user)
end
context 'for a user with the ability to unarchive a project' do
before do
group.add_owner(user)
post :unarchive, params: {
namespace_id: project.namespace.path,
id: project.path
}
end
it 'unarchives the project' do
expect(project.reload.archived?).to be_falsey
end
it 'redirects to projects path' do
expect(response).to have_gitlab_http_status(302)
expect(response).to redirect_to(project_path(project))
end
end
context 'for a user that does not have the ability to unarchive a project' do
before do
project.add_maintainer(user)
post :unarchive, params: {
namespace_id: project.namespace.path,
id: project.path
}
end
it 'does not unarchive the project' do
expect(project.reload.archived?).to be_truthy
end
it 'returns 404' do
expect(response).to have_gitlab_http_status(404)
end
end
end
describe '#housekeeping' do describe '#housekeeping' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:project) { create(:project, group: group) } let(:project) { create(:project, group: group) }
......
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