mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-03 21:12:09 +02:00
apply simple linting changes
This commit is contained in:
parent
f627e57199
commit
01dace952d
@ -32,9 +32,9 @@ type Group struct {
|
||||
Visibility structs.VisibleType `xorm:"NOT NULL DEFAULT 0"`
|
||||
Avatar string `xorm:"VARCHAR(64)"`
|
||||
|
||||
ParentGroupID int64 `xorm:"DEFAULT NULL"`
|
||||
ParentGroup *Group `xorm:"-"`
|
||||
Subgroups GroupList `xorm:"-"`
|
||||
ParentGroupID int64 `xorm:"DEFAULT NULL"`
|
||||
ParentGroup *Group `xorm:"-"`
|
||||
Subgroups RepoGroupList `xorm:"-"`
|
||||
|
||||
SortOrder int `xorm:"INDEX"`
|
||||
}
|
||||
@ -52,8 +52,8 @@ func (Group) TableName() string { return "repo_group" }
|
||||
|
||||
func init() {
|
||||
db.RegisterModel(new(Group))
|
||||
db.RegisterModel(new(GroupTeam))
|
||||
db.RegisterModel(new(GroupUnit))
|
||||
db.RegisterModel(new(RepoGroupTeam))
|
||||
db.RegisterModel(new(RepoGroupUnit))
|
||||
}
|
||||
|
||||
func (g *Group) doLoadSubgroups(ctx context.Context, recursive bool, cond builder.Cond, currentLevel int) error {
|
||||
@ -141,30 +141,30 @@ func (g *Group) CanAccessAtLevel(ctx context.Context, userID int64, level perm.A
|
||||
func (g *Group) IsOwnedBy(ctx context.Context, userID int64) (bool, error) {
|
||||
return db.GetEngine(ctx).
|
||||
Where("team_user.uid = ?", userID).
|
||||
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
|
||||
And("group_team.access_mode = ?", perm.AccessModeOwner).
|
||||
And("group_team.group_id = ?", g.ID).
|
||||
Table("group_team").
|
||||
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
|
||||
And("repo_group_team.access_mode = ?", perm.AccessModeOwner).
|
||||
And("repo_group_team.group_id = ?", g.ID).
|
||||
Table("repo_group_team").
|
||||
Exist()
|
||||
}
|
||||
|
||||
func (g *Group) CanCreateIn(ctx context.Context, userID int64) (bool, error) {
|
||||
return db.GetEngine(ctx).
|
||||
Where("team_user.uid = ?", userID).
|
||||
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
|
||||
And("group_team.group_id = ?", g.ID).
|
||||
And("group_team.can_create_in = ?", true).
|
||||
Table("group_team").
|
||||
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
|
||||
And("repo_group_team.group_id = ?", g.ID).
|
||||
And("repo_group_team.can_create_in = ?", true).
|
||||
Table("repo_group_team").
|
||||
Exist()
|
||||
}
|
||||
|
||||
func (g *Group) IsAdminOf(ctx context.Context, userID int64) (bool, error) {
|
||||
return db.GetEngine(ctx).
|
||||
Where("team_user.uid = ?", userID).
|
||||
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
|
||||
And("group_team.group_id = ?", g.ID).
|
||||
And("group_team.access_mode >= ?", perm.AccessModeAdmin).
|
||||
Table("group_team").
|
||||
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
|
||||
And("repo_group_team.group_id = ?", g.ID).
|
||||
And("repo_group_team.access_mode >= ?", perm.AccessModeAdmin).
|
||||
Table("repo_group_team").
|
||||
Exist()
|
||||
}
|
||||
|
||||
@ -224,11 +224,11 @@ func (opts FindGroupsOptions) ToConds() builder.Cond {
|
||||
}
|
||||
if opts.CanCreateIn.Has() && opts.ActorID > 0 {
|
||||
cond = cond.And(builder.In("id",
|
||||
builder.Select("group_team.group_id").
|
||||
From("group_team").
|
||||
builder.Select("repo_group_team.group_id").
|
||||
From("repo_group_team").
|
||||
Where(builder.Eq{"team_user.uid": opts.ActorID}).
|
||||
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
|
||||
And(builder.Eq{"group_team.can_create_in": true})))
|
||||
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
|
||||
And(builder.Eq{"repo_group_team.can_create_in": true})))
|
||||
}
|
||||
if opts.Name != "" {
|
||||
cond = cond.And(builder.Eq{"lower_name": opts.Name})
|
||||
@ -236,7 +236,7 @@ func (opts FindGroupsOptions) ToConds() builder.Cond {
|
||||
return cond
|
||||
}
|
||||
|
||||
func FindGroups(ctx context.Context, opts *FindGroupsOptions) (GroupList, error) {
|
||||
func FindGroups(ctx context.Context, opts *FindGroupsOptions) (RepoGroupList, error) {
|
||||
sess := db.GetEngine(ctx).Where(opts.ToConds())
|
||||
if opts.Page > 0 {
|
||||
sess = db.SetSessionPagination(sess, opts)
|
||||
@ -260,7 +260,7 @@ func findGroupsByCond(ctx context.Context, opts *FindGroupsOptions, cond builder
|
||||
return sess.Asc("sort_order")
|
||||
}
|
||||
|
||||
func FindGroupsByCond(ctx context.Context, opts *FindGroupsOptions, cond builder.Cond) (GroupList, error) {
|
||||
func FindGroupsByCond(ctx context.Context, opts *FindGroupsOptions, cond builder.Cond) (RepoGroupList, error) {
|
||||
defaultSize := 50
|
||||
if opts.PageSize > 0 {
|
||||
defaultSize = opts.PageSize
|
||||
@ -285,7 +285,7 @@ func UpdateGroupOwnerName(ctx context.Context, oldUser, newUser string) error {
|
||||
}
|
||||
|
||||
// GetParentGroupChain returns a slice containing a group and its ancestors
|
||||
func GetParentGroupChain(ctx context.Context, groupID int64) (GroupList, error) {
|
||||
func GetParentGroupChain(ctx context.Context, groupID int64) (RepoGroupList, error) {
|
||||
groupList := make([]*Group, 0, 20)
|
||||
currentGroupID := groupID
|
||||
for {
|
||||
@ -306,7 +306,8 @@ func GetParentGroupChain(ctx context.Context, groupID int64) (GroupList, error)
|
||||
return groupList, nil
|
||||
}
|
||||
|
||||
func GetParentGroupIDChain(ctx context.Context, groupID int64) (ids []int64, err error) {
|
||||
func GetParentGroupIDChain(ctx context.Context, groupID int64) ([]int64, error) {
|
||||
var ids []int64
|
||||
groupList, err := GetParentGroupChain(ctx, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -314,7 +315,7 @@ func GetParentGroupIDChain(ctx context.Context, groupID int64) (ids []int64, err
|
||||
ids = util.SliceMap(groupList, func(g *Group) int64 {
|
||||
return g.ID
|
||||
})
|
||||
return
|
||||
return ids, err
|
||||
}
|
||||
|
||||
// ParentGroupCond returns a condition matching a group and its ancestors
|
||||
|
||||
@ -11,9 +11,9 @@ import (
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
type GroupList []*Group
|
||||
type RepoGroupList []*Group
|
||||
|
||||
func (groups GroupList) LoadOwners(ctx context.Context) error {
|
||||
func (groups RepoGroupList) LoadOwners(ctx context.Context) error {
|
||||
for _, g := range groups {
|
||||
if g.Owner == nil {
|
||||
err := g.LoadOwner(ctx)
|
||||
|
||||
@ -10,23 +10,24 @@ import (
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// GroupTeam represents a relation for a team's access to a group
|
||||
type GroupTeam struct {
|
||||
// RepoGroupTeam represents a relation for a team's access to a group
|
||||
type RepoGroupTeam struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OrgID int64 `xorm:"INDEX"`
|
||||
TeamID int64 `xorm:"UNIQUE(s)"`
|
||||
GroupID int64 `xorm:"UNIQUE(s)"`
|
||||
AccessMode perm.AccessMode
|
||||
CanCreateIn bool
|
||||
Units []*GroupUnit `xorm:"-"`
|
||||
Units []*RepoGroupUnit `xorm:"-"`
|
||||
}
|
||||
|
||||
func (g *GroupTeam) LoadGroupUnits(ctx context.Context) (err error) {
|
||||
func (g *RepoGroupTeam) LoadGroupUnits(ctx context.Context) error {
|
||||
var err error
|
||||
g.Units, err = GetUnitsByGroupID(ctx, g.GroupID)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
func (g *GroupTeam) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessMode perm.AccessMode, exist bool) {
|
||||
func (g *RepoGroupTeam) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessMode perm.AccessMode, exist bool) {
|
||||
accessMode = perm.AccessModeNone
|
||||
if err := g.LoadGroupUnits(ctx); err != nil {
|
||||
log.Warn("Error loading units of team for group[%d] (ID: %d): %s", g.GroupID, g.TeamID, err.Error())
|
||||
@ -38,7 +39,7 @@ func (g *GroupTeam) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessM
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
return accessMode, exist
|
||||
}
|
||||
|
||||
// HasTeamGroup returns true if the given group belongs to a team.
|
||||
@ -48,7 +49,7 @@ func HasTeamGroup(ctx context.Context, orgID, teamID, groupID int64) bool {
|
||||
And("team_id=?", teamID).
|
||||
And("group_id=?", groupID).
|
||||
And("access_mode >= ?", perm.AccessModeRead).
|
||||
Get(new(GroupTeam))
|
||||
Get(new(RepoGroupTeam))
|
||||
return has
|
||||
}
|
||||
|
||||
@ -57,7 +58,7 @@ func AddTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access perm
|
||||
if access <= perm.AccessModeWrite {
|
||||
canCreateIn = false
|
||||
}
|
||||
_, err := db.GetEngine(ctx).Insert(&GroupTeam{
|
||||
_, err := db.GetEngine(ctx).Insert(&RepoGroupTeam{
|
||||
OrgID: orgID,
|
||||
GroupID: groupID,
|
||||
TeamID: teamID,
|
||||
@ -75,11 +76,11 @@ func UpdateTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access p
|
||||
err = AddTeamGroup(ctx, orgID, teamID, groupID, access, canCreateIn)
|
||||
} else {
|
||||
_, err = db.GetEngine(ctx).
|
||||
Table("group_team").
|
||||
Table("repo_group_team").
|
||||
Where("org_id=?", orgID).
|
||||
And("team_id=?", teamID).
|
||||
And("group_id =?", groupID).
|
||||
Update(&GroupTeam{
|
||||
Update(&RepoGroupTeam{
|
||||
OrgID: orgID,
|
||||
TeamID: teamID,
|
||||
GroupID: groupID,
|
||||
@ -93,7 +94,7 @@ func UpdateTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access p
|
||||
|
||||
// RemoveTeamGroup removes a group from a team
|
||||
func RemoveTeamGroup(ctx context.Context, orgID, teamID, groupID int64) error {
|
||||
_, err := db.DeleteByBean(ctx, &GroupTeam{
|
||||
_, err := db.DeleteByBean(ctx, &RepoGroupTeam{
|
||||
TeamID: teamID,
|
||||
GroupID: groupID,
|
||||
OrgID: orgID,
|
||||
@ -101,24 +102,24 @@ func RemoveTeamGroup(ctx context.Context, orgID, teamID, groupID int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func FindGroupTeams(ctx context.Context, groupID int64) (gteams []*GroupTeam, err error) {
|
||||
func FindGroupTeams(ctx context.Context, groupID int64) (gteams []*RepoGroupTeam, err error) {
|
||||
return gteams, db.GetEngine(ctx).
|
||||
Where("group_id=?", groupID).
|
||||
Table("group_team").
|
||||
Table("repo_group_team").
|
||||
Find(>eams)
|
||||
}
|
||||
|
||||
func FindGroupTeamByTeamID(ctx context.Context, groupID, teamID int64) (gteam *GroupTeam, err error) {
|
||||
gteam = new(GroupTeam)
|
||||
func FindGroupTeamByTeamID(ctx context.Context, groupID, teamID int64) (gteam *RepoGroupTeam, err error) {
|
||||
gteam = new(RepoGroupTeam)
|
||||
has, err := db.GetEngine(ctx).
|
||||
Where("group_id=?", groupID).
|
||||
And("team_id = ?", teamID).
|
||||
Table("group_team").
|
||||
Table("repo_group_team").
|
||||
Get(gteam)
|
||||
if !has {
|
||||
gteam = nil
|
||||
}
|
||||
return
|
||||
return gteam, err
|
||||
}
|
||||
|
||||
func GetAncestorPermissions(ctx context.Context, groupID, teamID int64) (perm.AccessMode, error) {
|
||||
@ -127,12 +128,12 @@ func GetAncestorPermissions(ctx context.Context, groupID, teamID int64) (perm.Ac
|
||||
if err != nil {
|
||||
return perm.AccessModeNone, err
|
||||
}
|
||||
gteams := make([]*GroupTeam, 0)
|
||||
gteams := make([]*RepoGroupTeam, 0)
|
||||
err = sess.In("group_id", groups).And("team_id = ?", teamID).Find(>eams)
|
||||
if err != nil {
|
||||
return perm.AccessModeNone, err
|
||||
}
|
||||
mapped := util.SliceMap(gteams, func(g *GroupTeam) perm.AccessMode {
|
||||
mapped := util.SliceMap(gteams, func(g *RepoGroupTeam) perm.AccessMode {
|
||||
return g.AccessMode
|
||||
})
|
||||
maxMode := max(mapped[0])
|
||||
|
||||
@ -8,8 +8,8 @@ import (
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
)
|
||||
|
||||
// GroupUnit describes all units of a repository group
|
||||
type GroupUnit struct {
|
||||
// RepoGroupUnit describes all units of a repository group
|
||||
type RepoGroupUnit struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
GroupID int64 `xorm:"UNIQUE(s)"`
|
||||
TeamID int64 `xorm:"UNIQUE(s)"`
|
||||
@ -17,16 +17,16 @@ type GroupUnit struct {
|
||||
AccessMode perm.AccessMode
|
||||
}
|
||||
|
||||
func (g *GroupUnit) Unit() unit.Unit {
|
||||
func (g *RepoGroupUnit) Unit() unit.Unit {
|
||||
return unit.Units[g.Type]
|
||||
}
|
||||
|
||||
func GetUnitsByGroupID(ctx context.Context, groupID int64) (units []*GroupUnit, err error) {
|
||||
func GetUnitsByGroupID(ctx context.Context, groupID int64) (units []*RepoGroupUnit, err error) {
|
||||
return units, db.GetEngine(ctx).Where("group_id = ?", groupID).Find(&units)
|
||||
}
|
||||
|
||||
func GetGroupUnit(ctx context.Context, groupID, teamID int64, unitType unit.Type) (unit *GroupUnit, err error) {
|
||||
unit = new(GroupUnit)
|
||||
func GetGroupUnit(ctx context.Context, groupID, teamID int64, unitType unit.Type) (unit *RepoGroupUnit, err error) {
|
||||
unit = new(RepoGroupUnit)
|
||||
_, err = db.GetEngine(ctx).
|
||||
Where("group_id = ?", groupID).
|
||||
And("team_id = ?", teamID).
|
||||
@ -35,8 +35,8 @@ func GetGroupUnit(ctx context.Context, groupID, teamID int64, unitType unit.Type
|
||||
return
|
||||
}
|
||||
|
||||
func GetMaxGroupUnit(ctx context.Context, groupID int64, unitType unit.Type) (unit *GroupUnit, err error) {
|
||||
units := make([]*GroupUnit, 0)
|
||||
func GetMaxGroupUnit(ctx context.Context, groupID int64, unitType unit.Type) (unit *RepoGroupUnit, err error) {
|
||||
units := make([]*RepoGroupUnit, 0)
|
||||
err = db.GetEngine(ctx).
|
||||
Where("group_id = ?", groupID).
|
||||
And("type = ?", unitType).
|
||||
|
||||
@ -35,13 +35,13 @@ func FindGroupMembers(ctx context.Context, groupID int64, opts *organization_mod
|
||||
return users, err
|
||||
}
|
||||
|
||||
func GetGroupTeams(ctx context.Context, groupID int64) (teams []*organization_model.Team, err error) {
|
||||
err = db.GetEngine(ctx).
|
||||
func GetGroupTeams(ctx context.Context, groupID int64) ([]*organization_model.Team, error) {
|
||||
var teams []*organization_model.Team
|
||||
return teams, db.GetEngine(ctx).
|
||||
Where("`group_team`.group_id = ?", groupID).
|
||||
Join("INNER", "group_team", "`group_team`.team_id = `team`.id").
|
||||
Asc("`team`.name").
|
||||
Find(&teams)
|
||||
return
|
||||
}
|
||||
|
||||
func IsGroupMember(ctx context.Context, groupID, userID int64) (bool, error) {
|
||||
|
||||
@ -24,10 +24,10 @@ func DedupeBy[E any, I comparable](s []E, id func(E) I) []E {
|
||||
filtered := make([]E, 0, len(s)) // slice will be clipped before returning
|
||||
seen := make(map[I]bool, len(s))
|
||||
for i := range s {
|
||||
itemId := id(s[i])
|
||||
if _, ok := seen[itemId]; !ok {
|
||||
itemID := id(s[i])
|
||||
if _, ok := seen[itemID]; !ok {
|
||||
filtered = append(filtered, s[i])
|
||||
seen[itemId] = true
|
||||
seen[itemID] = true
|
||||
}
|
||||
}
|
||||
return slices.Clip(filtered)
|
||||
|
||||
@ -23,10 +23,10 @@ func DeleteGroup(ctx context.Context, gid int64) error {
|
||||
}
|
||||
|
||||
// remove team permissions and units for deleted group
|
||||
if _, err = sess.Where("group_id = ?", gid).Delete(new(group_model.GroupTeam)); err != nil {
|
||||
if _, err = sess.Where("group_id = ?", gid).Delete(new(group_model.RepoGroupTeam)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = sess.Where("group_id = ?", gid).Delete(new(group_model.GroupUnit)); err != nil {
|
||||
if _, err = sess.Where("group_id = ?", gid).Delete(new(group_model.RepoGroupUnit)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ func NewGroup(ctx context.Context, g *group_model.Group) error {
|
||||
defer committer.Close()
|
||||
|
||||
if err = db.Insert(ctx, g); err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if err = RecalculateGroupAccess(ctx, g, true); err != nil {
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// group 12 is private
|
||||
@ -39,7 +38,7 @@ func TestMoveGroup(t *testing.T) {
|
||||
}
|
||||
origCount := unittest.GetCount(t, new(group_model.Group), cond.ToConds())
|
||||
|
||||
assert.NoError(t, MoveGroupItem(context.TODO(), gid, 123, true, -1))
|
||||
assert.NoError(t, MoveGroupItem(t.Context(), gid, 123, true, -1))
|
||||
unittest.AssertCountByCond(t, "repo_group", cond.ToConds(), origCount+1)
|
||||
}
|
||||
testfn(124)
|
||||
|
||||
@ -25,12 +25,12 @@ type WebSearchGroup struct {
|
||||
Repos []*repo_service.WebSearchRepository `json:"repos"`
|
||||
}
|
||||
|
||||
type GroupWebSearchResult struct {
|
||||
type WebSearchResult struct {
|
||||
OK bool `json:"ok"`
|
||||
Data *WebSearchGroup `json:"data"`
|
||||
}
|
||||
|
||||
type GroupWebSearchOptions struct {
|
||||
type WebSearchOptions struct {
|
||||
Ctx context.Context
|
||||
Locale translation.Locale
|
||||
Recurse bool
|
||||
@ -47,7 +47,7 @@ type WebSearchGroupRoot struct {
|
||||
Repos []*repo_service.WebSearchRepository
|
||||
}
|
||||
|
||||
type GroupWebSearchRootResult struct {
|
||||
type WebSearchGroupRootResult struct {
|
||||
OK bool `json:"ok"`
|
||||
Data *WebSearchGroupRoot `json:"data"`
|
||||
}
|
||||
@ -71,7 +71,7 @@ func ToWebSearchRepo(ctx context.Context, repo *repo_model.Repository) *repo_ser
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebSearchGroup) doLoadChildren(opts *GroupWebSearchOptions) error {
|
||||
func (w *WebSearchGroup) doLoadChildren(opts *WebSearchOptions) error {
|
||||
opts.RepoOpts.OwnerID = opts.OrgID
|
||||
opts.RepoOpts.GroupID = 0
|
||||
opts.GroupOpts.OwnerID = opts.OrgID
|
||||
@ -138,7 +138,7 @@ func (w *WebSearchGroup) doLoadChildren(opts *GroupWebSearchOptions) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ToWebSearchGroup(group *group_model.Group, opts *GroupWebSearchOptions) (*WebSearchGroup, error) {
|
||||
func ToWebSearchGroup(group *group_model.Group, opts *WebSearchOptions) (*WebSearchGroup, error) {
|
||||
res := new(WebSearchGroup)
|
||||
|
||||
res.Repos = make([]*repo_service.WebSearchRepository, 0)
|
||||
@ -152,8 +152,8 @@ func ToWebSearchGroup(group *group_model.Group, opts *GroupWebSearchOptions) (*W
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func SearchRepoGroupWeb(group *group_model.Group, opts *GroupWebSearchOptions) (*GroupWebSearchResult, error) {
|
||||
res := new(WebSearchGroup)
|
||||
func SearchRepoGroupWeb(group *group_model.Group, opts *WebSearchOptions) (*WebSearchResult, error) {
|
||||
var res *WebSearchGroup
|
||||
var err error
|
||||
res, err = ToWebSearchGroup(group, opts)
|
||||
if err != nil {
|
||||
@ -163,37 +163,8 @@ func SearchRepoGroupWeb(group *group_model.Group, opts *GroupWebSearchOptions) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &GroupWebSearchResult{
|
||||
return &WebSearchResult{
|
||||
Data: res,
|
||||
OK: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
/* func SearchRootItems(ctx context.Context, oid int64, groupSearchOptions *group_model.FindGroupsOptions, repoSearchOptions *repo_model.SearchRepoOptions, actor *user_model.User, recursive bool) (*WebSearchGroupRoot, error) {
|
||||
root := &WebSearchGroupRoot{
|
||||
Repos: make([]*repo_service.WebSearchRepository, 0),
|
||||
Groups: make([]*WebSearchGroup, 0),
|
||||
}
|
||||
groupSearchOptions.ParentGroupID = 0
|
||||
groups, err := group_model.FindGroupsByCond(ctx, groupSearchOptions, group_model.AccessibleGroupCondition(actor, unit.TypeInvalid))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, g := range groups {
|
||||
toAppend, err := ToWebSearchGroup(ctx, g, actor, oid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
root.Groups = append(root.Groups, toAppend)
|
||||
}
|
||||
repos, _, err := repo_model.SearchRepositoryByCondition(ctx, repoSearchOptions, repo_model.AccessibleRepositoryCondition(actor, unit.TypeInvalid), true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, r := range repos {
|
||||
root.Repos = append(root.Repos, ToWebSearchRepo(ctx, r))
|
||||
}
|
||||
|
||||
return root, nil
|
||||
}
|
||||
*/
|
||||
|
||||
@ -20,25 +20,25 @@ func AddTeamToGroup(ctx context.Context, group *group_model.Group, tname string)
|
||||
has := group_model.HasTeamGroup(ctx, group.OwnerID, t.ID, group.ID)
|
||||
if has {
|
||||
return fmt.Errorf("team '%s' already exists in group[%d]", tname, group.ID)
|
||||
} else {
|
||||
parentGroup, err := group_model.FindGroupTeamByTeamID(ctx, group.ID, t.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mode := t.AccessMode
|
||||
canCreateIn := t.CanCreateOrgRepo
|
||||
if parentGroup != nil {
|
||||
mode = max(t.AccessMode, parentGroup.AccessMode)
|
||||
canCreateIn = parentGroup.CanCreateIn || t.CanCreateOrgRepo
|
||||
}
|
||||
if err = group.LoadParentGroup(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
err = group_model.AddTeamGroup(ctx, group.ID, t.ID, group.ID, mode, canCreateIn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
parentGroup, err := group_model.FindGroupTeamByTeamID(ctx, group.ID, t.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mode := t.AccessMode
|
||||
canCreateIn := t.CanCreateOrgRepo
|
||||
if parentGroup != nil {
|
||||
mode = max(t.AccessMode, parentGroup.AccessMode)
|
||||
canCreateIn = parentGroup.CanCreateIn || t.CanCreateOrgRepo
|
||||
}
|
||||
if err = group.LoadParentGroup(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
err = group_model.AddTeamGroup(ctx, group.ID, t.ID, group.ID, mode, canCreateIn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -47,13 +47,10 @@ func DeleteTeamFromGroup(ctx context.Context, group *group_model.Group, org int6
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = group_model.RemoveTeamGroup(ctx, org, team.ID, group.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return group_model.RemoveTeamGroup(ctx, org, team.ID, group.ID)
|
||||
}
|
||||
|
||||
func UpdateGroupTeam(ctx context.Context, gt *group_model.GroupTeam) (err error) {
|
||||
func UpdateGroupTeam(ctx context.Context, gt *group_model.RepoGroupTeam) (err error) {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -95,9 +92,9 @@ func RecalculateGroupAccess(ctx context.Context, g *group_model.Group, isNew boo
|
||||
teams, err = org_model.GetTeamsWithAccessToGroup(ctx, g.OwnerID, g.ParentGroupID, perm.AccessModeRead)
|
||||
}
|
||||
for _, t := range teams {
|
||||
var gt *group_model.GroupTeam = nil
|
||||
var gt *group_model.RepoGroupTeam = nil
|
||||
if gt, err = group_model.FindGroupTeamByTeamID(ctx, g.ParentGroupID, t.ID); err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
if gt != nil {
|
||||
if err = group_model.UpdateTeamGroup(ctx, g.OwnerID, t.ID, g.ID, gt.AccessMode, gt.CanCreateIn, isNew); err != nil {
|
||||
@ -123,7 +120,7 @@ func RecalculateGroupAccess(ctx context.Context, g *group_model.Group, isNew boo
|
||||
newAccessMode = min(newAccessMode, gu.AccessMode)
|
||||
}
|
||||
if isNew {
|
||||
if _, err = sess.Table("group_unit").Insert(&group_model.GroupUnit{
|
||||
if _, err = sess.Table("repo_group_unit").Insert(&group_model.RepoGroupUnit{
|
||||
Type: u.Type,
|
||||
TeamID: t.ID,
|
||||
GroupID: g.ID,
|
||||
@ -132,11 +129,11 @@ func RecalculateGroupAccess(ctx context.Context, g *group_model.Group, isNew boo
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err = sess.Table("group_unit").Where(builder.Eq{
|
||||
if _, err = sess.Table("repo_group_unit").Where(builder.Eq{
|
||||
"type": u.Type,
|
||||
"team_id": t.ID,
|
||||
"group_id": g.ID,
|
||||
}).Cols("access_mode").Update(&group_model.GroupUnit{
|
||||
}).Cols("access_mode").Update(&group_model.RepoGroupUnit{
|
||||
AccessMode: newAccessMode,
|
||||
}); err != nil {
|
||||
return err
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user