diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-08 06:08:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-08 06:08:19 +0300 |
commit | bf293d47937b3332462689c3fecc868706553f3a (patch) | |
tree | 47f0f1063aa27e4529c23068537ce45d6adb4cf0 /app/services/personal_access_tokens | |
parent | 356e3c444dc8fab920d3547461b6ae721c5eb50f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/personal_access_tokens')
-rw-r--r-- | app/services/personal_access_tokens/create_service.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/app/services/personal_access_tokens/create_service.rb b/app/services/personal_access_tokens/create_service.rb index adb7924f35e..31ba88af46c 100644 --- a/app/services/personal_access_tokens/create_service.rb +++ b/app/services/personal_access_tokens/create_service.rb @@ -13,7 +13,7 @@ module PersonalAccessTokens def execute return ServiceResponse.error(message: 'Not permitted to create') unless creation_permitted? - token = target_user.personal_access_tokens.create(params.slice(*allowed_params)) + token = target_user.personal_access_tokens.create(personal_access_token_params) if token.persisted? log_event(token) @@ -31,13 +31,17 @@ module PersonalAccessTokens attr_reader :target_user, :ip_address - def allowed_params - [ - :name, - :impersonation, - :scopes, - :expires_at - ] + def personal_access_token_params + { + name: params[:name], + impersonation: params[:impersonation] || false, + scopes: params[:scopes], + expires_at: pat_expiration + } + end + + def pat_expiration + params[:expires_at].presence || PersonalAccessToken::MAX_PERSONAL_ACCESS_TOKEN_LIFETIME_IN_DAYS.days.from_now end def creation_permitted? |