Skip to content

Commit

Permalink
Let MinUnitAccessMode return correct perm (go-gitea#18675)
Browse files Browse the repository at this point in the history
- Don't let `TypeExternalTracker` or `TypeExternalWiki` influence the
minimal permission, as they won't be higher than read. So even if all
the other ones are write, these 2 will ensure that's not higher than
read.
- Partially resolves go-gitea#18572 (Point 1,2,5?)

Co-authored-by: zeripath <art27@cantab.net>
  • Loading branch information
2 people authored and Stelios Malathouras committed Mar 28, 2022
1 parent 1cfa6b7 commit 400cc9c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion models/unit/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,12 @@ func AllUnitKeyNames() []string {
// MinUnitAccessMode returns the minial permission of the permission map
func MinUnitAccessMode(unitsMap map[Type]perm.AccessMode) perm.AccessMode {
res := perm.AccessModeNone
for _, mode := range unitsMap {
for t, mode := range unitsMap {
// Don't allow `TypeExternal{Tracker,Wiki}` to influence this as they can only be set to READ perms.
if t == TypeExternalTracker || t == TypeExternalWiki {
continue
}

// get the minial permission great than AccessModeNone except all are AccessModeNone
if mode > perm.AccessModeNone && (res == perm.AccessModeNone || mode < res) {
res = mode
Expand Down

0 comments on commit 400cc9c

Please sign in to comment.