-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move token preperation logic to a concern
The methods to authorize and set the package/project from a token is also required in the webui controller. Therefore moving it to a concern in order to reuse them.
- Loading branch information
1 parent
2acf054
commit 8f5a76c
Showing
2 changed files
with
49 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Triggerable | ||
extend ActiveSupport::Concern | ||
|
||
def set_project | ||
# By default we operate on the package association | ||
@project = @token.package.try(:project) | ||
# If the token has no package, let's find one from the parameters | ||
@project ||= Project.get_by_name(params[:project]) | ||
# Remote projects are read-only, can't trigger something for them. | ||
# See https://github.com/openSUSE/open-build-service/wiki/Links#project-links | ||
raise Project::Errors::UnknownObjectError, "Sorry, triggering tokens for remote project \"#{params[:project]}\" is not possible." unless @project.is_a?(Project) | ||
end | ||
|
||
def set_package | ||
# By default we operate on the package association | ||
@package = @token.package | ||
# If the token has no package, let's find one from the parameters | ||
@package ||= Package.get_by_project_and_name(@project, | ||
params[:package], | ||
@token.package_find_options) | ||
return unless @project.links_to_remote? | ||
|
||
# The token has no package, we did not find a package in the database but the project has a link to remote. | ||
# See https://github.com/openSUSE/open-build-service/wiki/Links#project-links | ||
# In this case, we will try to trigger with the user input, no matter what it is | ||
@package ||= params[:package] | ||
|
||
# TODO: This should not happen right? But who knows... | ||
raise ActiveRecord::RecordNotFound unless @package | ||
end | ||
|
||
def set_object_to_authorize | ||
@token.object_to_authorize = package_from_project_link? ? @project : @package | ||
end | ||
|
||
def set_multibuild_flavor | ||
# Do NOT use @package.multibuild_flavor? here because the flavor need to be checked for the right source revision | ||
@multibuild_container = params[:package].gsub(/.*:/, '') if params[:package].present? && params[:package].include?(':') | ||
end | ||
|
||
def package_from_project_link? | ||
# a remote package is always included via project link | ||
!(@package.is_a?(Package) && @package.project == @project) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters