72e6b46cde
- Branding: default app name MokoGitea -> MokoGIT; all standalone 'MokoGitea' brand strings, comments, and copyright headers -> MokoGIT - Special repo/config names: .mokogitea/.mokogitea-private -> .mokogit/ .mokogit-private (workflow discovery, issue/PR templates, profile+wiki repo names in header.go, config dir renamed) - Lowercase: mokogitea -> mokogit (docker image refs, ntfy topic, mail tags, wiki docs, Joomla element/targetplatform, MCP package docs) - Actions system user mokogitea-actions -> mokogit-actions + DB migration #369 to rename the existing id=-2 user in place - Icon: bundle Moko favicon.svg as public/assets/img/{favicon,logo}.svg; wire PWA manifest (SiteManifest) + nav logo to the SVG - CHANGELOG entry documenting the rebrand Shared MOKOGITEA_* CI/compose env + org-secret names are intentionally left for the coordinated server cutover to avoid breaking cross-repo CI. Claude-Session: https://claude.ai/code/session_01Bqe7fAuHQeiLueYfeHFrHw
110 lines
2.9 KiB
Go
110 lines
2.9 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/structs"
|
|
)
|
|
|
|
const (
|
|
GhostUserID int64 = -1
|
|
GhostUserName = "Ghost"
|
|
)
|
|
|
|
// NewGhostUser creates and returns a fake user for someone has deleted their account.
|
|
func NewGhostUser() *User {
|
|
return &User{
|
|
ID: GhostUserID,
|
|
Name: GhostUserName,
|
|
LowerName: strings.ToLower(GhostUserName),
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
const (
|
|
ActionsUserID int64 = -2
|
|
ActionsUserName = "mokogit-actions"
|
|
ActionsUserEmail = "mokogit-actions[bot]@mokoconsulting.tech"
|
|
|
|
// Legacy names recognized as aliases for the actions bot user.
|
|
ActionsUserNameLegacyGitea = "gitea-actions"
|
|
ActionsUserNameLegacyGitHub = "github-actions"
|
|
)
|
|
|
|
// 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: "MokoGIT Actions",
|
|
Email: ActionsUserEmail,
|
|
KeepEmailPrivate: true,
|
|
LoginName: ActionsUserName,
|
|
Type: UserTypeBot,
|
|
Visibility: structs.VisibleTypePublic,
|
|
}
|
|
}
|
|
|
|
func NewActionsUserWithTaskID(id int64) *User {
|
|
u := NewActionsUser()
|
|
// LoginName is for only internal usage in this case, so it can be moved to other fields in the future
|
|
u.LoginSource = -1
|
|
u.LoginName = "@" + ActionsUserName + "/" + strconv.FormatInt(id, 10)
|
|
return u
|
|
}
|
|
|
|
func GetActionsUserTaskID(u *User) (int64, bool) {
|
|
if u == nil || u.ID != ActionsUserID {
|
|
return 0, false
|
|
}
|
|
prefix, payload, _ := strings.Cut(u.LoginName, "/")
|
|
if prefix != "@"+ActionsUserName {
|
|
return 0, false
|
|
} else if taskID, err := strconv.ParseInt(payload, 10, 64); err == nil {
|
|
return taskID, true
|
|
}
|
|
return 0, false
|
|
}
|
|
|
|
// IsActions checks whether this user is the built-in actions bot.
|
|
func (u *User) IsActions() bool {
|
|
return u != nil && u.ID == ActionsUserID
|
|
}
|
|
|
|
// IsGiteaActions is a deprecated alias for IsActions.
|
|
func (u *User) IsGiteaActions() bool {
|
|
return u.IsActions()
|
|
}
|
|
|
|
// isActionsName returns true if the given name (case-insensitive, with
|
|
// optional "[bot]" suffix stripped) matches any known actions bot name.
|
|
func isActionsName(name string) bool {
|
|
clean := strings.TrimSuffix(name, "[bot]")
|
|
return strings.EqualFold(clean, ActionsUserName) ||
|
|
strings.EqualFold(clean, ActionsUserNameLegacyGitea) ||
|
|
strings.EqualFold(clean, ActionsUserNameLegacyGitHub)
|
|
}
|
|
|
|
func GetSystemUserByName(name string) *User {
|
|
if strings.EqualFold(name, GhostUserName) {
|
|
return NewGhostUser()
|
|
}
|
|
if isActionsName(name) {
|
|
return NewActionsUser()
|
|
}
|
|
return nil
|
|
}
|