diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/auth/container_registry_authentication_service.rb | 6 | ||||
-rw-r--r-- | app/services/deploy_tokens/create_service.rb | 17 |
2 files changed, 19 insertions, 4 deletions
diff --git a/app/services/auth/container_registry_authentication_service.rb b/app/services/auth/container_registry_authentication_service.rb index 425ceb9c1a8..8f050072f74 100644 --- a/app/services/auth/container_registry_authentication_service.rb +++ b/app/services/auth/container_registry_authentication_service.rb @@ -124,8 +124,8 @@ module Auth end def can_user?(ability, project) - current_user.is_a?(User) && - can?(current_user, ability, project) + user = current_user.is_a?(User) ? current_user : nil + can?(user, ability, project) end def build_can_pull?(requested_project) @@ -143,7 +143,7 @@ module Auth def user_can_pull?(requested_project) has_authentication_ability?(:read_container_image) && - can?(current_user, :read_container_image, requested_project) + can_user?(:read_container_image, requested_project) end def deploy_token_can_pull?(requested_project) diff --git a/app/services/deploy_tokens/create_service.rb b/app/services/deploy_tokens/create_service.rb index a5d31dd9fa5..e623d94b444 100644 --- a/app/services/deploy_tokens/create_service.rb +++ b/app/services/deploy_tokens/create_service.rb @@ -1,7 +1,22 @@ module DeployTokens class CreateService < BaseService def execute - @project.deploy_tokens.build(params).tap(&:save) + @project.deploy_tokens.create(deploy_token_params) + end + + private + + def deploy_token_params + params[:expires_at] = expires_at_date + params + end + + def expires_at_date + params[:expires_at].present? ? default_expires_at : params[:expires_at] + end + + def default_expires_at + DeployToken::FUTURE_DATE end end end |