|
@@ -8,6 +8,7 @@ import (
|
|
|
"net/http"
|
|
|
|
|
|
"github.com/G-Node/gogs/internal/db"
|
|
|
+ "github.com/G-Node/gogs/internal/db/errors"
|
|
|
convert2 "github.com/G-Node/gogs/internal/route/api/v1/convert"
|
|
|
api "github.com/gogs/go-gogs-client"
|
|
|
|
|
@@ -29,12 +30,13 @@ func ListTeams(c *context.APIContext) {
|
|
|
}
|
|
|
|
|
|
func CreateTeam(c *context.APIContext, opt api.CreateTeamOption) {
|
|
|
- if !c.Org.Organization.IsOwnedBy(c.User.ID) {
|
|
|
+ org := c.Org.Organization
|
|
|
+ if !org.IsOwnedBy(c.User.ID) {
|
|
|
c.Error(http.StatusForbidden, "", "given user is not owner of organization")
|
|
|
return
|
|
|
}
|
|
|
team := &db.Team{
|
|
|
- OrgID: c.Org.Organization.ID,
|
|
|
+ OrgID: org.ID,
|
|
|
Name: opt.Name,
|
|
|
Description: opt.Description,
|
|
|
Authorize: db.ParseAccessMode(opt.Permission),
|
|
@@ -50,3 +52,55 @@ func CreateTeam(c *context.APIContext, opt api.CreateTeamOption) {
|
|
|
|
|
|
c.JSON(http.StatusCreated, convert2.ToTeam(team))
|
|
|
}
|
|
|
+
|
|
|
+func GetTeam(c *context.APIContext) {
|
|
|
+ teamname := c.Params(":team")
|
|
|
+ org := c.Org.Organization
|
|
|
+ team, err := org.GetTeam(teamname)
|
|
|
+ if err != nil {
|
|
|
+ c.NotFoundOrServerError("GetTeamByName", errors.IsTeamNotExist, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(200, convert2.ToTeam(team))
|
|
|
+}
|
|
|
+
|
|
|
+func EditTeam(c *context.APIContext, opt api.CreateTeamOption) {
|
|
|
+ teamname := c.Params(":team")
|
|
|
+ org := c.Org.Organization
|
|
|
+ if !org.IsOwnedBy(c.User.ID) {
|
|
|
+ c.Error(http.StatusForbidden, "", "given user is not owner of organization")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ oldteam, err := org.GetTeam(teamname)
|
|
|
+ if err != nil {
|
|
|
+ c.NotFoundOrServerError("EditTeamByName", errors.IsTeamNotExist, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ team := &db.Team{
|
|
|
+ ID: oldteam.ID,
|
|
|
+ OrgID: org.ID,
|
|
|
+ Name: opt.Name,
|
|
|
+ Description: opt.Description,
|
|
|
+ Authorize: db.ParseAccessMode(opt.Permission),
|
|
|
+ }
|
|
|
+ if err := db.UpdateTeam(team, oldteam.Authorize != team.Authorize); err != nil {
|
|
|
+ c.NotFoundOrServerError("EditTeamByName", errors.IsTeamNotExist, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.JSON(http.StatusCreated, convert2.ToTeam(team))
|
|
|
+}
|
|
|
+
|
|
|
+func DeleteTeam(c *context.APIContext) {
|
|
|
+ teamname := c.Params(":team")
|
|
|
+ org := c.Org.Organization
|
|
|
+ team, err := org.GetTeam(teamname)
|
|
|
+ if err != nil {
|
|
|
+ c.NotFoundOrServerError("DeleteTeamByName", errors.IsTeamNotExist, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if err := db.DeleteTeam(team); err != nil {
|
|
|
+ c.NotFoundOrServerError("DeleteTeamByName", errors.IsTeamNotExist, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c.NoContent()
|
|
|
+}
|