loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix CLI allowing creation of access tokens with existing name (#26071)

We are now:
- Making sure there is no existing access token with the same name
- Making sure the given scopes are valid (we already did this before but
now we have a message)

The logic is mostly taken from
https://github.com/go-gitea/gitea/blob/a12a5f3652c339b17b187ff424a480631a3c1e1e/routers/api/v1/user/app.go#L101-L123

Closes #26044

Signed-off-by: Yarden Shoham <git@yardenshoham.com>

authored by

Yarden Shoham and committed by
GitHub
d36ddfe2 3e4a4f9c

+16 -5
+16 -5
cmd/admin_user_generate_access_token.go
··· 57 57 return err 58 58 } 59 59 60 - accessTokenScope, err := auth_model.AccessTokenScope(c.String("scopes")).Normalize() 60 + // construct token with name and user so we can make sure it is unique 61 + t := &auth_model.AccessToken{ 62 + Name: c.String("token-name"), 63 + UID: user.ID, 64 + } 65 + 66 + exist, err := auth_model.AccessTokenByNameExists(t) 61 67 if err != nil { 62 68 return err 69 + } 70 + if exist { 71 + return fmt.Errorf("access token name has been used already") 63 72 } 64 73 65 - t := &auth_model.AccessToken{ 66 - Name: c.String("token-name"), 67 - UID: user.ID, 68 - Scope: accessTokenScope, 74 + // make sure the scopes are valid 75 + accessTokenScope, err := auth_model.AccessTokenScope(c.String("scopes")).Normalize() 76 + if err != nil { 77 + return fmt.Errorf("invalid access token scope provided: %w", err) 69 78 } 79 + t.Scope = accessTokenScope 70 80 81 + // create the token 71 82 if err := auth_model.NewAccessToken(t); err != nil { 72 83 return err 73 84 }