summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-01-29 19:30:43 +0100
committerGitHub <noreply@github.com>2021-01-29 19:30:43 +0100
commit0e0424c8ecaf6fa3cdd1fcfc154f188014c63dd8 (patch)
tree30faffc8d529ef405c9a8de25fec066ea2d393f8 /modules
parent05365816ab28bd23267feec8b3cd9d8721bc0dbe (diff)
downloadgitea-0e0424c8ecaf6fa3cdd1fcfc154f188014c63dd8.tar.gz
gitea-0e0424c8ecaf6fa3cdd1fcfc154f188014c63dd8.zip
Add Doctor FixWrongUserType (#14522)
* Add Doctor FixWrongUserType * use NoAutoTime
Diffstat (limited to 'modules')
-rw-r--r--modules/doctor/usertype.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/modules/doctor/usertype.go b/modules/doctor/usertype.go
new file mode 100644
index 0000000000..26c0d34cda
--- /dev/null
+++ b/modules/doctor/usertype.go
@@ -0,0 +1,40 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package doctor
+
+import (
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/log"
+)
+
+func checkUserType(logger log.Logger, autofix bool) error {
+ count, err := models.CountWrongUserType()
+ if err != nil {
+ logger.Critical("Error: %v whilst counting wrong user types")
+ return err
+ }
+ if count > 0 {
+ if autofix {
+ if count, err = models.FixWrongUserType(); err != nil {
+ logger.Critical("Error: %v whilst fixing wrong user types")
+ return err
+ }
+ logger.Info("%d users with wrong type fixed", count)
+ } else {
+ logger.Warn("%d users with wrong type exist", count)
+ }
+ }
+ return nil
+}
+
+func init() {
+ Register(&Check{
+ Title: "Check if user with wrong type exist",
+ Name: "check-user-type",
+ IsDefault: true,
+ Run: checkUserType,
+ Priority: 3,
+ })
+}