2024-02-07 09:37:48 -05:00
|
|
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/gitea/modules/validation"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FederatedUser struct {
|
2024-02-13 05:09:31 -05:00
|
|
|
ID int64 `xorm:"pk autoincr"`
|
2024-02-07 10:42:40 -05:00
|
|
|
UserID int64 `xorm:"NOT NULL"`
|
2024-04-09 10:38:49 -04:00
|
|
|
ExternalID string `xorm:"UNIQUE(federation_user_mapping) NOT NULL"`
|
2024-03-21 03:25:40 -04:00
|
|
|
FederationHostID int64 `xorm:"UNIQUE(federation_user_mapping) NOT NULL"`
|
2024-02-07 09:37:48 -05:00
|
|
|
}
|
|
|
|
|
2024-02-07 10:42:40 -05:00
|
|
|
func NewFederatedUser(userID int64, externalID string, federationHostID int64) (FederatedUser, error) {
|
2024-02-07 09:37:48 -05:00
|
|
|
result := FederatedUser{
|
|
|
|
UserID: userID,
|
|
|
|
ExternalID: externalID,
|
|
|
|
FederationHostID: federationHostID,
|
|
|
|
}
|
|
|
|
if valid, err := validation.IsValid(result); !valid {
|
|
|
|
return FederatedUser{}, err
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (user FederatedUser) Validate() []string {
|
|
|
|
var result []string
|
|
|
|
result = append(result, validation.ValidateNotEmpty(user.UserID, "UserID")...)
|
|
|
|
result = append(result, validation.ValidateNotEmpty(user.ExternalID, "ExternalID")...)
|
|
|
|
result = append(result, validation.ValidateNotEmpty(user.FederationHostID, "FederationHostID")...)
|
|
|
|
return result
|
|
|
|
}
|