mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.7 KiB
67 lines
1.7 KiB
9 years ago
|
// Copyright 2015 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 org
|
||
|
|
||
|
import (
|
||
|
api "github.com/gogits/go-gogs-client"
|
||
|
|
||
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
8 years ago
|
"github.com/gogits/gogs/routes/api/v1/convert"
|
||
|
"github.com/gogits/gogs/routes/api/v1/user"
|
||
9 years ago
|
)
|
||
|
|
||
8 years ago
|
func listUserOrgs(c *context.APIContext, u *models.User, all bool) {
|
||
9 years ago
|
if err := u.GetOrganizations(all); err != nil {
|
||
8 years ago
|
c.Error(500, "GetOrganizations", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
|
apiOrgs := make([]*api.Organization, len(u.Orgs))
|
||
|
for i := range u.Orgs {
|
||
9 years ago
|
apiOrgs[i] = convert.ToOrganization(u.Orgs[i])
|
||
9 years ago
|
}
|
||
8 years ago
|
c.JSON(200, &apiOrgs)
|
||
9 years ago
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations
|
||
8 years ago
|
func ListMyOrgs(c *context.APIContext) {
|
||
|
listUserOrgs(c, c.User, true)
|
||
9 years ago
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations
|
||
8 years ago
|
func ListUserOrgs(c *context.APIContext) {
|
||
|
u := user.GetUserByParams(c)
|
||
|
if c.Written() {
|
||
9 years ago
|
return
|
||
|
}
|
||
8 years ago
|
listUserOrgs(c, u, false)
|
||
9 years ago
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization
|
||
8 years ago
|
func Get(c *context.APIContext) {
|
||
|
c.JSON(200, convert.ToOrganization(c.Org.Organization))
|
||
9 years ago
|
}
|
||
|
|
||
|
// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization
|
||
8 years ago
|
func Edit(c *context.APIContext, form api.EditOrgOption) {
|
||
|
org := c.Org.Organization
|
||
|
if !org.IsOwnedBy(c.User.ID) {
|
||
|
c.Status(403)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
|
org.FullName = form.FullName
|
||
|
org.Description = form.Description
|
||
|
org.Website = form.Website
|
||
|
org.Location = form.Location
|
||
|
if err := models.UpdateUser(org); err != nil {
|
||
8 years ago
|
c.Error(500, "UpdateUser", err)
|
||
9 years ago
|
return
|
||
|
}
|
||
|
|
||
8 years ago
|
c.JSON(200, convert.ToOrganization(org))
|
||
9 years ago
|
}
|