summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-22 06:20:00 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-22 06:20:00 -0400
commit76cd448e7925997b60a54e8d9431ffd0826cc24e (patch)
tree3c99d9a07e579559ee0ec49bcb355ce893b40f5f
parent19104f156fd91b7d2cdc84b86dd27e6dcfa11416 (diff)
downloadgitea-76cd448e7925997b60a54e8d9431ffd0826cc24e.tar.gz
gitea-76cd448e7925997b60a54e8d9431ffd0826cc24e.zip
Add admin delete user
-rw-r--r--gogs.go2
-rw-r--r--models/action.go6
-rw-r--r--routers/admin/user.go35
-rw-r--r--templates/admin/users/edit.tmpl2
-rw-r--r--web.go1
5 files changed, 44 insertions, 2 deletions
diff --git a/gogs.go b/gogs.go
index 41df79280a..8ec4fd42f1 100644
--- a/gogs.go
+++ b/gogs.go
@@ -20,7 +20,7 @@ import (
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true
-const APP_VER = "0.1.5.0321"
+const APP_VER = "0.1.5.0322"
func init() {
base.AppVer = APP_VER
diff --git a/models/action.go b/models/action.go
index 89751b9779..12122ae240 100644
--- a/models/action.go
+++ b/models/action.go
@@ -7,6 +7,8 @@ package models
import (
"encoding/json"
"time"
+
+ "github.com/gogits/gogs/modules/log"
)
// Operation types of user action.
@@ -89,6 +91,8 @@ func CommitRepoAction(userId int64, userName string,
if err = UpdateRepository(repo); err != nil {
return err
}
+
+ log.Trace("action.CommitRepoAction: %d/%s", userId, repo.LowerName)
return nil
}
@@ -102,6 +106,8 @@ func NewRepoAction(user *User, repo *Repository) error {
RepoId: repo.Id,
RepoName: repo.Name,
})
+
+ log.Trace("action.NewRepoAction: %s/%s", user.LowerName, repo.LowerName)
return err
}
diff --git a/routers/admin/user.go b/routers/admin/user.go
index d6f8523218..fa27d11664 100644
--- a/routers/admin/user.go
+++ b/routers/admin/user.go
@@ -107,3 +107,38 @@ func EditUser(ctx *middleware.Context, params martini.Params, form auth.AdminEdi
log.Trace("%s User profile updated by admin(%s): %s", ctx.Req.RequestURI,
ctx.User.LowerName, ctx.User.LowerName)
}
+
+func DeleteUser(ctx *middleware.Context, params martini.Params) {
+ ctx.Data["Title"] = "Edit Account"
+ ctx.Data["PageIsUsers"] = true
+
+ uid, err := base.StrTo(params["userid"]).Int()
+ if err != nil {
+ ctx.Handle(200, "admin.user.EditUser", err)
+ return
+ }
+
+ u, err := models.GetUserById(int64(uid))
+ if err != nil {
+ ctx.Handle(200, "admin.user.EditUser", err)
+ return
+ }
+
+ if err = models.DeleteUser(u); err != nil {
+ ctx.Data["HasError"] = true
+ switch err {
+ case models.ErrUserOwnRepos:
+ ctx.Data["ErrorMsg"] = "This account still has ownership of repository, owner has to delete or transfer them first."
+ ctx.Data["User"] = u
+ ctx.HTML(200, "admin/users/edit")
+ default:
+ ctx.Handle(200, "admin.user.DeleteUser", err)
+ }
+ return
+ }
+
+ log.Trace("%s User deleted by admin(%s): %s", ctx.Req.RequestURI,
+ ctx.User.LowerName, ctx.User.LowerName)
+
+ ctx.Redirect("/admin/users", 302)
+}
diff --git a/templates/admin/users/edit.tmpl b/templates/admin/users/edit.tmpl
index 415bcedc92..2a9882423a 100644
--- a/templates/admin/users/edit.tmpl
+++ b/templates/admin/users/edit.tmpl
@@ -71,7 +71,7 @@
<div class="form-group">
<div class="col-md-offset-3 col-md-6">
<button type="submit" class="btn btn-lg btn-primary btn-block">Update account profile</button>
- <!-- <a type="button" href="/admin/users/{{.User.Id}}/delete" class="btn btn-lg btn-danger btn-block">Delete this account</a> -->
+ <a type="button" href="/admin/users/{{.User.Id}}/delete" class="btn btn-lg btn-danger btn-block">Delete this account</a>
</div>
</div>
</form>
diff --git a/web.go b/web.go
index bb316a6724..595b8f74ed 100644
--- a/web.go
+++ b/web.go
@@ -119,6 +119,7 @@ func runWeb(*cli.Context) {
m.Get("/admin/users", reqSignIn, adminReq, admin.Users)
m.Any("/admin/users/new", reqSignIn, adminReq, binding.BindIgnErr(auth.RegisterForm{}), admin.NewUser)
m.Any("/admin/users/:userid", reqSignIn, adminReq, binding.BindIgnErr(auth.AdminEditUserForm{}), admin.EditUser)
+ m.Any("/admin/users/:userid/delete", reqSignIn, adminReq, admin.DeleteUser)
m.Get("/admin/repos", reqSignIn, adminReq, admin.Repositories)
m.Get("/admin/config", reqSignIn, adminReq, admin.Config)