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>
(cherry picked from commit 040c830dec5c727a56d16df62b1673bce6fca645)

Conflicts:
	routers/api/v1/admin/user.go
  ignore this unrelated change
	templates/swagger/v1_json.tmpl
  regenerate
	tests/integration/api_org_test.go
  port as a standalone test instead of refactoring the tests
This commit is contained in:
Bruno Sofiato 2025-01-31 21:59:49 -03:00 committed by Earl Warren
parent f44f3cbc2a
commit 689fb82a70
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 130 additions and 0 deletions

View file

@ -99,6 +99,29 @@ func TestAPIOrgCreate(t *testing.T) {
assert.EqualValues(t, "user1", users[0].UserName)
}
func TestAPIOrgRename(t *testing.T) {
defer tests.PrepareTestEnv(t)()
token := getUserToken(t, "user1", auth_model.AccessTokenScopeWriteOrganization)
org := api.CreateOrgOption{
UserName: "user1_org",
FullName: "User1's organization",
Description: "This organization created by user1",
Website: "https://try.gitea.io",
Location: "Shanghai",
Visibility: "limited",
}
req := NewRequestWithJSON(t, "POST", "/api/v1/orgs", &org).
AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated)
req = NewRequestWithJSON(t, "POST", "/api/v1/orgs/user1_org/rename", &api.RenameOrgOption{
NewName: "renamed_org",
}).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent)
unittest.AssertExistsAndLoadBean(t, &org_model.Organization{Name: "renamed_org"})
}
func TestAPIOrgEdit(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user1")