Commit bc2eff8d authored by Douwe Maan's avatar Douwe Maan

Merge branch '44392-resolve-projects-creation-silently-failing-on-after-create-error' into 'master'

Resolve "For new created projects permissions are not inherited from group level"

Closes #44692

See merge request gitlab-org/gitlab-ce!18013
parents 5ac5767e 7fd9e39d
...@@ -273,6 +273,7 @@ class Service < ActiveRecord::Base ...@@ -273,6 +273,7 @@ class Service < ActiveRecord::Base
def self.build_from_template(project_id, template) def self.build_from_template(project_id, template)
service = template.dup service = template.dup
service.active = false unless service.valid?
service.template = false service.template = false
service.project_id = project_id service.project_id = project_id
service service
......
...@@ -90,9 +90,6 @@ module Projects ...@@ -90,9 +90,6 @@ module Projects
unless @project.gitlab_project_import? unless @project.gitlab_project_import?
@project.write_repository_config @project.write_repository_config
@project.create_wiki unless skip_wiki? @project.create_wiki unless skip_wiki?
create_services_from_active_templates(@project)
@project.create_labels
end end
event_service.create_project(@project, current_user) event_service.create_project(@project, current_user)
...@@ -121,21 +118,29 @@ module Projects ...@@ -121,21 +118,29 @@ module Projects
Project.transaction do Project.transaction do
@project.create_or_update_import_data(data: import_data[:data], credentials: import_data[:credentials]) if import_data @project.create_or_update_import_data(data: import_data[:data], credentials: import_data[:credentials]) if import_data
if @project.save && !@project.import? if @project.save
unless @project.gitlab_project_import?
create_services_from_active_templates(@project)
@project.create_labels
end
unless @project.import?
raise 'Failed to create repository' unless @project.create_repository raise 'Failed to create repository' unless @project.create_repository
end end
end end
end end
end
def fail(error:) def fail(error:)
message = "Unable to save project. Error: #{error}" message = "Unable to save project. Error: #{error}"
message << "Project ID: #{@project.id}" if @project && @project.id log_message = message.dup
Rails.logger.error(message) log_message << " Project ID: #{@project.id}" if @project&.id
Rails.logger.error(log_message)
if @project && @project.import? if @project
@project.errors.add(:base, message) @project.errors.add(:base, message)
@project.mark_import_as_failed(message) @project.mark_import_as_failed(message) if @project.import?
end end
@project @project
......
---
title: Project creation will now raise an error if a service template is invalid
merge_request: 18013
author:
type: fixed
...@@ -58,6 +58,21 @@ describe Service do ...@@ -58,6 +58,21 @@ describe Service do
end end
describe "Template" do describe "Template" do
describe '.build_from_template' do
context 'when template is invalid' do
it 'sets service template to inactive when template is invalid' do
project = create(:project)
template = JiraService.new(template: true, active: true)
template.save(validate: false)
service = described_class.build_from_template(project.id, template)
expect(service).to be_valid
expect(service.active).to be false
end
end
end
describe "for pushover service" do describe "for pushover service" do
let!(:service_template) do let!(:service_template) do
PushoverService.create( PushoverService.create(
......
...@@ -70,6 +70,16 @@ describe Projects::CreateService, '#execute' do ...@@ -70,6 +70,16 @@ describe Projects::CreateService, '#execute' do
opts[:default_branch] = 'master' opts[:default_branch] = 'master'
expect(create_project(user, opts)).to eq(nil) expect(create_project(user, opts)).to eq(nil)
end end
it 'sets invalid service as inactive' do
create(:service, type: 'JiraService', project: nil, template: true, active: true)
project = create_project(user, opts)
service = project.services.first
expect(project).to be_persisted
expect(service.active).to be false
end
end end
context 'wiki_enabled creates repository directory' do context 'wiki_enabled creates repository directory' do
...@@ -232,14 +242,15 @@ describe Projects::CreateService, '#execute' do ...@@ -232,14 +242,15 @@ describe Projects::CreateService, '#execute' do
end end
context 'when a bad service template is created' do context 'when a bad service template is created' do
it 'reports an error in the imported project' do it 'sets service to be inactive' do
opts[:import_url] = 'http://www.gitlab.com/gitlab-org/gitlab-ce' opts[:import_url] = 'http://www.gitlab.com/gitlab-org/gitlab-ce'
create(:service, type: 'DroneCiService', project: nil, template: true, active: true) create(:service, type: 'DroneCiService', project: nil, template: true, active: true)
project = create_project(user, opts) project = create_project(user, opts)
service = project.services.first
expect(project.errors.full_messages_for(:base).first).to match(/Unable to save project. Error: Unable to save DroneCiService/) expect(project).to be_persisted
expect(project.services.count).to eq 0 expect(service.active).to be false
end end
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