diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-24 17:49:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 17:49:20 +0800 |
commit | a666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch) | |
tree | 9ab1434b759a8a2cb275a83149903a823851e309 /modules/convert/convert.go | |
parent | 4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff) | |
download | gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip |
Move user related model into models/user (#17781)
* Move user related model into models/user
* Fix lint for windows
* Fix windows lint
* Fix windows lint
* Move some tests in models
* Merge
Diffstat (limited to 'modules/convert/convert.go')
-rw-r--r-- | modules/convert/convert.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 4229e6cc7d..f08a62588e 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -33,7 +33,7 @@ func ToEmail(email *user_model.EmailAddress) *api.Email { } // ToBranch convert a git.Commit and git.Branch to an api.Branch -func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *models.User, isRepoAdmin bool) (*api.Branch, error) { +func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) { if bp == nil { var hasPerm bool var err error @@ -83,15 +83,15 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models. // ToBranchProtection convert a ProtectedBranch to api.BranchProtection func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection { - pushWhitelistUsernames, err := models.GetUserNamesByIDs(bp.WhitelistUserIDs) + pushWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.WhitelistUserIDs) if err != nil { log.Error("GetUserNamesByIDs (WhitelistUserIDs): %v", err) } - mergeWhitelistUsernames, err := models.GetUserNamesByIDs(bp.MergeWhitelistUserIDs) + mergeWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.MergeWhitelistUserIDs) if err != nil { log.Error("GetUserNamesByIDs (MergeWhitelistUserIDs): %v", err) } - approvalsWhitelistUsernames, err := models.GetUserNamesByIDs(bp.ApprovalsWhitelistUserIDs) + approvalsWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.ApprovalsWhitelistUserIDs) if err != nil { log.Error("GetUserNamesByIDs (ApprovalsWhitelistUserIDs): %v", err) } @@ -276,7 +276,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey { } } -// ToOrganization convert models.User to api.Organization +// ToOrganization convert user_model.User to api.Organization func ToOrganization(org *models.Organization) *api.Organization { return &api.Organization{ ID: org.ID, @@ -355,12 +355,16 @@ func ToOAuth2Application(app *login.OAuth2Application) *api.OAuth2Application { // ToLFSLock convert a LFSLock to api.LFSLock func ToLFSLock(l *models.LFSLock) *api.LFSLock { + u, err := user_model.GetUserByID(l.OwnerID) + if err != nil { + return nil + } return &api.LFSLock{ ID: strconv.FormatInt(l.ID, 10), Path: l.Path, LockedAt: l.Created.Round(time.Second), Owner: &api.LFSLockOwner{ - Name: l.Owner.DisplayName(), + Name: u.DisplayName(), }, } } |