mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-23 09:30:50 +00:00
Allow users with explicit read access to give approvals (#8382)
This commit is contained in:
parent
736ad8f091
commit
4843723d00
3 changed files with 37 additions and 3 deletions
|
@ -735,11 +735,24 @@ func (repo *Repository) CanEnableEditor() bool {
|
|||
return !repo.IsMirror
|
||||
}
|
||||
|
||||
// GetReaders returns all users that have explicit read access or higher to the repository.
|
||||
func (repo *Repository) GetReaders() (_ []*User, err error) {
|
||||
return repo.getUsersWithAccessMode(x, AccessModeRead)
|
||||
}
|
||||
|
||||
// GetWriters returns all users that have write access to the repository.
|
||||
func (repo *Repository) GetWriters() (_ []*User, err error) {
|
||||
return repo.getUsersWithAccessMode(x, AccessModeWrite)
|
||||
}
|
||||
|
||||
// IsReader returns true if user has explicit read access or higher to the repository.
|
||||
func (repo *Repository) IsReader(userID int64) (bool, error) {
|
||||
if repo.OwnerID == userID {
|
||||
return true, nil
|
||||
}
|
||||
return x.Where("repo_id = ? AND user_id = ? AND mode >= ?", repo.ID, userID, AccessModeRead).Get(&Access{})
|
||||
}
|
||||
|
||||
// getUsersWithAccessMode returns users that have at least given access mode to the repository.
|
||||
func (repo *Repository) getUsersWithAccessMode(e Engine, mode AccessMode) (_ []*User, err error) {
|
||||
if err = repo.getOwner(e); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue