Skip to content

Commit f430050

Browse files
zeripathCosinwxiaoguanglunnyKN4CK3R
authored
Fix leaving organization bug on user settings -> orgs (#21983) (#22438)
Backport #21983 Fix #21772 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: 花墨 <shanee@live.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
1 parent 510c811 commit f430050

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
@@ -497,6 +497,7 @@ team_not_exist = The team does not exist.
497497
last_org_owner = You cannot remove the last user from the 'owners' team. There must be at least one owner for an organization.
498498
cannot_add_org_to_team = An organization cannot be added as a team member.
499499
duplicate_invite_to_team = The user was already invited as a team member.
500+
organization_leave_success = You have successfully left the organization %s.
500501

501502
invalid_ssh_key = Can not verify your SSH key: %s
502503
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
@@ -108,13 +108,20 @@ func MembersAction(ctx *context.Context) {
108108
}
109109
case "leave":
110110
err = models.RemoveOrgUser(org.ID, ctx.Doer.ID)
111-
if organization.IsErrLastOrgOwner(err) {
111+
if err == nil {
112+
ctx.Flash.Success(ctx.Tr("form.organization_leave_success", org.DisplayName()))
113+
ctx.JSON(http.StatusOK, map[string]interface{}{
114+
"redirect": "", // keep the user stay on current page, in case they want to do other operations.
115+
})
116+
} else if organization.IsErrLastOrgOwner(err) {
112117
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
113118
ctx.JSON(http.StatusOK, map[string]interface{}{
114119
"redirect": ctx.Org.OrgLink + "/members",
115120
})
116-
return
121+
} else {
122+
log.Error("RemoveOrgUser(%d,%d): %v", org.ID, ctx.Doer.ID, err)
117123
}
124+
return
118125
}
119126

120127
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)