diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index a0aa0587ee..acacf43d1a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -109,8 +109,12 @@ class RepositoriesController < ApplicationController end def destroy - @project.repository.destroy - flash[:notice] = I18n.t('repositories.delete_sucessful') + repository = @project.repository + if repository.destroy + flash[:notice] = I18n.t('repositories.delete_sucessful') + else + flash[:error] = repository.errors.full_messages.join("\n") + end redirect_to settings_repository_tab_path end diff --git a/app/models/repository.rb b/app/models/repository.rb index b050119601..0b28a88b76 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -432,8 +432,12 @@ class Repository < ActiveRecord::Base service = Scm::DeleteManagedRepositoryService.new(self) # Even if the service can't remove the physical repository, # we should continue removing the associated instance. - service.call - - true + if service.call + true + else + errors.add(:base, I18n.t('repositories.errors.filesystem_access_failed', + message: I18n.t('repositories.errors.deletion_failed'))) + raise ActiveRecord::Rollback + end end end diff --git a/app/services/scm/delete_managed_repository_service.rb b/app/services/scm/delete_managed_repository_service.rb index 65af32e4d1..d8f7a9db49 100644 --- a/app/services/scm/delete_managed_repository_service.rb +++ b/app/services/scm/delete_managed_repository_service.rb @@ -60,8 +60,8 @@ Scm::DeleteManagedRepositoryService = Struct.new :repository do true rescue SystemCallError => e - Rails.logger.error("An error occurred while accessing the repository '#{repository.root_url}' \ - on filesystem: #{e.message}") + Rails.logger.error("An error occurred while accessing the repository '#{repository.root_url}'" + + "on filesystem: #{e.message}") false end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 9e0385e1cf..5433fba1df 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1317,7 +1317,8 @@ en: build_failed: "Unable to create the repository with the selected configuration. %{reason}" empty_repository: "The repository exists, but is empty. It does not contain any revisions yet." exists_on_filesystem: "The repository directory exists already on filesystem." - filesystem_access_failed: "An error occurred while accessing the repository on filesystem: %{message}." + filesystem_access_failed: "An error occurred while accessing the repository on filesystem: %{message}" + deletion_failed: "The repository could not be deleted on disk due to lacking permissions. Please contact your administrator to resolve this issue." not_manageable: "This repository vendor cannot be managed by OpenProject." path_permission_failed: "An error occurred trying to create the following path: %{path}. Please ensure that OpenProject may write to that folder." unauthorized: "You're not authorized to access the repository or the credentials are invalid."