summaryrefslogtreecommitdiffstats
path: root/models/auth
diff options
context:
space:
mode:
authorqwerty287 <80460567+qwerty287@users.noreply.github.com>2022-10-09 14:07:41 +0200
committerGitHub <noreply@github.com>2022-10-09 20:07:41 +0800
commita813c9d8f3862fec934ff657fb4e490530167183 (patch)
tree877ca996565a94fa0f22d53e9e737dfd47ba8077 /models/auth
parent97f3f1988b2b544350f58aa8b49cb958bb4da5b5 (diff)
downloadgitea-a813c9d8f3862fec934ff657fb4e490530167183.tar.gz
gitea-a813c9d8f3862fec934ff657fb4e490530167183.zip
Allow creation of OAuth2 applications for orgs (#18084)
Adds the settings pages to create OAuth2 apps also to the org settings and allows to create apps for orgs. Refactoring: the oauth2 related templates are shared for instance-wide/org/user, and the backend code uses `OAuth2CommonHandlers` to share code for instance-wide/org/user. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models/auth')
-rw-r--r--models/auth/oauth2.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/models/auth/oauth2.go b/models/auth/oauth2.go
index 73c250d4af..abcd9e1ca6 100644
--- a/models/auth/oauth2.go
+++ b/models/auth/oauth2.go
@@ -225,7 +225,8 @@ func updateOAuth2Application(ctx context.Context, app *OAuth2Application) error
func deleteOAuth2Application(ctx context.Context, id, userid int64) error {
sess := db.GetEngine(ctx)
- if deleted, err := sess.Delete(&OAuth2Application{ID: id, UID: userid}); err != nil {
+ // the userid could be 0 if the app is instance-wide
+ if deleted, err := sess.Where(builder.Eq{"id": id, "uid": userid}).Delete(&OAuth2Application{}); err != nil {
return err
} else if deleted == 0 {
return ErrOAuthApplicationNotFound{ID: id}
@@ -476,7 +477,7 @@ func GetOAuth2GrantsByUserID(ctx context.Context, uid int64) ([]*OAuth2Grant, er
// RevokeOAuth2Grant deletes the grant with grantID and userID
func RevokeOAuth2Grant(ctx context.Context, grantID, userID int64) error {
- _, err := db.DeleteByBean(ctx, &OAuth2Grant{ID: grantID, UserID: userID})
+ _, err := db.GetEngine(ctx).Where(builder.Eq{"id": grantID, "user_id": userID}).Delete(&OAuth2Grant{})
return err
}