11package  group
22
33import  (
4- 	"code.gitea.io/gitea/models/perm" 
54	"context" 
65	"slices" 
76
87	"code.gitea.io/gitea/models/db" 
98	group_model "code.gitea.io/gitea/models/group" 
9+ 	"code.gitea.io/gitea/models/perm" 
1010	repo_model "code.gitea.io/gitea/models/repo" 
1111	"code.gitea.io/gitea/models/unit" 
1212	user_model "code.gitea.io/gitea/models/user" 
1313	"code.gitea.io/gitea/modules/log" 
14+ 
1415	"xorm.io/builder" 
1516)
1617
17- // GroupItem  - represents an item in a group, either a repository or a subgroup. 
18+ // Item  - represents an item in a group, either a repository or a subgroup. 
1819// used to display, for example, the group sidebar 
19- type  GroupItem  interface  {
20+ type  Item  interface  {
2021	Link () string 
2122	Title () string 
22- 	Parent () GroupItem 
23- 	Children (doer  * user_model.User ) []GroupItem 
23+ 	Parent () Item 
24+ 	Children (doer  * user_model.User ) []Item 
2425	Avatar (ctx  context.Context ) string 
2526	HasChildren (doer  * user_model.User ) bool 
2627	IsGroup () bool 
@@ -40,15 +41,15 @@ func (g *groupItemGroup) Title() string {
4041	return  g .Group .Name 
4142}
4243
43- func  (g  * groupItemGroup ) Parent () GroupItem  {
44+ func  (g  * groupItemGroup ) Parent () Item  {
4445	if  g .Group .ParentGroupID  ==  0  {
4546		return  nil 
4647	}
4748	group , _  :=  group_model .GetGroupByID (db .DefaultContext , g .Group .ParentGroupID )
4849	return  & groupItemGroup {group }
4950}
5051
51- func  (g  * groupItemGroup ) Children (doer  * user_model.User ) (items  []GroupItem ) {
52+ func  (g  * groupItemGroup ) Children (doer  * user_model.User ) (items  []Item ) {
5253	repos  :=  make ([]* repo_model.Repository , 0 )
5354	sess  :=  db .GetEngine (db .DefaultContext )
5455	err  :=  sess .Table ("repository" ).
@@ -57,11 +58,11 @@ func (g *groupItemGroup) Children(doer *user_model.User) (items []GroupItem) {
5758		Find (& repos )
5859	if  err  !=  nil  {
5960		log .Error ("%w" , err )
60- 		return  make ([]GroupItem , 0 )
61+ 		return  make ([]Item , 0 )
6162	}
6263	err  =  g .Group .LoadAccessibleSubgroups (db .DefaultContext , false , doer )
6364	if  err  !=  nil  {
64- 		return  make ([]GroupItem , 0 )
65+ 		return  make ([]Item , 0 )
6566	}
6667	slices .SortStableFunc (g .Group .Subgroups , func (a , b  * group_model.Group ) int  {
6768		return  a .SortOrder  -  b .SortOrder 
@@ -97,15 +98,17 @@ func (g *groupItemGroup) ID() int64 {
9798func  (g  * groupItemGroup ) Sort () int  {
9899	return  g .Group .SortOrder 
99100}
100- func  GetTopLevelGroupItemList (ctx  context.Context , orgID  int64 , doer  * user_model.User ) (rootItems  []GroupItem ) {
101+ 
102+ func  GetTopLevelGroupItemList (ctx  context.Context , orgID  int64 , doer  * user_model.User ) []Item  {
103+ 	var  rootItems  []Item 
101104	groups , err  :=  group_model .FindGroupsByCond (ctx , & group_model.FindGroupsOptions {
102105		ParentGroupID : 0 ,
103106		ActorID :       doer .ID ,
104107		OwnerID :       orgID ,
105108	}, group_model .
106109		AccessibleGroupCondition (doer , unit .TypeInvalid , perm .AccessModeRead ))
107110	if  err  !=  nil  {
108- 		return 
111+ 		return   nil 
109112	}
110113	repos  :=  make ([]* repo_model.Repository , 0 )
111114	cond  :=  builder .NewCond ().
@@ -115,7 +118,7 @@ func GetTopLevelGroupItemList(ctx context.Context, orgID int64, doer *user_model
115118	sess  :=  db .GetEngine (ctx )
116119	err  =  sess .Table ("repository" ).Where (cond ).Find (& repos )
117120	if  err  !=  nil  {
118- 		return 
121+ 		return   nil 
119122	}
120123	slices .SortStableFunc (groups , func (a , b  * group_model.Group ) int  {
121124		return  a .SortOrder  -  b .SortOrder 
@@ -129,12 +132,12 @@ func GetTopLevelGroupItemList(ctx context.Context, orgID int64, doer *user_model
129132	for  _ , r  :=  range  repos  {
130133		rootItems  =  append (rootItems , & groupItemRepo {r })
131134	}
132- 	return 
135+ 	return   rootItems 
133136}
134137
135- func  GroupItemHasChild ( it   GroupItem ,  other   int64 ,  ctx  context. Context , doer  * user_model.User ) bool  {
138+ func  ItemHasChild ( ctx  context. Context ,  it   Item ,  other   int64 , doer  * user_model.User ) bool  {
136139	for  _ , item  :=  range  it .Children (doer ) {
137- 		if  GroupItemHasChild ( item ,  other ,  ctx , doer ) {
140+ 		if  ItemHasChild ( ctx ,  item ,  other , doer ) {
138141			return  true 
139142		}
140143	}
0 commit comments