mirror of
https://github.com/go-gitea/gitea.git
synced 2025-06-23 06:28:01 +02:00
Continue working on new admin pages
This commit is contained in:
@ -23,8 +23,6 @@ import (
|
||||
|
||||
const (
|
||||
DASHBOARD base.TplName = "admin/dashboard"
|
||||
REPOS base.TplName = "admin/repos"
|
||||
AUTHS base.TplName = "admin/auths"
|
||||
CONFIG base.TplName = "admin/config"
|
||||
MONITOR_PROCESS base.TplName = "admin/monitor/process"
|
||||
MONITOR_CRON base.TplName = "admin/monitor/cron"
|
||||
@ -156,48 +154,6 @@ func Dashboard(ctx *middleware.Context) {
|
||||
ctx.HTML(200, DASHBOARD)
|
||||
}
|
||||
|
||||
func Repositories(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Repository Management"
|
||||
ctx.Data["PageIsRepos"] = true
|
||||
|
||||
p := com.StrTo(ctx.Query("p")).MustInt()
|
||||
if p < 1 {
|
||||
p = 1
|
||||
}
|
||||
pageNum := 50
|
||||
count := models.CountRepositories()
|
||||
curCount := int64((p-1)*pageNum + pageNum)
|
||||
if curCount > count {
|
||||
p = int(count) / pageNum
|
||||
} else if count > curCount {
|
||||
ctx.Data["NextPageNum"] = p + 1
|
||||
}
|
||||
if p > 1 {
|
||||
ctx.Data["LastPageNum"] = p - 1
|
||||
}
|
||||
|
||||
var err error
|
||||
ctx.Data["Repos"], err = models.GetRepositoriesWithUsers(pageNum, (p-1)*pageNum)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.Repositories", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, REPOS)
|
||||
}
|
||||
|
||||
func Auths(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Auth Sources"
|
||||
ctx.Data["PageIsAuths"] = true
|
||||
|
||||
var err error
|
||||
ctx.Data["Sources"], err = models.GetAuths()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.Auths", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, AUTHS)
|
||||
}
|
||||
|
||||
func Config(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Server Configuration"
|
||||
ctx.Data["PageIsConfig"] = true
|
||||
|
@ -5,8 +5,6 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
"github.com/go-xorm/core"
|
||||
|
||||
@ -19,21 +17,38 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
AUTHS base.TplName = "admin/auth/list"
|
||||
AUTH_NEW base.TplName = "admin/auth/new"
|
||||
AUTH_EDIT base.TplName = "admin/auth/edit"
|
||||
)
|
||||
|
||||
func Authentications(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.authentication")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminAuthentications"] = true
|
||||
|
||||
var err error
|
||||
ctx.Data["Sources"], err = models.GetAuths()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetAuths", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, AUTHS)
|
||||
}
|
||||
|
||||
func NewAuthSource(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "New Authentication"
|
||||
ctx.Data["PageIsAuths"] = true
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminAuthentications"] = true
|
||||
ctx.Data["LoginTypes"] = models.LoginTypes
|
||||
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
||||
ctx.HTML(200, AUTH_NEW)
|
||||
}
|
||||
|
||||
func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
||||
ctx.Data["Title"] = "New Authentication"
|
||||
ctx.Data["PageIsAuths"] = true
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminAuthentications"] = true
|
||||
ctx.Data["LoginTypes"] = models.LoginTypes
|
||||
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
||||
|
||||
@ -79,30 +94,29 @@ func NewAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
||||
}
|
||||
|
||||
if err := models.CreateSource(source); err != nil {
|
||||
ctx.Handle(500, "admin.auths.NewAuth(CreateSource)", err)
|
||||
ctx.Handle(500, "CreateSource", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("%s Authentication created by admin(%s): %s", ctx.Req.RequestURI,
|
||||
ctx.User.LowerName, strings.ToLower(form.AuthName))
|
||||
|
||||
log.Trace("Authentication created by admin(%s): %s", ctx.User.Name, form.AuthName)
|
||||
ctx.Redirect("/admin/auths")
|
||||
}
|
||||
|
||||
func EditAuthSource(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Edit Authentication"
|
||||
ctx.Data["PageIsAuths"] = true
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminAuthentications"] = true
|
||||
ctx.Data["LoginTypes"] = models.LoginTypes
|
||||
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
||||
|
||||
id, err := com.StrTo(ctx.Params(":authid")).Int64()
|
||||
if err != nil {
|
||||
ctx.Handle(404, "admin.auths.EditAuthSource", err)
|
||||
id := com.StrTo(ctx.Params(":authid")).MustInt64()
|
||||
if id == 0 {
|
||||
ctx.Handle(404, "EditAuthSource", nil)
|
||||
return
|
||||
}
|
||||
u, err := models.GetLoginSourceById(id)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.user.EditUser(GetLoginSourceById)", err)
|
||||
ctx.Handle(500, "GetLoginSourceById", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Source"] = u
|
||||
@ -110,7 +124,9 @@ func EditAuthSource(ctx *middleware.Context) {
|
||||
}
|
||||
|
||||
func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
||||
ctx.Data["Title"] = "Edit Authentication"
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminAuthentications"] = true
|
||||
ctx.Data["PageIsAuths"] = true
|
||||
ctx.Data["LoginTypes"] = models.LoginTypes
|
||||
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
||||
@ -158,44 +174,38 @@ func EditAuthSourcePost(ctx *middleware.Context, form auth.AuthenticationForm) {
|
||||
}
|
||||
|
||||
if err := models.UpdateSource(&u); err != nil {
|
||||
ctx.Handle(500, "admin.auths.EditAuth(UpdateSource)", err)
|
||||
ctx.Handle(500, "UpdateSource", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("%s Authentication changed by admin(%s): %s", ctx.Req.RequestURI,
|
||||
ctx.User.LowerName, form.AuthName)
|
||||
|
||||
ctx.Redirect("/admin/auths")
|
||||
log.Trace("Authentication changed by admin(%s): %s", ctx.User.Name, form.AuthName)
|
||||
ctx.Flash.Success(ctx.Tr("admin.auths.update_success"))
|
||||
ctx.Redirect("/admin/auths/" + ctx.Params(":authid"))
|
||||
}
|
||||
|
||||
func DeleteAuthSource(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Delete Authentication"
|
||||
ctx.Data["PageIsAuths"] = true
|
||||
|
||||
id, err := com.StrTo(ctx.Params(":authid")).Int64()
|
||||
if err != nil {
|
||||
ctx.Handle(404, "admin.auths.DeleteAuth", err)
|
||||
id := com.StrTo(ctx.Params(":authid")).MustInt64()
|
||||
if id == 0 {
|
||||
ctx.Handle(404, "DeleteAuthSource", nil)
|
||||
return
|
||||
}
|
||||
|
||||
a, err := models.GetLoginSourceById(id)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.auths.DeleteAuth(GetLoginSourceById)", err)
|
||||
ctx.Handle(500, "GetLoginSourceById", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = models.DelLoginSource(a); err != nil {
|
||||
switch err {
|
||||
case models.ErrAuthenticationUserUsed:
|
||||
ctx.Flash.Error("This authentication still has used by some users, you should move them and then delete again.")
|
||||
ctx.Flash.Error("form.still_own_user")
|
||||
ctx.Redirect("/admin/auths/" + ctx.Params(":authid"))
|
||||
default:
|
||||
ctx.Handle(500, "admin.auths.DeleteAuth(DelLoginSource)", err)
|
||||
ctx.Handle(500, "DelLoginSource", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Trace("%s Authentication deleted by admin(%s): %s", ctx.Req.RequestURI,
|
||||
ctx.User.LowerName, ctx.User.LowerName)
|
||||
|
||||
log.Trace("Authentication deleted by admin(%s): %s", ctx.User.Name, a.Name)
|
||||
ctx.Redirect("/admin/auths")
|
||||
}
|
32
routers/admin/orgs.go
Normal file
32
routers/admin/orgs.go
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
ORGS base.TplName = "admin/org/list"
|
||||
)
|
||||
|
||||
func Organizations(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.orgs")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminOrganizations"] = true
|
||||
|
||||
pageNum := 50
|
||||
p := pagination(ctx, models.CountOrganizations(), pageNum)
|
||||
|
||||
var err error
|
||||
ctx.Data["Orgs"], err = models.GetOrganizations(pageNum, (p-1)*pageNum)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetUsers", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, ORGS)
|
||||
}
|
32
routers/admin/repos.go
Normal file
32
routers/admin/repos.go
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
const (
|
||||
REPOS base.TplName = "admin/repo/list"
|
||||
)
|
||||
|
||||
func Repositories(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.repositories")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminRepositories"] = true
|
||||
|
||||
pageNum := 50
|
||||
p := pagination(ctx, models.CountRepositories(), pageNum)
|
||||
|
||||
var err error
|
||||
ctx.Data["Repos"], err = models.GetRepositoriesWithUsers(pageNum, (p-1)*pageNum)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetRepositoriesWithUsers", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, REPOS)
|
||||
}
|
@ -22,17 +22,11 @@ const (
|
||||
USER_EDIT base.TplName = "admin/user/edit"
|
||||
)
|
||||
|
||||
func Users(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.users")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminUsers"] = true
|
||||
|
||||
func pagination(ctx *middleware.Context, count int64, pageNum int) int {
|
||||
p := com.StrTo(ctx.Query("p")).MustInt()
|
||||
if p < 1 {
|
||||
p = 1
|
||||
}
|
||||
pageNum := 50
|
||||
count := models.CountUsers()
|
||||
curCount := int64((p-1)*pageNum + pageNum)
|
||||
if curCount > count {
|
||||
p = int(count) / pageNum
|
||||
@ -42,11 +36,21 @@ func Users(ctx *middleware.Context) {
|
||||
if p > 1 {
|
||||
ctx.Data["LastPageNum"] = p - 1
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func Users(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.users")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminUsers"] = true
|
||||
|
||||
pageNum := 50
|
||||
p := pagination(ctx, models.CountUsers(), pageNum)
|
||||
|
||||
var err error
|
||||
ctx.Data["Users"], err = models.GetUsers(pageNum, (p-1)*pageNum)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "admin.Users(GetUsers)", err)
|
||||
ctx.Handle(500, "GetUsers", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, USERS)
|
||||
|
Reference in New Issue
Block a user