activitypub: Implement an instance-wide actor

An instance-wide actor is required for outgoing signed requests that are
done on behalf of the instance, rather than on behalf of other actors.
Such things include updating profile information, or fetching public
keys.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-08-05 10:50:26 +02:00
parent cd17eb0fa7
commit f121e87aa6
No known key found for this signature in database
5 changed files with 198 additions and 0 deletions

View file

@ -4,8 +4,10 @@
package user
import (
"net/url"
"strings"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
)
@ -68,3 +70,28 @@ func NewActionsUser() *User {
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
}