Commit 79d90cb6 authored by James Ramsay's avatar James Ramsay

Use Projects::UpdateService to archive projects

System hooks were not being triggered when projects were archived or
unarchived. Reuse the Projects::UpdateService to automatically
trigger system hooks and increase code reuse.
parent c60cb393
......@@ -148,7 +148,7 @@ class ProjectsController < Projects::ApplicationController
def archive
return access_denied! unless can?(current_user, :archive_project, @project)
@project.archive!
::Projects::UpdateService.new(@project, current_user, archived: true).execute
respond_to do |format|
format.html { redirect_to project_path(@project) }
......@@ -158,7 +158,7 @@ class ProjectsController < Projects::ApplicationController
def unarchive
return access_denied! unless can?(current_user, :archive_project, @project)
@project.unarchive!
::Projects::UpdateService.new(@project, current_user, archived: false).execute
respond_to do |format|
format.html { redirect_to project_path(@project) }
......
......@@ -1320,14 +1320,6 @@ class Project < ActiveRecord::Base
:visibility_level
end
def archive!
update_attribute(:archived, true)
end
def unarchive!
update_attribute(:archived, false)
end
def change_head(branch)
if repository.branch_exists?(branch)
repository.before_change_head
......
---
title: Trigger system hooks when project is archived/unarchived
merge_request: 20995
author:
type: added
......@@ -321,7 +321,7 @@ module API
post ':id/archive' do
authorize!(:archive_project, user_project)
user_project.archive!
::Projects::UpdateService.new(user_project, current_user, archived: true).execute
present user_project, with: Entities::Project
end
......@@ -332,7 +332,7 @@ module API
post ':id/unarchive' do
authorize!(:archive_project, user_project)
user_project.unarchive!
::Projects::UpdateService.new(@project, current_user, archived: false).execute
present user_project, with: Entities::Project
end
......
......@@ -53,14 +53,14 @@ describe 'Explore Groups page', :js do
expect(find('.js-groups-list-holder .content-list li:first-child .stats .number-projects')).to have_text("1")
# Archive project
empty_project.archive!
::Projects::UpdateService.new(empty_project, user, archived: true).execute
visit explore_groups_path
# Check project count
expect(find('.js-groups-list-holder .content-list li:first-child .stats .number-projects')).to have_text("0")
# Unarchive project
empty_project.unarchive!
::Projects::UpdateService.new(empty_project, user, archived: false).execute
visit explore_groups_path
# Check project count
......
......@@ -52,6 +52,7 @@ describe 'Group issues page' do
context 'issues list', :nested_groups do
let(:subgroup) { create(:group, parent: group) }
let(:subgroup_project) { create(:project, :public, group: subgroup)}
let(:user_in_group) { create(:group_member, :maintainer, user: create(:user), group: group ).user }
let!(:issue) { create(:issue, project: project, title: 'root group issue') }
let!(:subgroup_issue) { create(:issue, project: subgroup_project, title: 'subgroup issue') }
......@@ -67,7 +68,7 @@ describe 'Group issues page' do
context 'when project is archived' do
before do
project.archive!
::Projects::UpdateService.new(project, user_in_group, archived: true).execute
end
it 'does not render issue' do
......
......@@ -55,7 +55,7 @@ describe LabelsFinder do
context 'filtering by group_id' do
it 'returns labels available for any non-archived project within the group' do
group_1.add_developer(user)
project_1.archive!
::Projects::UpdateService.new(project_1, user, archived: true).execute
finder = described_class.new(user, group_id: group_1.id)
expect(finder.execute).to eq [group_label_2, group_label_1, project_label_5]
......
......@@ -36,7 +36,7 @@ describe MoveToProjectFinder do
it 'does not return archived projects' do
reporter_project.add_reporter(user)
reporter_project.archive!
::Projects::UpdateService.new(reporter_project, user, archived: true).execute
other_reporter_project = create(:project)
other_reporter_project.add_reporter(user)
......
......@@ -429,7 +429,7 @@ describe API::Internal do
context "archived project" do
before do
project.add_developer(user)
project.archive!
::Projects::UpdateService.new(project, user, archived: true).execute
end
context "git pull" do
......
......@@ -1677,7 +1677,7 @@ describe API::Projects do
context 'on an archived project' do
before do
project.archive!
::Projects::UpdateService.new(project, user, archived: true).execute
end
it 'remains archived' do
......@@ -1713,7 +1713,7 @@ describe API::Projects do
context 'on an archived project' do
before do
project.archive!
::Projects::UpdateService.new(project, user, archived: true).execute
end
it 'unarchives the project' do
......
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