Skip to content

Commit

Permalink
Move check_and_remove_repositories to a concern
Browse files Browse the repository at this point in the history
It's only used in SourceProjectController and SourceProjectMetaController.
  • Loading branch information
hennevogel committed Dec 21, 2023
1 parent 47f15b6 commit 4503919
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/api/app/controllers/concerns/check_and_remove_repositories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module CheckAndRemoveRepositories
extend ActiveSupport::Concern

def check_and_remove_repositories!(repositories, opts)
result = Project.check_repositories(repositories) unless opts[:force]
raise Source::Errors::RepoDependency, result[:error] if !opts[:force] && result[:error]

result = Project.remove_repositories(repositories, opts)
raise Source::Errors::ChangeProjectNoPermission, result[:error] if !opts[:force] && result[:error]
end
end
8 changes: 0 additions & 8 deletions src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ def package_command
dispatch_command(:package_command, @command)
end

def check_and_remove_repositories!(repositories, opts)
result = Project.check_repositories(repositories) unless opts[:force]
raise RepoDependency, result[:error] if !opts[:force] && result[:error]

result = Project.remove_repositories(repositories, opts)
raise ChangeProjectNoPermission, result[:error] if !opts[:force] && result[:error]
end

def pubkey_path
# check for project
@prj = Project.get_by_name(params[:project])
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/controllers/source_project_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class SourceProjectController < SourceController
include CheckAndRemoveRepositories

# GET /source/:project
def show
project_name = params[:project]
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/controllers/source_project_meta_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class SourceProjectMetaController < SourceController
include CheckAndRemoveRepositories

validate_action update: { request: :project, response: :status }
validate_action show: { response: :project }

Expand Down

0 comments on commit 4503919

Please sign in to comment.