From 09d170ac05531555461da1e5aca9d17d18269f23 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 19 Jan 2019 13:26:34 +0100 Subject: [PATCH 01/46] fix merge conflicts --- models/issue.go | 4 ++++ models/migrations/v79.go | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 models/migrations/v79.go diff --git a/models/issue.go b/models/issue.go index baca512ab0d0f..a2ae1dc81ae75 100644 --- a/models/issue.go +++ b/models/issue.go @@ -57,6 +57,10 @@ type Issue struct { Reactions ReactionList `xorm:"-"` TotalTrackedTime int64 `xorm:"-"` Assignees []*User `xorm:"-"` + + // IsLocked limits commenting abilities to users on an issue + // with write access + IsLocked bool `xorm:"NOT NULL DEFAULT false"` } var ( diff --git a/models/migrations/v79.go b/models/migrations/v79.go new file mode 100644 index 0000000000000..f93abda49de48 --- /dev/null +++ b/models/migrations/v79.go @@ -0,0 +1,19 @@ +// Copyright 2019 The Gitea 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 migrations + +import ( + "github.com/go-xorm/xorm" +) + +func addIsLockedToIssues(x *xorm.Engine) error { + // Issue see models/issue.go + type Issue struct { + ID int64 `xorm:"pk autoincr"` + IsLocked bool `xorm:"NOT NULL DEFAULT false"` + } + + return x.Sync2(new(Issue)) +} From 59b2c1ff8aa78f95af632352b4b192b85403918e Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 11 Oct 2018 14:33:08 +0100 Subject: [PATCH 02/46] initial implementation of issue locking --- models/issue_comment.go | 4 +++ models/issue_lock.go | 23 +++++++++++++++ options/locale/locale_en-US.ini | 2 ++ routers/repo/issue_lock.go | 29 +++++++++++++++++++ routers/routes/routes.go | 2 ++ .../repo/issue/view_content/sidebar.tmpl | 20 +++++++++++++ 6 files changed, 80 insertions(+) create mode 100644 models/issue_lock.go create mode 100644 routers/repo/issue_lock.go diff --git a/models/issue_comment.go b/models/issue_comment.go index 6c87650a3c243..91da7fb3bb4cf 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -80,6 +80,10 @@ const ( CommentTypeCode // Reviews a pull request by giving general feedback CommentTypeReview + // Lock an issue, giving only collaborators access + CommentTypeLock + // Unlocks a previously locked issue + CommentTypeUnlock ) // CommentTag defines comment tag type diff --git a/models/issue_lock.go b/models/issue_lock.go new file mode 100644 index 0000000000000..c871aeca0a65c --- /dev/null +++ b/models/issue_lock.go @@ -0,0 +1,23 @@ +// Copyright 2018 The Gitea 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 models + +// LockIssue locks an issue. This would limit commenting abilities to +// users with write access to the repo +func LockIssue(user *User, issue *Issue) error { + issue.IsLocked = true + + if err := UpdateIssueCols(issue, "is_locked"); err != nil { + return err + } + + _, err := CreateComment(&CreateCommentOptions{ + Doer: user, + Issue: issue, + Repo: issue.Repo, + Type: CommentTypeLock, + }) + return err +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 151629ea6d0bd..a148f65e5b5ee 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -771,6 +771,8 @@ issues.attachment.open_tab = `Click to see "%s" in a new tab` issues.attachment.download = `Click to download "%s"` issues.subscribe = Subscribe issues.unsubscribe = Unsubscribe +issues.lock = Lock conversation +issues.unlock = Unlock conversation issues.tracker = Time Tracker issues.start_tracking_short = Start issues.start_tracking = Start Time Tracking diff --git a/routers/repo/issue_lock.go b/routers/repo/issue_lock.go new file mode 100644 index 0000000000000..9191b6d69f490 --- /dev/null +++ b/routers/repo/issue_lock.go @@ -0,0 +1,29 @@ +// Copyright 2018 The Gitea 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 repo + +import ( + "net/http" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/context" +) + +// LockIssue locks an issue. This would limit commenting abilities to +// users with write access to the repo. +func LockIssue(c *context.Context) { + issue := GetActionIssue(c) + if c.Written() { + return + } + + if err := models.LockIssue(c.User, issue); err != nil { + c.ServerError("LockIssue", err) + return + } + + url := issue.HTMLURL() + c.Redirect(url, http.StatusSeeOther) +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index afbb31d780281..62fe23ef1266a 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -557,6 +557,8 @@ func RegisterRoutes(m *macaron.Macaron) { }) }) m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction) + + m.Post("/lock", repo.LockIssue) }) m.Post("/labels", reqRepoIssuesOrPullsWriter, repo.UpdateIssueLabel) diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 8d5df5d748c82..c19541526d804 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -335,6 +335,26 @@ {{end}} + +
+
+
+
+ + {{$.CsrfTokenHtml}} + +
+
+
+ {{if .CanCreateIssueDependencies}} From 8b6afb312ea87f1db36657760dbc4a0f2050d089 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 11 Oct 2018 14:42:43 +0100 Subject: [PATCH 03/46] an issue cannot be locked twice --- options/locale/locale_en-US.ini | 1 + routers/repo/issue_lock.go | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a148f65e5b5ee..a5b6bf9eb6877 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -773,6 +773,7 @@ issues.subscribe = Subscribe issues.unsubscribe = Unsubscribe issues.lock = Lock conversation issues.unlock = Unlock conversation +issues.lock_duplicate = "An issue cannot be locked twice" issues.tracker = Time Tracker issues.start_tracking_short = Start issues.start_tracking = Start Time Tracking diff --git a/routers/repo/issue_lock.go b/routers/repo/issue_lock.go index 9191b6d69f490..7a6e39cd76d2f 100644 --- a/routers/repo/issue_lock.go +++ b/routers/repo/issue_lock.go @@ -13,17 +13,23 @@ import ( // LockIssue locks an issue. This would limit commenting abilities to // users with write access to the repo. -func LockIssue(c *context.Context) { - issue := GetActionIssue(c) - if c.Written() { +func LockIssue(ctx *context.Context) { + + issue := GetActionIssue(ctx) + if ctx.Written() { + return + } + + if issue.IsLocked { + ctx.Flash.Error(ctx.Tr("repo.issues.lock_duplicate")) + ctx.Redirect(issue.HTMLURL()) return } - if err := models.LockIssue(c.User, issue); err != nil { - c.ServerError("LockIssue", err) + if err := models.LockIssue(ctx.User, issue); err != nil { + ctx.ServerError("LockIssue", err) return } - url := issue.HTMLURL() - c.Redirect(url, http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) } From 249676214f35ea428b197368c7993341df697cfb Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 11 Oct 2018 14:56:32 +0100 Subject: [PATCH 04/46] add better UI indicators for (un)locked issues --- templates/repo/issue/view_content/sidebar.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index c19541526d804..91aa32e37d603 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -339,10 +339,10 @@
-
+ {{$.CsrfTokenHtml}} -
-
{{.i18n.Tr "loading"}}
-{{if .IsAttachmentEnabled}} +{{if and .IsAttachmentEnabled (not .Issue.IsLocked) }}
{{end}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index f152878996124..2d188a91fb51b 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -336,6 +336,7 @@ {{end}} + {{ if .IsRepoAdmin }}
@@ -353,6 +354,7 @@
+ {{ end }} From f4578b8f66f60e31a5d06333565d17982ae2a6ad Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 11 Oct 2018 16:37:18 +0100 Subject: [PATCH 12/46] restrict commenting on a locked issue --- options/locale/locale_en-US.ini | 1 + routers/repo/issue.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 65d37b0820db2..feac8fc7e8e53 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -777,6 +777,7 @@ issues.lock_duplicate = An issue cannot be locked twice. issues.unlock_error = Cannot unlock an issue that is not locked. issues.lock_comment = "locked this issue and limited conversation to collaborators %s" issues.unlock_comment = "unlocked this issue %s" +issues.comment_on_locked = You cannnot comment on a locked issue. issues.tracker = Time Tracker issues.start_tracking_short = Start issues.start_tracking = Start Time Tracking diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 586c179b98316..e509610433cb0 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -1105,6 +1105,12 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { return } + if issue.IsLocked { + ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) + ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) + return + } + var attachments []string if setting.AttachmentEnabled { attachments = form.Files From 41cb4ef7a2745471fb61dbdfe90626c53bd365d4 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 11 Oct 2018 16:59:56 +0100 Subject: [PATCH 13/46] remove entire comment box block if issue is locked --- templates/repo/issue/comment_tab.tmpl | 2 +- templates/repo/issue/view_content.tmpl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/repo/issue/comment_tab.tmpl b/templates/repo/issue/comment_tab.tmpl index 70be7bc808bff..6bb48d3da38cc 100644 --- a/templates/repo/issue/comment_tab.tmpl +++ b/templates/repo/issue/comment_tab.tmpl @@ -11,7 +11,7 @@ {{.i18n.Tr "loading"}} -{{if and .IsAttachmentEnabled (not .Issue.IsLocked) }} +{{if .IsAttachmentEnabled }}
{{end}} diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index ce2699af35778..60bcd01beede5 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -69,6 +69,7 @@ {{end}} {{if .IsSigned}} + {{ if not .Issue.IsLocked }} + {{ end }} {{else}}
-
diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 60bcd01beede5..f35da69ef3e29 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -69,7 +69,7 @@ {{end}} {{if .IsSigned}} - {{ if not .Issue.IsLocked }} + {{ if or .IsRepoAdmin .IsRepoWriter (or (not .Issue.IsLocked)) }} {{else if eq .Type 24}}
- + From d7e6c0a0a938f73710c3af8d65448f18d683c044 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 11 Oct 2018 17:51:32 +0100 Subject: [PATCH 16/46] make sure users with write access can actually make comments on a locked issue --- routers/repo/issue.go | 5 +++++ routers/routes/routes.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 586c179b98316..e8fc839d37063 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -1102,6 +1102,11 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull)) { ctx.Error(403) + } + + if issue.IsLocked && (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) { + ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) + ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) return } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index dbaa5db48de93..4c3cfb5a46b91 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -558,8 +558,8 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction) - m.Post("/lock", reqRepoAdmin, repo.LockIssue) - m.Post("/unlock", reqRepoAdmin, repo.UnlockIssue) + m.Post("/lock", reqRepoWriter, repo.LockIssue) + m.Post("/unlock", reqRepoWriter, repo.UnlockIssue) }) m.Post("/labels", reqRepoIssuesOrPullsWriter, repo.UpdateIssueLabel) From f517a6199452feb71db5511a7b57264dc31c4517 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 11 Oct 2018 17:54:16 +0100 Subject: [PATCH 17/46] simplify conditions --- routers/repo/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index e8fc839d37063..1163ae169fd8a 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -1104,7 +1104,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { ctx.Error(403) } - if issue.IsLocked && (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) { + if issue.IsLocked && !ctx.Repo.IsWriter() && !ctx.User.IsAdmin { ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) return From f4c5d3d83b09b4c963f0b37c9f673daf7d1a0350 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 12 Oct 2018 01:40:19 +0100 Subject: [PATCH 18/46] add modal so as to implement reasons --- options/locale/locale_en-US.ini | 6 +++ .../repo/issue/view_content/sidebar.tmpl | 44 +++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index feac8fc7e8e53..56716ebf9ba92 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -777,6 +777,12 @@ issues.lock_duplicate = An issue cannot be locked twice. issues.unlock_error = Cannot unlock an issue that is not locked. issues.lock_comment = "locked this issue and limited conversation to collaborators %s" issues.unlock_comment = "unlocked this issue %s" +issues.lock_confirm = Lock +issues.unlock_confirm = Unlock +issues.lock.notice = This will limit discussion on this issue to collaborators only. +issues.unlock.notice = This will allow anyone to comment on this issue. +issues.lock.title = Lock issue +issues.unlock.title = Unlock issue issues.comment_on_locked = You cannnot comment on a locked issue. issues.tracker = Time Tracker issues.start_tracking_short = Start diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 2d188a91fb51b..85189b5bfbcb1 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -340,9 +340,7 @@
-
- {{$.CsrfTokenHtml}} -
- {{ end }} + + + + {{ end }}
From 40ec39f2329bb5164c1e61887359ea15341de829 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 12 Oct 2018 22:19:17 +0100 Subject: [PATCH 19/46] add modal to prompt user with information about effects of (un)locking an issue --- options/locale/locale_en-US.ini | 11 +++++++---- templates/repo/issue/view_content/sidebar.tmpl | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 56716ebf9ba92..0cf36d9c89cb1 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -779,10 +779,13 @@ issues.lock_comment = "locked this issue and limited conversation to collaborato issues.unlock_comment = "unlocked this issue %s" issues.lock_confirm = Lock issues.unlock_confirm = Unlock -issues.lock.notice = This will limit discussion on this issue to collaborators only. -issues.unlock.notice = This will allow anyone to comment on this issue. -issues.lock.title = Lock issue -issues.unlock.title = Unlock issue +issues.lock.notice_1 = - Other users can’t add new comments to this issue. +issues.lock.notice_2 = - You and other collaborators with access to this repository can still leave comments that others can see. +issues.lock.notice_3 = - You can always unlock this issue again in the future. +issues.unlock.notice_1 = - Everyone would be able to comment on this issue once more. +issues.unlock.notice_2 = - You can always lock this issue again in the future. +issues.lock.title = Lock conversation on this issue. +issues.unlock.title = Unlock conversation on this issue. issues.comment_on_locked = You cannnot comment on a locked issue. issues.tracker = Time Tracker issues.start_tracking_short = Start diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 85189b5bfbcb1..8d37872ace645 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -365,9 +365,12 @@
{{ if .Issue.IsLocked }} - {{.i18n.Tr "repo.issues.unlock.notice"}}
+ {{.i18n.Tr "repo.issues.unlock.notice_1"}}
+ {{.i18n.Tr "repo.issues.unlock.notice_2"}}
{{ else }} - {{.i18n.Tr "repo.issues.lock.notice"}}
+ {{.i18n.Tr "repo.issues.lock.notice_1"}}
+ {{.i18n.Tr "repo.issues.lock.notice_2"}}
+ {{.i18n.Tr "repo.issues.lock.notice_3"}}
{{ end }}
From 693006469c1c8c1b18114fa56b38d462e6b3af47 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 12 Oct 2018 23:05:26 +0100 Subject: [PATCH 20/46] update UI to include lock reasons --- custom/conf/app.ini.sample | 4 ++++ modules/setting/defaults.go | 1 + modules/setting/setting.go | 12 ++++++++++ options/locale/locale_en-US.ini | 1 + routers/repo/issue.go | 6 +++++ .../repo/issue/view_content/sidebar.tmpl | 23 +++++++++++++++++++ 6 files changed, 47 insertions(+) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 20de7236bcd08..b3272bfacdbcd 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -67,6 +67,10 @@ MAX_FILES = 5 ; List of prefixes used in Pull Request title to mark them as Work In Progress WORK_IN_PROGRESS_PREFIXES=WIP:,[WIP] +[repository.issue] +; List of reasons why a Pull Request or Issue can be locked +LOCK_REASONS="Too heated","Off topic", "Resolved" + [ui] ; Number of repositories that are displayed on one explore page EXPLORE_PAGING_NUM = 20 diff --git a/modules/setting/defaults.go b/modules/setting/defaults.go index 48257284c7517..18133a76bade5 100644 --- a/modules/setting/defaults.go +++ b/modules/setting/defaults.go @@ -9,4 +9,5 @@ var ( defaultLangNames = strings.Split("English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,Українська,日本語,español,português do Brasil,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어", ",") defaultPullRequestWorkInProgressPrefixes = strings.Split("WIP:,[WIP]", ",") defaultThemes = strings.Split("gitea", "arc-green") + defaultIssuesLockReason = strings.Split("Too heated,Off topic,Resolved", ",") ) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 2560c091073ee..78bea9eac783c 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -237,6 +237,11 @@ var ( PullRequest struct { WorkInProgressPrefixes []string } `ini:"repository.pull-request"` + + // Issue Setting + Issue struct { + LockReasons []string + } `ini:"repository.issue"` }{ AnsiCharset: "", ForcePrivate: false, @@ -288,6 +293,13 @@ var ( }{ WorkInProgressPrefixes: defaultPullRequestWorkInProgressPrefixes, }, + + // Issue settings + Issue: struct { + LockReasons []string + }{ + LockReasons: defaultIssuesLockReason, + }, } RepoRootPath string ScriptType = "bash" diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 0cf36d9c89cb1..8d7764362f338 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -784,6 +784,7 @@ issues.lock.notice_2 = - You and other collaborators with access to this reposit issues.lock.notice_3 = - You can always unlock this issue again in the future. issues.unlock.notice_1 = - Everyone would be able to comment on this issue once more. issues.unlock.notice_2 = - You can always lock this issue again in the future. +issues.lock.reason = Reason for locking issues.lock.title = Lock conversation on this issue. issues.unlock.title = Unlock conversation on this issue. issues.comment_on_locked = You cannnot comment on a locked issue. diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 1163ae169fd8a..fd3206fcc40c1 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -878,10 +878,16 @@ func ViewIssue(ctx *context.Context) { ctx.Data["Issue"] = issue ctx.Data["ReadOnly"] = true ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string) +<<<<<<< HEAD ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID) ctx.Data["IsIssueWriter"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) ctx.Data["IsRepoAdmin"] = ctx.IsSigned && ctx.Repo.IsAdmin() && ctx.User.IsAdmin ctx.Data["IsWriter"] = ctx.IsSigned && ctx.Repo.IsWriter() && ctx.User.IsAdmin +======= + ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin) + ctx.Data["IsRepoWriter"] = ctx.IsSigned && (ctx.Repo.IsWriter() || ctx.User.IsAdmin) + ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons +>>>>>>> update UI to include lock reasons ctx.HTML(200, tplIssueView) } diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 8d37872ace645..b261488a9b26f 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -377,7 +377,30 @@
{{.CsrfTokenHtml}} + +
+ {{ .i18n.Tr "repo.issues.lock.reason" }} +
+
+
From 53becb7f73a50ff64e7d2bba2a7b9e74bb4307de Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 12 Oct 2018 23:07:06 +0100 Subject: [PATCH 21/46] only show reasons in modal when locking an issue --- templates/repo/issue/view_content/sidebar.tmpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index b261488a9b26f..d54c78095d2bd 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -378,6 +378,7 @@ method="post"> {{.CsrfTokenHtml}} + {{ if not .Issue.IsLocked }}
{{ .i18n.Tr "repo.issues.lock.reason" }}
@@ -402,6 +403,7 @@
+ {{ end }}
{{.i18n.Tr "settings.cancel"}}
From 7abf90f263d490fa68c9663ec47fdc0bf154e65d Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 12 Oct 2018 23:45:58 +0100 Subject: [PATCH 22/46] validate reasons --- modules/auth/repo_form.go | 27 +++++++++++++++++++++++++++ modules/auth/repo_form_test.go | 25 +++++++++++++++++++++++++ options/locale/locale_en-US.ini | 1 + routers/repo/issue_lock.go | 9 ++++++++- routers/routes/routes.go | 2 +- 5 files changed, 62 insertions(+), 2 deletions(-) diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index a600ecc8fe831..8f338884e3a7a 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -10,6 +10,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers/utils" "github.com/Unknwon/com" @@ -306,6 +307,32 @@ func (f *ReactionForm) Validate(ctx *macaron.Context, errs binding.Errors) bindi return validate(errs, ctx.Data, f, ctx.Locale) } +// IssueLockForm form for locking an issue +type IssueLockForm struct { + Reason string `binding:"Required"` +} + +// Validate validates the fields +func (i *IssueLockForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { + return validate(errs, ctx.Data, i, ctx.Locale) +} + +// HasValidReason checks to make sure that the reason submitted in +// the form matches any of the values in the config +func (i IssueLockForm) HasValidReason() bool { + if strings.TrimSpace(i.Reason) == "" { + return true + } + + for _, v := range setting.Repository.Issue.LockReasons { + if v == i.Reason { + return true + } + } + + return false +} + // _____ .__.__ __ // / \ |__| | ____ _______/ |_ ____ ____ ____ // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \ diff --git a/modules/auth/repo_form_test.go b/modules/auth/repo_form_test.go index f6223d6c8a0ae..a3369b006ed12 100644 --- a/modules/auth/repo_form_test.go +++ b/modules/auth/repo_form_test.go @@ -7,6 +7,7 @@ package auth import ( "testing" + "code.gitea.io/gitea/modules/setting" "github.com/stretchr/testify/assert" ) @@ -39,3 +40,27 @@ func TestSubmitReviewForm_IsEmpty(t *testing.T) { assert.Equal(t, v.expected, v.form.HasEmptyContent()) } } + +func TestIssueLock_HasValidReason(t *testing.T) { + + // Init settings + _ = setting.Repository + + cases := []struct { + form IssueLockForm + expected bool + }{ + {IssueLockForm{""}, true}, // an empty reason is accepted + {IssueLockForm{"Off-topic"}, true}, + {IssueLockForm{"Too heated"}, true}, + {IssueLockForm{"Spam"}, true}, + {IssueLockForm{"Resolved"}, true}, + + {IssueLockForm{"ZZZZ"}, false}, + {IssueLockForm{"I want to lock this issue"}, false}, + } + + for _, v := range cases { + assert.Equal(t, v.expected, v.form.HasValidReason()) + } +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 8d7764362f338..a4818a56e3de6 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -773,6 +773,7 @@ issues.subscribe = Subscribe issues.unsubscribe = Unsubscribe issues.lock = Lock conversation issues.unlock = Unlock conversation +issues.lock.unknown_reason = Cannot lock an issue with an unknown reason. issues.lock_duplicate = An issue cannot be locked twice. issues.unlock_error = Cannot unlock an issue that is not locked. issues.lock_comment = "locked this issue and limited conversation to collaborators %s" diff --git a/routers/repo/issue_lock.go b/routers/repo/issue_lock.go index 137e7e9f52596..78b6a171b3a1e 100644 --- a/routers/repo/issue_lock.go +++ b/routers/repo/issue_lock.go @@ -8,12 +8,13 @@ import ( "net/http" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/context" ) // LockIssue locks an issue. This would limit commenting abilities to // users with write access to the repo. -func LockIssue(ctx *context.Context) { +func LockIssue(ctx *context.Context, form auth.IssueLockForm) { issue := GetActionIssue(ctx) if ctx.Written() { @@ -26,6 +27,12 @@ func LockIssue(ctx *context.Context) { return } + if !form.HasValidReason() { + ctx.Flash.Error(ctx.Tr("repo.issues.lock.unknown_reason")) + ctx.Redirect(issue.HTMLURL()) + return + } + if err := models.LockIssue(ctx.User, issue); err != nil { ctx.ServerError("LockIssue", err) return diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 4c3cfb5a46b91..84bcaeb0e1ed5 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -558,7 +558,7 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction) - m.Post("/lock", reqRepoWriter, repo.LockIssue) + m.Post("/lock", reqRepoWriter, bindIgnErr(auth.IssueLockForm{}), repo.LockIssue) m.Post("/unlock", reqRepoWriter, repo.UnlockIssue) }) From 6b633c16886527e3b56dcc512a173664a4cd3ad2 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 13 Oct 2018 00:01:22 +0100 Subject: [PATCH 23/46] add reason for locking an issue to the DB --- models/issue_lock.go | 32 ++++++++++++++++++++------------ routers/repo/issue_lock.go | 11 +++++++++-- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/models/issue_lock.go b/models/issue_lock.go index 3aac5a2ff6710..b0d57416fcd0b 100644 --- a/models/issue_lock.go +++ b/models/issue_lock.go @@ -4,29 +4,37 @@ package models +// IssueLockOptions defines options for locking and/or unlocking an issue/PR +type IssueLockOptions struct { + Doer *User + Issue *Issue + Reason string +} + // LockIssue locks an issue. This would limit commenting abilities to // users with write access to the repo -func LockIssue(user *User, issue *Issue) error { - issue.IsLocked = true - return lockOrUnlockIssue(user, issue, CommentTypeLock) +func LockIssue(opts *IssueLockOptions) error { + opts.Issue.IsLocked = true + return lockOrUnlockIssue(opts, CommentTypeLock) } // UnlockIssue unlocks a previously locked issue. -func UnlockIssue(user *User, issue *Issue) error { - issue.IsLocked = false - return lockOrUnlockIssue(user, issue, CommentTypeUnlock) +func UnlockIssue(opts *IssueLockOptions) error { + opts.Issue.IsLocked = false + return lockOrUnlockIssue(opts, CommentTypeUnlock) } -func lockOrUnlockIssue(user *User, issue *Issue, commentType CommentType) error { - if err := UpdateIssueCols(issue, "is_locked"); err != nil { +func lockOrUnlockIssue(opts *IssueLockOptions, commentType CommentType) error { + if err := UpdateIssueCols(opts.Issue, "is_locked"); err != nil { return err } _, err := CreateComment(&CreateCommentOptions{ - Doer: user, - Issue: issue, - Repo: issue.Repo, - Type: commentType, + Doer: opts.Doer, + Issue: opts.Issue, + Repo: opts.Issue.Repo, + Type: commentType, + Content: opts.Reason, }) return err } diff --git a/routers/repo/issue_lock.go b/routers/repo/issue_lock.go index 78b6a171b3a1e..97ae5d2e9aa0d 100644 --- a/routers/repo/issue_lock.go +++ b/routers/repo/issue_lock.go @@ -33,7 +33,11 @@ func LockIssue(ctx *context.Context, form auth.IssueLockForm) { return } - if err := models.LockIssue(ctx.User, issue); err != nil { + if err := models.LockIssue(&models.IssueLockOptions{ + Doer: ctx.User, + Issue: issue, + Reason: form.Reason, + }); err != nil { ctx.ServerError("LockIssue", err) return } @@ -55,7 +59,10 @@ func UnlockIssue(ctx *context.Context) { return } - if err := models.UnlockIssue(ctx.User, issue); err != nil { + if err := models.UnlockIssue(&models.IssueLockOptions{ + Doer: ctx.User, + Issue: issue, + }); err != nil { ctx.ServerError("UnlockIssue", err) return } From 52da337e5acb78bd6bbe754773c30d0abd14bf41 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 13 Oct 2018 00:34:27 +0100 Subject: [PATCH 24/46] update UI to include lock reasons stated --- options/locale/locale_en-US.ini | 4 ++-- templates/repo/issue/view_content/comments.tmpl | 14 ++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a4818a56e3de6..e172c3d4c50f7 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -776,8 +776,8 @@ issues.unlock = Unlock conversation issues.lock.unknown_reason = Cannot lock an issue with an unknown reason. issues.lock_duplicate = An issue cannot be locked twice. issues.unlock_error = Cannot unlock an issue that is not locked. -issues.lock_comment = "locked this issue and limited conversation to collaborators %s" -issues.unlock_comment = "unlocked this issue %s" +issues.lock_comment = "locked %s %s and limited conversation to collaborators %s" +issues.unlock_comment = "unlocked this conversation %s" issues.lock_confirm = Lock issues.unlock_confirm = Unlock issues.lock.notice_1 = - Other users can’t add new comments to this issue. diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index e242d4256acbf..88ae590f1c56c 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -359,16 +359,14 @@ + {{ $formatting := "" }} + {{ if .Content }} + {{ $formatting = "as " }} + {{ end }} + {{.Poster.Name}} - {{$.i18n.Tr "repo.issues.lock_comment" $createdStr | Safe}} + {{$.i18n.Tr "repo.issues.lock_comment" $formatting .Content $createdStr | Safe}} - - {{if .Content}} -
- - {{.Content}} -
- {{end}}
{{else if eq .Type 24}}
From b8b2103a969a7f3e3eb62beb5f0392b2211d92e9 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 13 Oct 2018 13:26:06 +0100 Subject: [PATCH 25/46] fix unrelated changes plus added commas --- custom/conf/app.ini.sample | 6 +++--- templates/repo/issue/comment_tab.tmpl | 2 +- templates/repo/issue/view_content/comments.tmpl | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index b3272bfacdbcd..05eb6bd5d5947 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -69,7 +69,7 @@ WORK_IN_PROGRESS_PREFIXES=WIP:,[WIP] [repository.issue] ; List of reasons why a Pull Request or Issue can be locked -LOCK_REASONS="Too heated","Off topic", "Resolved" +LOCK_REASONS=Too heated,Off-topic,Resolved,Spam [ui] ; Number of repositories that are displayed on one explore page @@ -340,8 +340,8 @@ ENABLE_CAPTCHA = false CAPTCHA_TYPE = image ; Enable recaptcha to use Google's recaptcha service ; Go to https://www.google.com/recaptcha/admin to sign up for a key -RECAPTCHA_SECRET = -RECAPTCHA_SITEKEY = +RECAPTCHA_SECRET = +RECAPTCHA_SITEKEY = ; Default value for KeepEmailPrivate ; Each new user will get the value of this setting copied into their profile DEFAULT_KEEP_EMAIL_PRIVATE = false diff --git a/templates/repo/issue/comment_tab.tmpl b/templates/repo/issue/comment_tab.tmpl index 4330e8de2cfef..7c6417048430d 100644 --- a/templates/repo/issue/comment_tab.tmpl +++ b/templates/repo/issue/comment_tab.tmpl @@ -11,7 +11,7 @@ {{.i18n.Tr "loading"}}
-{{if .IsAttachmentEnabled }} +{{if .IsAttachmentEnabled}}
{{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 88ae590f1c56c..c3d810e9f9da1 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -5,7 +5,7 @@ 5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 12 = START_TRACKING, 13 = STOP_TRACKING, 14 = ADD_TIME_MANUAL, 16 = ADDED_DEADLINE, 17 = MODIFIED_DEADLINE, 18 = REMOVED_DEADLINE, 19 = ADD_DEPENDENCY, 20 = - REMOVE_DEPENDENCY, 21 = CODE, 22 = REVIEW 23 = ISSUE_LOCKED 24 = ISSUE_LOCKED --> + REMOVE_DEPENDENCY, 21 = CODE, 22 = REVIEW, 23 = ISSUE_LOCKED, 24 = ISSUE_LOCKED --> {{if eq .Type 0}} {{end}} {{end}} From ca444dd104d46a3575485d4c53b09a4613050806 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sun, 14 Oct 2018 18:10:44 +0100 Subject: [PATCH 27/46] rename function name as per review --- models/issue_lock.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/models/issue_lock.go b/models/issue_lock.go index b0d57416fcd0b..bcc3bfcbd8771 100644 --- a/models/issue_lock.go +++ b/models/issue_lock.go @@ -14,17 +14,28 @@ type IssueLockOptions struct { // LockIssue locks an issue. This would limit commenting abilities to // users with write access to the repo func LockIssue(opts *IssueLockOptions) error { - opts.Issue.IsLocked = true - return lockOrUnlockIssue(opts, CommentTypeLock) + return updateIssueLock(opts, true) } // UnlockIssue unlocks a previously locked issue. func UnlockIssue(opts *IssueLockOptions) error { - opts.Issue.IsLocked = false - return lockOrUnlockIssue(opts, CommentTypeUnlock) + return updateIssueLock(opts, false) } -func lockOrUnlockIssue(opts *IssueLockOptions, commentType CommentType) error { +func updateIssueLock(opts *IssueLockOptions, lock bool) error { + if opts.Issue.IsLocked == lock { + return nil + } + + opts.Issue.IsLocked = lock + + var commentType CommentType + if opts.Issue.IsLocked { + commentType = CommentTypeLock + } else { + commentType = CommentTypeUnlock + } + if err := UpdateIssueCols(opts.Issue, "is_locked"); err != nil { return err } From 2b44d24cbaf31ffd09f866857eee31d86af9403a Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Wed, 17 Oct 2018 17:29:05 +0100 Subject: [PATCH 28/46] prevent user creating issues' comment via the api too --- routers/api/v1/repo/issue_comment.go | 6 ++++++ routers/repo/issue.go | 20 +++++++++++++++++--- routers/routes/routes.go | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 720513f00720b..2ab783e317fcc 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -5,6 +5,7 @@ package repo import ( + "errors" "time" "code.gitea.io/gitea/models" @@ -169,6 +170,11 @@ func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOpti return } + if issue.IsLocked && !ctx.Repo.IsWriter() && !ctx.User.IsAdmin { + ctx.Error(500, "CreateIssueComment", errors.New(ctx.Tr("repo.issues.comment_on_locked"))) + return + } + comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Body, nil) if err != nil { ctx.Error(500, "CreateIssueComment", err) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index fd3206fcc40c1..e07179dc12bbf 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -57,6 +57,23 @@ var ( } ) +// MustAllowUserComment checks to make sure if an issue is locked. +// If locked and user has permissions to write to the repository, +// then the comment is allowed, else it is blocked +func MustAllowUserComment(ctx *context.Context) { + + issue := GetActionIssue(ctx) + if ctx.Written() { + return + } + + if issue.IsLocked && !ctx.Repo.IsWriter() && !ctx.User.IsAdmin { + ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) + ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) + return + } +} + // MustEnableIssues check if repository enable internal issues func MustEnableIssues(ctx *context.Context) { if !ctx.Repo.CanRead(models.UnitTypeIssues) && @@ -878,16 +895,13 @@ func ViewIssue(ctx *context.Context) { ctx.Data["Issue"] = issue ctx.Data["ReadOnly"] = true ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string) -<<<<<<< HEAD ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID) ctx.Data["IsIssueWriter"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) ctx.Data["IsRepoAdmin"] = ctx.IsSigned && ctx.Repo.IsAdmin() && ctx.User.IsAdmin ctx.Data["IsWriter"] = ctx.IsSigned && ctx.Repo.IsWriter() && ctx.User.IsAdmin -======= ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin) ctx.Data["IsRepoWriter"] = ctx.IsSigned && (ctx.Repo.IsWriter() || ctx.User.IsAdmin) ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons ->>>>>>> update UI to include lock reasons ctx.HTML(200, tplIssueView) } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 84bcaeb0e1ed5..92c395bf7a31a 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -548,7 +548,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/add", repo.AddDependency) m.Post("/delete", repo.RemoveDependency) }) - m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) + m.Combo("/comments").Post(repo.MustAllowUserComment, bindIgnErr(auth.CreateCommentForm{}), repo.NewComment) m.Group("/times", func() { m.Post("/add", bindIgnErr(auth.AddTimeManuallyForm{}), repo.AddTimeManually) m.Group("/stopwatch", func() { From e9b48f7f820eb5e72f4d5eb8811e47ec5b47dfcb Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Wed, 17 Oct 2018 18:13:55 +0100 Subject: [PATCH 29/46] update translations --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index e172c3d4c50f7..91d4513fb7aab 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -788,7 +788,7 @@ issues.unlock.notice_2 = - You can always lock this issue again in the future. issues.lock.reason = Reason for locking issues.lock.title = Lock conversation on this issue. issues.unlock.title = Unlock conversation on this issue. -issues.comment_on_locked = You cannnot comment on a locked issue. +issues.comment_on_locked = You cannot comment on a locked issue. issues.tracker = Time Tracker issues.start_tracking_short = Start issues.start_tracking = Start Time Tracking From cdda82fdf0365e219c44deb8e7d493f9a06859d8 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Wed, 16 Jan 2019 21:08:55 +0100 Subject: [PATCH 30/46] update copyright years --- models/issue_lock.go | 2 +- routers/repo/issue_lock.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/issue_lock.go b/models/issue_lock.go index bcc3bfcbd8771..5a2d996b640d6 100644 --- a/models/issue_lock.go +++ b/models/issue_lock.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Gitea Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/routers/repo/issue_lock.go b/routers/repo/issue_lock.go index 97ae5d2e9aa0d..fa8758831938e 100644 --- a/routers/repo/issue_lock.go +++ b/routers/repo/issue_lock.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Gitea Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. From d9ad8ec1adbae9b67fe2f4087c2f1238408d9abf Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 17 Jan 2019 11:42:56 +0100 Subject: [PATCH 31/46] fix build --- models/repo_permission.go | 6 ++++++ routers/routes/routes.go | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/models/repo_permission.go b/models/repo_permission.go index 9dd7cc559d2c9..8c18a6dadd663 100644 --- a/models/repo_permission.go +++ b/models/repo_permission.go @@ -16,6 +16,12 @@ func (p *Permission) IsOwner() bool { return p.AccessMode >= AccessModeOwner } +// IsWriter checks if the current user has write or higher access to the +// repository. +func (p *Permission) IsWriter() bool { + return p.AccessMode >= AccessModeWrite +} + // IsAdmin returns true if current user has admin or higher access of repository. func (p *Permission) IsAdmin() bool { return p.AccessMode >= AccessModeAdmin diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 92c395bf7a31a..457d64477a904 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -406,6 +406,13 @@ func RegisterRoutes(m *macaron.Macaron) { reqRepoIssuesOrPullsWriter := context.RequireRepoWriterOr(models.UnitTypeIssues, models.UnitTypePullRequests) reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests) + reqRepoWriter := func(ctx *context.Context) { + if !ctx.Repo.IsWriter() { + ctx.Error(403) + return + } + } + // ***** START: Organization ***** m.Group("/org", func() { m.Group("", func() { From 24f68feda402bbefd40da915eb7d80fe4b9f5309 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 17 Jan 2019 12:54:30 +0100 Subject: [PATCH 32/46] update comparision table --- docs/content/doc/features/comparison.en-us.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/doc/features/comparison.en-us.md b/docs/content/doc/features/comparison.en-us.md index c9682b506f6e3..1808828d8a987 100644 --- a/docs/content/doc/features/comparison.en-us.md +++ b/docs/content/doc/features/comparison.en-us.md @@ -81,7 +81,7 @@ _Symbols used in table:_ | Related issues | ✘ | ✘ | ⁄ | ✘ | ✓ | ✘ | ✘ | | Confidential issues | ✘ | ✘ | ✘ | ✓ | ✓ | ✘ | ✘ | | Comment reactions | ✓ | ✘ | ✓ | ✓ | ✓ | ✘ | ✘ | -| Lock Discussion | ✘ | ✘ | ✓ | ✓ | ✓ | ✘ | ✘ | +| Lock Discussion | ✓ | ✘ | ✓ | ✓ | ✓ | ✘ | ✘ | | Batch issue handling | ✓ | ✘ | ✓ | ✓ | ✓ | ✘ | ✘ | | Issue Boards | ✘ | ✘ | ✘ | ✓ | ✓ | ✘ | ✘ | | Create new branches from issues | ✘ | ✘ | ✘ | ✓ | ✓ | ✘ | ✘ | From d902bd4bd2663cedcbcfc14eee5a09d1ac8108ce Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 17 Jan 2019 13:28:10 +0100 Subject: [PATCH 33/46] update default lock reasons --- modules/setting/defaults.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/setting/defaults.go b/modules/setting/defaults.go index 18133a76bade5..738494b6b2b21 100644 --- a/modules/setting/defaults.go +++ b/modules/setting/defaults.go @@ -9,5 +9,5 @@ var ( defaultLangNames = strings.Split("English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,Українська,日本語,español,português do Brasil,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어", ",") defaultPullRequestWorkInProgressPrefixes = strings.Split("WIP:,[WIP]", ",") defaultThemes = strings.Split("gitea", "arc-green") - defaultIssuesLockReason = strings.Split("Too heated,Off topic,Resolved", ",") + defaultIssuesLockReason = strings.Split("Too heated,Off-topic,Resolved,Spam", ",") ) From 59ed8be9b3d7e628ba507652c37d8b04148fe660 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 17 Jan 2019 13:35:52 +0100 Subject: [PATCH 34/46] update docs --- custom/conf/app.ini.sample | 4 ++-- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 05eb6bd5d5947..64a083d3b8d88 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -340,8 +340,8 @@ ENABLE_CAPTCHA = false CAPTCHA_TYPE = image ; Enable recaptcha to use Google's recaptcha service ; Go to https://www.google.com/recaptcha/admin to sign up for a key -RECAPTCHA_SECRET = -RECAPTCHA_SITEKEY = +RECAPTCHA_SECRET = +RECAPTCHA_SITEKEY = ; Default value for KeepEmailPrivate ; Each new user will get the value of this setting copied into their profile DEFAULT_KEEP_EMAIL_PRIVATE = false diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 6d17f78cef30d..136709336ef7e 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -70,6 +70,9 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `WORK_IN_PROGRESS_PREFIXES`: **WIP:,\[WIP\]**: List of prefixes used in Pull Request title to mark them as Work In Progress +### Repository - Issue (`repository.issue`) +- `LOCK_REASONS`: **Too heated,Off-topic,Resolved,Spam**: A list of reasons why a Pull Request or Issue can be locked + ## UI (`ui`) - `EXPLORE_PAGING_NUM`: **20**: Number of repositories that are shown in one explore page. From 0268e9089ca50f5b814677111f6c0aeba3b52325 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 19 Jan 2019 15:28:01 +0100 Subject: [PATCH 35/46] try to align icons --- templates/repo/issue/view_content/comments.tmpl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 463e8a58f84d2..d70eff0f29a8f 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -354,7 +354,8 @@ {{else if eq .Type 23}}
- + @@ -370,7 +371,8 @@
{{else if eq .Type 24}}
- + From b25d7e75305ff926f78f91836b04d6b8abb185ef Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sun, 20 Jan 2019 11:35:36 +0100 Subject: [PATCH 36/46] fix merge conflicts --- modules/setting/defaults.go | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 modules/setting/defaults.go diff --git a/modules/setting/defaults.go b/modules/setting/defaults.go deleted file mode 100644 index 738494b6b2b21..0000000000000 --- a/modules/setting/defaults.go +++ /dev/null @@ -1,13 +0,0 @@ -package setting - -import ( - "strings" -) - -var ( - defaultLangs = strings.Split("en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,uk-UA,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR", ",") - defaultLangNames = strings.Split("English,简体中文,繁體中文(香港),繁體中文(台灣),Deutsch,français,Nederlands,latviešu,русский,Українська,日本語,español,português do Brasil,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어", ",") - defaultPullRequestWorkInProgressPrefixes = strings.Split("WIP:,[WIP]", ",") - defaultThemes = strings.Split("gitea", "arc-green") - defaultIssuesLockReason = strings.Split("Too heated,Off-topic,Resolved,Spam", ",") -) From e8e13fac3cb4a5d4542b465399821b02dbc52798 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sun, 20 Jan 2019 15:26:45 +0100 Subject: [PATCH 37/46] fix tests --- modules/setting/setting.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 031df49f0d113..ad54014891b93 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -300,7 +300,7 @@ var ( Issue: struct { LockReasons []string }{ - LockReasons: strings.Split("Too heated,Off-topic,Resolved", ","), + LockReasons: strings.Split("Too heated,Off-topic,Spam,Resolved", ","), }, } RepoRootPath string From e6779a669ab3895a7a455f861a7fc70c41689727 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 24 Jan 2019 13:12:48 +0100 Subject: [PATCH 38/46] fix template --- templates/repo/issue/view_content.tmpl | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index ca68d27eadf96..3f4360aa07cb8 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -147,6 +147,7 @@ {{end}}
+{{ end }} {{ template "repo/issue/view_content/sidebar" . }} From f0037784975e3aa3b48445aefa7ce060313678e1 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Thu, 24 Jan 2019 14:35:52 +0100 Subject: [PATCH 39/46] fix template --- templates/repo/issue/view_content.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 3f4360aa07cb8..055b24f93b351 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -145,9 +145,9 @@ {{end}} {{end}} + {{end}} -{{ end }} {{ template "repo/issue/view_content/sidebar" . }} From 3272f1e31753ff67b4c2e53e95baa47d6d8c3f7e Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 26 Jan 2019 08:49:54 +0100 Subject: [PATCH 40/46] use CanWrite instead of creating a new method, IsWriter --- models/repo_permission.go | 6 ------ routers/api/v1/repo/issue_comment.go | 2 +- routers/repo/issue.go | 8 ++++---- routers/routes/routes.go | 2 +- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/models/repo_permission.go b/models/repo_permission.go index 8c18a6dadd663..9dd7cc559d2c9 100644 --- a/models/repo_permission.go +++ b/models/repo_permission.go @@ -16,12 +16,6 @@ func (p *Permission) IsOwner() bool { return p.AccessMode >= AccessModeOwner } -// IsWriter checks if the current user has write or higher access to the -// repository. -func (p *Permission) IsWriter() bool { - return p.AccessMode >= AccessModeWrite -} - // IsAdmin returns true if current user has admin or higher access of repository. func (p *Permission) IsAdmin() bool { return p.AccessMode >= AccessModeAdmin diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 2ab783e317fcc..486b8a725823e 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -170,7 +170,7 @@ func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOpti return } - if issue.IsLocked && !ctx.Repo.IsWriter() && !ctx.User.IsAdmin { + if issue.IsLocked && !ctx.Repo.CanWrite(models.UnitTypeIssues) && !ctx.User.IsAdmin { ctx.Error(500, "CreateIssueComment", errors.New(ctx.Tr("repo.issues.comment_on_locked"))) return } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index d5fcd8f244bcc..9a66f6a29642e 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -67,7 +67,7 @@ func MustAllowUserComment(ctx *context.Context) { return } - if issue.IsLocked && !ctx.Repo.IsWriter() && !ctx.User.IsAdmin { + if issue.IsLocked && !ctx.Repo.CanWrite(models.UnitTypeIssues) && !ctx.User.IsAdmin { ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) return @@ -914,9 +914,9 @@ func ViewIssue(ctx *context.Context) { ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID) ctx.Data["IsIssueWriter"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) ctx.Data["IsRepoAdmin"] = ctx.IsSigned && ctx.Repo.IsAdmin() && ctx.User.IsAdmin - ctx.Data["IsWriter"] = ctx.IsSigned && ctx.Repo.IsWriter() && ctx.User.IsAdmin + ctx.Data["IsWriter"] = ctx.IsSigned && ctx.Repo.CanWrite(models.UnitTypeIssues) && ctx.User.IsAdmin ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin) - ctx.Data["IsRepoWriter"] = ctx.IsSigned && (ctx.Repo.IsWriter() || ctx.User.IsAdmin) + ctx.Data["IsRepoWriter"] = ctx.IsSigned && (ctx.Repo.CanWrite(models.UnitTypeIssues) || ctx.User.IsAdmin) ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons ctx.HTML(200, tplIssueView) } @@ -1140,7 +1140,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { ctx.Error(403) } - if issue.IsLocked && !ctx.Repo.IsWriter() && !ctx.User.IsAdmin { + if issue.IsLocked && !ctx.Repo.CanWrite(models.UnitTypeIssues) && !ctx.User.IsAdmin { ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) return diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 74bfbe98bcdc8..cba814d63a8d1 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -407,7 +407,7 @@ func RegisterRoutes(m *macaron.Macaron) { reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests) reqRepoWriter := func(ctx *context.Context) { - if !ctx.Repo.IsWriter() { + if !ctx.Repo.CanWrite(models.UnitTypeIssues) { ctx.Error(403) return } From 2e3502f0022124d5c8020fecc1e8df483b1c9655 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 26 Jan 2019 18:04:13 +0100 Subject: [PATCH 41/46] fix @kolaente review --- routers/repo/issue.go | 6 ++---- routers/routes/routes.go | 6 +++--- templates/repo/issue/view_content.tmpl | 2 +- templates/repo/issue/view_content/comments.tmpl | 6 +++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 9a66f6a29642e..12ce4e7c2ec19 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -69,7 +69,7 @@ func MustAllowUserComment(ctx *context.Context) { if issue.IsLocked && !ctx.Repo.CanWrite(models.UnitTypeIssues) && !ctx.User.IsAdmin { ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) - ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) + ctx.Redirect(issue.HTMLURL()) return } } @@ -913,10 +913,8 @@ func ViewIssue(ctx *context.Context) { ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string) ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID) ctx.Data["IsIssueWriter"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) - ctx.Data["IsRepoAdmin"] = ctx.IsSigned && ctx.Repo.IsAdmin() && ctx.User.IsAdmin - ctx.Data["IsWriter"] = ctx.IsSigned && ctx.Repo.CanWrite(models.UnitTypeIssues) && ctx.User.IsAdmin ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin) - ctx.Data["IsRepoWriter"] = ctx.IsSigned && (ctx.Repo.CanWrite(models.UnitTypeIssues) || ctx.User.IsAdmin) + ctx.Data["IsRepoIssuesWriter"] = ctx.IsSigned && (ctx.Repo.CanWrite(models.UnitTypeIssues) || ctx.User.IsAdmin) ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons ctx.HTML(200, tplIssueView) } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index cba814d63a8d1..2855249bd3c99 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -406,7 +406,7 @@ func RegisterRoutes(m *macaron.Macaron) { reqRepoIssuesOrPullsWriter := context.RequireRepoWriterOr(models.UnitTypeIssues, models.UnitTypePullRequests) reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests) - reqRepoWriter := func(ctx *context.Context) { + reqRepoIssueWriter := func(ctx *context.Context) { if !ctx.Repo.CanWrite(models.UnitTypeIssues) { ctx.Error(403) return @@ -564,8 +564,8 @@ func RegisterRoutes(m *macaron.Macaron) { }) }) m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction) - m.Post("/lock", reqRepoWriter, bindIgnErr(auth.IssueLockForm{}), repo.LockIssue) - m.Post("/unlock", reqRepoWriter, repo.UnlockIssue) + m.Post("/lock", reqRepoIssueWriter, bindIgnErr(auth.IssueLockForm{}), repo.LockIssue) + m.Post("/unlock", reqRepoIssueWriter, repo.UnlockIssue) }, context.RepoMustNotBeArchived()) m.Post("/labels", reqRepoIssuesOrPullsWriter, repo.UpdateIssueLabel) diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 055b24f93b351..7445dcce86a5c 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -70,7 +70,7 @@ {{ template "repo/issue/view_content/pull". }} {{end}} {{if .IsSigned}} - {{ if or .IsRepoAdmin .IsRepoWriter (or (not .Issue.IsLocked)) }} + {{ if or .IsRepoAdmin .IsRepoIssuesWriter (or (not .Issue.IsLocked)) }}
diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 8178e53b8ab63..6e27f507d61c0 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -3,9 +3,9 @@ + 13 = STOP_TRACKING, 14 = ADD_TIME_MANUAL, 16 = ADDED_DEADLINE, 17 = MODIFIED_DEADLINE, + 18 = REMOVED_DEADLINE, 19 = ADD_DEPENDENCY, 20 = REMOVE_DEPENDENCY, 21 = CODE, + 22 = REVIEW, 23 = ISSUE_LOCKED, 24 = ISSUE_LOCKED --> {{if eq .Type 0}}
From 865c6185f3c8f83df32899290b9dcce47a4f2907 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Sat, 26 Jan 2019 18:17:57 +0100 Subject: [PATCH 42/46] 403 instead of 500 --- routers/api/v1/repo/issue_comment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 486b8a725823e..3e6f04eb7a344 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -171,7 +171,7 @@ func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOpti } if issue.IsLocked && !ctx.Repo.CanWrite(models.UnitTypeIssues) && !ctx.User.IsAdmin { - ctx.Error(500, "CreateIssueComment", errors.New(ctx.Tr("repo.issues.comment_on_locked"))) + ctx.Error(403, "CreateIssueComment", errors.New(ctx.Tr("repo.issues.comment_on_locked"))) return } From 29cf5f0fb801a9bb5f306e09fd2a810582708265 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Mon, 28 Jan 2019 11:17:04 +0100 Subject: [PATCH 43/46] use HTMLURL instead --- routers/repo/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 12ce4e7c2ec19..1d4fd1fce94f3 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -1140,7 +1140,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { if issue.IsLocked && !ctx.Repo.CanWrite(models.UnitTypeIssues) && !ctx.User.IsAdmin { ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) - ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) + ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) return } From e85b63b1f752259e8d3618091a4912e1bd1333d0 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Mon, 11 Feb 2019 19:29:54 +0100 Subject: [PATCH 44/46] fix issue with a text not being translatable --- options/locale/locale_en-US.ini | 2 +- templates/repo/issue/view_content/comments.tmpl | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index e0466a35d96d7..b75e5c65639a8 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -784,7 +784,7 @@ issues.unlock = Unlock conversation issues.lock.unknown_reason = Cannot lock an issue with an unknown reason. issues.lock_duplicate = An issue cannot be locked twice. issues.unlock_error = Cannot unlock an issue that is not locked. -issues.lock_comment = "locked %s %s and limited conversation to collaborators %s" +issues.lock_with_reason = "locked as %s and limited conversation to collaborators %s" issues.unlock_comment = "unlocked this conversation %s" issues.lock_confirm = Lock issues.unlock_confirm = Unlock diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 491658248c8c7..c71588e584d1a 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -6,7 +6,7 @@ 5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 12 = START_TRACKING, 13 = STOP_TRACKING, 14 = ADD_TIME_MANUAL, 16 = ADDED_DEADLINE, 17 = MODIFIED_DEADLINE, 18 = REMOVED_DEADLINE, 19 = ADD_DEPENDENCY, 20 = REMOVE_DEPENDENCY, 21 = CODE, - 22 = REVIEW, 23 = ISSUE_LOCKED, 24 = ISSUE_LOCKED --> + 22 = REVIEW, 23 = ISSUE_LOCKED, 24 = ISSUE_UNLOCKED --> {{if eq .Type 0}}
@@ -367,13 +367,8 @@ - {{ $formatting := "" }} - {{ if .Content }} - {{ $formatting = "as " }} - {{ end }} - {{.Poster.Name}} - {{$.i18n.Tr "repo.issues.lock_comment" $formatting .Content $createdStr | Safe}} + {{$.i18n.Tr "repo.issues.lock_with_reason" .Content $createdStr | Safe}}
{{else if eq .Type 24}} From 831560135f4a57af0197b86d37d8491a7ad04a60 Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Mon, 11 Feb 2019 19:33:23 +0100 Subject: [PATCH 45/46] add migration --- models/migrations/migrations.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 174e7b51566f8..f5e48a27de2e2 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -212,6 +212,8 @@ var migrations = []Migration{ NewMigration("rename repo is_bare to repo is_empty", renameRepoIsBareToIsEmpty), // v79 -> v80 NewMigration("add can close issues via commit in any branch", addCanCloseIssuesViaCommitInAnyBranch), + // v80 -> v81 + NewMigration("add is locked to issues", addIsLockedToIssues), } // Migrate database to current version From 09d5eb753c8d413aaf3af87429edffe7c98c9f1c Mon Sep 17 00:00:00 2001 From: Lanre Adelowo Date: Fri, 15 Feb 2019 16:49:01 +0100 Subject: [PATCH 46/46] added another translation --- options/locale/locale_en-US.ini | 1 + templates/repo/issue/view_content/comments.tmpl | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b75e5c65639a8..fe1bdb007fb22 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -785,6 +785,7 @@ issues.lock.unknown_reason = Cannot lock an issue with an unknown reason. issues.lock_duplicate = An issue cannot be locked twice. issues.unlock_error = Cannot unlock an issue that is not locked. issues.lock_with_reason = "locked as %s and limited conversation to collaborators %s" +issues.lock_no_reason = "locked and limited conversation to collaborators %s" issues.unlock_comment = "unlocked this conversation %s" issues.lock_confirm = Lock issues.unlock_confirm = Unlock diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index c71588e584d1a..ac7e9a23326b7 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -367,9 +367,15 @@ + {{ if .Content }} {{.Poster.Name}} {{$.i18n.Tr "repo.issues.lock_with_reason" .Content $createdStr | Safe}} + {{ else }} + {{.Poster.Name}} + {{$.i18n.Tr "repo.issues.lock_no_reason" $createdStr | Safe}} + + {{ end }}
{{else if eq .Type 24}}