diff options
author | zeripath <art27@cantab.net> | 2021-08-27 03:57:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-26 22:57:40 -0400 |
commit | e37342db0c102ef12ae70072d9f4bbef89338085 (patch) | |
tree | 50598f0627960e60aec866568a29e3cffa378c5b /routers/web/org | |
parent | 3289aceec2b760e690fe7505d22ff685950cd0e7 (diff) | |
download | gitea-e37342db0c102ef12ae70072d9f4bbef89338085.tar.gz gitea-e37342db0c102ef12ae70072d9f4bbef89338085.zip |
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 <art27@cantab.net>
* avoid for-in
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Revert "avoid for-in"
This reverts commit 2af9a6f9d46ed31b6fc6e3a29e695577dcf09f75.
* Apply suggestions from code review
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'routers/web/org')
-rw-r--r-- | routers/web/org/members.go | 19 | ||||
-rw-r--r-- | routers/web/org/teams.go | 34 |
2 files changed, 47 insertions, 6 deletions
diff --git a/routers/web/org/members.go b/routers/web/org/members.go index 84aaa28f60..ef5a69e157 100644 --- a/routers/web/org/members.go +++ b/routers/web/org/members.go @@ -99,14 +99,18 @@ func MembersAction(ctx *context.Context) { err = org.RemoveMember(uid) if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) - ctx.Redirect(ctx.Org.OrgLink + "/members") + ctx.JSON(http.StatusOK, map[string]interface{}{ + "redirect": ctx.Org.OrgLink + "/members", + }) return } case "leave": err = org.RemoveMember(ctx.User.ID) if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) - ctx.Redirect(ctx.Org.OrgLink + "/members") + ctx.JSON(http.StatusOK, map[string]interface{}{ + "redirect": ctx.Org.OrgLink + "/members", + }) return } } @@ -120,9 +124,12 @@ func MembersAction(ctx *context.Context) { return } - if ctx.Params(":action") != "leave" { - ctx.Redirect(ctx.Org.OrgLink + "/members") - } else { - ctx.Redirect(setting.AppSubURL + "/") + redirect := ctx.Org.OrgLink + "/members" + if ctx.Params(":action") == "leave" { + redirect = setting.AppSubURL + "/" } + + ctx.JSON(http.StatusOK, map[string]interface{}{ + "redirect": redirect, + }) } 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) |