mirror of
https://github.com/go-gitea/gitea
synced 2025-07-16 07:18:37 +00:00
Inclusion of rename organization api (#33303)
This adds an endpoint (`/orgs/{org}/rename`) to rename organizations. I've modeled the endpoint using the rename user endpoint -- `/admin/users/{username}/rename` -- as base. It is the 1st time I wrote a new API endpoint (I've tried to follow the rename users endpoint code while writing it). So feel free to ping me if there is something wrong or missing. Resolves #32995 --------- Signed-off-by: Bruno Sofiato <bruno.sofiato@gmail.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -315,6 +315,44 @@ func Get(ctx *context.APIContext) {
|
||||
ctx.JSON(http.StatusOK, org)
|
||||
}
|
||||
|
||||
func Rename(ctx *context.APIContext) {
|
||||
// swagger:operation POST /orgs/{org}/rename organization renameOrg
|
||||
// ---
|
||||
// summary: Rename an organization
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: org
|
||||
// in: path
|
||||
// description: existing org name
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: body
|
||||
// in: body
|
||||
// required: true
|
||||
// schema:
|
||||
// "$ref": "#/definitions/RenameOrgOption"
|
||||
// responses:
|
||||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.RenameOrgOption)
|
||||
orgUser := ctx.Org.Organization.AsUser()
|
||||
if err := user_service.RenameUser(ctx, orgUser, form.NewName); err != nil {
|
||||
if user_model.IsErrUserAlreadyExist(err) || db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) || db.IsErrNameCharsNotAllowed(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "RenameOrg", err)
|
||||
} else {
|
||||
ctx.ServerError("RenameOrg", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// Edit change an organization's information
|
||||
func Edit(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /orgs/{org} organization orgEdit
|
||||
|
Reference in New Issue
Block a user