blob: e81b6b1b96b1abf7eab8c25811e96381f929c100 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright 2016 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package admin
import (
convert2 "gogs.io/gogs/internal/route/api/v1/convert"
user2 "gogs.io/gogs/internal/route/api/v1/user"
"net/http"
api "github.com/gogs/go-gogs-client"
"gogs.io/gogs/internal/context"
"gogs.io/gogs/internal/db"
)
func CreateTeam(c *context.APIContext, form api.CreateTeamOption) {
team := &db.Team{
OrgID: c.Org.Organization.ID,
Name: form.Name,
Description: form.Description,
Authorize: db.ParseAccessMode(form.Permission),
}
if err := db.NewTeam(team); err != nil {
if db.IsErrTeamAlreadyExist(err) {
c.Error(http.StatusUnprocessableEntity, "", err)
} else {
c.ServerError("NewTeam", err)
}
return
}
c.JSON(http.StatusCreated, convert2.ToTeam(team))
}
func AddTeamMember(c *context.APIContext) {
u := user2.GetUserByParams(c)
if c.Written() {
return
}
if err := c.Org.Team.AddMember(u.ID); err != nil {
c.ServerError("AddMember", err)
return
}
c.NoContent()
}
func RemoveTeamMember(c *context.APIContext) {
u := user2.GetUserByParams(c)
if c.Written() {
return
}
if err := c.Org.Team.RemoveMember(u.ID); err != nil {
c.ServerError("RemoveMember", err)
return
}
c.NoContent()
}
|