diff options
author | Rob Richards <goodeveningthisisrobrichards@gmail.com> | 2017-03-23 11:57:43 -0500 |
---|---|---|
committer | 无闻 <u@gogs.io> | 2017-03-23 12:57:43 -0400 |
commit | 902372067cad9cfe7360473d1b985217a308a949 (patch) | |
tree | fd8ea405312907007e1b8f25e029672e0127c052 | |
parent | 7adaf8f8122f1f6f28c28abbd652bec1490523b0 (diff) |
user/settings: add repositories panel (#4312)
* Add Repositories panel to user settings
issue #4277
* modified personal repo settings format
-rw-r--r-- | cmd/web.go | 5 | ||||
-rw-r--r-- | routers/user/setting.go | 63 | ||||
-rw-r--r-- | templates/user/settings/navbar.tmpl | 3 | ||||
-rw-r--r-- | templates/user/settings/repos.tmpl | 49 |
4 files changed, 119 insertions, 1 deletions
@@ -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 diff --git a/routers/user/setting.go b/routers/user/setting.go index c2c273c2..70e00a3d 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -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 diff --git a/templates/user/settings/navbar.tmpl b/templates/user/settings/navbar.tmpl index 4293fed0..a7744b5a 100644 --- a/templates/user/settings/navbar.tmpl +++ b/templates/user/settings/navbar.tmpl @@ -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> diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl new file mode 100644 index 00000000..e19dbfb4 --- /dev/null +++ b/templates/user/settings/repos.tmpl @@ -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" .}} |