diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2018-03-19 19:11:12 +0300 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-07 05:20:16 +0300 |
commit | db18993f652425b72c4b854e18a002e0ec44b196 (patch) | |
tree | 7466e5f6b154bd79e72c13a5021d92eb9d7e4a13 /app/controllers | |
parent | aade8b3652573db40e7b777c72caa922b0bc12ef (diff) |
Create barebones for Deploytoken
Includes:
- Model, factories, create service and controller actions
- As usual, includes specs for everything
- Builds UI (copy from PAT)
- Add revoke action
Closes #31591
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/projects/deploy_tokens_controller.rb | 34 | ||||
-rw-r--r-- | app/controllers/projects/settings/repository_controller.rb | 10 |
2 files changed, 44 insertions, 0 deletions
diff --git a/app/controllers/projects/deploy_tokens_controller.rb b/app/controllers/projects/deploy_tokens_controller.rb new file mode 100644 index 00000000000..ecc6db50f2f --- /dev/null +++ b/app/controllers/projects/deploy_tokens_controller.rb @@ -0,0 +1,34 @@ +class Projects::DeployTokensController < Projects::ApplicationController + before_action :authorize_admin_project! + + def create + @token = DeployTokens::CreateService.new(@project, current_user, deploy_token_params).execute + token_params = {} + + if @token.valid? + flash[:notice] = 'Your new project deploy token has been created.' + else + token_params = @token.attributes.slice("name", "scopes", "expires_at") + flash[:alert] = @token.errors.full_messages.join(', ').html_safe + end + + redirect_to project_settings_repository_path(project, deploy_token: token_params) + end + + def revoke + @token = @project.deploy_tokens.find(params[:id]) + @token.revoke! + + redirect_to project_settings_repository_path(project) + end + + private + + def deploy_token_params + params.require(:deploy_token).permit(:name, :expires_at, scopes: []) + end + + def authorize_admin_project! + return render_404 unless can?(current_user, :admin_project, @project) + end +end diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb index dd9e4a2af3e..28897cc5946 100644 --- a/app/controllers/projects/settings/repository_controller.rb +++ b/app/controllers/projects/settings/repository_controller.rb @@ -5,7 +5,9 @@ module Projects def show @deploy_keys = DeployKeysPresenter.new(@project, current_user: current_user) + @deploy_tokens = DeployTokensPresenter.new(@project.deploy_tokens.active, current_user: current_user, project: project) + define_deploy_token define_protected_refs end @@ -51,6 +53,14 @@ module Projects gon.push(protectable_branches_for_dropdown) gon.push(access_levels_options) end + + def define_deploy_token + @deploy_token = @project.deploy_tokens.build(deploy_token_attributes) + end + + def deploy_token_attributes + params.fetch(:deploy_token, {}).permit(:name, :expires_at, scopes: []) + end end end end |