mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-21 04:37:13 -04:00
Team permission allow different unit has different permission (#17811)
* Team permission allow different unit has different permission * Finish the interface and the logic * Fix lint * Fix translation * align center for table cell content * Fix fixture * merge * Fix test * Add deprecated * Improve code * Add tooltip * Fix swagger * Fix newline * Fix tests * Fix tests * Fix test * Fix test * Max permission of external wiki and issues should be read * Move team units with limited max level below units table * Update label and column names * Some improvements * Fix lint * Some improvements * Fix template variables * Add permission docs * improve doc * Fix fixture * Fix bug * Fix some bug * fix * gofumpt * Integration test for migration (#18124) integrations: basic test for Gitea {dump,restore}-repo This is a first step for integration testing of DumpRepository and RestoreRepository. It: runs a Gitea server, dumps a repo via DumpRepository to the filesystem, restores the repo via RestoreRepository from the filesystem, dumps the restored repository to the filesystem, compares the first and second dump and expects them to be identical The verification is trivial and the goal is to add more tests for each topic of the dump. Signed-off-by: Loïc Dachary <loic@dachary.org> * Team permission allow different unit has different permission * Finish the interface and the logic * Fix lint * Fix translation * align center for table cell content * Fix fixture * merge * Fix test * Add deprecated * Improve code * Add tooltip * Fix swagger * Fix newline * Fix tests * Fix tests * Fix test * Fix test * Max permission of external wiki and issues should be read * Move team units with limited max level below units table * Update label and column names * Some improvements * Fix lint * Some improvements * Fix template variables * Add permission docs * improve doc * Fix fixture * Fix bug * Fix some bug * Fix bug Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Aravinth Manivannan <realaravinth@batsense.net>
This commit is contained in:
parent
12ad6dd0e3
commit
8760af752a
27 changed files with 610 additions and 170 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
@ -17,14 +18,15 @@ type Type int
|
|||
|
||||
// Enumerate all the unit types
|
||||
const (
|
||||
TypeCode Type = iota + 1 // 1 code
|
||||
TypeIssues // 2 issues
|
||||
TypePullRequests // 3 PRs
|
||||
TypeReleases // 4 Releases
|
||||
TypeWiki // 5 Wiki
|
||||
TypeExternalWiki // 6 ExternalWiki
|
||||
TypeExternalTracker // 7 ExternalTracker
|
||||
TypeProjects // 8 Kanban board
|
||||
TypeInvalid Type = iota // 0 invalid
|
||||
TypeCode // 1 code
|
||||
TypeIssues // 2 issues
|
||||
TypePullRequests // 3 PRs
|
||||
TypeReleases // 4 Releases
|
||||
TypeWiki // 5 Wiki
|
||||
TypeExternalWiki // 6 ExternalWiki
|
||||
TypeExternalTracker // 7 ExternalTracker
|
||||
TypeProjects // 8 Kanban board
|
||||
)
|
||||
|
||||
// Value returns integer value for unit type
|
||||
|
@ -170,11 +172,12 @@ func (u *Type) CanBeDefault() bool {
|
|||
|
||||
// Unit is a section of one repository
|
||||
type Unit struct {
|
||||
Type Type
|
||||
NameKey string
|
||||
URI string
|
||||
DescKey string
|
||||
Idx int
|
||||
Type Type
|
||||
NameKey string
|
||||
URI string
|
||||
DescKey string
|
||||
Idx int
|
||||
MaxAccessMode perm.AccessMode // The max access mode of the unit. i.e. Read means this unit can only be read.
|
||||
}
|
||||
|
||||
// CanDisable returns if this unit could be disabled.
|
||||
|
@ -198,6 +201,7 @@ var (
|
|||
"/",
|
||||
"repo.code.desc",
|
||||
0,
|
||||
perm.AccessModeOwner,
|
||||
}
|
||||
|
||||
UnitIssues = Unit{
|
||||
|
@ -206,6 +210,7 @@ var (
|
|||
"/issues",
|
||||
"repo.issues.desc",
|
||||
1,
|
||||
perm.AccessModeOwner,
|
||||
}
|
||||
|
||||
UnitExternalTracker = Unit{
|
||||
|
@ -214,6 +219,7 @@ var (
|
|||
"/issues",
|
||||
"repo.ext_issues.desc",
|
||||
1,
|
||||
perm.AccessModeRead,
|
||||
}
|
||||
|
||||
UnitPullRequests = Unit{
|
||||
|
@ -222,6 +228,7 @@ var (
|
|||
"/pulls",
|
||||
"repo.pulls.desc",
|
||||
2,
|
||||
perm.AccessModeOwner,
|
||||
}
|
||||
|
||||
UnitReleases = Unit{
|
||||
|
@ -230,6 +237,7 @@ var (
|
|||
"/releases",
|
||||
"repo.releases.desc",
|
||||
3,
|
||||
perm.AccessModeOwner,
|
||||
}
|
||||
|
||||
UnitWiki = Unit{
|
||||
|
@ -238,6 +246,7 @@ var (
|
|||
"/wiki",
|
||||
"repo.wiki.desc",
|
||||
4,
|
||||
perm.AccessModeOwner,
|
||||
}
|
||||
|
||||
UnitExternalWiki = Unit{
|
||||
|
@ -246,6 +255,7 @@ var (
|
|||
"/wiki",
|
||||
"repo.ext_wiki.desc",
|
||||
4,
|
||||
perm.AccessModeRead,
|
||||
}
|
||||
|
||||
UnitProjects = Unit{
|
||||
|
@ -254,6 +264,7 @@ var (
|
|||
"/projects",
|
||||
"repo.projects.desc",
|
||||
5,
|
||||
perm.AccessModeOwner,
|
||||
}
|
||||
|
||||
// Units contains all the units
|
||||
|
@ -269,15 +280,51 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
// FindUnitTypes give the unit key name and return unit
|
||||
// FindUnitTypes give the unit key names and return unit
|
||||
func FindUnitTypes(nameKeys ...string) (res []Type) {
|
||||
for _, key := range nameKeys {
|
||||
var found bool
|
||||
for t, u := range Units {
|
||||
if strings.EqualFold(key, u.NameKey) {
|
||||
res = append(res, t)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
res = append(res, TypeInvalid)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TypeFromKey give the unit key name and return unit
|
||||
func TypeFromKey(nameKey string) Type {
|
||||
for t, u := range Units {
|
||||
if strings.EqualFold(nameKey, u.NameKey) {
|
||||
return t
|
||||
}
|
||||
}
|
||||
return TypeInvalid
|
||||
}
|
||||
|
||||
// AllUnitKeyNames returns all unit key names
|
||||
func AllUnitKeyNames() []string {
|
||||
res := make([]string, 0, len(Units))
|
||||
for _, u := range Units {
|
||||
res = append(res, u.NameKey)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// get the minial permission great than AccessModeNone except all are AccessModeNone
|
||||
if mode > perm.AccessModeNone && (res == perm.AccessModeNone || mode < res) {
|
||||
res = mode
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue