mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 13:43:55 +03:00
introduce federated repo
This commit is contained in:
parent
3b30c678e7
commit
b4bb41e0e3
5 changed files with 69 additions and 3 deletions
|
@ -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
|
||||
```
|
||||
|
|
36
models/repo/federated_repo.go
Normal file
36
models/repo/federated_repo.go
Normal 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
|
||||
}
|
|
@ -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
|
||||
|
|
12
models/repo/repo_repository.go
Normal file
12
models/repo/repo_repository.go
Normal 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))
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue