mirror of https://codeberg.org/forgejo/forgejo.git
Compare commits
3 Commits
1c7a9b00be
...
5ce359b14e
Author | SHA1 | Date |
---|---|---|
Michael Jerger | 5ce359b14e | |
Michael Jerger | 8b90194d1b | |
Michael Jerger | b2c3eb1644 |
|
@ -131,11 +131,13 @@ package "code.gitea.io/gitea/models/user"
|
|||
func (ErrUserInactive).Unwrap
|
||||
func IsErrExternalLoginUserAlreadyExist
|
||||
func IsErrExternalLoginUserNotExist
|
||||
func NewFederatedUser
|
||||
func IsErrUserSettingIsNotExist
|
||||
func GetUserAllSettings
|
||||
func DeleteUserSetting
|
||||
func GetUserEmailsByNames
|
||||
func GetUserNamesByIDs
|
||||
func DeleteFederatedUser
|
||||
|
||||
package "code.gitea.io/gitea/modules/activitypub"
|
||||
func (*Client).Post
|
||||
|
@ -169,16 +171,6 @@ package "code.gitea.io/gitea/modules/eventsource"
|
|||
|
||||
package "code.gitea.io/gitea/modules/forgefed"
|
||||
func NewForgeLike
|
||||
func NewPersonID
|
||||
func (PersonID).AsWebfinger
|
||||
func (PersonID).AsLoginName
|
||||
func (PersonID).HostSuffix
|
||||
func (PersonID).Validate
|
||||
func NewRepositoryID
|
||||
func (RepositoryID).Validate
|
||||
func (ForgePerson).MarshalJSON
|
||||
func (*ForgePerson).UnmarshalJSON
|
||||
func (ForgePerson).Validate
|
||||
func GetItemByType
|
||||
func JSONUnmarshalerFn
|
||||
func NotEmpty
|
||||
|
|
|
@ -68,6 +68,10 @@ var migrations = []*Migration{
|
|||
NewMigration("Remove Gitea-specific columns from the repository and badge tables", RemoveGiteaSpecificColumnsFromRepositoryAndBadge),
|
||||
// v15 -> v16
|
||||
NewMigration("Create the `federation_host` table", CreateFederationHostTable),
|
||||
// v16 -> v17
|
||||
NewMigration("Create the `federated_user` table", CreateFederatedUserTable),
|
||||
// v17 -> v18
|
||||
NewMigration("Add `normalized_federated_uri` column to `user` table", AddNormalizedFederatedURIToUser),
|
||||
}
|
||||
|
||||
// GetCurrentDBVersion returns the current Forgejo database version.
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package forgejo_migrations //nolint:revive
|
||||
|
||||
import "xorm.io/xorm"
|
||||
|
||||
type FederatedUser struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UserID int64 `xorm:"NOT NULL"`
|
||||
ExternalID string `xorm:"UNIQUE(federation_user_mapping) NOT NULL"`
|
||||
FederationHostID int64 `xorm:"UNIQUE(federation_user_mapping) NOT NULL"`
|
||||
}
|
||||
|
||||
func CreateFederatedUserTable(x *xorm.Engine) error {
|
||||
return x.Sync(new(FederatedUser))
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package forgejo_migrations //nolint:revive
|
||||
|
||||
import "xorm.io/xorm"
|
||||
|
||||
func AddNormalizedFederatedURIToUser(x *xorm.Engine) error {
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
NormalizedFederatedURI string
|
||||
}
|
||||
return x.Sync(&User{})
|
||||
}
|
|
@ -307,8 +307,8 @@ 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 {
|
||||
// APActorID returns the IRI to the api endpoint of the user
|
||||
func (u *User) APActorID() string {
|
||||
return fmt.Sprintf("%vapi/v1/activitypub/user-id/%v", setting.AppURL, url.PathEscape(fmt.Sprintf("%v", u.ID)))
|
||||
}
|
||||
|
||||
|
|
|
@ -108,12 +108,12 @@ func TestGetAllUsers(t *testing.T) {
|
|||
assert.False(t, found[user_model.UserTypeOrganization], users)
|
||||
}
|
||||
|
||||
func TestAPAPIURL(t *testing.T) {
|
||||
func TestAPActorID(t *testing.T) {
|
||||
user := user_model.User{ID: 1}
|
||||
url := user.APAPIURL()
|
||||
url := user.APActorID()
|
||||
expected := "https://try.gitea.io/api/v1/activitypub/user-id/1"
|
||||
if url != expected {
|
||||
t.Errorf("unexpected APAPIURL, expected: %q, actual: %q", expected, url)
|
||||
t.Errorf("unexpected APActorID, expected: %q, actual: %q", expected, url)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ func CreateUserFromAP(ctx context.Context, personID fm.PersonID, federationHostI
|
|||
return nil, nil, err
|
||||
}
|
||||
newUser := user.User{
|
||||
LowerName: strings.ToLower(person.PreferredUsername.String()),
|
||||
LowerName: strings.ToLower(name),
|
||||
Name: name,
|
||||
FullName: fullName,
|
||||
Email: email,
|
||||
|
|
|
@ -91,7 +91,7 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
|
|||
`"openRegistrations":true,"usage":{"users":{"total":14,"activeHalfyear":2}},"metadata":{}}`)
|
||||
fmt.Fprint(res, responseBody)
|
||||
})
|
||||
federatedRoutes.HandleFunc("/api/v1/activitypub/user-id/2",
|
||||
federatedRoutes.HandleFunc("/api/v1/activitypub/user-id/15",
|
||||
func(res http.ResponseWriter, req *http.Request) {
|
||||
// curl -H "Accept: application/json" https://federated-repo.prod.meissa.de/api/v1/activitypub/user-id/2
|
||||
responseBody := fmt.Sprintf(`{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],` +
|
||||
|
@ -132,7 +132,7 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
|
|||
activity := []byte(fmt.Sprintf(
|
||||
`{"type":"Like",`+
|
||||
`"startTime":"%s",`+
|
||||
`"actor":"%s/api/v1/activitypub/user-id/2",`+
|
||||
`"actor":"%s/api/v1/activitypub/user-id/15",`+
|
||||
`"object":"%s/api/v1/activitypub/repository-id/%v"}`,
|
||||
time.Now().UTC().Format(time.RFC3339),
|
||||
federatedSrv.URL, srv.URL, repositoryID))
|
||||
|
@ -142,7 +142,9 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &forgefed.FederationHost{HostFqdn: "127.0.0.1"})
|
||||
federationHost := unittest.AssertExistsAndLoadBean(t, &forgefed.FederationHost{HostFqdn: "127.0.0.1"})
|
||||
federatedUser := unittest.AssertExistsAndLoadBean(t, &user.FederatedUser{ExternalID: "15", FederationHostID: federationHost.ID})
|
||||
unittest.AssertExistsAndLoadBean(t, &user.User{ID: federatedUser.UserID})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue