Esempio n. 1
0
// https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization
func CreateOrg(ctx *middleware.Context, 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.ORGANIZATION,
	}
	if err := models.CreateOrganization(org, u); err != nil {
		if models.IsErrUserAlreadyExist(err) ||
			models.IsErrNameReserved(err) ||
			models.IsErrNamePatternNotAllowed(err) {
			ctx.APIError(422, "CreateOrganization", err)
		} else {
			ctx.APIError(500, "CreateOrganization", err)
		}
		return
	}

	ctx.JSON(201, convert.ToApiOrganization(org))
}
Esempio n. 2
0
// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization
func Get(ctx *middleware.Context) {
	org := user.GetUserByParamsName(ctx, ":orgname")
	if ctx.Written() {
		return
	}
	ctx.JSON(200, convert.ToApiOrganization(org))
}
Esempio n. 3
0
func listUserOrgs(ctx *middleware.Context, u *models.User, all bool) {
	if err := u.GetOrganizations(all); err != nil {
		ctx.APIError(500, "GetOrganizations", err)
		return
	}

	apiOrgs := make([]*api.Organization, len(u.Orgs))
	for i := range u.Orgs {
		apiOrgs[i] = convert.ToApiOrganization(u.Orgs[i])
	}
	ctx.JSON(200, &apiOrgs)
}
Esempio n. 4
0
// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization
func Edit(ctx *middleware.Context, form api.EditOrgOption) {
	org := user.GetUserByParamsName(ctx, ":orgname")
	if ctx.Written() {
		return
	}

	if !org.IsOwnedBy(ctx.User.Id) {
		ctx.Error(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.APIError(500, "UpdateUser", err)
		return
	}

	ctx.JSON(200, convert.ToApiOrganization(org))
}