// https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) { u := user.GetUserByParams(ctx) if ctx.Written() { return } org := &models.User{ Name: form.UserName, FullName: form.FullName, Description: form.Description, Website: form.Website, Location: form.Location, IsActive: true, Type: models.USER_TYPE_ORGANIZATION, } if err := models.CreateOrganization(org, u); err != nil { if models.IsErrUserAlreadyExist(err) || models.IsErrNameReserved(err) || models.IsErrNamePatternNotAllowed(err) { ctx.Error(422, "", err) } else { ctx.Error(500, "CreateOrganization", err) } return } ctx.JSON(201, convert.ToOrganization(org)) }
// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization func Get(ctx *context.APIContext) { org := user.GetUserByParamsName(ctx, ":orgname") if ctx.Written() { return } ctx.JSON(200, convert.ToOrganization(org)) }
func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) { if err := u.GetOrganizations(all); err != nil { ctx.Error(500, "GetOrganizations", err) return } apiOrgs := make([]*api.Organization, len(u.Orgs)) for i := range u.Orgs { apiOrgs[i] = convert.ToOrganization(u.Orgs[i]) } ctx.JSON(200, &apiOrgs) }
// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization func Edit(ctx *context.APIContext, form api.EditOrgOption) { org := ctx.Org.Organization if !org.IsOwnedBy(ctx.User.ID) { ctx.Status(403) return } org.FullName = form.FullName org.Description = form.Description org.Website = form.Website org.Location = form.Location if err := models.UpdateUser(org); err != nil { ctx.Error(500, "UpdateUser", err) return } ctx.JSON(200, convert.ToOrganization(org)) }
// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization func Edit(ctx *context.APIContext, form api.EditOrgOption) { org := user.GetUserByParamsName(ctx, ":orgname") if ctx.Written() { return } if !org.IsOwnedBy(ctx.User.Id) { ctx.Status(403) return } org.FullName = form.FullName org.Description = form.Description org.Website = form.Website org.Location = form.Location if err := models.UpdateUser(org); err != nil { ctx.Error(500, "UpdateUser", err) return } ctx.JSON(200, convert.ToOrganization(org)) }
// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization func Get(ctx *context.APIContext) { ctx.JSON(200, convert.ToOrganization(ctx.Org.Organization)) }