diff options
author | evolvedlight <steve@evolvedlight.co.uk> | 2014-10-13 20:30:31 +0100 |
---|---|---|
committer | evolvedlight <steve@evolvedlight.co.uk> | 2014-10-13 20:30:31 +0100 |
commit | 8d2a6fc484b540819e211d52b8d54e97269f0918 (patch) | |
tree | e5bfe7d3937bb2d18ba2fb50ea72514bd5bb4e13 /routers | |
parent | 29ac3980ffdb5faa525d77fddc109c9023ebe257 (diff) | |
parent | 89bd994c836ecc9b6ceb80849f470521e1b15917 (diff) | |
download | gitea-8d2a6fc484b540819e211d52b8d54e97269f0918.tar.gz gitea-8d2a6fc484b540819e211d52b8d54e97269f0918.zip |
Merge remote-tracking branch 'upstream/dev'
Conflicts:
models/repo.go
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/notice.go | 46 | ||||
-rw-r--r-- | routers/admin/orgs.go | 2 | ||||
-rw-r--r-- | routers/admin/users.go | 10 | ||||
-rw-r--r-- | routers/org/setting.go | 2 | ||||
-rw-r--r-- | routers/org/teams.go | 5 | ||||
-rw-r--r-- | routers/repo/commit.go | 6 | ||||
-rw-r--r-- | routers/repo/setting.go | 77 | ||||
-rw-r--r-- | routers/repo/view.go | 2 | ||||
-rw-r--r-- | routers/user/setting.go | 10 |
9 files changed, 142 insertions, 18 deletions
diff --git a/routers/admin/notice.go b/routers/admin/notice.go new file mode 100644 index 0000000000..b431946366 --- /dev/null +++ b/routers/admin/notice.go @@ -0,0 +1,46 @@ +// 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/Unknwon/com" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/middleware" +) + +const ( + NOTICES base.TplName = "admin/notice" +) + +func Notices(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("admin.notices") + ctx.Data["PageIsAdmin"] = true + ctx.Data["PageIsAdminNotices"] = true + + pageNum := 50 + p := pagination(ctx, models.CountNotices(), pageNum) + + notices, err := models.GetNotices(pageNum, (p-1)*pageNum) + if err != nil { + ctx.Handle(500, "GetNotices", err) + return + } + ctx.Data["Notices"] = notices + ctx.HTML(200, NOTICES) +} + +func DeleteNotice(ctx *middleware.Context) { + id := com.StrTo(ctx.Params(":id")).MustInt64() + if err := models.DeleteNotice(id); err != nil { + ctx.Handle(500, "DeleteNotice", err) + return + } + log.Trace("System notice deleted by admin(%s): %d", ctx.User.Name, id) + ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) + ctx.Redirect("/admin/notices") +} diff --git a/routers/admin/orgs.go b/routers/admin/orgs.go index e813e47420..54d7af5cb3 100644 --- a/routers/admin/orgs.go +++ b/routers/admin/orgs.go @@ -25,7 +25,7 @@ func Organizations(ctx *middleware.Context) { var err error ctx.Data["Orgs"], err = models.GetOrganizations(pageNum, (p-1)*pageNum) if err != nil { - ctx.Handle(500, "GetUsers", err) + ctx.Handle(500, "GetOrganizations", err) return } ctx.HTML(200, ORGS) diff --git a/routers/admin/users.go b/routers/admin/users.go index fc3b0cbce0..c9adf2d856 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -24,14 +24,14 @@ const ( ) func pagination(ctx *middleware.Context, count int64, pageNum int) int { - p := com.StrTo(ctx.Query("p")).MustInt() + p := ctx.QueryInt("p") if p < 1 { p = 1 } curCount := int64((p-1)*pageNum + pageNum) - if curCount > count { + if curCount >= count { p = int(count) / pageNum - } else if count > curCount { + } else { ctx.Data["NextPageNum"] = p + 1 } if p > 1 { @@ -48,12 +48,12 @@ func Users(ctx *middleware.Context) { pageNum := 50 p := pagination(ctx, models.CountUsers(), pageNum) - var err error - ctx.Data["Users"], err = models.GetUsers(pageNum, (p-1)*pageNum) + users, err := models.GetUsers(pageNum, (p-1)*pageNum) if err != nil { ctx.Handle(500, "GetUsers", err) return } + ctx.Data["Users"] = users ctx.HTML(200, USERS) } diff --git a/routers/org/setting.go b/routers/org/setting.go index 0522f99803..41ec4a2141 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -92,7 +92,7 @@ func SettingsDelete(ctx *middleware.Context) { ctx.Handle(500, "DeleteOrganization", err) } } else { - log.Trace("Organization deleted: %s", ctx.User.Name) + log.Trace("Organization deleted: %s", org.Name) ctx.Redirect(setting.AppSubUrl + "/") } return diff --git a/routers/org/teams.go b/routers/org/teams.go index 9aa8e50214..77a7b6e13c 100644 --- a/routers/org/teams.go +++ b/routers/org/teams.go @@ -124,6 +124,11 @@ func TeamsRepoAction(ctx *middleware.Context) { var repo *models.Repository repo, err = models.GetRepositoryByName(ctx.Org.Organization.Id, repoName) if err != nil { + if err == models.ErrRepoNotExist { + ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo")) + ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories") + return + } ctx.Handle(500, "GetRepositoryByName", err) return } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 9791cc5511..b2c2e0f9ac 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -159,6 +159,7 @@ func Diff(ctx *middleware.Context) { ctx.Data["IsImageFile"] = isImageFile ctx.Data["Title"] = commit.Summary() + " ยท " + base.ShortSha(commitId) ctx.Data["Commit"] = commit + ctx.Data["Author"] = models.ValidateCommitWithEmail(commit) ctx.Data["Diff"] = diff ctx.Data["Parents"] = parents ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 @@ -212,6 +213,7 @@ func CompareDiff(ctx *middleware.Context) { ctx.Handle(500, "CommitsBeforeUntil", err) return } + commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["CommitCount"] = commits.Len() @@ -274,13 +276,15 @@ func FileHistory(ctx *middleware.Context) { nextPage = 0 } - ctx.Data["Commits"], err = ctx.Repo.GitRepo.CommitsByFileAndRange( + commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange( branchName, fileName, page) if err != nil { ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err) return } + commits = models.ValidateCommitsWithEmails(commits) + ctx.Data["Commits"] = commits ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["FileName"] = fileName diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 48089787fe..971c5bef2a 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -16,6 +16,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" @@ -26,6 +27,8 @@ const ( SETTINGS_OPTIONS base.TplName = "repo/settings/options" COLLABORATION base.TplName = "repo/settings/collaboration" HOOKS base.TplName = "repo/settings/hooks" + GITHOOKS base.TplName = "repo/settings/githooks" + GITHOOK_EDIT base.TplName = "repo/settings/githook_edit" HOOK_NEW base.TplName = "repo/settings/hook_new" ORG_HOOK_NEW base.TplName = "org/settings/hook_new" ) @@ -193,9 +196,16 @@ func SettingsCollaboration(ctx *middleware.Context) { return } + // Check if user is organization member. + if ctx.Repo.Owner.IsOrganization() && ctx.Repo.Owner.IsOrgMember(u.Id) { + ctx.Flash.Info(ctx.Tr("repo.settings.user_is_org_member")) + ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration") + return + } + if err = models.AddAccess(&models.Access{UserName: name, RepoName: repoLink, Mode: models.WRITABLE}); err != nil { - ctx.Handle(500, "AddAccess2", err) + ctx.Handle(500, "AddAccess", err) return } @@ -244,16 +254,20 @@ func SettingsCollaboration(ctx *middleware.Context) { return } - us := make([]*models.User, len(names)) - for i, name := range names { - us[i], err = models.GetUserByName(name) + collaborators := make([]*models.User, 0, len(names)) + for _, name := range names { + u, err := models.GetUserByName(name) if err != nil { ctx.Handle(500, "GetUserByName", err) return } + // Does not show organization members. + if ctx.Repo.Owner.IsOrganization() && ctx.Repo.Owner.IsOrgMember(u.Id) { + continue + } + collaborators = append(collaborators, u) } - - ctx.Data["Collaborators"] = us + ctx.Data["Collaborators"] = collaborators ctx.HTML(200, COLLABORATION) } @@ -591,3 +605,54 @@ func getOrgRepoCtx(ctx *middleware.Context) (*OrgRepoCtx, error) { return &OrgRepoCtx{}, errors.New("Unable to set OrgRepo context") } } + +func GitHooks(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("repo.settings") + ctx.Data["PageIsSettingsGitHooks"] = true + + hooks, err := ctx.Repo.GitRepo.Hooks() + if err != nil { + ctx.Handle(500, "Hooks", err) + return + } + ctx.Data["Hooks"] = hooks + + ctx.HTML(200, GITHOOKS) +} + +func GitHooksEdit(ctx *middleware.Context) { + ctx.Data["Title"] = ctx.Tr("repo.settings") + ctx.Data["PageIsSettingsGitHooks"] = true + + name := ctx.Params(":name") + hook, err := ctx.Repo.GitRepo.GetHook(name) + if err != nil { + if err == git.ErrNotValidHook { + ctx.Handle(404, "GetHook", err) + } else { + ctx.Handle(500, "GetHook", err) + } + return + } + ctx.Data["Hook"] = hook + ctx.HTML(200, GITHOOK_EDIT) +} + +func GitHooksEditPost(ctx *middleware.Context) { + name := ctx.Params(":name") + hook, err := ctx.Repo.GitRepo.GetHook(name) + if err != nil { + if err == git.ErrNotValidHook { + ctx.Handle(404, "GetHook", err) + } else { + ctx.Handle(500, "GetHook", err) + } + return + } + hook.Content = ctx.Query("content") + if err = hook.Update(); err != nil { + ctx.Handle(500, "hook.Update", err) + return + } + ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks/git") +} diff --git a/routers/repo/view.go b/routers/repo/view.go index ba76a6adae..26fa0b4c76 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -166,7 +166,7 @@ func Home(ctx *middleware.Context) { } if readmeFile != nil { - ctx.Data["ReadmeInHome"] = true + ctx.Data["ReadmeInList"] = true ctx.Data["ReadmeExist"] = true if dataRc, err := readmeFile.Data(); err != nil { ctx.Handle(404, "repo.SinglereadmeFile.LookupBlob", err) diff --git a/routers/user/setting.go b/routers/user/setting.go index 8f778acd0d..778f27ac50 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -177,9 +177,13 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { cleanContent := strings.Replace(form.Content, "\n", "", -1) if ok, err := models.CheckPublicKeyString(cleanContent); !ok { - ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) - ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") - return + if err == models.ErrKeyUnableVerify { + ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key")) + } else { + ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) + ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") + return + } } k := &models.PublicKey{ |