From e37342db0c102ef12ae70072d9f4bbef89338085 Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 27 Aug 2021 03:57:40 +0100 Subject: Add modals to Organization and Team remove/leave (#16471) * Add modals to Organization and Team remove/leave Add confirmation modals to Organization and Team remove and leave. Fix #16215 Signed-off-by: Andrew Thornton * avoid for-in Signed-off-by: Andrew Thornton * Revert "avoid for-in" This reverts commit 2af9a6f9d46ed31b6fc6e3a29e695577dcf09f75. * Apply suggestions from code review Co-authored-by: silverwind Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: silverwind Co-authored-by: techknowlogick --- routers/web/org/teams.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'routers/web/org/teams.go') diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 4725f19b3d..c93fcd062b 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -66,6 +66,23 @@ func TeamsAction(ctx *context.Context) { err = ctx.Org.Team.AddMember(ctx.User.ID) case "leave": err = ctx.Org.Team.RemoveMember(ctx.User.ID) + if err != nil { + if models.IsErrLastOrgOwner(err) { + ctx.Flash.Error(ctx.Tr("form.last_org_owner")) + } else { + log.Error("Action(%s): %v", ctx.Params(":action"), err) + ctx.JSON(http.StatusOK, map[string]interface{}{ + "ok": false, + "err": err.Error(), + }) + return + } + } + ctx.JSON(http.StatusOK, + map[string]interface{}{ + "redirect": ctx.Org.OrgLink + "/teams/", + }) + return case "remove": if !ctx.Org.IsOwner { ctx.Error(http.StatusNotFound) @@ -73,6 +90,23 @@ func TeamsAction(ctx *context.Context) { } err = ctx.Org.Team.RemoveMember(uid) page = "team" + if err != nil { + if models.IsErrLastOrgOwner(err) { + ctx.Flash.Error(ctx.Tr("form.last_org_owner")) + } else { + log.Error("Action(%s): %v", ctx.Params(":action"), err) + ctx.JSON(http.StatusOK, map[string]interface{}{ + "ok": false, + "err": err.Error(), + }) + return + } + } + ctx.JSON(http.StatusOK, + map[string]interface{}{ + "redirect": ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName, + }) + return case "add": if !ctx.Org.IsOwner { ctx.Error(http.StatusNotFound) -- cgit v1.2.3