mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-04 14:46:57 -05:00
Add admin delete user
This commit is contained in:
parent
19104f156f
commit
76cd448e79
2
gogs.go
2
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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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>
|
||||
|
1
web.go
1
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user