-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Show lock owner instead of repo owner on LFS setting page #31788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1bdfab7
fix: show lock owner
wolfogre 4773709
chore: fix header
wolfogre cdf82af
test: TestLFSLockView
wolfogre a48aedc
test: improve
wolfogre 448a8e4
chore: $lock
wolfogre 765ff4b
fix: ghost user
wolfogre 0cd0d0f
Merge branch 'main' into bugfix/lfs_lock_owner
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package git | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
user_model "code.gitea.io/gitea/models/user" | ||
"code.gitea.io/gitea/modules/container" | ||
) | ||
|
||
// LFSLockList is a list of LFSLock | ||
type LFSLockList []*LFSLock | ||
|
||
// LoadAttributes loads the attributes for the given locks | ||
func (locks LFSLockList) LoadAttributes(ctx context.Context) error { | ||
if len(locks) == 0 { | ||
return nil | ||
} | ||
|
||
if err := locks.LoadOwner(ctx); err != nil { | ||
return fmt.Errorf("load owner: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// LoadOwner loads the owner of the locks | ||
func (locks LFSLockList) LoadOwner(ctx context.Context) error { | ||
if len(locks) == 0 { | ||
return nil | ||
} | ||
|
||
usersIDs := container.FilterSlice(locks, func(lock *LFSLock) (int64, bool) { | ||
return lock.OwnerID, true | ||
}) | ||
users := make(map[int64]*user_model.User, len(usersIDs)) | ||
if err := db.GetEngine(ctx). | ||
In("id", usersIDs). | ||
Find(&users); err != nil { | ||
return fmt.Errorf("find users: %w", err) | ||
} | ||
for _, v := range locks { | ||
v.Owner = users[v.OwnerID] | ||
if v.Owner == nil { // not exist | ||
v.Owner = user_model.NewGhostUser() | ||
} | ||
} | ||
wolfogre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.