1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00

introduce federated repo

This commit is contained in:
Michael Jerger 2024-03-21 08:25:40 +01:00
parent 3b30c678e7
commit b4bb41e0e3
5 changed files with 69 additions and 3 deletions

View file

@ -102,8 +102,26 @@ classDiagram
}
}
namespace repository {
class Repository {
<<Aggregate Root>>
ID int64
}
class FederatedRepository {
ID int64
RepositoryID int64
ExternalID string
FederationHost int64
Validate() []string
}
}
User *-- FederatedUser: FederatedUser.UserID
PersonID -- FederatedUser : mapped by PersonID.ID == FederatedUser.externalID & FederationHost.ID
PersonID -- FederationHost : mapped by PersonID.Host == FederationHost.HostFqdn
FederatedUser -- FederationHost
Repository *-- FederatedRepository
FederatedRepository -- FederationHost
```

View file

@ -0,0 +1,36 @@
// Copyright 2024 The forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repo
import (
"code.gitea.io/gitea/modules/validation"
)
// FederatedRepo represents a federated Repository Actor connected with a local Repo
type FederatedRepo struct {
ID int64 `xorm:"pk autoincr"`
RepositoryID int64 `xorm:"NOT NULL"`
ExternalID string `xorm:"TEXT UNIQUE(federation_repo_mapping) NOT NULL"`
FederationHostID int64 `xorm:"UNIQUE(federation_repo_mapping) NOT NULL"`
}
func NewFederatedRepo(repositoryID int64, externalID string, federationHostID int64) (FederatedRepo, error) {
result := FederatedRepo{
RepositoryID: repositoryID,
ExternalID: externalID,
FederationHostID: federationHostID,
}
if valid, err := validation.IsValid(result); !valid {
return FederatedRepo{}, err
}
return result, nil
}
func (user FederatedRepo) Validate() []string {
var result []string
result = append(result, validation.ValidateNotEmpty(user.RepositoryID, "UserID")...)
result = append(result, validation.ValidateNotEmpty(user.ExternalID, "ExternalID")...)
result = append(result, validation.ValidateNotEmpty(user.FederationHostID, "FederationHostID")...)
return result
}

View file

@ -1,4 +1,4 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// Copyright 2021, 2024 The Gitea & forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repo

View file

@ -0,0 +1,12 @@
// Copyright 2024 The forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repo
import (
"code.gitea.io/gitea/models/db"
)
func init() {
db.RegisterModel(new(FederatedRepo))
}

View file

@ -10,8 +10,8 @@ import (
type FederatedUser struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"NOT NULL"`
ExternalID string `xorm:"TEXT UNIQUE(federation_mapping) NOT NULL"`
FederationHostID int64 `xorm:"UNIQUE(federation_mapping) NOT NULL"`
ExternalID string `xorm:"TEXT UNIQUE(federation_user_mapping) NOT NULL"`
FederationHostID int64 `xorm:"UNIQUE(federation_user_mapping) NOT NULL"`
}
func NewFederatedUser(userID int64, externalID string, federationHostID int64) (FederatedUser, error) {