diff options
Diffstat (limited to 'app/services/personal_access_tokens/create_service.rb')
-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? |