diff options
author | Unknown <joe2010xtmf@163.com> | 2014-06-28 00:40:07 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-06-28 00:40:07 -0400 |
commit | 6e448b07145fbb090e0da6deb97f244c2bfd7ba7 (patch) | |
tree | af17fdea008d56d154c1098d05993475c0fee652 /routers/org/org.go | |
parent | ee9b7f322ff4c4c14952c2f83fb03e90fa583cad (diff) | |
download | gitea-6e448b07145fbb090e0da6deb97f244c2bfd7ba7.tar.gz gitea-6e448b07145fbb090e0da6deb97f244c2bfd7ba7.zip |
Finish delete organization
Diffstat (limited to 'routers/org/org.go')
-rw-r--r-- | routers/org/org.go | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/routers/org/org.go b/routers/org/org.go index c036a8e5dc..7b2c4d7320 100644 --- a/routers/org/org.go +++ b/routers/org/org.go @@ -30,7 +30,6 @@ func Members(ctx *middleware.Context, params martini.Params) { ctx.HTML(200, "org/members") } - func New(ctx *middleware.Context) { ctx.Data["Title"] = "Create An Organization" ctx.HTML(200, NEW) @@ -160,3 +159,47 @@ func SettingsPost(ctx *middleware.Context, params martini.Params, form auth.OrgS ctx.Flash.Success("Organization profile has been successfully updated.") ctx.Redirect("/org/" + org.Name + "/settings") } + +func DeletePost(ctx *middleware.Context, params martini.Params) { + ctx.Data["Title"] = "Settings" + + org, err := models.GetUserByName(params["org"]) + if err != nil { + if err == models.ErrUserNotExist { + ctx.Handle(404, "org.DeletePost(GetUserByName)", err) + } else { + ctx.Handle(500, "org.DeletePost(GetUserByName)", err) + } + return + } + ctx.Data["Org"] = org + + if !models.IsOrganizationOwner(org.Id, ctx.User.Id) { + ctx.Error(403) + return + } + + tmpUser := models.User{ + Passwd: ctx.Query("password"), + Salt: ctx.User.Salt, + } + tmpUser.EncodePasswd() + if tmpUser.Passwd != ctx.User.Passwd { + ctx.Flash.Error("Password is not correct. Make sure you are owner of this account.") + } else { + if err := models.DeleteOrganization(org); err != nil { + switch err { + case models.ErrUserOwnRepos: + ctx.Flash.Error("This organization still have ownership of repository, you have to delete or transfer them first.") + default: + ctx.Handle(500, "org.DeletePost(DeleteOrganization)", err) + return + } + } else { + ctx.Redirect("/") + return + } + } + + ctx.Redirect("/org/" + org.Name + "/settings") +} |