mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-29 04:36:18 +01:00
federated-star: finalize receive activity (#3871)
PR will finalize the ability to receive a federated star from a remote instance. This is part of: https://codeberg.org/forgejo/forgejo/pulls/1680 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3871 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Michael Jerger <michael.jerger@meissa-gmbh.de> Co-committed-by: Michael Jerger <michael.jerger@meissa-gmbh.de>
This commit is contained in:
parent
32222d7d0a
commit
b01f3bb2a1
3 changed files with 20 additions and 1 deletions
|
@ -45,7 +45,6 @@ package "code.gitea.io/gitea/models/dbfs"
|
|||
|
||||
package "code.gitea.io/gitea/models/forgefed"
|
||||
func GetFederationHost
|
||||
func UpdateFederationHost
|
||||
|
||||
package "code.gitea.io/gitea/models/forgejo/semver"
|
||||
func GetVersion
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/forgefed"
|
||||
"code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/activitypub"
|
||||
"code.gitea.io/gitea/modules/auth/password"
|
||||
|
@ -78,6 +79,20 @@ func ProcessLikeActivity(ctx context.Context, form any, repositoryID int64) (int
|
|||
}
|
||||
log.Info("Got user:%v", user.Name)
|
||||
|
||||
// execute the activity if the repo was not stared already
|
||||
alreadyStared := repo.IsStaring(ctx, user.ID, repositoryID)
|
||||
if !alreadyStared {
|
||||
err = repo.StarRepo(ctx, user.ID, repositoryID, true)
|
||||
if err != nil {
|
||||
return http.StatusNotAcceptable, "Error staring", err
|
||||
}
|
||||
}
|
||||
federationHost.LatestActivity = activity.StartTime
|
||||
err = forgefed.UpdateFederationHost(ctx, federationHost)
|
||||
if err != nil {
|
||||
return http.StatusNotAcceptable, "Error updating federatedHost", err
|
||||
}
|
||||
|
||||
return 0, "", nil
|
||||
}
|
||||
|
||||
|
|
|
@ -203,6 +203,11 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
|
|||
|
||||
federatedUser = unittest.AssertExistsAndLoadBean(t, &user.FederatedUser{ExternalID: "30", FederationHostID: federationHost.ID})
|
||||
unittest.AssertExistsAndLoadBean(t, &user.User{ID: federatedUser.UserID})
|
||||
|
||||
// Replay activity2.
|
||||
resp, err = c.Post(activity2, repoInboxURL)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusNotAcceptable, resp.StatusCode)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue