summaryrefslogtreecommitdiffstats
path: root/models/perm
diff options
context:
space:
mode:
Diffstat (limited to 'models/perm')
-rw-r--r--models/perm/access/repo_permission.go55
-rw-r--r--models/perm/access_mode.go9
2 files changed, 21 insertions, 43 deletions
diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go
index ee76e48200..64df5355bb 100644
--- a/models/perm/access/repo_permission.go
+++ b/models/perm/access/repo_permission.go
@@ -102,45 +102,28 @@ func (p *Permission) CanWriteIssuesOrPulls(isPull bool) bool {
return p.CanWrite(unit.TypeIssues)
}
-// ColorFormat writes a colored string for these Permissions
-func (p *Permission) ColorFormat(s fmt.State) {
- noColor := log.ColorBytes(log.Reset)
-
- format := "perm_model.AccessMode: %-v, %d Units, %d UnitsMode(s): [ "
- args := []interface{}{
- p.AccessMode,
- log.NewColoredValueBytes(len(p.Units), &noColor),
- log.NewColoredValueBytes(len(p.UnitsMode), &noColor),
- }
- if s.Flag('+') {
- for i, unit := range p.Units {
- config := ""
- if unit.Config != nil {
- configBytes, err := unit.Config.ToDB()
- config = string(configBytes)
- if err != nil {
- config = err.Error()
- }
+func (p *Permission) LogString() string {
+ format := "<Permission AccessMode=%s, %d Units, %d UnitsMode(s): [ "
+ args := []any{p.AccessMode.String(), len(p.Units), len(p.UnitsMode)}
+
+ for i, unit := range p.Units {
+ config := ""
+ if unit.Config != nil {
+ configBytes, err := unit.Config.ToDB()
+ config = string(configBytes)
+ if err != nil {
+ config = err.Error()
}
- format += "\nUnits[%d]: ID: %d RepoID: %d Type: %-v Config: %s"
- args = append(args,
- log.NewColoredValueBytes(i, &noColor),
- log.NewColoredIDValue(unit.ID),
- log.NewColoredIDValue(unit.RepoID),
- unit.Type,
- config)
- }
- for key, value := range p.UnitsMode {
- format += "\nUnitMode[%-v]: %-v"
- args = append(args,
- key,
- value)
}
- } else {
- format += "..."
+ format += "\nUnits[%d]: ID: %d RepoID: %d Type: %s Config: %s"
+ args = append(args, i, unit.ID, unit.RepoID, unit.Type.LogString(), config)
+ }
+ for key, value := range p.UnitsMode {
+ format += "\nUnitMode[%-v]: %-v"
+ args = append(args, key.LogString(), value.LogString())
}
- format += " ]"
- log.ColorFprintf(s, format, args...)
+ format += " ]>"
+ return fmt.Sprintf(format, args...)
}
// GetUserRepoPermission returns the user permissions to the repository
diff --git a/models/perm/access_mode.go b/models/perm/access_mode.go
index c482e296bc..a37bc1f0e1 100644
--- a/models/perm/access_mode.go
+++ b/models/perm/access_mode.go
@@ -5,8 +5,6 @@ package perm
import (
"fmt"
-
- "code.gitea.io/gitea/modules/log"
)
// AccessMode specifies the users access mode
@@ -40,11 +38,8 @@ func (mode AccessMode) String() string {
}
}
-// ColorFormat provides a ColorFormatted version of this AccessMode
-func (mode AccessMode) ColorFormat(s fmt.State) {
- log.ColorFprintf(s, "%d:%s",
- log.NewColoredIDValue(mode),
- mode)
+func (mode AccessMode) LogString() string {
+ return fmt.Sprintf("<AccessMode:%d:%s>", mode, mode.String())
}
// ParseAccessMode returns corresponding access mode to given permission string.