Inclusion of rename organization api

Signed-off-by: Bruno Sofiato <bruno.sofiato@gmail.com>
pull/33303/head
Bruno Sofiato 3 weeks ago
parent ab347fd0f7
commit ff24828608
No known key found for this signature in database
  1. 9
      modules/structs/org.go
  2. 1
      routers/api/v1/api.go
  3. 41
      routers/api/v1/org/org.go
  4. 3
      routers/api/v1/swagger/options.go
  5. 56
      templates/swagger/v1_json.tmpl

@ -57,3 +57,12 @@ type EditOrgOption struct {
Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
RepoAdminChangeTeamAccess *bool `json:"repo_admin_change_team_access"`
}
// RenameOrgOption options when renaming an organization
type RenameOrgOption struct {
// New username for this org. This name cannot be in use yet by any other user.
//
// required: true
// unique: true
NewName string `json:"new_name" binding:"Required"`
}

@ -1530,6 +1530,7 @@ func Routes() *web.Router {
m.Combo("").Get(org.Get).
Patch(reqToken(), reqOrgOwnership(), bind(api.EditOrgOption{}), org.Edit).
Delete(reqToken(), reqOrgOwnership(), org.Delete)
m.Post("/rename", reqToken(), reqOrgOwnership(), bind(api.RenameOrgOption{}), org.Rename)
m.Combo("/repos").Get(user.ListOrgRepos).
Post(reqToken(), bind(api.CreateRepoOption{}), repo.CreateOrgRepo)
m.Group("/members", func() {

@ -315,6 +315,47 @@ 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"
org := ctx.Org.Organization
form := web.GetForm(ctx).(*api.RenameOrgOption)
if err := user_service.RenameUser(ctx, org.AsUser(), form.NewName); err != nil {
if user_model.IsErrUserAlreadyExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "RenameOrg", ctx.Tr("form.username_been_taken"))
} else if db.IsErrNameReserved(err) {
ctx.Error(http.StatusUnprocessableEntity, "RenameOrg", ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name))
} else if db.IsErrNamePatternNotAllowed(err) {
ctx.Error(http.StatusUnprocessableEntity, "RenameOrg", ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern))
} else {
ctx.ServerError("RenameOrg", err)
}
}
}
// Edit change an organization's information
func Edit(ctx *context.APIContext) {
// swagger:operation PATCH /orgs/{org} organization orgEdit

@ -208,6 +208,9 @@ type swaggerParameterBodies struct {
// in:body
CreateVariableOption api.CreateVariableOption
// in:body
RenameOrgOption api.RenameOrgOption
// in:body
UpdateVariableOption api.UpdateVariableOption
}

@ -2991,6 +2991,46 @@
}
}
},
"/orgs/{org}/rename": {
"post": {
"produces": [
"application/json"
],
"tags": [
"organization"
],
"summary": "Rename an organization",
"operationId": "renameOrg",
"parameters": [
{
"type": "string",
"description": "existing org name",
"name": "org",
"in": "path",
"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"
}
}
}
},
"/orgs/{org}/repos": {
"get": {
"produces": [
@ -24207,6 +24247,22 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"RenameOrgOption": {
"description": "RenameOrgOption options when renaming an organization",
"type": "object",
"required": [
"new_name"
],
"properties": {
"new_name": {
"description": "New username for this org. This name cannot be in use yet by any other user.",
"type": "string",
"uniqueItems": true,
"x-go-name": "NewName"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"RenameUserOption": {
"description": "RenameUserOption options when renaming a user",
"type": "object",

Loading…
Cancel
Save