2014-08-29 20:50:43 +08:00
|
|
|
package admin
|
|
|
|
|
|
|
|
|
|
import (
|
2019-10-23 23:03:17 -07:00
|
|
|
"github.com/unknwon/paginater"
|
2020-02-20 02:25:02 +08:00
|
|
|
log "unknwon.dev/clog/v2"
|
2017-02-09 19:29:59 -05:00
|
|
|
|
2020-02-22 09:05:26 +08:00
|
|
|
"gogs.io/gogs/internal/conf"
|
2019-10-24 01:51:46 -07:00
|
|
|
"gogs.io/gogs/internal/context"
|
2024-02-18 19:39:41 -05:00
|
|
|
"gogs.io/gogs/internal/database"
|
2014-08-29 20:50:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2017-04-05 09:17:21 -04:00
|
|
|
REPOS = "admin/repo/list"
|
2014-08-29 20:50:43 +08:00
|
|
|
)
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func Repos(c *context.Context) {
|
|
|
|
|
c.Data["Title"] = c.Tr("admin.repositories")
|
|
|
|
|
c.Data["PageIsAdmin"] = true
|
|
|
|
|
c.Data["PageIsAdminRepositories"] = true
|
2014-08-29 20:50:43 +08:00
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
page := c.QueryInt("page")
|
2017-03-17 19:17:40 -04:00
|
|
|
if page <= 0 {
|
|
|
|
|
page = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (
|
2024-02-18 19:39:41 -05:00
|
|
|
repos []*database.Repository
|
2017-03-17 19:17:40 -04:00
|
|
|
count int64
|
|
|
|
|
err error
|
|
|
|
|
)
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
keyword := c.Query("q")
|
2022-03-06 16:33:45 +08:00
|
|
|
if keyword == "" {
|
2024-02-18 19:39:41 -05:00
|
|
|
repos, err = database.Repositories(page, conf.UI.Admin.RepoPagingNum)
|
2017-03-17 19:17:40 -04:00
|
|
|
if err != nil {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "list repositories")
|
2017-03-17 19:17:40 -04:00
|
|
|
return
|
|
|
|
|
}
|
2024-02-18 19:39:41 -05:00
|
|
|
count = database.CountRepositories(true)
|
2017-03-17 19:17:40 -04:00
|
|
|
} else {
|
2024-02-18 19:39:41 -05:00
|
|
|
repos, count, err = database.SearchRepositoryByName(&database.SearchRepoOptions{
|
2017-03-17 19:17:40 -04:00
|
|
|
Keyword: keyword,
|
|
|
|
|
OrderBy: "id ASC",
|
|
|
|
|
Private: true,
|
|
|
|
|
Page: page,
|
2020-02-22 09:05:26 +08:00
|
|
|
PageSize: conf.UI.Admin.RepoPagingNum,
|
2017-03-17 19:17:40 -04:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "search repository by name")
|
2017-03-17 19:17:40 -04:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Data["Keyword"] = keyword
|
|
|
|
|
c.Data["Total"] = count
|
2020-02-22 09:05:26 +08:00
|
|
|
c.Data["Page"] = paginater.New(int(count), conf.UI.Admin.RepoPagingNum, page, 5)
|
2017-03-17 19:17:40 -04:00
|
|
|
|
2024-02-18 19:39:41 -05:00
|
|
|
if err = database.RepositoryList(repos).LoadAttributes(); err != nil {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "load attributes")
|
2017-03-17 19:17:40 -04:00
|
|
|
return
|
|
|
|
|
}
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Data["Repos"] = repos
|
2017-03-17 19:17:40 -04:00
|
|
|
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Success(REPOS)
|
2014-08-29 20:50:43 +08:00
|
|
|
}
|
2015-12-05 17:39:29 -05:00
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func DeleteRepo(c *context.Context) {
|
2024-02-18 19:39:41 -05:00
|
|
|
repo, err := database.GetRepositoryByID(c.QueryInt64("id"))
|
2015-12-05 17:39:29 -05:00
|
|
|
if err != nil {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "get repository by ID")
|
2015-12-05 17:39:29 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-18 19:39:41 -05:00
|
|
|
if err := database.DeleteRepository(repo.MustOwner().ID, repo.ID); err != nil {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "delete repository")
|
2015-12-05 17:39:29 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Flash.Success(c.Tr("repo.settings.deletion_success"))
|
2023-02-02 21:25:25 +08:00
|
|
|
c.JSONSuccess(map[string]any{
|
2020-02-22 09:05:26 +08:00
|
|
|
"redirect": conf.Server.Subpath + "/admin/repos?page=" + c.Query("page"),
|
2015-12-05 17:39:29 -05:00
|
|
|
})
|
|
|
|
|
}
|