summaryrefslogtreecommitdiffstats
path: root/models/user/user_system.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-12-12 23:57:56 +0100
commite68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch)
tree97775d6c13b0f416af55314eb6a89ef792474615 /models/user/user_system.go
parentInitial commit. (diff)
downloadforgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz
forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to '')
-rw-r--r--models/user/user_system.go97
1 files changed, 97 insertions, 0 deletions
diff --git a/models/user/user_system.go b/models/user/user_system.go
new file mode 100644
index 0000000..ba9a213
--- /dev/null
+++ b/models/user/user_system.go
@@ -0,0 +1,97 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package user
+
+import (
+ "net/url"
+ "strings"
+
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/structs"
+)
+
+const (
+ GhostUserID = -1
+ GhostUserName = "Ghost"
+ GhostUserLowerName = "ghost"
+)
+
+// NewGhostUser creates and returns a fake user for someone has deleted their account.
+func NewGhostUser() *User {
+ return &User{
+ ID: GhostUserID,
+ Name: GhostUserName,
+ LowerName: GhostUserLowerName,
+ }
+}
+
+// IsGhost check if user is fake user for a deleted account
+func (u *User) IsGhost() bool {
+ if u == nil {
+ return false
+ }
+ 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 = "forgejo-actions"
+ ActionsFullName = "Forgejo Actions"
+ ActionsEmail = "noreply@forgejo.org"
+)
+
+// NewActionsUser creates and returns a fake user for running the actions.
+func NewActionsUser() *User {
+ return &User{
+ ID: ActionsUserID,
+ Name: ActionsUserName,
+ LowerName: ActionsUserName,
+ IsActive: true,
+ FullName: ActionsFullName,
+ Email: ActionsEmail,
+ KeepEmailPrivate: true,
+ LoginName: ActionsUserName,
+ Type: UserTypeIndividual,
+ AllowCreateOrganization: true,
+ Visibility: structs.VisibleTypePublic,
+ }
+}
+
+func (u *User) IsActions() bool {
+ return u != nil && u.ID == ActionsUserID
+}
+
+const (
+ APActorUserID = -3
+ APActorUserName = "actor"
+ APActorEmail = "noreply@forgejo.org"
+)
+
+func NewAPActorUser() *User {
+ return &User{
+ ID: APActorUserID,
+ Name: APActorUserName,
+ LowerName: APActorUserName,
+ IsActive: true,
+ Email: APActorEmail,
+ KeepEmailPrivate: true,
+ LoginName: APActorUserName,
+ Type: UserTypeIndividual,
+ Visibility: structs.VisibleTypePublic,
+ }
+}
+
+func APActorUserAPActorID() string {
+ path, _ := url.JoinPath(setting.AppURL, "/api/v1/activitypub/actor")
+ return path
+}