forked from forgejo/forgejo
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
|
@ -32,7 +32,7 @@ type Team struct {
|
|||
LowerName string
|
||||
Name string
|
||||
Description string
|
||||
Authorize perm.AccessMode
|
||||
AccessMode perm.AccessMode `xorm:"'authorize'"`
|
||||
Repos []*repo_model.Repository `xorm:"-"`
|
||||
Members []*user_model.User `xorm:"-"`
|
||||
NumRepos int
|
||||
|
@ -126,7 +126,7 @@ func (t *Team) ColorFormat(s fmt.State) {
|
|||
log.NewColoredIDValue(t.ID),
|
||||
t.Name,
|
||||
log.NewColoredIDValue(t.OrgID),
|
||||
t.Authorize)
|
||||
t.AccessMode)
|
||||
}
|
||||
|
||||
// GetUnits return a list of available units for a team
|
||||
|
@ -145,15 +145,29 @@ func (t *Team) getUnits(e db.Engine) (err error) {
|
|||
|
||||
// GetUnitNames returns the team units names
|
||||
func (t *Team) GetUnitNames() (res []string) {
|
||||
if t.AccessMode >= perm.AccessModeAdmin {
|
||||
return unit.AllUnitKeyNames()
|
||||
}
|
||||
|
||||
for _, u := range t.Units {
|
||||
res = append(res, unit.Units[u.Type].NameKey)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// HasWriteAccess returns true if team has at least write level access mode.
|
||||
func (t *Team) HasWriteAccess() bool {
|
||||
return t.Authorize >= perm.AccessModeWrite
|
||||
// GetUnitsMap returns the team units permissions
|
||||
func (t *Team) GetUnitsMap() map[string]string {
|
||||
m := make(map[string]string)
|
||||
if t.AccessMode >= perm.AccessModeAdmin {
|
||||
for _, u := range unit.Units {
|
||||
m[u.NameKey] = t.AccessMode.String()
|
||||
}
|
||||
} else {
|
||||
for _, u := range t.Units {
|
||||
m[u.Unit().NameKey] = u.AccessMode.String()
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// IsOwnerTeam returns true if team is owner team.
|
||||
|
@ -455,16 +469,25 @@ func (t *Team) UnitEnabled(tp unit.Type) bool {
|
|||
}
|
||||
|
||||
func (t *Team) unitEnabled(e db.Engine, tp unit.Type) bool {
|
||||
return t.unitAccessMode(e, tp) > perm.AccessModeNone
|
||||
}
|
||||
|
||||
// UnitAccessMode returns if the team has the given unit type enabled
|
||||
func (t *Team) UnitAccessMode(tp unit.Type) perm.AccessMode {
|
||||
return t.unitAccessMode(db.GetEngine(db.DefaultContext), tp)
|
||||
}
|
||||
|
||||
func (t *Team) unitAccessMode(e db.Engine, tp unit.Type) perm.AccessMode {
|
||||
if err := t.getUnits(e); err != nil {
|
||||
log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error())
|
||||
}
|
||||
|
||||
for _, unit := range t.Units {
|
||||
if unit.Type == tp {
|
||||
return true
|
||||
return unit.AccessMode
|
||||
}
|
||||
}
|
||||
return false
|
||||
return perm.AccessModeNone
|
||||
}
|
||||
|
||||
// IsUsableTeamName tests if a name could be as team name
|
||||
|
@ -661,7 +684,7 @@ func UpdateTeam(t *Team, authChanged, includeAllChanged bool) (err error) {
|
|||
Delete(new(TeamUnit)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = sess.Cols("org_id", "team_id", "type").Insert(&t.Units); err != nil {
|
||||
if _, err = sess.Cols("org_id", "team_id", "type", "access_mode").Insert(&t.Units); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -1033,10 +1056,11 @@ func GetTeamsWithAccessToRepo(orgID, repoID int64, mode perm.AccessMode) ([]*Tea
|
|||
|
||||
// TeamUnit describes all units of a repository
|
||||
type TeamUnit struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OrgID int64 `xorm:"INDEX"`
|
||||
TeamID int64 `xorm:"UNIQUE(s)"`
|
||||
Type unit.Type `xorm:"UNIQUE(s)"`
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OrgID int64 `xorm:"INDEX"`
|
||||
TeamID int64 `xorm:"UNIQUE(s)"`
|
||||
Type unit.Type `xorm:"UNIQUE(s)"`
|
||||
AccessMode perm.AccessMode
|
||||
}
|
||||
|
||||
// Unit returns Unit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue