1
1
package group
2
2
3
3
import (
4
+ "fmt"
4
5
"net/http"
5
6
"strings"
6
7
@@ -12,12 +13,22 @@ import (
12
13
group_service "code.gitea.io/gitea/services/group"
13
14
)
14
15
15
- func createCommonGroup (ctx * context.APIContext , parentGroupID int64 ) (* api.Group , error ) {
16
+ func createCommonGroup (ctx * context.APIContext , parentGroupID , ownerID int64 ) (* api.Group , error ) {
17
+ if ownerID < 1 {
18
+ if parentGroupID < 1 {
19
+ return nil , fmt .Errorf ("cannot determine new group's owner" )
20
+ }
21
+ npg , err := group_model .GetGroupByID (ctx , parentGroupID )
22
+ if err != nil {
23
+ return nil , err
24
+ }
25
+ ownerID = npg .OwnerID
26
+ }
16
27
form := web .GetForm (ctx ).(* api.NewGroupOption )
17
28
group := & group_model.Group {
18
29
Name : form .Name ,
19
30
Description : form .Description ,
20
- OwnerID : ctx . Org . Organization . ID ,
31
+ OwnerID : ownerID ,
21
32
LowerName : strings .ToLower (form .Name ),
22
33
Visibility : form .Visibility ,
23
34
ParentGroupID : parentGroupID ,
@@ -45,6 +56,7 @@ func NewGroup(ctx *context.APIContext) {
45
56
// required: true
46
57
// - name: body
47
58
// in: body
59
+ // required: true
48
60
// schema:
49
61
// "$ref": "#/definitions/CreateGroupOption"
50
62
// responses:
@@ -54,7 +66,7 @@ func NewGroup(ctx *context.APIContext) {
54
66
// "$ref": "#/responses/notFound"
55
67
// "422":
56
68
// "$ref": "#/responses/validationError"
57
- ag , err := createCommonGroup (ctx , 0 )
69
+ ag , err := createCommonGroup (ctx , 0 , ctx . Org . Organization . ID )
58
70
if err != nil {
59
71
ctx .APIErrorInternal (err )
60
72
return
@@ -80,6 +92,7 @@ func NewSubGroup(ctx *context.APIContext) {
80
92
// required: true
81
93
// - name: body
82
94
// in: body
95
+ // required: true
83
96
// schema:
84
97
// "$ref": "#/definitions/CreateGroupOption"
85
98
// responses:
@@ -94,7 +107,7 @@ func NewSubGroup(ctx *context.APIContext) {
94
107
err error
95
108
)
96
109
gid := ctx .PathParamInt64 ("group_id" )
97
- group , err = createCommonGroup (ctx , gid )
110
+ group , err = createCommonGroup (ctx , gid , 0 )
98
111
if err != nil {
99
112
ctx .APIErrorInternal (err )
100
113
return
@@ -120,6 +133,7 @@ func MoveGroup(ctx *context.APIContext) {
120
133
// required: true
121
134
// - name: body
122
135
// in: body
136
+ // required: true
123
137
// schema:
124
138
// "$ref": "#/definitions/MoveGroupOption"
125
139
// responses:
@@ -185,6 +199,7 @@ func EditGroup(ctx *context.APIContext) {
185
199
// required: true
186
200
// - name: body
187
201
// in: body
202
+ // required: true
188
203
// schema:
189
204
// "$ref": "#/definitions/EditGroupOption"
190
205
// responses:
@@ -245,10 +260,6 @@ func GetGroup(ctx *context.APIContext) {
245
260
// type: integer
246
261
// format: int64
247
262
// required: true
248
- // - name: body
249
- // in: body
250
- // schema:
251
- // "$ref": "#/definitions/EditGroupOption"
252
263
// responses:
253
264
// "200":
254
265
// "$ref": "#/responses/Group"
@@ -288,11 +299,6 @@ func DeleteGroup(ctx *context.APIContext) {
288
299
// produces:
289
300
// - application/json
290
301
// parameters:
291
- // - name: owner
292
- // in: path
293
- // description: owner of the group to delete
294
- // type: string
295
- // required: true
296
302
// - name: group_id
297
303
// in: path
298
304
// description: id of the group to delete
0 commit comments