Skip to content

Commit

Permalink
Fix leaving organization bug on user settings -> orgs (go-gitea#21983)
Browse files Browse the repository at this point in the history
Backport go-gitea#21983

Fix go-gitea#21772

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
  • Loading branch information
2 people authored and zeripath committed Jan 13, 2023
1 parent 421d879 commit 88da582
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ team_not_exist = The team does not exist.
last_org_owner = You cannot remove the last user from the 'owners' team. There must be at least one owner for an organization.
cannot_add_org_to_team = An organization cannot be added as a team member.
duplicate_invite_to_team = The user was already invited as a team member.
organization_leave_success = You have successfully left the organization %s.

invalid_ssh_key = Can not verify your SSH key: %s
invalid_gpg_key = Can not verify your GPG key: %s
Expand Down
11 changes: 9 additions & 2 deletions routers/web/org/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,20 @@ func MembersAction(ctx *context.Context) {
}
case "leave":
err = models.RemoveOrgUser(org.ID, ctx.Doer.ID)
if organization.IsErrLastOrgOwner(err) {
if err == nil {
ctx.Flash.Success(ctx.Tr("form.organization_leave_success", org.DisplayName()))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": "", // keep the user stay on current page, in case they want to do other operations.
})
} else if organization.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": ctx.Org.OrgLink + "/members",
})
return
} else {
log.Error("RemoveOrgUser(%d,%d): %v", org.ID, ctx.Doer.ID, err)
}
return
}

if err != nil {
Expand Down
18 changes: 16 additions & 2 deletions templates/user/settings/organization.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
{{range .Orgs}}
<div class="item">
<div class="right floated content">
<form method="post" action="{{.OrganisationLink}}/members/action/leave">
<form>
{{$.CsrfTokenHtml}}
<button type="submit" class="ui primary small button" name="uid" value="{{.ID}}">{{$.locale.Tr "org.members.leave"}}</button>
<button class="ui red button delete-button" data-modal-id="leave-organization"
data-url="{{.OrganisationLink}}/members/action/leave" data-datauid="{{$.SignedUser.ID}}"
data-name="{{$.SignedUser.DisplayName}}"
data-data-organization-name="{{.DisplayName}}">{{$.locale.Tr "org.members.leave"}}
</button>
</form>
</div>
{{avatar . 28 "mini"}}
Expand All @@ -36,4 +40,14 @@
</div>
</div>
</div>
<div class="ui small basic delete modal" id="leave-organization">
<div class="ui icon header">
{{svg "octicon-x" 16 "close inside"}}
{{$.locale.Tr "org.members.leave"}}
</div>
<div class="content">
<p>{{$.locale.Tr "org.members.leave.detail" `<span class="dataOrganizationName"></span>` | Safe}}</p>
</div>
{{template "base/delete_modal_actions" .}}
</div>
{{template "base/footer" .}}

0 comments on commit 88da582

Please sign in to comment.