mirror of https://github.com/gogs/gogs.git
user/settings: add repositories panel (#4312)
* Add Repositories panel to user settings issue #4277 * modified personal repo settings formatpull/4343/head
parent
7adaf8f812
commit
902372067c
|
@ -255,7 +255,10 @@ func runWeb(ctx *cli.Context) error {
|
|||
m.Get("", user.SettingsOrganizations)
|
||||
m.Post("/leave", user.SettingsLeaveOrganization)
|
||||
})
|
||||
|
||||
m.Group("/repos", func() {
|
||||
m.Get("", user.SettingsRepos)
|
||||
m.Post("/delete", user.SettingsDeleteRepo)
|
||||
})
|
||||
m.Route("/delete", "GET,POST", user.SettingsDelete)
|
||||
}, reqSignIn, func(ctx *context.Context) {
|
||||
ctx.Data["PageIsUserSettings"] = true
|
||||
|
|
|
@ -7,9 +7,11 @@ package user
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
"github.com/Unknwon/paginater"
|
||||
log "gopkg.in/clog.v1"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
|
@ -30,6 +32,7 @@ const (
|
|||
SETTINGS_SOCIAL base.TplName = "user/settings/social"
|
||||
SETTINGS_APPLICATIONS base.TplName = "user/settings/applications"
|
||||
SETTINGS_ORGANIZATIONS base.TplName = "user/settings/organizations"
|
||||
SETTINGS_REPOS base.TplName = "user/settings/repos"
|
||||
SETTINGS_DELETE base.TplName = "user/settings/delete"
|
||||
NOTIFICATION base.TplName = "user/notification"
|
||||
SECURITY base.TplName = "user/security"
|
||||
|
@ -450,6 +453,66 @@ func SettingsLeaveOrganization(ctx *context.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
func SettingsRepos(ctx *context.Context) {
|
||||
|
||||
ctx.Data["Title"] = ctx.Tr("admin.repositories")
|
||||
ctx.Data["PageIsSettingsRepositories"] = true
|
||||
|
||||
keyword := ctx.Query("q")
|
||||
page := ctx.QueryInt("page")
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
|
||||
Keyword: keyword,
|
||||
UserID: ctx.User.ID,
|
||||
OrderBy: "lower_name",
|
||||
Page: page,
|
||||
PageSize: setting.UI.Admin.RepoPagingNum,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Handle(500, "SearchRepositoryByName", err)
|
||||
return
|
||||
}
|
||||
if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
|
||||
ctx.Handle(500, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Total"] = count
|
||||
ctx.Data["Page"] = paginater.New(int(count), setting.UI.Admin.RepoPagingNum, page, 5)
|
||||
ctx.Data["Repos"] = repos
|
||||
ctx.HTML(200, SETTINGS_REPOS)
|
||||
}
|
||||
|
||||
func SettingsDeleteRepo(ctx *context.Context) {
|
||||
repo, err := models.GetRepositoryByID(ctx.QueryInt64("id"))
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetRepositoryByID", err)
|
||||
return
|
||||
}
|
||||
// make sure the user owns the repository or is an admin before allowing them to delete it
|
||||
if repo.OwnerID == ctx.User.ID || ctx.User.IsAdmin {
|
||||
if err := models.DeleteRepository(repo.MustOwner().ID, repo.ID); err != nil {
|
||||
ctx.Handle(500, "DeleteRepository", err)
|
||||
return
|
||||
}
|
||||
log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
"redirect": setting.AppSubUrl + "/user/settings/repos?page=" + ctx.Query("page") + "&q=" + url.QueryEscape(ctx.Query("q")),
|
||||
})
|
||||
} else {
|
||||
// logged in user doesn't have rights to delete this repository
|
||||
err := errors.New("You do not have rights to delete repository '" + repo.FullName() + "'")
|
||||
ctx.Handle(403, "SettingsDeleteRepo", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func SettingsDelete(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsDelete"] = true
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
<a class="{{if .PageIsSettingsOrganizations}}active{{end}} item" href="{{AppSubUrl}}/user/settings/organizations">
|
||||
{{.i18n.Tr "settings.orgs"}}
|
||||
</a>
|
||||
<a class="{{if .PageIsSettingsRepositories}}active{{end}} item" href="{{AppSubUrl}}/user/settings/repos">
|
||||
{{.i18n.Tr "admin.repositories"}}
|
||||
</a>
|
||||
<a class="{{if .PageIsSettingsDelete}}active{{end}} item" href="{{AppSubUrl}}/user/settings/delete">
|
||||
{{.i18n.Tr "settings.delete"}}
|
||||
</a>
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
{{template "base/head" .}}
|
||||
<div class="user">
|
||||
<div class="ui container">
|
||||
<div class="ui grid">
|
||||
{{template "user/settings/navbar" .}}
|
||||
<div class="twelve wide column content">
|
||||
{{template "base/alert" .}}
|
||||
<h4 class="ui top attached header">
|
||||
{{.i18n.Tr "admin.repositories"}} ({{.i18n.Tr "admin.total" .Total}})
|
||||
</h4>
|
||||
<div class="ui attached segment">
|
||||
{{template "admin/base/search" .}}
|
||||
</div>
|
||||
|
||||
{{range .Repos}}
|
||||
<div class="ui attached segment repos">
|
||||
<div class="ui list">
|
||||
<div class="item">
|
||||
<a href="{{AppSubUrl}}/{{.Owner.Name}}/{{.Name}}">
|
||||
<span class="octicon octicon-repo text light grey"></span>
|
||||
{{.Owner.Name}}/{{.Name}}
|
||||
</a>
|
||||
<span class="ui text light grey">{{.Size | FileSize}}</span>
|
||||
{{if .IsPrivate}}
|
||||
<div class="right floated content">
|
||||
<a class="ui red tiny button inline text-thin delete-button" href="" data-url="{{$.Link}}/leave?page={{$.Page.Current}}" data-id="{{.ID}}">{{$.i18n.Tr "settings.leave"}}</a>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{template "admin/base/page" .}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ui small basic leave modal">
|
||||
<div class="ui icon header">
|
||||
{{.i18n.Tr "teams.leave"}}
|
||||
</div>
|
||||
<div class="content">
|
||||
<p>{{.i18n.Tr "teams.leave_desc"}}</p>
|
||||
</div>
|
||||
{{template "base/delete_modal_actions" .}}
|
||||
</div>
|
||||
{{template "base/footer" .}}
|
Loading…
Reference in New Issue