-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add controller and views to trigger tokens through the webui * Adapt autocomplete javascript to support `:package` and `:project` param names * Add corresponding policies
- Loading branch information
1 parent
8f5a76c
commit 0eb73e5
Showing
7 changed files
with
106 additions
and
2 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
52 changes: 52 additions & 0 deletions
52
src/api/app/controllers/webui/users/token_triggers_controller.rb
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,52 @@ | ||
class Webui::Users::TokenTriggersController < Webui::WebuiController | ||
include Pundit | ||
include Triggerable | ||
|
||
before_action :set_token | ||
before_action :set_project, except: [:show] | ||
before_action :set_package, except: [:show] | ||
before_action :set_object_to_authorize, except: [:show] | ||
# set_multibuild_flavor needs to run after the set_object_to_authorize callback | ||
append_before_action :set_multibuild_flavor, except: [:show] | ||
|
||
rescue_from 'Project::Errors::UnknownObjectError' do |exception| | ||
flash[:error] = "#{exception.message}" | ||
redirect_to tokens_url | ||
end | ||
|
||
rescue_from 'Package::Errors::UnknownObjectError' do |exception| | ||
flash[:error] = "#{exception.message}" | ||
redirect_to tokens_url | ||
end | ||
|
||
def show | ||
authorize @token, :show? | ||
end | ||
|
||
def update | ||
authorize @token, :webui_trigger? | ||
|
||
opts = { project: @project, package: @package, repository: params[:repository], arch: params[:arch] } | ||
opts[:multibuild_flavor] = @multibuild_container if @multibuild_container.present? | ||
|
||
begin | ||
@token.call(opts) | ||
flash[:success] = "Token with id #{@token.id} successfully triggered!" | ||
rescue Token::Errors::NoReleaseTargetFound, Project::Errors::WritePermissionError => e | ||
flash[:error] = "Failed to trigger token: #{e.message}" | ||
rescue Backend::NotFoundError => e | ||
flash[:error] = "Failed to trigger token: #{e.summary}" | ||
end | ||
|
||
redirect_to tokens_url | ||
end | ||
|
||
private | ||
|
||
def set_token | ||
@token = Token.find(params[:id]) | ||
rescue ActiveRecord::RecordNotFound => e | ||
flash[:error] = e.message | ||
redirect_to tokens_url | ||
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
6 changes: 6 additions & 0 deletions
6
src/api/app/views/webui/users/token_triggers/_breadcrumb_items.html.haml
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,6 @@ | ||
%li.breadcrumb-item | ||
= link_to('Your Profile', user_path(User.session!)) | ||
|
||
- if action_name == 'show' | ||
%li.breadcrumb-item.active{ 'aria-current' => 'page' } | ||
Trigger Token |
34 changes: 34 additions & 0 deletions
34
src/api/app/views/webui/users/token_triggers/show.html.haml
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,34 @@ | ||
- @pagetitle = 'Trigger Token' | ||
|
||
.card | ||
.card-body | ||
%h3.mb-3= @pagetitle | ||
|
||
-# "as: :token" to have a consistent name across all various token classes | ||
= form_for(@token, as: :token, url: token_trigger_path, method: :put, local: false) do |f| | ||
.form-row | ||
.col-12.col-md-10.col-lg-9 | ||
.form-group | ||
= f.label(:id, 'Id:') | ||
= @token.id | ||
.form-group | ||
= f.label(:type, 'Operation:') | ||
= @token.class.token_name.capitalize | ||
- token_package = @token.package | ||
- if token_package.present? | ||
= fields_for(:package, token_package) do |token_fields| | ||
.form-group | ||
= token_fields.label(:project, 'Project:') | ||
= token_package.project | ||
.form-group | ||
= token_fields.label(:package, 'Package:') | ||
= token_package.name | ||
- else | ||
.form-group.row | ||
.col-sm | ||
= render partial: 'webui/shared/autocomplete', locals: { html_id: 'project', label: 'Project:', required: true, | ||
data: { source: autocomplete_projects_path(local: true) } } | ||
.col-sm | ||
= render partial: 'webui/shared/autocomplete', locals: { html_id: 'package', label: 'Package:', required: true, | ||
data: { source: autocomplete_packages_path }, disabled: true } | ||
= f.submit('Trigger', class: 'btn btn-primary px-4 mt-3 mt-sm-0') |
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
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