aboutsummaryrefslogtreecommitdiffstats
path: root/models/user/user.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-12-20 10:05:29 -0800
committerGitHub <noreply@github.com>2024-12-20 18:05:29 +0000
commit751fe8b714f8ebd5fa915e893402776c4856d6c2 (patch)
tree04c16b9574ef8ea394ac2565ed2efb18728ce85c /models/user/user.go
parent4774151e5339431dcd7fde70f084e7a0ff0b6cf6 (diff)
downloadgitea-751fe8b714f8ebd5fa915e893402776c4856d6c2.tar.gz
gitea-751fe8b714f8ebd5fa915e893402776c4856d6c2.zip
Move some errors to their own sub packages (#32880)
Diffstat (limited to 'models/user/user.go')
-rw-r--r--models/user/user.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/models/user/user.go b/models/user/user.go
index bd92693b6e..72caafc3ba 100644
--- a/models/user/user.go
+++ b/models/user/user.go
@@ -788,6 +788,21 @@ func createUser(ctx context.Context, u *User, meta *Meta, createdByAdmin bool, o
return committer.Commit()
}
+// ErrDeleteLastAdminUser represents a "DeleteLastAdminUser" kind of error.
+type ErrDeleteLastAdminUser struct {
+ UID int64
+}
+
+// IsErrDeleteLastAdminUser checks if an error is a ErrDeleteLastAdminUser.
+func IsErrDeleteLastAdminUser(err error) bool {
+ _, ok := err.(ErrDeleteLastAdminUser)
+ return ok
+}
+
+func (err ErrDeleteLastAdminUser) Error() string {
+ return fmt.Sprintf("can not delete the last admin user [uid: %d]", err.UID)
+}
+
// IsLastAdminUser check whether user is the last admin
func IsLastAdminUser(ctx context.Context, user *User) bool {
if user.IsAdmin && CountUsers(ctx, &CountUserFilter{IsAdmin: optional.Some(true)}) <= 1 {