Skip to content

Commit 7020c4a

Browse files
Cosinwxiaoguang
andauthored
Fix leaving organization bug on user settings -> orgs (#21983)
Fix #21772 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent fdfd77f commit 7020c4a

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Diff for: options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ team_not_exist = The team does not exist.
505505
last_org_owner = You cannot remove the last user from the 'owners' team. There must be at least one owner for an organization.
506506
cannot_add_org_to_team = An organization cannot be added as a team member.
507507
duplicate_invite_to_team = The user was already invited as a team member.
508+
organization_leave_success = You have successfully left the organization %s.
508509

509510
invalid_ssh_key = Can not verify your SSH key: %s
510511
invalid_gpg_key = Can not verify your GPG key: %s

Diff for: routers/web/org/members.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,20 @@ func MembersAction(ctx *context.Context) {
107107
}
108108
case "leave":
109109
err = models.RemoveOrgUser(org.ID, ctx.Doer.ID)
110-
if organization.IsErrLastOrgOwner(err) {
110+
if err == nil {
111+
ctx.Flash.Success(ctx.Tr("form.organization_leave_success", org.DisplayName()))
112+
ctx.JSON(http.StatusOK, map[string]interface{}{
113+
"redirect": "", // keep the user stay on current page, in case they want to do other operations.
114+
})
115+
} else if organization.IsErrLastOrgOwner(err) {
111116
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
112117
ctx.JSON(http.StatusOK, map[string]interface{}{
113118
"redirect": ctx.Org.OrgLink + "/members",
114119
})
115-
return
120+
} else {
121+
log.Error("RemoveOrgUser(%d,%d): %v", org.ID, ctx.Doer.ID, err)
116122
}
123+
return
117124
}
118125

119126
if err != nil {

Diff for: templates/user/settings/organization.tmpl

+16-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
{{range .Orgs}}
1818
<div class="item">
1919
<div class="right floated content">
20-
<form method="post" action="{{.OrganisationLink}}/members/action/leave">
20+
<form>
2121
{{$.CsrfTokenHtml}}
22-
<button type="submit" class="ui primary small button" name="uid" value="{{.ID}}">{{$.locale.Tr "org.members.leave"}}</button>
22+
<button class="ui red button delete-button" data-modal-id="leave-organization"
23+
data-url="{{.OrganisationLink}}/members/action/leave" data-datauid="{{$.SignedUser.ID}}"
24+
data-name="{{$.SignedUser.DisplayName}}"
25+
data-data-organization-name="{{.DisplayName}}">{{$.locale.Tr "org.members.leave"}}
26+
</button>
2327
</form>
2428
</div>
2529
{{avatar . 28 "mini"}}
@@ -36,4 +40,14 @@
3640
</div>
3741
</div>
3842
</div>
43+
<div class="ui small basic delete modal" id="leave-organization">
44+
<div class="ui icon header">
45+
{{svg "octicon-x" 16 "close inside"}}
46+
{{$.locale.Tr "org.members.leave"}}
47+
</div>
48+
<div class="content">
49+
<p>{{$.locale.Tr "org.members.leave.detail" `<span class="dataOrganizationName"></span>` | Safe}}</p>
50+
</div>
51+
{{template "base/delete_modal_actions" .}}
52+
</div>
3953
{{template "base/footer" .}}

0 commit comments

Comments
 (0)