aboutsummaryrefslogtreecommitdiffstats
path: root/models/user/user_system.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/user/user_system.go')
-rw-r--r--models/user/user_system.go49
1 files changed, 28 insertions, 21 deletions
diff --git a/models/user/user_system.go b/models/user/user_system.go
index 612cdb2cae..e07274d291 100644
--- a/models/user/user_system.go
+++ b/models/user/user_system.go
@@ -10,9 +10,8 @@ import (
)
const (
- GhostUserID = -1
- GhostUserName = "Ghost"
- GhostUserLowerName = "ghost"
+ GhostUserID int64 = -1
+ GhostUserName = "Ghost"
)
// NewGhostUser creates and returns a fake user for someone has deleted their account.
@@ -20,10 +19,14 @@ func NewGhostUser() *User {
return &User{
ID: GhostUserID,
Name: GhostUserName,
- LowerName: GhostUserLowerName,
+ LowerName: strings.ToLower(GhostUserName),
}
}
+func IsGhostUserName(name string) bool {
+ return strings.EqualFold(name, GhostUserName)
+}
+
// IsGhost check if user is fake user for a deleted account
func (u *User) IsGhost() bool {
if u == nil {
@@ -32,22 +35,16 @@ func (u *User) IsGhost() bool {
return u.ID == GhostUserID && u.Name == GhostUserName
}
-// NewReplaceUser creates and returns a fake user for external user
-func NewReplaceUser(name string) *User {
- return &User{
- ID: 0,
- Name: name,
- LowerName: strings.ToLower(name),
- }
-}
-
const (
- ActionsUserID = -2
- ActionsUserName = "gitea-actions"
- ActionsFullName = "Gitea Actions"
- ActionsEmail = "teabot@gitea.io"
+ ActionsUserID int64 = -2
+ ActionsUserName = "gitea-actions"
+ ActionsUserEmail = "teabot@gitea.io"
)
+func IsGiteaActionsUserName(name string) bool {
+ return strings.EqualFold(name, ActionsUserName)
+}
+
// NewActionsUser creates and returns a fake user for running the actions.
func NewActionsUser() *User {
return &User{
@@ -55,16 +52,26 @@ func NewActionsUser() *User {
Name: ActionsUserName,
LowerName: ActionsUserName,
IsActive: true,
- FullName: ActionsFullName,
- Email: ActionsEmail,
+ FullName: "Gitea Actions",
+ Email: ActionsUserEmail,
KeepEmailPrivate: true,
LoginName: ActionsUserName,
- Type: UserTypeIndividual,
+ Type: UserTypeBot,
AllowCreateOrganization: true,
Visibility: structs.VisibleTypePublic,
}
}
-func (u *User) IsActions() bool {
+func (u *User) IsGiteaActions() bool {
return u != nil && u.ID == ActionsUserID
}
+
+func GetSystemUserByName(name string) *User {
+ if IsGhostUserName(name) {
+ return NewGhostUser()
+ }
+ if IsGiteaActionsUserName(name) {
+ return NewActionsUser()
+ }
+ return nil
+}