File tree Expand file tree Collapse file tree 3 files changed +31
-16
lines changed
Expand file tree Collapse file tree 3 files changed +31
-16
lines changed Original file line number Diff line number Diff line change @@ -90,31 +90,38 @@ type GroupAssignmentOptions struct {
9090 RequireGroupAdmin bool
9191}
9292
93+ func groupAssignment (ctx * Context ) {
94+ if ctx .RepoGroup .Group == nil {
95+ GetGroupByParams (ctx )
96+ }
97+ if ctx .Written () {
98+ return
99+ }
100+ canAccess , err := ctx .RepoGroup .Group .CanAccess (ctx , ctx .Doer )
101+ if err != nil {
102+ ctx .ServerError ("error checking group access" , err )
103+ return
104+ }
105+ if ! canAccess {
106+ ctx .NotFound (nil )
107+ return
108+ }
109+ }
110+
93111func GroupAssignment (args GroupAssignmentOptions ) func (ctx * Context ) {
94112 return func (ctx * Context ) {
95113 var err error
96114
97- if ctx .RepoGroup .Group == nil {
98- GetGroupByParams (ctx )
99- if ctx .Written () {
100- return
101- }
115+ groupAssignment (ctx )
116+ if ctx .Written () {
117+ return
102118 }
103119
104120 group := ctx .RepoGroup .Group
105121 if ctx .RepoGroup .Group .Visibility != structs .VisibleTypePublic && ! ctx .IsSigned {
106122 ctx .NotFound (err )
107123 return
108124 }
109- canAccess , err := ctx .RepoGroup .Group .CanAccess (ctx , ctx .Doer )
110- if err != nil {
111- ctx .ServerError ("error checking group access" , err )
112- return
113- }
114- if ! canAccess {
115- ctx .NotFound (nil )
116- return
117- }
118125
119126 if ctx .RepoGroup .Group .Visibility == structs .VisibleTypePrivate {
120127 args .RequireMember = true
Original file line number Diff line number Diff line change @@ -35,7 +35,9 @@ func CanWriteToBranch() func(ctx *Context) {
3535// RequireUnitWriter returns a middleware for requiring repository write to one of the unit permission
3636func RequireUnitWriter (unitTypes ... unit.Type ) func (ctx * Context ) {
3737 return func (ctx * Context ) {
38- if slices .ContainsFunc (unitTypes , ctx .Repo .CanWrite ) {
38+ if slices .ContainsFunc (unitTypes , ctx .Repo .CanWrite ) || (ctx .RepoGroup != nil && slices .ContainsFunc (unitTypes , func (u unit.Type ) bool {
39+ return ctx .RepoGroup .CanWriteUnit (ctx , u )
40+ })) {
3941 return
4042 }
4143 ctx .NotFound (nil )
@@ -46,7 +48,7 @@ func RequireUnitWriter(unitTypes ...unit.Type) func(ctx *Context) {
4648func RequireUnitReader (unitTypes ... unit.Type ) func (ctx * Context ) {
4749 return func (ctx * Context ) {
4850 for _ , unitType := range unitTypes {
49- if ctx .Repo .CanRead (unitType ) {
51+ if ctx .Repo .CanRead (unitType ) || ctx . RepoGroup . CanReadUnit ( ctx , unitType ) {
5052 return
5153 }
5254 if unitType == unit .TypeCode && canWriteAsMaintainer (ctx ) {
Original file line number Diff line number Diff line change @@ -525,6 +525,12 @@ func RepoAssignment(ctx *Context) {
525525 if repo .GroupID != gid {
526526 ctx .NotFound (nil )
527527 }
528+ if gid > 0 {
529+ groupAssignment (ctx )
530+ }
531+ if ctx .Written () {
532+ return
533+ }
528534 repo .Owner = ctx .Repo .Owner
529535
530536 repoAssignment (ctx , repo )
You can’t perform that action at this time.
0 commit comments