mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-21 14:02:14 +02:00
apply simple linting changes
This commit is contained in:
@@ -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
|
||||
}
|
||||
*/
|
||||
|
||||
+25
-28
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user