mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 08:57:03 -05:00
clean up aliases
This commit is contained in:
parent
e733809ef2
commit
b2cc848e7d
2 changed files with 27 additions and 30 deletions
|
@ -9,22 +9,21 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
forgefed_model "code.gitea.io/gitea/models/forgefed"
|
"code.gitea.io/gitea/models/forgefed"
|
||||||
"code.gitea.io/gitea/models/repo"
|
"code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
"code.gitea.io/gitea/models/user"
|
||||||
"github.com/google/uuid"
|
"code.gitea.io/gitea/modules/activitypub"
|
||||||
|
|
||||||
api "code.gitea.io/gitea/modules/activitypub"
|
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/validation"
|
"code.gitea.io/gitea/modules/validation"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
pwd_gen "github.com/sethvargo/go-password/password"
|
pwd_gen "github.com/sethvargo/go-password/password"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LikeActivity(ctx *context.APIContext, form any, repositoryId int64) (error, int, string) {
|
func LikeActivity(ctx *context.APIContext, form any, repositoryId int64) (error, int, string) {
|
||||||
activity := form.(*forgefed_model.ForgeLike)
|
activity := form.(*forgefed.ForgeLike)
|
||||||
if res, err := validation.IsValid(activity); !res {
|
if res, err := validation.IsValid(activity); !res {
|
||||||
return err, http.StatusNotAcceptable, "Invalid activity"
|
return err, http.StatusNotAcceptable, "Invalid activity"
|
||||||
}
|
}
|
||||||
|
@ -32,11 +31,11 @@ func LikeActivity(ctx *context.APIContext, form any, repositoryId int64) (error,
|
||||||
|
|
||||||
// parse actorID (person)
|
// parse actorID (person)
|
||||||
actorURI := activity.Actor.GetID().String()
|
actorURI := activity.Actor.GetID().String()
|
||||||
rawActorID, err := forgefed_model.NewActorID(actorURI)
|
rawActorID, err := forgefed.NewActorID(actorURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, http.StatusInternalServerError, "Invalid ActorID"
|
return err, http.StatusInternalServerError, "Invalid ActorID"
|
||||||
}
|
}
|
||||||
federationHost, err := forgefed_model.FindFederationHostByFqdn(ctx, rawActorID.Host)
|
federationHost, err := forgefed.FindFederationHostByFqdn(ctx, rawActorID.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, http.StatusInternalServerError, "Could not loading FederationHost"
|
return err, http.StatusInternalServerError, "Could not loading FederationHost"
|
||||||
}
|
}
|
||||||
|
@ -50,14 +49,14 @@ func LikeActivity(ctx *context.APIContext, form any, repositoryId int64) (error,
|
||||||
if !activity.IsNewer(federationHost.LatestActivity) {
|
if !activity.IsNewer(federationHost.LatestActivity) {
|
||||||
return fmt.Errorf("Activity already processed"), http.StatusNotAcceptable, "Activity out of order."
|
return fmt.Errorf("Activity already processed"), http.StatusNotAcceptable, "Activity out of order."
|
||||||
}
|
}
|
||||||
actorID, err := forgefed_model.NewPersonID(actorURI, string(federationHost.NodeInfo.Source))
|
actorID, err := forgefed.NewPersonID(actorURI, string(federationHost.NodeInfo.Source))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, http.StatusNotAcceptable, "Invalid PersonID"
|
return err, http.StatusNotAcceptable, "Invalid PersonID"
|
||||||
}
|
}
|
||||||
log.Info("Actor accepted:%v", actorID)
|
log.Info("Actor accepted:%v", actorID)
|
||||||
|
|
||||||
// parse objectID (repository)
|
// parse objectID (repository)
|
||||||
objectID, err := forgefed_model.NewRepositoryID(activity.Object.GetID().String(), string(forgefed_model.ForgejoSourceType))
|
objectID, err := forgefed.NewRepositoryID(activity.Object.GetID().String(), string(forgefed.ForgejoSourceType))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, http.StatusNotAcceptable, "Invalid objectId"
|
return err, http.StatusNotAcceptable, "Invalid objectId"
|
||||||
}
|
}
|
||||||
|
@ -67,7 +66,7 @@ func LikeActivity(ctx *context.APIContext, form any, repositoryId int64) (error,
|
||||||
log.Info("Object accepted:%v", objectID)
|
log.Info("Object accepted:%v", objectID)
|
||||||
|
|
||||||
// Check if user already exists
|
// Check if user already exists
|
||||||
user, _, err := user_model.FindFederatedUser(ctx, actorID.ID, federationHost.ID)
|
user, _, err := user.FindFederatedUser(ctx, actorID.ID, federationHost.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, http.StatusInternalServerError, "Searching for user failed"
|
return err, http.StatusInternalServerError, "Searching for user failed"
|
||||||
}
|
}
|
||||||
|
@ -91,7 +90,7 @@ func LikeActivity(ctx *context.APIContext, form any, repositoryId int64) (error,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
federationHost.LatestActivity = activity.StartTime
|
federationHost.LatestActivity = activity.StartTime
|
||||||
err = forgefed_model.UpdateFederationHost(ctx, federationHost)
|
err = forgefed.UpdateFederationHost(ctx, federationHost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, http.StatusNotAcceptable, "Error updating federatedHost"
|
return err, http.StatusNotAcceptable, "Error updating federatedHost"
|
||||||
}
|
}
|
||||||
|
@ -99,9 +98,9 @@ func LikeActivity(ctx *context.APIContext, form any, repositoryId int64) (error,
|
||||||
return nil, 0, ""
|
return nil, 0, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateFederationHostFromAP(ctx *context.APIContext, actorID forgefed_model.ActorID) (*forgefed_model.FederationHost, error) {
|
func CreateFederationHostFromAP(ctx *context.APIContext, actorID forgefed.ActorID) (*forgefed.FederationHost, error) {
|
||||||
actionsUser := user_model.NewActionsUser()
|
actionsUser := user.NewActionsUser()
|
||||||
client, err := api.NewClient(ctx, actionsUser, "no idea where to get key material.")
|
client, err := activitypub.NewClient(ctx, actionsUser, "no idea where to get key material.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -109,7 +108,7 @@ func CreateFederationHostFromAP(ctx *context.APIContext, actorID forgefed_model.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nodeInfoWellKnown, err := forgefed_model.NewNodeInfoWellKnown(body)
|
nodeInfoWellKnown, err := forgefed.NewNodeInfoWellKnown(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -117,25 +116,25 @@ func CreateFederationHostFromAP(ctx *context.APIContext, actorID forgefed_model.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nodeInfo, err := forgefed_model.NewNodeInfo(body)
|
nodeInfo, err := forgefed.NewNodeInfo(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result, err := forgefed_model.NewFederationHost(nodeInfo, actorID.Host)
|
result, err := forgefed.NewFederationHost(nodeInfo, actorID.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = forgefed_model.CreateFederationHost(ctx, &result)
|
err = forgefed.CreateFederationHost(ctx, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateUserFromAP(ctx *context.APIContext, personID forgefed_model.PersonID, federationHostID int64) (*user_model.User, *user_model.FederatedUser, error) {
|
func CreateUserFromAP(ctx *context.APIContext, personID forgefed.PersonID, federationHostID int64) (*user.User, *user.FederatedUser, error) {
|
||||||
// ToDo: Do we get a publicKeyId from server, repo or owner or repo?
|
// ToDo: Do we get a publicKeyId from server, repo or owner or repo?
|
||||||
actionsUser := user_model.NewActionsUser()
|
actionsUser := user.NewActionsUser()
|
||||||
client, err := api.NewClient(ctx, actionsUser, "no idea where to get key material.")
|
client, err := activitypub.NewClient(ctx, actionsUser, "no idea where to get key material.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -145,7 +144,7 @@ func CreateUserFromAP(ctx *context.APIContext, personID forgefed_model.PersonID,
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
person := forgefed_model.ForgePerson{}
|
person := forgefed.ForgePerson{}
|
||||||
err = person.UnmarshalJSON(body)
|
err = person.UnmarshalJSON(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -170,7 +169,7 @@ func CreateUserFromAP(ctx *context.APIContext, personID forgefed_model.PersonID,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
user := user_model.User{
|
newUser := user.User{
|
||||||
LowerName: strings.ToLower(person.PreferredUsername.String()),
|
LowerName: strings.ToLower(person.PreferredUsername.String()),
|
||||||
Name: name,
|
Name: name,
|
||||||
FullName: fullName,
|
FullName: fullName,
|
||||||
|
@ -179,18 +178,18 @@ func CreateUserFromAP(ctx *context.APIContext, personID forgefed_model.PersonID,
|
||||||
Passwd: password,
|
Passwd: password,
|
||||||
MustChangePassword: false,
|
MustChangePassword: false,
|
||||||
LoginName: loginName,
|
LoginName: loginName,
|
||||||
Type: user_model.UserTypeRemoteUser,
|
Type: user.UserTypeRemoteUser,
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
}
|
}
|
||||||
federatedUser := user_model.FederatedUser{
|
federatedUser := user.FederatedUser{
|
||||||
ExternalID: personID.ID,
|
ExternalID: personID.ID,
|
||||||
FederationHostID: federationHostID,
|
FederationHostID: federationHostID,
|
||||||
}
|
}
|
||||||
err = user_model.CreateFederatedUser(ctx, &user, &federatedUser)
|
err = user.CreateFederatedUser(ctx, &newUser, &federatedUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
log.Info("Created federatedUser:%q", federatedUser)
|
log.Info("Created federatedUser:%q", federatedUser)
|
||||||
|
|
||||||
return &user, &federatedUser, nil
|
return &newUser, &federatedUser, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ func Repository(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "Set Name", err)
|
ctx.Error(http.StatusInternalServerError, "Set Name", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response(ctx, repo)
|
response(ctx, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +77,5 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(httpStatus, title, err)
|
ctx.Error(httpStatus, title, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Status(http.StatusNoContent)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue