Module: DeployTokenMethods
- Included in:
- Groups::DeployTokens::CreateService, Groups::DeployTokens::DestroyService, Projects::DeployTokens::CreateService, Projects::DeployTokens::DestroyService
- Defined in:
- app/services/concerns/deploy_token_methods.rb
Instance Method Summary collapse
- #create_deploy_token_for(entity, current_user, params) ⇒ Object
- #create_deploy_token_payload_for(deploy_token) ⇒ Object
- #destroy_deploy_token(entity, params) ⇒ Object
Instance Method Details
#create_deploy_token_for(entity, current_user, params) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/services/concerns/deploy_token_methods.rb', line 4 def create_deploy_token_for(entity, current_user, params) entity_name = entity.class.name.downcase params[:deploy_token_type] = DeployToken.deploy_token_types[:"#{entity_name}_type"] params[:"#{entity_name}_id"] = entity.id entity.deploy_tokens.create(params) do |deploy_token| deploy_token.username = params[:username].presence deploy_token.creator_id = current_user.id end end |
#create_deploy_token_payload_for(deploy_token) ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/services/concerns/deploy_token_methods.rb', line 21 def create_deploy_token_payload_for(deploy_token) if deploy_token.persisted? success(deploy_token: deploy_token, http_status: :created) else error(deploy_token.errors..to_sentence, :bad_request, pass_back: { deploy_token: deploy_token }) end end |
#destroy_deploy_token(entity, params) ⇒ Object
15 16 17 18 19 |
# File 'app/services/concerns/deploy_token_methods.rb', line 15 def destroy_deploy_token(entity, params) deploy_token = entity.deploy_tokens.find(params[:token_id]) deploy_token.destroy end |