2021-11-28 06:58:28 -05:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-11-28 06:58:28 -05:00
|
|
|
|
|
|
|
package perm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AccessMode specifies the users access mode
|
|
|
|
type AccessMode int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// AccessModeNone no access
|
|
|
|
AccessModeNone AccessMode = iota // 0
|
|
|
|
// AccessModeRead read access
|
|
|
|
AccessModeRead // 1
|
|
|
|
// AccessModeWrite write access
|
|
|
|
AccessModeWrite // 2
|
|
|
|
// AccessModeAdmin admin access
|
|
|
|
AccessModeAdmin // 3
|
|
|
|
// AccessModeOwner owner access
|
|
|
|
AccessModeOwner // 4
|
|
|
|
)
|
|
|
|
|
|
|
|
func (mode AccessMode) String() string {
|
|
|
|
switch mode {
|
|
|
|
case AccessModeRead:
|
|
|
|
return "read"
|
|
|
|
case AccessModeWrite:
|
|
|
|
return "write"
|
|
|
|
case AccessModeAdmin:
|
|
|
|
return "admin"
|
|
|
|
case AccessModeOwner:
|
|
|
|
return "owner"
|
|
|
|
default:
|
|
|
|
return "none"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ColorFormat provides a ColorFormatted version of this AccessMode
|
|
|
|
func (mode AccessMode) ColorFormat(s fmt.State) {
|
|
|
|
log.ColorFprintf(s, "%d:%s",
|
|
|
|
log.NewColoredIDValue(mode),
|
|
|
|
mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseAccessMode returns corresponding access mode to given permission string.
|
|
|
|
func ParseAccessMode(permission string) AccessMode {
|
|
|
|
switch permission {
|
2022-01-04 22:37:00 -05:00
|
|
|
case "read":
|
|
|
|
return AccessModeRead
|
2021-11-28 06:58:28 -05:00
|
|
|
case "write":
|
|
|
|
return AccessModeWrite
|
|
|
|
case "admin":
|
|
|
|
return AccessModeAdmin
|
|
|
|
default:
|
2022-01-04 22:37:00 -05:00
|
|
|
return AccessModeNone
|
2021-11-28 06:58:28 -05:00
|
|
|
}
|
|
|
|
}
|