This commit is contained in:
Michael Jerger 2024-05-16 08:15:43 +02:00
parent fe3473fc8b
commit 1c7a9b00be
6 changed files with 278 additions and 0 deletions

View file

@ -1,5 +1,6 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Copyright 2019 The Gitea Authors. All rights reserved.
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package user
@ -131,6 +132,9 @@ type User struct {
AvatarEmail string `xorm:"NOT NULL"`
UseCustomAvatar bool
// For federation
NormalizedFederatedURI string
// Counters
NumFollowers int
NumFollowing int `xorm:"NOT NULL DEFAULT 0"`
@ -303,6 +307,11 @@ func (u *User) HTMLURL() string {
return setting.AppURL + url.PathEscape(u.Name)
}
// APAPIURL returns the IRI to the api endpoint of the user
func (u *User) APAPIURL() string {
return fmt.Sprintf("%vapi/v1/activitypub/user-id/%v", setting.AppURL, url.PathEscape(fmt.Sprintf("%v", u.ID)))
}
// OrganisationLink returns the organization sub page link.
func (u *User) OrganisationLink() string {
return setting.AppSubURL + "/org/" + url.PathEscape(u.Name)
@ -834,6 +843,17 @@ func ValidateUser(u *User, cols ...string) error {
return nil
}
func (u User) Validate() []string {
var result []string
if err := ValidateUser(&u); err != nil {
result = append(result, err.Error())
}
if err := ValidateEmail(u.Email); err != nil {
result = append(result, err.Error())
}
return result
}
// UpdateUserCols update user according special columns
func UpdateUserCols(ctx context.Context, u *User, cols ...string) error {
if err := ValidateUser(u, cols...); err != nil {