From 8ef16c7cfb389093d4b1725273b295b9d99fd3f7 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 01:04:48 +0200 Subject: [PATCH 01/27] Don't apply wrap around submit buttons on review form --- web_src/less/_repository.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 67a79d45e5b2..004d91da881d 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -1655,7 +1655,7 @@ @media (max-width: 480px) { padding-top: .25rem; - .ui.button { + .ui.button:not(.btn-submit) { padding-left: .5rem; padding-right: .5rem; display: flex; From a8306a3e01d38485f609ba7e8bcd136ef307d0de Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 01:18:31 +0200 Subject: [PATCH 02/27] Don't allow the issue view headers to stack. - Show it horizontally, instead of giving each their own row. --- templates/repo/issue/view.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/view.tmpl b/templates/repo/issue/view.tmpl index acfd25e7e024..c1fedac04ce9 100644 --- a/templates/repo/issue/view.tmpl +++ b/templates/repo/issue/view.tmpl @@ -2,7 +2,7 @@
{{template "repo/header" .}}
-
+
{{template "repo/issue/navbar" .}}
From 5689d9f3628d11888bded8cbe8eed51d7333df29 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 01:47:59 +0200 Subject: [PATCH 03/27] Have nice issue/pulls list headers --- templates/repo/issue/list.tmpl | 2 +- web_src/less/_repository.less | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 63d746f570a1..ba7f1c1480b1 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -2,7 +2,7 @@
{{template "repo/header" .}}
-
+
{{template "repo/issue/navbar" .}}
diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 004d91da881d..7cf1607390e9 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -3237,3 +3237,22 @@ td.blob-excerpt { transform: scale(105%); box-shadow: 0 .5rem 1rem var(--color-shadow) !important; } + +@media @mediaSm { + .issue-list-headers.ui[class].grid { + > div:nth-child(1) { + order: 1; + width: 50%; + } + + > div:nth-child(2) { + order: 3; + width: 100%; + } + + > div.column:not(.row):nth-child(3) { + order: 2; + width: 50%; + } + } +} From bed6577d09bd8e14cabfbbf2cf7e62a5e0b70fe7 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 01:57:00 +0200 Subject: [PATCH 04/27] Don't overflow on notification table --- web_src/less/_user.less | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web_src/less/_user.less b/web_src/less/_user.less index 828402211562..09a5f189120c 100644 --- a/web_src/less/_user.less +++ b/web_src/less/_user.less @@ -7,7 +7,7 @@ display: block; font-weight: 600; font-size: 1.3rem; - margin-top: -.2rem; + margin-top: -0.2rem; line-height: 1.3rem; } @@ -47,7 +47,7 @@ #profile-avatar { background: none; - padding: 1rem 1rem .25rem; + padding: 1rem 1rem 0.25rem; img { width: 100%; @@ -175,3 +175,7 @@ max-width: 60px; } } + +#notification_div .tab.segment { + overflow-x: scroll; +} From 0ead5590cb870d09cc047acab8f9f2ad5c9a5962 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 15:53:52 +0200 Subject: [PATCH 05/27] Fix repo buttons overflowing - Don't show SVG(major cause for taking up space and being shown as "column"). - Allow it to be a new columnif the number is too big. --- web_src/less/_repository.less | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 7cf1607390e9..ce17192e6bb5 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -2965,8 +2965,11 @@ tbody.commit-list { } .repo-buttons { - display: flex; align-items: center; + display: flex; + flex-direction: row; + flex-wrap: wrap; + word-break: keep-all; @media @mediaSm { margin-top: 1em; @@ -3011,6 +3014,11 @@ tbody.commit-list { pointer-events: none !important; } } + @media @mediaSm { + .svg { + display: none; + } + } } .tag-code { From e7876e2f0bb3f0c6b0be48cba823a01d90c2f763 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 16:00:09 +0200 Subject: [PATCH 06/27] Properly show tables on mobile --- web_src/less/_admin.less | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/web_src/less/_admin.less b/web_src/less/_admin.less index 97c8e0d5c896..d8dd680b202f 100644 --- a/web_src/less/_admin.less +++ b/web_src/less/_admin.less @@ -62,6 +62,9 @@ dd { margin-left: 275px; + @media @mediaSm { + margin-left: 5%; + } } dt { @@ -72,6 +75,11 @@ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; + + @media @mediaSm { + width: auto; + margin-right: .5em; + } } } From e78db22a039eac6278311d224609ae1b70998232 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 16:04:46 +0200 Subject: [PATCH 07/27] Properly show table on user accounts - Force semantic to not stack it, and let the overflow be scrollable. --- templates/admin/user/list.tmpl | 2 +- web_src/less/_admin.less | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index 93e6f38c2701..755e4436f89d 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -61,7 +61,7 @@
- +
diff --git a/web_src/less/_admin.less b/web_src/less/_admin.less index d8dd680b202f..3af0c57d110d 100644 --- a/web_src/less/_admin.less +++ b/web_src/less/_admin.less @@ -12,6 +12,7 @@ .table.segment { padding: 0; font-size: 13px; + overflow-x: scroll; &:not(.striped) { thead { From a4ed98b544a7ddaed7e2d838b46996e0c25b61c8 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 16:08:03 +0200 Subject: [PATCH 08/27] Properly show all tables on admin for mobile --- templates/admin/auth/list.tmpl | 2 +- templates/admin/emails/list.tmpl | 2 +- templates/admin/org/list.tmpl | 2 +- templates/admin/packages/list.tmpl | 2 +- templates/admin/repo/list.tmpl | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/admin/auth/list.tmpl b/templates/admin/auth/list.tmpl index 71e5bfbda8d7..b4a703e4139f 100644 --- a/templates/admin/auth/list.tmpl +++ b/templates/admin/auth/list.tmpl @@ -10,7 +10,7 @@
-
ID{{SortArrow "oldest" "newest" .SortType false}}
+
diff --git a/templates/admin/emails/list.tmpl b/templates/admin/emails/list.tmpl index e73213c1dfa7..277c777a89c0 100644 --- a/templates/admin/emails/list.tmpl +++ b/templates/admin/emails/list.tmpl @@ -30,7 +30,7 @@
-
ID
+
diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index 75c4d39196cf..0782ef64e97a 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -13,7 +13,7 @@ {{template "admin/base/search" .}}
- +
diff --git a/templates/admin/packages/list.tmpl b/templates/admin/packages/list.tmpl index 373a97407b5e..df89d8bed236 100644 --- a/templates/admin/packages/list.tmpl +++ b/templates/admin/packages/list.tmpl @@ -29,7 +29,7 @@
-
ID{{SortArrow "oldest" "newest" $.SortType false}}
+
diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index d7561dde7d2b..da05bfab962e 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -13,7 +13,7 @@ {{template "admin/repo/search" .}}
-
ID
+
From 330afac392851ad3fdce33321f9f2bdb61c16321 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 16:10:43 +0200 Subject: [PATCH 09/27] Fix cron/notice tables on admin --- templates/admin/cron.tmpl | 2 +- templates/admin/monitor.tmpl | 2 +- templates/admin/notice.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/admin/cron.tmpl b/templates/admin/cron.tmpl index 30277177ed0c..a73813ef8804 100644 --- a/templates/admin/cron.tmpl +++ b/templates/admin/cron.tmpl @@ -3,7 +3,7 @@
-
ID{{SortArrow "oldest" "newest" $.SortType false}}
+
diff --git a/templates/admin/monitor.tmpl b/templates/admin/monitor.tmpl index 443159f8ceaa..86686101acf5 100644 --- a/templates/admin/monitor.tmpl +++ b/templates/admin/monitor.tmpl @@ -8,7 +8,7 @@ {{.i18n.Tr "admin.monitor.queues"}}
-
+
diff --git a/templates/admin/notice.tmpl b/templates/admin/notice.tmpl index 9fec53b3156f..8d0e1c2206d1 100644 --- a/templates/admin/notice.tmpl +++ b/templates/admin/notice.tmpl @@ -7,7 +7,7 @@ {{.i18n.Tr "admin.notices.system_notice_list"}} ({{.i18n.Tr "admin.total" .Total}})
-
{{.i18n.Tr "admin.monitor.queue.name"}}
+
From b9e8fa5beb300eac7bd0623c9d7201a9e3a92a4a Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 29 Apr 2022 02:05:21 +0200 Subject: [PATCH 10/27] More width on viewing comments --- templates/repo/issue/view_content.tmpl | 7 +++-- web_src/less/_repository.less | 41 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 46a2a3969bd6..b5f838e9d0aa 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -41,6 +41,9 @@ {{if .Repository.OriginalURL}} ({{$.i18n.Tr "repo.migrated_from" (.Repository.OriginalURL|Escape) (.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}} {{else}} + + {{avatar .Issue.Poster}} + {{.Issue.Poster.GetDisplayName}} {{.i18n.Tr "repo.issues.commented_at" (.Issue.HashTag|Escape) $createdStr | Safe}} @@ -50,12 +53,12 @@
{{if gt .Issue.ShowRole 0}} {{if (.Issue.ShowRole.HasRole "Writer")}} -
+
{{$.i18n.Tr "repo.issues.collaborator"}}
{{end}} {{if (.Issue.ShowRole.HasRole "Owner")}} -
+
{{$.i18n.Tr "repo.issues.owner"}}
{{end}} diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index cb1539866a8f..065f890326b7 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -861,6 +861,10 @@ } } + .inline-timeline-avatar { + display: none; + } + .avatar.image, .avatar.image img { width: 20px; @@ -3284,4 +3288,41 @@ td.blob-excerpt { width: 50%; } } + + .repository.view.issue .comment-list { + .timeline, + .timeline-item { + margin-left: 0; + } + + .timeline { + &::before { + left: 14px; + } + + .inline-timeline-avatar { + display: flex; + margin-bottom: auto; + + img.avatar.image { + height: 24px; + width: 24px; + } + } + + .comment-header { + &::before, + &::after { + content: unset; + } + + padding-left: 4px; + } + + .timeline-avatar, + .comment-header-right .role-label { + display: none; + } + } + } } From f6175148ae8ae2ea8e345e09db3c7c938b002a59 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 29 Apr 2022 02:28:28 +0200 Subject: [PATCH 11/27] Fix linting --- web_src/less/_user.less | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/less/_user.less b/web_src/less/_user.less index 09a5f189120c..e19298681985 100644 --- a/web_src/less/_user.less +++ b/web_src/less/_user.less @@ -7,7 +7,7 @@ display: block; font-weight: 600; font-size: 1.3rem; - margin-top: -0.2rem; + margin-top: -.2rem; line-height: 1.3rem; } @@ -47,7 +47,7 @@ #profile-avatar { background: none; - padding: 1rem 1rem 0.25rem; + padding: 1rem 1rem .25rem; img { width: 100%; From 00839b218b10872e27367adcf77252e09c941ed1 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 29 Apr 2022 02:46:41 +0200 Subject: [PATCH 12/27] Fix other avatars --- templates/repo/issue/view_content/comments.tmpl | 3 +++ web_src/less/_repository.less | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 7b0941148f42..1b88ae73934b 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -35,6 +35,9 @@ ({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}} {{else}} + + {{avatar .Poster}} + {{.Poster.GetDisplayName}} diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 065f890326b7..4450f552b57c 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -2666,7 +2666,7 @@ background: var(--color-box-header); border-bottom: 1px solid var(--color-secondary) !important; font-weight: normal !important; - padding: .5rem 1rem !important; + padding: .5rem 1rem; margin: 0 !important; position: relative; color: var(--color-text-light-2); From 920b683c46a55e41ce5af99a44a2e48a02a080a5 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 29 Apr 2022 08:44:40 +0000 Subject: [PATCH 13/27] Don't error when branch's commit doesn't exist (#19547) * Don't error when branch's commit doesn't exist - If one of the branches no longer exists, don't throw an error, it's possible that the branch was destroyed during the process. Simply skip it and disregard it. - Resolves #19541 * Don't send empty objects * Use more minimal approach --- routers/api/v1/repo/branch.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index 794d367b53e7..c030a896a792 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -259,10 +259,15 @@ func ListBranches(ctx *context.APIContext) { return } - apiBranches := make([]*api.Branch, len(branches)) + apiBranches := make([]*api.Branch, 0, len(branches)) for i := range branches { c, err := branches[i].GetCommit() if err != nil { + // Skip if this branch doesn't exist anymore. + if git.IsErrNotExist(err) { + totalNumOfBranches-- + continue + } ctx.Error(http.StatusInternalServerError, "GetCommit", err) return } @@ -271,11 +276,12 @@ func ListBranches(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) return } - apiBranches[i], err = convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) + apiBranch, err := convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) if err != nil { ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err) return } + apiBranches = append(apiBranches, apiBranch) } ctx.SetLinkHeader(totalNumOfBranches, listOptions.PageSize) From 7834260ab0b1f5a03b31c8812eae654c9bdc3e02 Mon Sep 17 00:00:00 2001 From: parnic Date: Fri, 29 Apr 2022 04:30:54 -0500 Subject: [PATCH 14/27] Fix Pull Request comment filename word breaks (#19535) * Fix word breaks in Chrome This fixes word wrapping on the filename for a comment on a PR. A previous commit fixed this problem in Firefox, but not Chrome. Fixes #16248 * Don't break Outdated badge This prevents the Outdated badge on a PR from wrapping in the middle of the word for a comment on a long filename. * Move word break to recommended element * Add overflow-wrap per PR review * Update web_src/less/helpers.less Co-authored-by: silverwind Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao --- templates/repo/issue/view_content/comments.tmpl | 4 ++-- web_src/less/helpers.less | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 1b88ae73934b..54df1c51fa5f 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -508,13 +508,13 @@ {{ range $filename, $lines := .Review.CodeComments}} {{range $line, $comms := $lines}}
-
+
{{$invalid := (index $comms 0).Invalidated}} {{$resolved := (index $comms 0).IsResolved}} {{$resolveDoer := (index $comms 0).ResolveDoer}} {{$isNotPending := (not (eq (index $comms 0).Review.Type 0))}}
- {{$filename}} + {{$filename}} {{if $invalid }} {{$.i18n.Tr "repo.issues.review.outdated"}} diff --git a/web_src/less/helpers.less b/web_src/less/helpers.less index 6904083da8b9..0c4bf1753af3 100644 --- a/web_src/less/helpers.less +++ b/web_src/less/helpers.less @@ -27,6 +27,8 @@ .word-break { word-wrap: break-word !important; + word-break: break-word; /* compat: Safari */ + overflow-wrap: anywhere; } .ellipsis { From 6d0240b2b3f829641967116bd39ca5090f0bf401 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Fri, 29 Apr 2022 12:26:52 +0200 Subject: [PATCH 15/27] Permalink files In PR diff (#19534) --- templates/repo/diff/box.tmpl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index b7135de59fdb..c3af6bbd1192 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -39,7 +39,7 @@
  - {{.Name}} + {{.Name}} {{end}} {{if .Diff.IsIncomplete}} @@ -57,7 +57,8 @@ {{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}} {{$isCsv := (call $.IsCsvFile $file)}} {{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}} -
+ {{$nameHash := Sha1 $file.Name}} +

- {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.i18n.Tr "repo.stored_lfs"}}){{end}} + {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.i18n.Tr "repo.stored_lfs"}}){{end}} {{if $file.IsGenerated}} {{$.i18n.Tr "repo.diff.generated"}} {{end}} From 7bcee58b13dc341b59cf19adfcfbe7b58d9eff16 Mon Sep 17 00:00:00 2001 From: Florin Hillebrand Date: Fri, 29 Apr 2022 14:24:38 +0200 Subject: [PATCH 16/27] Add API to query collaborators permission for a repository (#18761) Targeting #14936, #15332 Adds a collaborator permissions API endpoint according to GitHub API: https://docs.github.com/en/rest/collaborators/collaborators#get-repository-permissions-for-a-user to retrieve a collaborators permissions for a specific repository. ### Checks the repository permissions of a collaborator. `GET` `/repos/{owner}/{repo}/collaborators/{collaborator}/permission` Possible `permission` values are `admin`, `write`, `read`, `owner`, `none`. ```json { "permission": "admin", "role_name": "admin", "user": {} } ``` Where `permission` and `role_name` hold the same `permission` value and `user` is filled with the user API object. Only admins are allowed to use this API endpoint. --- integrations/api_repo_collaborator_test.go | 131 +++++++++++++++++++++ models/fixtures/user.yml | 32 +++++ modules/convert/user.go | 9 ++ modules/structs/repo_collaborator.go | 7 ++ routers/api/v1/api.go | 9 +- routers/api/v1/repo/collaborators.go | 55 +++++++++ routers/api/v1/swagger/repo.go | 7 ++ templates/swagger/v1_json.tmpl | 70 +++++++++++ 8 files changed, 317 insertions(+), 3 deletions(-) create mode 100644 integrations/api_repo_collaborator_test.go diff --git a/integrations/api_repo_collaborator_test.go b/integrations/api_repo_collaborator_test.go new file mode 100644 index 000000000000..fdca1d915024 --- /dev/null +++ b/integrations/api_repo_collaborator_test.go @@ -0,0 +1,131 @@ +// Copyright 2022 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 integrations + +import ( + "net/http" + "net/url" + "testing" + + "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" + api "code.gitea.io/gitea/modules/structs" + + "github.com/stretchr/testify/assert" +) + +func TestAPIRepoCollaboratorPermission(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository) + repo2Owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo2.OwnerID}).(*user_model.User) + + user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User) + user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User) + user10 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10}).(*user_model.User) + user11 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 11}).(*user_model.User) + + session := loginUser(t, repo2Owner.Name) + testCtx := NewAPITestContext(t, repo2Owner.Name, repo2.Name) + + t.Run("RepoOwnerShouldBeOwner", func(t *testing.T) { + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, repo2Owner.Name, testCtx.Token) + resp := session.MakeRequest(t, req, http.StatusOK) + + var repoPermission api.RepoCollaboratorPermission + DecodeJSON(t, resp, &repoPermission) + + assert.Equal(t, "owner", repoPermission.Permission) + }) + + t.Run("CollaboratorWithReadAccess", func(t *testing.T) { + t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeRead)) + + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user4.Name, testCtx.Token) + resp := session.MakeRequest(t, req, http.StatusOK) + + var repoPermission api.RepoCollaboratorPermission + DecodeJSON(t, resp, &repoPermission) + + assert.Equal(t, "read", repoPermission.Permission) + }) + + t.Run("CollaboratorWithWriteAccess", func(t *testing.T) { + t.Run("AddUserAsCollaboratorWithWriteAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeWrite)) + + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user4.Name, testCtx.Token) + resp := session.MakeRequest(t, req, http.StatusOK) + + var repoPermission api.RepoCollaboratorPermission + DecodeJSON(t, resp, &repoPermission) + + assert.Equal(t, "write", repoPermission.Permission) + }) + + t.Run("CollaboratorWithAdminAccess", func(t *testing.T) { + t.Run("AddUserAsCollaboratorWithAdminAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeAdmin)) + + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user4.Name, testCtx.Token) + resp := session.MakeRequest(t, req, http.StatusOK) + + var repoPermission api.RepoCollaboratorPermission + DecodeJSON(t, resp, &repoPermission) + + assert.Equal(t, "admin", repoPermission.Permission) + }) + + t.Run("CollaboratorNotFound", func(t *testing.T) { + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, "non-existent-user", testCtx.Token) + session.MakeRequest(t, req, http.StatusNotFound) + }) + + t.Run("CollaboratorCanQueryItsPermissions", func(t *testing.T) { + t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user5.Name, perm.AccessModeRead)) + + _session := loginUser(t, user5.Name) + _testCtx := NewAPITestContext(t, user5.Name, repo2.Name) + + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user5.Name, _testCtx.Token) + resp := _session.MakeRequest(t, req, http.StatusOK) + + var repoPermission api.RepoCollaboratorPermission + DecodeJSON(t, resp, &repoPermission) + + assert.Equal(t, "read", repoPermission.Permission) + }) + + t.Run("CollaboratorCanQueryItsPermissions", func(t *testing.T) { + t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user5.Name, perm.AccessModeRead)) + + _session := loginUser(t, user5.Name) + _testCtx := NewAPITestContext(t, user5.Name, repo2.Name) + + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user5.Name, _testCtx.Token) + resp := _session.MakeRequest(t, req, http.StatusOK) + + var repoPermission api.RepoCollaboratorPermission + DecodeJSON(t, resp, &repoPermission) + + assert.Equal(t, "read", repoPermission.Permission) + }) + + t.Run("RepoAdminCanQueryACollaboratorsPermissions", func(t *testing.T) { + t.Run("AddUserAsCollaboratorWithAdminAccess", doAPIAddCollaborator(testCtx, user10.Name, perm.AccessModeAdmin)) + t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user11.Name, perm.AccessModeRead)) + + _session := loginUser(t, user10.Name) + _testCtx := NewAPITestContext(t, user10.Name, repo2.Name) + + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user11.Name, _testCtx.Token) + resp := _session.MakeRequest(t, req, http.StatusOK) + + var repoPermission api.RepoCollaboratorPermission + DecodeJSON(t, resp, &repoPermission) + + assert.Equal(t, "read", repoPermission.Permission) + }) + }) +} diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 670b30562130..67ba869c76b0 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -4,6 +4,7 @@ id: 1 lower_name: user1 name: user1 + login_name: user1 full_name: User One email: user1@example.com email_notifications_preference: enabled @@ -21,6 +22,7 @@ id: 2 lower_name: user2 name: user2 + login_name: user2 full_name: " < Ur Tw >< " email: user2@example.com keep_email_private: true @@ -42,6 +44,7 @@ id: 3 lower_name: user3 name: user3 + login_name: user3 full_name: " <<<< >> >> > >> > >>> >> " email: user3@example.com email_notifications_preference: onmention @@ -60,6 +63,7 @@ id: 4 lower_name: user4 name: user4 + login_name: user4 full_name: " " email: user4@example.com email_notifications_preference: onmention @@ -78,6 +82,7 @@ id: 5 lower_name: user5 name: user5 + login_name: user5 full_name: User Five email: user5@example.com email_notifications_preference: enabled @@ -97,6 +102,7 @@ id: 6 lower_name: user6 name: user6 + login_name: user6 full_name: User Six email: user6@example.com email_notifications_preference: enabled @@ -115,6 +121,7 @@ id: 7 lower_name: user7 name: user7 + login_name: user7 full_name: User Seven email: user7@example.com email_notifications_preference: disabled @@ -133,6 +140,7 @@ id: 8 lower_name: user8 name: user8 + login_name: user8 full_name: User Eight email: user8@example.com email_notifications_preference: enabled @@ -152,6 +160,7 @@ id: 9 lower_name: user9 name: user9 + login_name: user9 full_name: User Nine email: user9@example.com email_notifications_preference: onmention @@ -169,6 +178,7 @@ id: 10 lower_name: user10 name: user10 + login_name: user10 full_name: User Ten email: user10@example.com passwd_hash_algo: argon2 @@ -185,6 +195,7 @@ id: 11 lower_name: user11 name: user11 + login_name: user11 full_name: User Eleven email: user11@example.com passwd_hash_algo: argon2 @@ -201,6 +212,7 @@ id: 12 lower_name: user12 name: user12 + login_name: user12 full_name: User 12 email: user12@example.com passwd_hash_algo: argon2 @@ -217,6 +229,7 @@ id: 13 lower_name: user13 name: user13 + login_name: user13 full_name: User 13 email: user13@example.com passwd_hash_algo: argon2 @@ -233,6 +246,7 @@ id: 14 lower_name: user14 name: user14 + login_name: user14 full_name: User 14 email: user14@example.com passwd_hash_algo: argon2 @@ -249,6 +263,7 @@ id: 15 lower_name: user15 name: user15 + login_name: user15 full_name: User 15 email: user15@example.com passwd_hash_algo: argon2 @@ -265,6 +280,7 @@ id: 16 lower_name: user16 name: user16 + login_name: user16 full_name: User 16 email: user16@example.com passwd_hash_algo: argon2 @@ -281,6 +297,7 @@ id: 17 lower_name: user17 name: user17 + login_name: user17 full_name: User 17 email: user17@example.com passwd_hash_algo: argon2 @@ -299,6 +316,7 @@ id: 18 lower_name: user18 name: user18 + login_name: user18 full_name: User 18 email: user18@example.com passwd_hash_algo: argon2 @@ -315,6 +333,7 @@ id: 19 lower_name: user19 name: user19 + login_name: user19 full_name: User 19 email: user19@example.com passwd_hash_algo: argon2 @@ -333,6 +352,7 @@ id: 20 lower_name: user20 name: user20 + login_name: user20 full_name: User 20 email: user20@example.com passwd_hash_algo: argon2 @@ -349,6 +369,7 @@ id: 21 lower_name: user21 name: user21 + login_name: user21 full_name: User 21 email: user21@example.com passwd_hash_algo: argon2 @@ -365,6 +386,7 @@ id: 22 lower_name: limited_org name: limited_org + login_name: limited_org full_name: Limited Org email: limited_org@example.com passwd_hash_algo: argon2 @@ -384,6 +406,7 @@ id: 23 lower_name: privated_org name: privated_org + login_name: privated_org full_name: Privated Org email: privated_org@example.com passwd_hash_algo: argon2 @@ -403,6 +426,7 @@ id: 24 lower_name: user24 name: user24 + login_name: user24 full_name: "user24" email: user24@example.com keep_email_private: true @@ -423,6 +447,7 @@ id: 25 lower_name: org25 name: org25 + login_name: org25 full_name: "org25" email: org25@example.com passwd_hash_algo: argon2 @@ -440,6 +465,7 @@ id: 26 lower_name: org26 name: org26 + login_name: org26 full_name: "Org26" email: org26@example.com email_notifications_preference: onmention @@ -459,6 +485,7 @@ id: 27 lower_name: user27 name: user27 + login_name: user27 full_name: User Twenty-Seven email: user27@example.com email_notifications_preference: enabled @@ -475,6 +502,7 @@ id: 28 lower_name: user28 name: user28 + login_name: user28 full_name: "user27" email: user28@example.com keep_email_private: true @@ -495,6 +523,7 @@ id: 29 lower_name: user29 name: user29 + login_name: user29 full_name: User 29 email: user29@example.com passwd_hash_algo: argon2 @@ -512,6 +541,7 @@ id: 30 lower_name: user30 name: user30 + login_name: user30 full_name: User Thirty email: user30@example.com passwd_hash_algo: argon2 @@ -530,6 +560,7 @@ id: 31 lower_name: user31 name: user31 + login_name: user31 full_name: "user31" email: user31@example.com passwd_hash_algo: argon2 @@ -547,6 +578,7 @@ id: 32 lower_name: user32 name: user32 + login_name: user32 full_name: User 32 (U2F test) email: user32@example.com passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password diff --git a/modules/convert/user.go b/modules/convert/user.go index dc4a8c49c776..2b07d21838d7 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -95,3 +95,12 @@ func User2UserSettings(user *user_model.User) api.UserSettings { DiffViewStyle: user.DiffViewStyle, } } + +// ToUserAndPermission return User and its collaboration permission for a repository +func ToUserAndPermission(user, doer *user_model.User, accessMode perm.AccessMode) api.RepoCollaboratorPermission { + return api.RepoCollaboratorPermission{ + User: ToUser(user, doer), + Permission: accessMode.String(), + RoleName: accessMode.String(), + } +} diff --git a/modules/structs/repo_collaborator.go b/modules/structs/repo_collaborator.go index 2b4fa390d2b2..2f9c8992a168 100644 --- a/modules/structs/repo_collaborator.go +++ b/modules/structs/repo_collaborator.go @@ -8,3 +8,10 @@ package structs type AddCollaboratorOption struct { Permission *string `json:"permission"` } + +// RepoCollaboratorPermission to get repository permission for a collaborator +type RepoCollaboratorPermission struct { + Permission string `json:"permission"` + RoleName string `json:"role_name"` + User *User `json:"user"` +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 782500e6c86f..9351cc1510ff 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -810,9 +810,12 @@ func Routes() *web.Route { }, reqToken(), reqAdmin(), reqWebhooksEnabled()) m.Group("/collaborators", func() { m.Get("", reqAnyRepoReader(), repo.ListCollaborators) - m.Combo("/{collaborator}").Get(reqAnyRepoReader(), repo.IsCollaborator). - Put(reqAdmin(), bind(api.AddCollaboratorOption{}), repo.AddCollaborator). - Delete(reqAdmin(), repo.DeleteCollaborator) + m.Group("/{collaborator}", func() { + m.Combo("").Get(reqAnyRepoReader(), repo.IsCollaborator). + Put(reqAdmin(), bind(api.AddCollaboratorOption{}), repo.AddCollaborator). + Delete(reqAdmin(), repo.DeleteCollaborator) + m.Get("/permission", repo.GetRepoPermissions) + }, reqToken()) }, reqToken()) m.Get("/assignees", reqToken(), reqAnyRepoReader(), repo.GetAssignees) m.Get("/reviewers", reqToken(), reqAnyRepoReader(), repo.GetReviewers) diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index 3bb6113d772a..2db1724b2a9f 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -233,6 +233,61 @@ func DeleteCollaborator(ctx *context.APIContext) { ctx.Status(http.StatusNoContent) } +// GetRepoPermissions gets repository permissions for a user +func GetRepoPermissions(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/collaborators/{collaborator}/permission repository repoGetRepoPermissions + // --- + // summary: Get repository permissions for a user + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: collaborator + // in: path + // description: username of the collaborator + // type: string + // required: true + // responses: + // "200": + // "$ref": "#/responses/RepoCollaboratorPermission" + // "404": + // "$ref": "#/responses/notFound" + // "403": + // "$ref": "#/responses/forbidden" + + if !ctx.Doer.IsAdmin && ctx.Doer.LoginName != ctx.Params(":collaborator") && !ctx.IsUserRepoAdmin() { + ctx.Error(http.StatusForbidden, "User", "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own") + return + } + + collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator")) + if err != nil { + if user_model.IsErrUserNotExist(err) { + ctx.Error(http.StatusNotFound, "GetUserByName", err) + } else { + ctx.Error(http.StatusInternalServerError, "GetUserByName", err) + } + return + } + + permission, err := models.GetUserRepoPermission(ctx, ctx.Repo.Repository, collaborator) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err) + return + } + + ctx.JSON(http.StatusOK, convert.ToUserAndPermission(collaborator, ctx.ContextUser, permission.AccessMode)) +} + // GetReviewers return all users that can be requested to review in this repo func GetReviewers(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/reviewers repository repoGetReviewers diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index 40aeca677de8..ab802db7812f 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -344,3 +344,10 @@ type swaggerWikiCommitList struct { // in:body Body api.WikiCommitList `json:"body"` } + +// RepoCollaboratorPermission +// swagger:response RepoCollaboratorPermission +type swaggerRepoCollaboratorPermission struct { + // in:body + Body api.RepoCollaboratorPermission `json:"body"` +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index d57a3a580b92..3e4813f22cfb 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3129,6 +3129,52 @@ } } }, + "/repos/{owner}/{repo}/collaborators/{collaborator}/permission": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Get repository permissions for a user", + "operationId": "repoGetRepoPermissions", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "username of the collaborator", + "name": "collaborator", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/RepoCollaboratorPermission" + }, + "403": { + "$ref": "#/responses/forbidden" + }, + "404": { + "$ref": "#/responses/notFound" + } + } + } + }, "/repos/{owner}/{repo}/commits": { "get": { "produces": [ @@ -17451,6 +17497,24 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "RepoCollaboratorPermission": { + "description": "RepoCollaboratorPermission to get repository permission for a collaborator", + "type": "object", + "properties": { + "permission": { + "type": "string", + "x-go-name": "Permission" + }, + "role_name": { + "type": "string", + "x-go-name": "RoleName" + }, + "user": { + "$ref": "#/definitions/User" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "RepoCommit": { "type": "object", "title": "RepoCommit contains information of a commit in the context of a repository.", @@ -19126,6 +19190,12 @@ } } }, + "RepoCollaboratorPermission": { + "description": "RepoCollaboratorPermission", + "schema": { + "$ref": "#/definitions/RepoCollaboratorPermission" + } + }, "Repository": { "description": "Repository", "schema": { From a0c79fb144325b8f6cdaea455665681212f6e530 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 29 Apr 2022 16:39:27 +0200 Subject: [PATCH 17/27] Mute link in diff header (#19556) Followup to https://github.com/go-gitea/gitea/pull/19534. Make the link render in color only on hover. --- templates/repo/diff/box.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index c3af6bbd1192..6f67f36422ec 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -77,7 +77,7 @@ {{template "repo/diff/stats" dict "file" . "root" $}} {{end}}

- {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.i18n.Tr "repo.stored_lfs"}}){{end}} + {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.i18n.Tr "repo.stored_lfs"}}){{end}} {{if $file.IsGenerated}} {{$.i18n.Tr "repo.diff.generated"}} {{end}} From 0f9f73d516bb5d6a318ee3d34ca6d54c7df7cd4e Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Fri, 29 Apr 2022 21:38:11 +0200 Subject: [PATCH 18/27] Respect DefaultUserIsRestricted system default when creating new user (#19310) * Apply DefaultUserIsRestricted in CreateUser * Enforce system defaults in CreateUser Allow for overwrites with CreateUserOverwriteOptions * Fix compilation errors * Add "restricted" option to create user command * Add "restricted" option to create user admin api * Respect default setting.Service.RegisterEmailConfirm and setting.Service.RegisterManualConfirm where needed * Revert "Respect default setting.Service.RegisterEmailConfirm and setting.Service.RegisterManualConfirm where needed" This reverts commit ee95d3e8dc9e9fff4fa66a5111e4d3930280e033. --- cmd/admin.go | 20 ++++++++-- models/user/user.go | 37 ++++++++++++++++++- modules/structs/admin_user.go | 1 + routers/api/v1/admin/user.go | 16 +++++--- routers/install/install.go | 16 +++++--- routers/web/admin/users.go | 8 +++- routers/web/auth/auth.go | 18 ++++----- routers/web/auth/linkaccount.go | 3 +- routers/web/auth/oauth.go | 21 ++++++----- routers/web/auth/openid.go | 9 ++--- services/auth/reverseproxy.go | 13 +++++-- .../auth/source/ldap/source_authenticate.go | 25 +++++++------ services/auth/source/ldap/source_sync.go | 25 +++++++------ .../auth/source/pam/source_authenticate.go | 7 +++- .../auth/source/smtp/source_authenticate.go | 6 ++- services/auth/sspi_windows.go | 26 +++++++------ templates/swagger/v1_json.tmpl | 4 ++ 17 files changed, 170 insertions(+), 85 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index e4a254c61390..36cac50a47fb 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -25,6 +25,7 @@ import ( repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/storage" + "code.gitea.io/gitea/modules/util" auth_service "code.gitea.io/gitea/services/auth" "code.gitea.io/gitea/services/auth/source/oauth2" "code.gitea.io/gitea/services/auth/source/smtp" @@ -114,6 +115,10 @@ var ( Name: "access-token", Usage: "Generate access token for the user", }, + cli.BoolFlag{ + Name: "restricted", + Usage: "Make a restricted user account", + }, }, } @@ -559,17 +564,26 @@ func runCreateUser(c *cli.Context) error { changePassword = c.Bool("must-change-password") } + restricted := util.OptionalBoolNone + + if c.IsSet("restricted") { + restricted = util.OptionalBoolOf(c.Bool("restricted")) + } + u := &user_model.User{ Name: username, Email: c.String("email"), Passwd: password, - IsActive: true, IsAdmin: c.Bool("admin"), MustChangePassword: changePassword, - Theme: setting.UI.DefaultTheme, } - if err := user_model.CreateUser(u); err != nil { + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsActive: util.OptionalBoolTrue, + IsRestricted: restricted, + } + + if err := user_model.CreateUser(u, overwriteDefault); err != nil { return fmt.Errorf("CreateUser: %v", err) } diff --git a/models/user/user.go b/models/user/user.go index c84889523918..5b556c988414 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -621,7 +621,14 @@ func IsUsableUsername(name string) error { // CreateUserOverwriteOptions are an optional options who overwrite system defaults on user creation type CreateUserOverwriteOptions struct { - Visibility structs.VisibleType + KeepEmailPrivate util.OptionalBool + Visibility *structs.VisibleType + AllowCreateOrganization util.OptionalBool + EmailNotificationsPreference *string + MaxRepoCreation *int + Theme *string + IsRestricted util.OptionalBool + IsActive util.OptionalBool } // CreateUser creates record of a new user. @@ -637,10 +644,36 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e u.EmailNotificationsPreference = setting.Admin.DefaultEmailNotification u.MaxRepoCreation = -1 u.Theme = setting.UI.DefaultTheme + u.IsRestricted = setting.Service.DefaultUserIsRestricted + u.IsActive = !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm) // overwrite defaults if set if len(overwriteDefault) != 0 && overwriteDefault[0] != nil { - u.Visibility = overwriteDefault[0].Visibility + overwrite := overwriteDefault[0] + if !overwrite.KeepEmailPrivate.IsNone() { + u.KeepEmailPrivate = overwrite.KeepEmailPrivate.IsTrue() + } + if overwrite.Visibility != nil { + u.Visibility = *overwrite.Visibility + } + if !overwrite.AllowCreateOrganization.IsNone() { + u.AllowCreateOrganization = overwrite.AllowCreateOrganization.IsTrue() + } + if overwrite.EmailNotificationsPreference != nil { + u.EmailNotificationsPreference = *overwrite.EmailNotificationsPreference + } + if overwrite.MaxRepoCreation != nil { + u.MaxRepoCreation = *overwrite.MaxRepoCreation + } + if overwrite.Theme != nil { + u.Theme = *overwrite.Theme + } + if !overwrite.IsRestricted.IsNone() { + u.IsRestricted = overwrite.IsRestricted.IsTrue() + } + if !overwrite.IsActive.IsNone() { + u.IsActive = overwrite.IsActive.IsTrue() + } } // validate data diff --git a/modules/structs/admin_user.go b/modules/structs/admin_user.go index facf16a39552..eccbf29a46f0 100644 --- a/modules/structs/admin_user.go +++ b/modules/structs/admin_user.go @@ -19,6 +19,7 @@ type CreateUserOption struct { Password string `json:"password" binding:"Required;MaxSize(255)"` MustChangePassword *bool `json:"must_change_password"` SendNotify bool `json:"send_notify"` + Restricted *bool `json:"restricted"` Visibility string `json:"visibility" binding:"In(,public,limited,private)"` } diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index bf176f95710b..775802449abb 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -22,6 +22,7 @@ import ( "code.gitea.io/gitea/modules/password" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/api/v1/user" "code.gitea.io/gitea/routers/api/v1/utils" @@ -82,7 +83,6 @@ func CreateUser(ctx *context.APIContext) { Email: form.Email, Passwd: form.Password, MustChangePassword: true, - IsActive: true, LoginType: auth.Plain, } if form.MustChangePassword != nil { @@ -108,11 +108,17 @@ func CreateUser(ctx *context.APIContext) { return } - var overwriteDefault *user_model.CreateUserOverwriteOptions + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsActive: util.OptionalBoolTrue, + } + + if form.Restricted != nil { + overwriteDefault.IsRestricted = util.OptionalBoolOf(*form.Restricted) + } + if form.Visibility != "" { - overwriteDefault = &user_model.CreateUserOverwriteOptions{ - Visibility: api.VisibilityModes[form.Visibility], - } + visibility := api.VisibilityModes[form.Visibility] + overwriteDefault.Visibility = &visibility } if err := user_model.CreateUser(u, overwriteDefault); err != nil { diff --git a/routers/install/install.go b/routers/install/install.go index ec1719439f53..9d28bc1571ac 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -499,13 +499,17 @@ func SubmitInstall(ctx *context.Context) { // Create admin account if len(form.AdminName) > 0 { u := &user_model.User{ - Name: form.AdminName, - Email: form.AdminEmail, - Passwd: form.AdminPasswd, - IsAdmin: true, - IsActive: true, + Name: form.AdminName, + Email: form.AdminEmail, + Passwd: form.AdminPasswd, + IsAdmin: true, } - if err = user_model.CreateUser(u); err != nil { + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsRestricted: util.OptionalBoolFalse, + IsActive: util.OptionalBoolTrue, + } + + if err = user_model.CreateUser(u, overwriteDefault); err != nil { if !user_model.IsErrUserAlreadyExist(err) { setting.InstallLock = false ctx.Data["Err_AdminName"] = true diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index fcfea5380128..57da319d794b 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -125,10 +125,14 @@ func NewUserPost(ctx *context.Context) { Name: form.UserName, Email: form.Email, Passwd: form.Password, - IsActive: true, LoginType: auth.Plain, } + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsActive: util.OptionalBoolTrue, + Visibility: &form.Visibility, + } + if len(form.LoginType) > 0 { fields := strings.Split(form.LoginType, "-") if len(fields) == 2 { @@ -163,7 +167,7 @@ func NewUserPost(ctx *context.Context) { u.MustChangePassword = form.MustChangePassword } - if err := user_model.CreateUser(u, &user_model.CreateUserOverwriteOptions{Visibility: form.Visibility}); err != nil { + if err := user_model.CreateUser(u, overwriteDefault); err != nil { switch { case user_model.IsErrUserAlreadyExist(err): ctx.Data["Err_UserName"] = true diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index c82fde49eb2f..e8250616abdf 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -507,14 +507,12 @@ func SignUpPost(ctx *context.Context) { } u := &user_model.User{ - Name: form.UserName, - Email: form.Email, - Passwd: form.Password, - IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm), - IsRestricted: setting.Service.DefaultUserIsRestricted, + Name: form.UserName, + Email: form.Email, + Passwd: form.Password, } - if !createAndHandleCreatedUser(ctx, tplSignUp, form, u, nil, false) { + if !createAndHandleCreatedUser(ctx, tplSignUp, form, u, nil, nil, false) { // error already handled return } @@ -525,8 +523,8 @@ func SignUpPost(ctx *context.Context) { // createAndHandleCreatedUser calls createUserInContext and // then handleUserCreated. -func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) bool { - if !createUserInContext(ctx, tpl, form, u, gothUser, allowLink) { +func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, overwrites *user_model.CreateUserOverwriteOptions, gothUser *goth.User, allowLink bool) bool { + if !createUserInContext(ctx, tpl, form, u, overwrites, gothUser, allowLink) { return false } return handleUserCreated(ctx, u, gothUser) @@ -534,8 +532,8 @@ func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form int // createUserInContext creates a user and handles errors within a given context. // Optionally a template can be specified. -func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) (ok bool) { - if err := user_model.CreateUser(u); err != nil { +func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, overwrites *user_model.CreateUserOverwriteOptions, gothUser *goth.User, allowLink bool) (ok bool) { + if err := user_model.CreateUser(u, overwrites); err != nil { if allowLink && (user_model.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) { if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingAuto { var user *user_model.User diff --git a/routers/web/auth/linkaccount.go b/routers/web/auth/linkaccount.go index bf5fb83265ba..c3e96f077a87 100644 --- a/routers/web/auth/linkaccount.go +++ b/routers/web/auth/linkaccount.go @@ -283,13 +283,12 @@ func LinkAccountPostRegister(ctx *context.Context) { Name: form.UserName, Email: form.Email, Passwd: form.Password, - IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm), LoginType: auth.OAuth2, LoginSource: authSource.ID, LoginName: gothUser.UserID, } - if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, &gothUser, false) { + if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, nil, &gothUser, false) { // error already handled return } diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index 12de208ad7bc..4c3e3c3ace39 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -24,6 +24,7 @@ import ( "code.gitea.io/gitea/modules/session" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web/middleware" auth_service "code.gitea.io/gitea/services/auth" @@ -867,19 +868,21 @@ func SignInOAuthCallback(ctx *context.Context) { return } u = &user_model.User{ - Name: getUserName(&gothUser), - FullName: gothUser.Name, - Email: gothUser.Email, - IsActive: !setting.OAuth2Client.RegisterEmailConfirm, - LoginType: auth.OAuth2, - LoginSource: authSource.ID, - LoginName: gothUser.UserID, - IsRestricted: setting.Service.DefaultUserIsRestricted, + Name: getUserName(&gothUser), + FullName: gothUser.Name, + Email: gothUser.Email, + LoginType: auth.OAuth2, + LoginSource: authSource.ID, + LoginName: gothUser.UserID, + } + + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsActive: util.OptionalBoolOf(!setting.OAuth2Client.RegisterEmailConfirm), } setUserGroupClaims(authSource, u, &gothUser) - if !createAndHandleCreatedUser(ctx, base.TplName(""), nil, u, &gothUser, setting.OAuth2Client.AccountLinking != setting.OAuth2AccountLinkingDisabled) { + if !createAndHandleCreatedUser(ctx, base.TplName(""), nil, u, overwriteDefault, &gothUser, setting.OAuth2Client.AccountLinking != setting.OAuth2AccountLinkingDisabled) { // error already handled return } diff --git a/routers/web/auth/openid.go b/routers/web/auth/openid.go index f3189887a530..3012d8c5a55e 100644 --- a/routers/web/auth/openid.go +++ b/routers/web/auth/openid.go @@ -423,12 +423,11 @@ func RegisterOpenIDPost(ctx *context.Context) { } u := &user_model.User{ - Name: form.UserName, - Email: form.Email, - Passwd: password, - IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm), + Name: form.UserName, + Email: form.Email, + Passwd: password, } - if !createUserInContext(ctx, tplSignUpOID, form, u, nil, false) { + if !createUserInContext(ctx, tplSignUpOID, form, u, nil, nil, false) { // error already handled return } diff --git a/services/auth/reverseproxy.go b/services/auth/reverseproxy.go index 1b151f6504e3..299d7abd34ae 100644 --- a/services/auth/reverseproxy.go +++ b/services/auth/reverseproxy.go @@ -12,6 +12,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/mailer" @@ -105,11 +106,15 @@ func (r *ReverseProxy) newUser(req *http.Request) *user_model.User { } user := &user_model.User{ - Name: username, - Email: email, - IsActive: true, + Name: username, + Email: email, } - if err := user_model.CreateUser(user); err != nil { + + overwriteDefault := user_model.CreateUserOverwriteOptions{ + IsActive: util.OptionalBoolTrue, + } + + if err := user_model.CreateUser(user, &overwriteDefault); err != nil { // FIXME: should I create a system notice? log.Error("CreateUser: %v", err) return nil diff --git a/services/auth/source/ldap/source_authenticate.go b/services/auth/source/ldap/source_authenticate.go index ddd70627ed3f..d8d11f18e1ef 100644 --- a/services/auth/source/ldap/source_authenticate.go +++ b/services/auth/source/ldap/source_authenticate.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/mailer" user_service "code.gitea.io/gitea/services/user" ) @@ -85,19 +86,21 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str } user = &user_model.User{ - LowerName: strings.ToLower(sr.Username), - Name: sr.Username, - FullName: composeFullName(sr.Name, sr.Surname, sr.Username), - Email: sr.Mail, - LoginType: source.authSource.Type, - LoginSource: source.authSource.ID, - LoginName: userName, - IsActive: true, - IsAdmin: sr.IsAdmin, - IsRestricted: sr.IsRestricted, + LowerName: strings.ToLower(sr.Username), + Name: sr.Username, + FullName: composeFullName(sr.Name, sr.Surname, sr.Username), + Email: sr.Mail, + LoginType: source.authSource.Type, + LoginSource: source.authSource.ID, + LoginName: userName, + IsAdmin: sr.IsAdmin, + } + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsRestricted: util.OptionalBoolOf(sr.IsRestricted), + IsActive: util.OptionalBoolTrue, } - err := user_model.CreateUser(user) + err := user_model.CreateUser(user, overwriteDefault) if err != nil { return user, err } diff --git a/services/auth/source/ldap/source_sync.go b/services/auth/source/ldap/source_sync.go index 65efed78c17c..a245f4c6ff0d 100644 --- a/services/auth/source/ldap/source_sync.go +++ b/services/auth/source/ldap/source_sync.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models/organization" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/util" user_service "code.gitea.io/gitea/services/user" ) @@ -102,19 +103,21 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error { log.Trace("SyncExternalUsers[%s]: Creating user %s", source.authSource.Name, su.Username) usr = &user_model.User{ - LowerName: su.LowerName, - Name: su.Username, - FullName: fullName, - LoginType: source.authSource.Type, - LoginSource: source.authSource.ID, - LoginName: su.Username, - Email: su.Mail, - IsAdmin: su.IsAdmin, - IsRestricted: su.IsRestricted, - IsActive: true, + LowerName: su.LowerName, + Name: su.Username, + FullName: fullName, + LoginType: source.authSource.Type, + LoginSource: source.authSource.ID, + LoginName: su.Username, + Email: su.Mail, + IsAdmin: su.IsAdmin, + } + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsRestricted: util.OptionalBoolOf(su.IsRestricted), + IsActive: util.OptionalBoolTrue, } - err = user_model.CreateUser(usr) + err = user_model.CreateUser(usr, overwriteDefault) if err != nil { log.Error("SyncExternalUsers[%s]: Error creating user %s: %v", source.authSource.Name, su.Username, err) diff --git a/services/auth/source/pam/source_authenticate.go b/services/auth/source/pam/source_authenticate.go index d5bd9409963f..16ddc0598e47 100644 --- a/services/auth/source/pam/source_authenticate.go +++ b/services/auth/source/pam/source_authenticate.go @@ -12,6 +12,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/auth/pam" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/mailer" "github.com/google/uuid" @@ -58,10 +59,12 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str LoginType: auth.PAM, LoginSource: source.authSource.ID, LoginName: userName, // This is what the user typed in - IsActive: true, + } + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsActive: util.OptionalBoolTrue, } - if err := user_model.CreateUser(user); err != nil { + if err := user_model.CreateUser(user, overwriteDefault); err != nil { return user, err } diff --git a/services/auth/source/smtp/source_authenticate.go b/services/auth/source/smtp/source_authenticate.go index 3be2f1128de2..dff24d494ee0 100644 --- a/services/auth/source/smtp/source_authenticate.go +++ b/services/auth/source/smtp/source_authenticate.go @@ -74,10 +74,12 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str LoginType: auth_model.SMTP, LoginSource: source.authSource.ID, LoginName: userName, - IsActive: true, + } + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsActive: util.OptionalBoolTrue, } - if err := user_model.CreateUser(user); err != nil { + if err := user_model.CreateUser(user, overwriteDefault); err != nil { return user, err } diff --git a/services/auth/sspi_windows.go b/services/auth/sspi_windows.go index 63e70e61d433..9bc4041a74ac 100644 --- a/services/auth/sspi_windows.go +++ b/services/auth/sspi_windows.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/auth/source/sspi" "code.gitea.io/gitea/services/mailer" @@ -187,17 +188,20 @@ func (s *SSPI) shouldAuthenticate(req *http.Request) (shouldAuth bool) { func (s *SSPI) newUser(username string, cfg *sspi.Source) (*user_model.User, error) { email := gouuid.New().String() + "@localhost.localdomain" user := &user_model.User{ - Name: username, - Email: email, - KeepEmailPrivate: true, - Passwd: gouuid.New().String(), - IsActive: cfg.AutoActivateUsers, - Language: cfg.DefaultLanguage, - UseCustomAvatar: true, - Avatar: avatars.DefaultAvatarLink(), - EmailNotificationsPreference: user_model.EmailNotificationsDisabled, - } - if err := user_model.CreateUser(user); err != nil { + Name: username, + Email: email, + Passwd: gouuid.New().String(), + Language: cfg.DefaultLanguage, + UseCustomAvatar: true, + Avatar: avatars.DefaultAvatarLink(), + } + emailNotificationPreference := user_model.EmailNotificationsDisabled + overwriteDefault := &user_model.CreateUserOverwriteOptions{ + IsActive: util.OptionalBoolOf(cfg.AutoActivateUsers), + KeepEmailPrivate: util.OptionalBoolTrue, + EmailNotificationsPreference: &emailNotificationPreference, + } + if err := user_model.CreateUser(user, overwriteDefault); err != nil { return nil, err } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 3e4813f22cfb..20e80967bcee 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -14471,6 +14471,10 @@ "type": "string", "x-go-name": "Password" }, + "restricted": { + "type": "boolean", + "x-go-name": "Restricted" + }, "send_notify": { "type": "boolean", "x-go-name": "SendNotify" From a257cd46e2799a9f329d9b286beabc7076998b53 Mon Sep 17 00:00:00 2001 From: GiteaBot Date: Sat, 30 Apr 2022 00:10:15 +0000 Subject: [PATCH 19/27] [skip ci] Updated translations via Crowdin --- options/locale/locale_pt-PT.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/options/locale/locale_pt-PT.ini b/options/locale/locale_pt-PT.ini index 1780f4fa2ec7..d8801f7517b9 100644 --- a/options/locale/locale_pt-PT.ini +++ b/options/locale/locale_pt-PT.ini @@ -1486,6 +1486,8 @@ pulls.desc=Habilitar pedidos de integração e revisão de código. pulls.new=Novo pedido de integração pulls.view=Ver pedido de integração pulls.compare_changes=Novo pedido de integração +pulls.allow_edits_from_maintainers_desc=Utilizadores com acesso de escrita no ramo base também podem fazer envios para este ramo +pulls.allow_edits_from_maintainers_err=Não foi possível fazer a modificação pulls.compare_changes_desc=Escolha o ramo de destino e o ramo de origem. pulls.compare_base=integrar em pulls.compare_compare=puxar de From 9a4deffeeca980ad12ecd7208681e719c7457f99 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 30 Apr 2022 14:50:56 +0200 Subject: [PATCH 20/27] fix #19545 (#19563) --- modules/repository/repo.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/repository/repo.go b/modules/repository/repo.go index 0dffa322d056..30ca6fdff84e 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -93,7 +93,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err) } - if err = git.Clone(ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{ + if err := git.Clone(ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{ Mirror: true, Quiet: true, Timeout: migrateTimeout, @@ -104,11 +104,12 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, if err := util.RemoveAll(wikiPath); err != nil { return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err) } + } else { + if err := git.WriteCommitGraph(ctx, wikiPath); err != nil { + return repo, err + } } } - if err := git.WriteCommitGraph(ctx, wikiPath); err != nil { - return repo, err - } } if repo.OwnerID == u.ID { From 577710cd89a31cb5e65eea2c94a3da0ef8b7e994 Mon Sep 17 00:00:00 2001 From: Ivan Fedorov Date: Sat, 30 Apr 2022 16:40:55 +0300 Subject: [PATCH 21/27] Added X-Mailer header to outgoing emails (#19562) - It's a non-standard mentioned in https://www.ietf.org/rfc/rfc2076.html#section-3.4 - This header makes emails filtering easier --- services/mailer/mail.go | 1 + 1 file changed, 1 insertion(+) diff --git a/services/mailer/mail.go b/services/mailer/mail.go index a5b60f71ec31..bdd7e25cabd4 100644 --- a/services/mailer/mail.go +++ b/services/mailer/mail.go @@ -367,6 +367,7 @@ func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient //"List-Post": https://github.com/go-gitea/gitea/pull/13585 "List-Unsubscribe": ctx.Issue.HTMLURL(), + "X-Mailer": "Gitea", "X-Gitea-Reason": reason, "X-Gitea-Sender": ctx.Doer.DisplayName(), "X-Gitea-Recipient": recipient.DisplayName(), From 9da61e395ed7ed524fb02b537003a0f913810bb1 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 30 Apr 2022 16:32:01 +0200 Subject: [PATCH 22/27] Use middleware to open gitRepo (#19559) --- routers/api/v1/api.go | 2 +- routers/api/v1/utils/git.go | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 9351cc1510ff..ce0719ddd85f 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1014,7 +1014,7 @@ func Routes() *web.Route { m.Group("/{ref}", func() { m.Get("/status", repo.GetCombinedCommitStatusByRef) m.Get("/statuses", repo.GetCommitStatusesByRef) - }) + }, context.ReferencesGitRepo()) }, reqRepoReader(unit.TypeCode)) m.Group("/git", func() { m.Group("/commits", func() { diff --git a/routers/api/v1/utils/git.go b/routers/api/v1/utils/git.go index 9f02bc8083f9..ac64d5b87bfe 100644 --- a/routers/api/v1/utils/git.go +++ b/routers/api/v1/utils/git.go @@ -5,6 +5,7 @@ package utils import ( + "fmt" "net/http" "code.gitea.io/gitea/modules/context" @@ -35,12 +36,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string { // GetGitRefs return git references based on filter func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) { if ctx.Repo.GitRepo == nil { - var err error - ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) - if err != nil { - return nil, "OpenRepository", err - } - defer ctx.Repo.GitRepo.Close() + return nil, "", fmt.Errorf("no open git repo found in context") } if len(filter) > 0 { filter = "refs/" + filter From 9d0048ffe914ae3245e179e75d16a630f220361f Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 1 May 2022 00:27:40 +0200 Subject: [PATCH 23/27] Add comments for display: none --- web_src/less/_repository.less | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 4450f552b57c..06b9b90544dd 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -861,6 +861,7 @@ } } + /* Don't show the inline timeline avatar on desktop. */ .inline-timeline-avatar { display: none; } @@ -3319,6 +3320,8 @@ td.blob-excerpt { padding-left: 4px; } + /* Don't show the general avatar, we show the inline avatar on mobile. + * And don't show the role labels, there's no place for that. */ .timeline-avatar, .comment-header-right .role-label { display: none; From e413709a6858837adf4ceadb5ee8765108b1c18a Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 1 May 2022 00:39:15 +0200 Subject: [PATCH 24/27] Revert broken commits --- cmd/admin.go | 20 +-- integrations/api_repo_collaborator_test.go | 131 ------------------ models/fixtures/user.yml | 32 ----- models/user/user.go | 37 +---- modules/convert/user.go | 9 -- modules/repository/repo.go | 9 +- modules/structs/admin_user.go | 1 - modules/structs/repo_collaborator.go | 7 - options/locale/locale_pt-PT.ini | 2 - routers/api/v1/admin/user.go | 16 +-- routers/api/v1/api.go | 11 +- routers/api/v1/repo/branch.go | 10 +- routers/api/v1/repo/collaborators.go | 55 -------- routers/api/v1/swagger/repo.go | 7 - routers/api/v1/utils/git.go | 8 +- routers/install/install.go | 16 +-- routers/web/admin/users.go | 8 +- routers/web/auth/auth.go | 18 +-- routers/web/auth/linkaccount.go | 3 +- routers/web/auth/oauth.go | 21 ++- routers/web/auth/openid.go | 9 +- services/auth/reverseproxy.go | 13 +- .../auth/source/ldap/source_authenticate.go | 25 ++-- services/auth/source/ldap/source_sync.go | 25 ++-- .../auth/source/pam/source_authenticate.go | 7 +- .../auth/source/smtp/source_authenticate.go | 6 +- services/auth/sspi_windows.go | 26 ++-- services/mailer/mail.go | 1 - templates/repo/diff/box.tmpl | 7 +- .../repo/issue/view_content/comments.tmpl | 4 +- templates/swagger/v1_json.tmpl | 74 ---------- web_src/less/helpers.less | 2 - 32 files changed, 106 insertions(+), 514 deletions(-) delete mode 100644 integrations/api_repo_collaborator_test.go diff --git a/cmd/admin.go b/cmd/admin.go index 36cac50a47fb..e4a254c61390 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -25,7 +25,6 @@ import ( repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/storage" - "code.gitea.io/gitea/modules/util" auth_service "code.gitea.io/gitea/services/auth" "code.gitea.io/gitea/services/auth/source/oauth2" "code.gitea.io/gitea/services/auth/source/smtp" @@ -115,10 +114,6 @@ var ( Name: "access-token", Usage: "Generate access token for the user", }, - cli.BoolFlag{ - Name: "restricted", - Usage: "Make a restricted user account", - }, }, } @@ -564,26 +559,17 @@ func runCreateUser(c *cli.Context) error { changePassword = c.Bool("must-change-password") } - restricted := util.OptionalBoolNone - - if c.IsSet("restricted") { - restricted = util.OptionalBoolOf(c.Bool("restricted")) - } - u := &user_model.User{ Name: username, Email: c.String("email"), Passwd: password, + IsActive: true, IsAdmin: c.Bool("admin"), MustChangePassword: changePassword, + Theme: setting.UI.DefaultTheme, } - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsActive: util.OptionalBoolTrue, - IsRestricted: restricted, - } - - if err := user_model.CreateUser(u, overwriteDefault); err != nil { + if err := user_model.CreateUser(u); err != nil { return fmt.Errorf("CreateUser: %v", err) } diff --git a/integrations/api_repo_collaborator_test.go b/integrations/api_repo_collaborator_test.go deleted file mode 100644 index fdca1d915024..000000000000 --- a/integrations/api_repo_collaborator_test.go +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2022 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 integrations - -import ( - "net/http" - "net/url" - "testing" - - "code.gitea.io/gitea/models/perm" - repo_model "code.gitea.io/gitea/models/repo" - "code.gitea.io/gitea/models/unittest" - user_model "code.gitea.io/gitea/models/user" - api "code.gitea.io/gitea/modules/structs" - - "github.com/stretchr/testify/assert" -) - -func TestAPIRepoCollaboratorPermission(t *testing.T) { - onGiteaRun(t, func(t *testing.T, u *url.URL) { - repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository) - repo2Owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo2.OwnerID}).(*user_model.User) - - user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User) - user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User) - user10 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10}).(*user_model.User) - user11 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 11}).(*user_model.User) - - session := loginUser(t, repo2Owner.Name) - testCtx := NewAPITestContext(t, repo2Owner.Name, repo2.Name) - - t.Run("RepoOwnerShouldBeOwner", func(t *testing.T) { - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, repo2Owner.Name, testCtx.Token) - resp := session.MakeRequest(t, req, http.StatusOK) - - var repoPermission api.RepoCollaboratorPermission - DecodeJSON(t, resp, &repoPermission) - - assert.Equal(t, "owner", repoPermission.Permission) - }) - - t.Run("CollaboratorWithReadAccess", func(t *testing.T) { - t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeRead)) - - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user4.Name, testCtx.Token) - resp := session.MakeRequest(t, req, http.StatusOK) - - var repoPermission api.RepoCollaboratorPermission - DecodeJSON(t, resp, &repoPermission) - - assert.Equal(t, "read", repoPermission.Permission) - }) - - t.Run("CollaboratorWithWriteAccess", func(t *testing.T) { - t.Run("AddUserAsCollaboratorWithWriteAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeWrite)) - - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user4.Name, testCtx.Token) - resp := session.MakeRequest(t, req, http.StatusOK) - - var repoPermission api.RepoCollaboratorPermission - DecodeJSON(t, resp, &repoPermission) - - assert.Equal(t, "write", repoPermission.Permission) - }) - - t.Run("CollaboratorWithAdminAccess", func(t *testing.T) { - t.Run("AddUserAsCollaboratorWithAdminAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeAdmin)) - - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user4.Name, testCtx.Token) - resp := session.MakeRequest(t, req, http.StatusOK) - - var repoPermission api.RepoCollaboratorPermission - DecodeJSON(t, resp, &repoPermission) - - assert.Equal(t, "admin", repoPermission.Permission) - }) - - t.Run("CollaboratorNotFound", func(t *testing.T) { - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, "non-existent-user", testCtx.Token) - session.MakeRequest(t, req, http.StatusNotFound) - }) - - t.Run("CollaboratorCanQueryItsPermissions", func(t *testing.T) { - t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user5.Name, perm.AccessModeRead)) - - _session := loginUser(t, user5.Name) - _testCtx := NewAPITestContext(t, user5.Name, repo2.Name) - - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user5.Name, _testCtx.Token) - resp := _session.MakeRequest(t, req, http.StatusOK) - - var repoPermission api.RepoCollaboratorPermission - DecodeJSON(t, resp, &repoPermission) - - assert.Equal(t, "read", repoPermission.Permission) - }) - - t.Run("CollaboratorCanQueryItsPermissions", func(t *testing.T) { - t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user5.Name, perm.AccessModeRead)) - - _session := loginUser(t, user5.Name) - _testCtx := NewAPITestContext(t, user5.Name, repo2.Name) - - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user5.Name, _testCtx.Token) - resp := _session.MakeRequest(t, req, http.StatusOK) - - var repoPermission api.RepoCollaboratorPermission - DecodeJSON(t, resp, &repoPermission) - - assert.Equal(t, "read", repoPermission.Permission) - }) - - t.Run("RepoAdminCanQueryACollaboratorsPermissions", func(t *testing.T) { - t.Run("AddUserAsCollaboratorWithAdminAccess", doAPIAddCollaborator(testCtx, user10.Name, perm.AccessModeAdmin)) - t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user11.Name, perm.AccessModeRead)) - - _session := loginUser(t, user10.Name) - _testCtx := NewAPITestContext(t, user10.Name, repo2.Name) - - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission?token=%s", repo2Owner.Name, repo2.Name, user11.Name, _testCtx.Token) - resp := _session.MakeRequest(t, req, http.StatusOK) - - var repoPermission api.RepoCollaboratorPermission - DecodeJSON(t, resp, &repoPermission) - - assert.Equal(t, "read", repoPermission.Permission) - }) - }) -} diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 67ba869c76b0..670b30562130 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -4,7 +4,6 @@ id: 1 lower_name: user1 name: user1 - login_name: user1 full_name: User One email: user1@example.com email_notifications_preference: enabled @@ -22,7 +21,6 @@ id: 2 lower_name: user2 name: user2 - login_name: user2 full_name: " < Ur Tw >< " email: user2@example.com keep_email_private: true @@ -44,7 +42,6 @@ id: 3 lower_name: user3 name: user3 - login_name: user3 full_name: " <<<< >> >> > >> > >>> >> " email: user3@example.com email_notifications_preference: onmention @@ -63,7 +60,6 @@ id: 4 lower_name: user4 name: user4 - login_name: user4 full_name: " " email: user4@example.com email_notifications_preference: onmention @@ -82,7 +78,6 @@ id: 5 lower_name: user5 name: user5 - login_name: user5 full_name: User Five email: user5@example.com email_notifications_preference: enabled @@ -102,7 +97,6 @@ id: 6 lower_name: user6 name: user6 - login_name: user6 full_name: User Six email: user6@example.com email_notifications_preference: enabled @@ -121,7 +115,6 @@ id: 7 lower_name: user7 name: user7 - login_name: user7 full_name: User Seven email: user7@example.com email_notifications_preference: disabled @@ -140,7 +133,6 @@ id: 8 lower_name: user8 name: user8 - login_name: user8 full_name: User Eight email: user8@example.com email_notifications_preference: enabled @@ -160,7 +152,6 @@ id: 9 lower_name: user9 name: user9 - login_name: user9 full_name: User Nine email: user9@example.com email_notifications_preference: onmention @@ -178,7 +169,6 @@ id: 10 lower_name: user10 name: user10 - login_name: user10 full_name: User Ten email: user10@example.com passwd_hash_algo: argon2 @@ -195,7 +185,6 @@ id: 11 lower_name: user11 name: user11 - login_name: user11 full_name: User Eleven email: user11@example.com passwd_hash_algo: argon2 @@ -212,7 +201,6 @@ id: 12 lower_name: user12 name: user12 - login_name: user12 full_name: User 12 email: user12@example.com passwd_hash_algo: argon2 @@ -229,7 +217,6 @@ id: 13 lower_name: user13 name: user13 - login_name: user13 full_name: User 13 email: user13@example.com passwd_hash_algo: argon2 @@ -246,7 +233,6 @@ id: 14 lower_name: user14 name: user14 - login_name: user14 full_name: User 14 email: user14@example.com passwd_hash_algo: argon2 @@ -263,7 +249,6 @@ id: 15 lower_name: user15 name: user15 - login_name: user15 full_name: User 15 email: user15@example.com passwd_hash_algo: argon2 @@ -280,7 +265,6 @@ id: 16 lower_name: user16 name: user16 - login_name: user16 full_name: User 16 email: user16@example.com passwd_hash_algo: argon2 @@ -297,7 +281,6 @@ id: 17 lower_name: user17 name: user17 - login_name: user17 full_name: User 17 email: user17@example.com passwd_hash_algo: argon2 @@ -316,7 +299,6 @@ id: 18 lower_name: user18 name: user18 - login_name: user18 full_name: User 18 email: user18@example.com passwd_hash_algo: argon2 @@ -333,7 +315,6 @@ id: 19 lower_name: user19 name: user19 - login_name: user19 full_name: User 19 email: user19@example.com passwd_hash_algo: argon2 @@ -352,7 +333,6 @@ id: 20 lower_name: user20 name: user20 - login_name: user20 full_name: User 20 email: user20@example.com passwd_hash_algo: argon2 @@ -369,7 +349,6 @@ id: 21 lower_name: user21 name: user21 - login_name: user21 full_name: User 21 email: user21@example.com passwd_hash_algo: argon2 @@ -386,7 +365,6 @@ id: 22 lower_name: limited_org name: limited_org - login_name: limited_org full_name: Limited Org email: limited_org@example.com passwd_hash_algo: argon2 @@ -406,7 +384,6 @@ id: 23 lower_name: privated_org name: privated_org - login_name: privated_org full_name: Privated Org email: privated_org@example.com passwd_hash_algo: argon2 @@ -426,7 +403,6 @@ id: 24 lower_name: user24 name: user24 - login_name: user24 full_name: "user24" email: user24@example.com keep_email_private: true @@ -447,7 +423,6 @@ id: 25 lower_name: org25 name: org25 - login_name: org25 full_name: "org25" email: org25@example.com passwd_hash_algo: argon2 @@ -465,7 +440,6 @@ id: 26 lower_name: org26 name: org26 - login_name: org26 full_name: "Org26" email: org26@example.com email_notifications_preference: onmention @@ -485,7 +459,6 @@ id: 27 lower_name: user27 name: user27 - login_name: user27 full_name: User Twenty-Seven email: user27@example.com email_notifications_preference: enabled @@ -502,7 +475,6 @@ id: 28 lower_name: user28 name: user28 - login_name: user28 full_name: "user27" email: user28@example.com keep_email_private: true @@ -523,7 +495,6 @@ id: 29 lower_name: user29 name: user29 - login_name: user29 full_name: User 29 email: user29@example.com passwd_hash_algo: argon2 @@ -541,7 +512,6 @@ id: 30 lower_name: user30 name: user30 - login_name: user30 full_name: User Thirty email: user30@example.com passwd_hash_algo: argon2 @@ -560,7 +530,6 @@ id: 31 lower_name: user31 name: user31 - login_name: user31 full_name: "user31" email: user31@example.com passwd_hash_algo: argon2 @@ -578,7 +547,6 @@ id: 32 lower_name: user32 name: user32 - login_name: user32 full_name: User 32 (U2F test) email: user32@example.com passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f4701772a025a # password diff --git a/models/user/user.go b/models/user/user.go index 5b556c988414..c84889523918 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -621,14 +621,7 @@ func IsUsableUsername(name string) error { // CreateUserOverwriteOptions are an optional options who overwrite system defaults on user creation type CreateUserOverwriteOptions struct { - KeepEmailPrivate util.OptionalBool - Visibility *structs.VisibleType - AllowCreateOrganization util.OptionalBool - EmailNotificationsPreference *string - MaxRepoCreation *int - Theme *string - IsRestricted util.OptionalBool - IsActive util.OptionalBool + Visibility structs.VisibleType } // CreateUser creates record of a new user. @@ -644,36 +637,10 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e u.EmailNotificationsPreference = setting.Admin.DefaultEmailNotification u.MaxRepoCreation = -1 u.Theme = setting.UI.DefaultTheme - u.IsRestricted = setting.Service.DefaultUserIsRestricted - u.IsActive = !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm) // overwrite defaults if set if len(overwriteDefault) != 0 && overwriteDefault[0] != nil { - overwrite := overwriteDefault[0] - if !overwrite.KeepEmailPrivate.IsNone() { - u.KeepEmailPrivate = overwrite.KeepEmailPrivate.IsTrue() - } - if overwrite.Visibility != nil { - u.Visibility = *overwrite.Visibility - } - if !overwrite.AllowCreateOrganization.IsNone() { - u.AllowCreateOrganization = overwrite.AllowCreateOrganization.IsTrue() - } - if overwrite.EmailNotificationsPreference != nil { - u.EmailNotificationsPreference = *overwrite.EmailNotificationsPreference - } - if overwrite.MaxRepoCreation != nil { - u.MaxRepoCreation = *overwrite.MaxRepoCreation - } - if overwrite.Theme != nil { - u.Theme = *overwrite.Theme - } - if !overwrite.IsRestricted.IsNone() { - u.IsRestricted = overwrite.IsRestricted.IsTrue() - } - if !overwrite.IsActive.IsNone() { - u.IsActive = overwrite.IsActive.IsTrue() - } + u.Visibility = overwriteDefault[0].Visibility } // validate data diff --git a/modules/convert/user.go b/modules/convert/user.go index 2b07d21838d7..dc4a8c49c776 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -95,12 +95,3 @@ func User2UserSettings(user *user_model.User) api.UserSettings { DiffViewStyle: user.DiffViewStyle, } } - -// ToUserAndPermission return User and its collaboration permission for a repository -func ToUserAndPermission(user, doer *user_model.User, accessMode perm.AccessMode) api.RepoCollaboratorPermission { - return api.RepoCollaboratorPermission{ - User: ToUser(user, doer), - Permission: accessMode.String(), - RoleName: accessMode.String(), - } -} diff --git a/modules/repository/repo.go b/modules/repository/repo.go index 30ca6fdff84e..0dffa322d056 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -93,7 +93,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err) } - if err := git.Clone(ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{ + if err = git.Clone(ctx, wikiRemotePath, wikiPath, git.CloneRepoOptions{ Mirror: true, Quiet: true, Timeout: migrateTimeout, @@ -104,12 +104,11 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, if err := util.RemoveAll(wikiPath); err != nil { return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err) } - } else { - if err := git.WriteCommitGraph(ctx, wikiPath); err != nil { - return repo, err - } } } + if err := git.WriteCommitGraph(ctx, wikiPath); err != nil { + return repo, err + } } if repo.OwnerID == u.ID { diff --git a/modules/structs/admin_user.go b/modules/structs/admin_user.go index eccbf29a46f0..facf16a39552 100644 --- a/modules/structs/admin_user.go +++ b/modules/structs/admin_user.go @@ -19,7 +19,6 @@ type CreateUserOption struct { Password string `json:"password" binding:"Required;MaxSize(255)"` MustChangePassword *bool `json:"must_change_password"` SendNotify bool `json:"send_notify"` - Restricted *bool `json:"restricted"` Visibility string `json:"visibility" binding:"In(,public,limited,private)"` } diff --git a/modules/structs/repo_collaborator.go b/modules/structs/repo_collaborator.go index 2f9c8992a168..2b4fa390d2b2 100644 --- a/modules/structs/repo_collaborator.go +++ b/modules/structs/repo_collaborator.go @@ -8,10 +8,3 @@ package structs type AddCollaboratorOption struct { Permission *string `json:"permission"` } - -// RepoCollaboratorPermission to get repository permission for a collaborator -type RepoCollaboratorPermission struct { - Permission string `json:"permission"` - RoleName string `json:"role_name"` - User *User `json:"user"` -} diff --git a/options/locale/locale_pt-PT.ini b/options/locale/locale_pt-PT.ini index d8801f7517b9..1780f4fa2ec7 100644 --- a/options/locale/locale_pt-PT.ini +++ b/options/locale/locale_pt-PT.ini @@ -1486,8 +1486,6 @@ pulls.desc=Habilitar pedidos de integração e revisão de código. pulls.new=Novo pedido de integração pulls.view=Ver pedido de integração pulls.compare_changes=Novo pedido de integração -pulls.allow_edits_from_maintainers_desc=Utilizadores com acesso de escrita no ramo base também podem fazer envios para este ramo -pulls.allow_edits_from_maintainers_err=Não foi possível fazer a modificação pulls.compare_changes_desc=Escolha o ramo de destino e o ramo de origem. pulls.compare_base=integrar em pulls.compare_compare=puxar de diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index 775802449abb..bf176f95710b 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -22,7 +22,6 @@ import ( "code.gitea.io/gitea/modules/password" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/api/v1/user" "code.gitea.io/gitea/routers/api/v1/utils" @@ -83,6 +82,7 @@ func CreateUser(ctx *context.APIContext) { Email: form.Email, Passwd: form.Password, MustChangePassword: true, + IsActive: true, LoginType: auth.Plain, } if form.MustChangePassword != nil { @@ -108,17 +108,11 @@ func CreateUser(ctx *context.APIContext) { return } - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsActive: util.OptionalBoolTrue, - } - - if form.Restricted != nil { - overwriteDefault.IsRestricted = util.OptionalBoolOf(*form.Restricted) - } - + var overwriteDefault *user_model.CreateUserOverwriteOptions if form.Visibility != "" { - visibility := api.VisibilityModes[form.Visibility] - overwriteDefault.Visibility = &visibility + overwriteDefault = &user_model.CreateUserOverwriteOptions{ + Visibility: api.VisibilityModes[form.Visibility], + } } if err := user_model.CreateUser(u, overwriteDefault); err != nil { diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index ce0719ddd85f..782500e6c86f 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -810,12 +810,9 @@ func Routes() *web.Route { }, reqToken(), reqAdmin(), reqWebhooksEnabled()) m.Group("/collaborators", func() { m.Get("", reqAnyRepoReader(), repo.ListCollaborators) - m.Group("/{collaborator}", func() { - m.Combo("").Get(reqAnyRepoReader(), repo.IsCollaborator). - Put(reqAdmin(), bind(api.AddCollaboratorOption{}), repo.AddCollaborator). - Delete(reqAdmin(), repo.DeleteCollaborator) - m.Get("/permission", repo.GetRepoPermissions) - }, reqToken()) + m.Combo("/{collaborator}").Get(reqAnyRepoReader(), repo.IsCollaborator). + Put(reqAdmin(), bind(api.AddCollaboratorOption{}), repo.AddCollaborator). + Delete(reqAdmin(), repo.DeleteCollaborator) }, reqToken()) m.Get("/assignees", reqToken(), reqAnyRepoReader(), repo.GetAssignees) m.Get("/reviewers", reqToken(), reqAnyRepoReader(), repo.GetReviewers) @@ -1014,7 +1011,7 @@ func Routes() *web.Route { m.Group("/{ref}", func() { m.Get("/status", repo.GetCombinedCommitStatusByRef) m.Get("/statuses", repo.GetCommitStatusesByRef) - }, context.ReferencesGitRepo()) + }) }, reqRepoReader(unit.TypeCode)) m.Group("/git", func() { m.Group("/commits", func() { diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index c030a896a792..794d367b53e7 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -259,15 +259,10 @@ func ListBranches(ctx *context.APIContext) { return } - apiBranches := make([]*api.Branch, 0, len(branches)) + apiBranches := make([]*api.Branch, len(branches)) for i := range branches { c, err := branches[i].GetCommit() if err != nil { - // Skip if this branch doesn't exist anymore. - if git.IsErrNotExist(err) { - totalNumOfBranches-- - continue - } ctx.Error(http.StatusInternalServerError, "GetCommit", err) return } @@ -276,12 +271,11 @@ func ListBranches(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) return } - apiBranch, err := convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) + apiBranches[i], err = convert.ToBranch(ctx.Repo.Repository, branches[i], c, branchProtection, ctx.Doer, ctx.Repo.IsAdmin()) if err != nil { ctx.Error(http.StatusInternalServerError, "convert.ToBranch", err) return } - apiBranches = append(apiBranches, apiBranch) } ctx.SetLinkHeader(totalNumOfBranches, listOptions.PageSize) diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index 2db1724b2a9f..3bb6113d772a 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -233,61 +233,6 @@ func DeleteCollaborator(ctx *context.APIContext) { ctx.Status(http.StatusNoContent) } -// GetRepoPermissions gets repository permissions for a user -func GetRepoPermissions(ctx *context.APIContext) { - // swagger:operation GET /repos/{owner}/{repo}/collaborators/{collaborator}/permission repository repoGetRepoPermissions - // --- - // summary: Get repository permissions for a user - // produces: - // - application/json - // parameters: - // - name: owner - // in: path - // description: owner of the repo - // type: string - // required: true - // - name: repo - // in: path - // description: name of the repo - // type: string - // required: true - // - name: collaborator - // in: path - // description: username of the collaborator - // type: string - // required: true - // responses: - // "200": - // "$ref": "#/responses/RepoCollaboratorPermission" - // "404": - // "$ref": "#/responses/notFound" - // "403": - // "$ref": "#/responses/forbidden" - - if !ctx.Doer.IsAdmin && ctx.Doer.LoginName != ctx.Params(":collaborator") && !ctx.IsUserRepoAdmin() { - ctx.Error(http.StatusForbidden, "User", "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own") - return - } - - collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator")) - if err != nil { - if user_model.IsErrUserNotExist(err) { - ctx.Error(http.StatusNotFound, "GetUserByName", err) - } else { - ctx.Error(http.StatusInternalServerError, "GetUserByName", err) - } - return - } - - permission, err := models.GetUserRepoPermission(ctx, ctx.Repo.Repository, collaborator) - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err) - return - } - - ctx.JSON(http.StatusOK, convert.ToUserAndPermission(collaborator, ctx.ContextUser, permission.AccessMode)) -} - // GetReviewers return all users that can be requested to review in this repo func GetReviewers(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/reviewers repository repoGetReviewers diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index ab802db7812f..40aeca677de8 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -344,10 +344,3 @@ type swaggerWikiCommitList struct { // in:body Body api.WikiCommitList `json:"body"` } - -// RepoCollaboratorPermission -// swagger:response RepoCollaboratorPermission -type swaggerRepoCollaboratorPermission struct { - // in:body - Body api.RepoCollaboratorPermission `json:"body"` -} diff --git a/routers/api/v1/utils/git.go b/routers/api/v1/utils/git.go index ac64d5b87bfe..9f02bc8083f9 100644 --- a/routers/api/v1/utils/git.go +++ b/routers/api/v1/utils/git.go @@ -5,7 +5,6 @@ package utils import ( - "fmt" "net/http" "code.gitea.io/gitea/modules/context" @@ -36,7 +35,12 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string { // GetGitRefs return git references based on filter func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) { if ctx.Repo.GitRepo == nil { - return nil, "", fmt.Errorf("no open git repo found in context") + var err error + ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) + if err != nil { + return nil, "OpenRepository", err + } + defer ctx.Repo.GitRepo.Close() } if len(filter) > 0 { filter = "refs/" + filter diff --git a/routers/install/install.go b/routers/install/install.go index 9d28bc1571ac..ec1719439f53 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -499,17 +499,13 @@ func SubmitInstall(ctx *context.Context) { // Create admin account if len(form.AdminName) > 0 { u := &user_model.User{ - Name: form.AdminName, - Email: form.AdminEmail, - Passwd: form.AdminPasswd, - IsAdmin: true, + Name: form.AdminName, + Email: form.AdminEmail, + Passwd: form.AdminPasswd, + IsAdmin: true, + IsActive: true, } - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsRestricted: util.OptionalBoolFalse, - IsActive: util.OptionalBoolTrue, - } - - if err = user_model.CreateUser(u, overwriteDefault); err != nil { + if err = user_model.CreateUser(u); err != nil { if !user_model.IsErrUserAlreadyExist(err) { setting.InstallLock = false ctx.Data["Err_AdminName"] = true diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index 57da319d794b..fcfea5380128 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -125,14 +125,10 @@ func NewUserPost(ctx *context.Context) { Name: form.UserName, Email: form.Email, Passwd: form.Password, + IsActive: true, LoginType: auth.Plain, } - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsActive: util.OptionalBoolTrue, - Visibility: &form.Visibility, - } - if len(form.LoginType) > 0 { fields := strings.Split(form.LoginType, "-") if len(fields) == 2 { @@ -167,7 +163,7 @@ func NewUserPost(ctx *context.Context) { u.MustChangePassword = form.MustChangePassword } - if err := user_model.CreateUser(u, overwriteDefault); err != nil { + if err := user_model.CreateUser(u, &user_model.CreateUserOverwriteOptions{Visibility: form.Visibility}); err != nil { switch { case user_model.IsErrUserAlreadyExist(err): ctx.Data["Err_UserName"] = true diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index e8250616abdf..c82fde49eb2f 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -507,12 +507,14 @@ func SignUpPost(ctx *context.Context) { } u := &user_model.User{ - Name: form.UserName, - Email: form.Email, - Passwd: form.Password, + Name: form.UserName, + Email: form.Email, + Passwd: form.Password, + IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm), + IsRestricted: setting.Service.DefaultUserIsRestricted, } - if !createAndHandleCreatedUser(ctx, tplSignUp, form, u, nil, nil, false) { + if !createAndHandleCreatedUser(ctx, tplSignUp, form, u, nil, false) { // error already handled return } @@ -523,8 +525,8 @@ func SignUpPost(ctx *context.Context) { // createAndHandleCreatedUser calls createUserInContext and // then handleUserCreated. -func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, overwrites *user_model.CreateUserOverwriteOptions, gothUser *goth.User, allowLink bool) bool { - if !createUserInContext(ctx, tpl, form, u, overwrites, gothUser, allowLink) { +func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) bool { + if !createUserInContext(ctx, tpl, form, u, gothUser, allowLink) { return false } return handleUserCreated(ctx, u, gothUser) @@ -532,8 +534,8 @@ func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form int // createUserInContext creates a user and handles errors within a given context. // Optionally a template can be specified. -func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, overwrites *user_model.CreateUserOverwriteOptions, gothUser *goth.User, allowLink bool) (ok bool) { - if err := user_model.CreateUser(u, overwrites); err != nil { +func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) (ok bool) { + if err := user_model.CreateUser(u); err != nil { if allowLink && (user_model.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) { if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingAuto { var user *user_model.User diff --git a/routers/web/auth/linkaccount.go b/routers/web/auth/linkaccount.go index c3e96f077a87..bf5fb83265ba 100644 --- a/routers/web/auth/linkaccount.go +++ b/routers/web/auth/linkaccount.go @@ -283,12 +283,13 @@ func LinkAccountPostRegister(ctx *context.Context) { Name: form.UserName, Email: form.Email, Passwd: form.Password, + IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm), LoginType: auth.OAuth2, LoginSource: authSource.ID, LoginName: gothUser.UserID, } - if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, nil, &gothUser, false) { + if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, &gothUser, false) { // error already handled return } diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index 4c3e3c3ace39..12de208ad7bc 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -24,7 +24,6 @@ import ( "code.gitea.io/gitea/modules/session" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web/middleware" auth_service "code.gitea.io/gitea/services/auth" @@ -868,21 +867,19 @@ func SignInOAuthCallback(ctx *context.Context) { return } u = &user_model.User{ - Name: getUserName(&gothUser), - FullName: gothUser.Name, - Email: gothUser.Email, - LoginType: auth.OAuth2, - LoginSource: authSource.ID, - LoginName: gothUser.UserID, - } - - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsActive: util.OptionalBoolOf(!setting.OAuth2Client.RegisterEmailConfirm), + Name: getUserName(&gothUser), + FullName: gothUser.Name, + Email: gothUser.Email, + IsActive: !setting.OAuth2Client.RegisterEmailConfirm, + LoginType: auth.OAuth2, + LoginSource: authSource.ID, + LoginName: gothUser.UserID, + IsRestricted: setting.Service.DefaultUserIsRestricted, } setUserGroupClaims(authSource, u, &gothUser) - if !createAndHandleCreatedUser(ctx, base.TplName(""), nil, u, overwriteDefault, &gothUser, setting.OAuth2Client.AccountLinking != setting.OAuth2AccountLinkingDisabled) { + if !createAndHandleCreatedUser(ctx, base.TplName(""), nil, u, &gothUser, setting.OAuth2Client.AccountLinking != setting.OAuth2AccountLinkingDisabled) { // error already handled return } diff --git a/routers/web/auth/openid.go b/routers/web/auth/openid.go index 3012d8c5a55e..f3189887a530 100644 --- a/routers/web/auth/openid.go +++ b/routers/web/auth/openid.go @@ -423,11 +423,12 @@ func RegisterOpenIDPost(ctx *context.Context) { } u := &user_model.User{ - Name: form.UserName, - Email: form.Email, - Passwd: password, + Name: form.UserName, + Email: form.Email, + Passwd: password, + IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm), } - if !createUserInContext(ctx, tplSignUpOID, form, u, nil, nil, false) { + if !createUserInContext(ctx, tplSignUpOID, form, u, nil, false) { // error already handled return } diff --git a/services/auth/reverseproxy.go b/services/auth/reverseproxy.go index 299d7abd34ae..1b151f6504e3 100644 --- a/services/auth/reverseproxy.go +++ b/services/auth/reverseproxy.go @@ -12,7 +12,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/mailer" @@ -106,15 +105,11 @@ func (r *ReverseProxy) newUser(req *http.Request) *user_model.User { } user := &user_model.User{ - Name: username, - Email: email, + Name: username, + Email: email, + IsActive: true, } - - overwriteDefault := user_model.CreateUserOverwriteOptions{ - IsActive: util.OptionalBoolTrue, - } - - if err := user_model.CreateUser(user, &overwriteDefault); err != nil { + if err := user_model.CreateUser(user); err != nil { // FIXME: should I create a system notice? log.Error("CreateUser: %v", err) return nil diff --git a/services/auth/source/ldap/source_authenticate.go b/services/auth/source/ldap/source_authenticate.go index d8d11f18e1ef..ddd70627ed3f 100644 --- a/services/auth/source/ldap/source_authenticate.go +++ b/services/auth/source/ldap/source_authenticate.go @@ -13,7 +13,6 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/mailer" user_service "code.gitea.io/gitea/services/user" ) @@ -86,21 +85,19 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str } user = &user_model.User{ - LowerName: strings.ToLower(sr.Username), - Name: sr.Username, - FullName: composeFullName(sr.Name, sr.Surname, sr.Username), - Email: sr.Mail, - LoginType: source.authSource.Type, - LoginSource: source.authSource.ID, - LoginName: userName, - IsAdmin: sr.IsAdmin, - } - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsRestricted: util.OptionalBoolOf(sr.IsRestricted), - IsActive: util.OptionalBoolTrue, + LowerName: strings.ToLower(sr.Username), + Name: sr.Username, + FullName: composeFullName(sr.Name, sr.Surname, sr.Username), + Email: sr.Mail, + LoginType: source.authSource.Type, + LoginSource: source.authSource.ID, + LoginName: userName, + IsActive: true, + IsAdmin: sr.IsAdmin, + IsRestricted: sr.IsRestricted, } - err := user_model.CreateUser(user, overwriteDefault) + err := user_model.CreateUser(user) if err != nil { return user, err } diff --git a/services/auth/source/ldap/source_sync.go b/services/auth/source/ldap/source_sync.go index a245f4c6ff0d..65efed78c17c 100644 --- a/services/auth/source/ldap/source_sync.go +++ b/services/auth/source/ldap/source_sync.go @@ -15,7 +15,6 @@ import ( "code.gitea.io/gitea/models/organization" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/util" user_service "code.gitea.io/gitea/services/user" ) @@ -103,21 +102,19 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error { log.Trace("SyncExternalUsers[%s]: Creating user %s", source.authSource.Name, su.Username) usr = &user_model.User{ - LowerName: su.LowerName, - Name: su.Username, - FullName: fullName, - LoginType: source.authSource.Type, - LoginSource: source.authSource.ID, - LoginName: su.Username, - Email: su.Mail, - IsAdmin: su.IsAdmin, - } - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsRestricted: util.OptionalBoolOf(su.IsRestricted), - IsActive: util.OptionalBoolTrue, + LowerName: su.LowerName, + Name: su.Username, + FullName: fullName, + LoginType: source.authSource.Type, + LoginSource: source.authSource.ID, + LoginName: su.Username, + Email: su.Mail, + IsAdmin: su.IsAdmin, + IsRestricted: su.IsRestricted, + IsActive: true, } - err = user_model.CreateUser(usr, overwriteDefault) + err = user_model.CreateUser(usr) if err != nil { log.Error("SyncExternalUsers[%s]: Error creating user %s: %v", source.authSource.Name, su.Username, err) diff --git a/services/auth/source/pam/source_authenticate.go b/services/auth/source/pam/source_authenticate.go index 16ddc0598e47..d5bd9409963f 100644 --- a/services/auth/source/pam/source_authenticate.go +++ b/services/auth/source/pam/source_authenticate.go @@ -12,7 +12,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/auth/pam" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/mailer" "github.com/google/uuid" @@ -59,12 +58,10 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str LoginType: auth.PAM, LoginSource: source.authSource.ID, LoginName: userName, // This is what the user typed in - } - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsActive: util.OptionalBoolTrue, + IsActive: true, } - if err := user_model.CreateUser(user, overwriteDefault); err != nil { + if err := user_model.CreateUser(user); err != nil { return user, err } diff --git a/services/auth/source/smtp/source_authenticate.go b/services/auth/source/smtp/source_authenticate.go index dff24d494ee0..3be2f1128de2 100644 --- a/services/auth/source/smtp/source_authenticate.go +++ b/services/auth/source/smtp/source_authenticate.go @@ -74,12 +74,10 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str LoginType: auth_model.SMTP, LoginSource: source.authSource.ID, LoginName: userName, - } - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsActive: util.OptionalBoolTrue, + IsActive: true, } - if err := user_model.CreateUser(user, overwriteDefault); err != nil { + if err := user_model.CreateUser(user); err != nil { return user, err } diff --git a/services/auth/sspi_windows.go b/services/auth/sspi_windows.go index 9bc4041a74ac..63e70e61d433 100644 --- a/services/auth/sspi_windows.go +++ b/services/auth/sspi_windows.go @@ -16,7 +16,6 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/auth/source/sspi" "code.gitea.io/gitea/services/mailer" @@ -188,20 +187,17 @@ func (s *SSPI) shouldAuthenticate(req *http.Request) (shouldAuth bool) { func (s *SSPI) newUser(username string, cfg *sspi.Source) (*user_model.User, error) { email := gouuid.New().String() + "@localhost.localdomain" user := &user_model.User{ - Name: username, - Email: email, - Passwd: gouuid.New().String(), - Language: cfg.DefaultLanguage, - UseCustomAvatar: true, - Avatar: avatars.DefaultAvatarLink(), - } - emailNotificationPreference := user_model.EmailNotificationsDisabled - overwriteDefault := &user_model.CreateUserOverwriteOptions{ - IsActive: util.OptionalBoolOf(cfg.AutoActivateUsers), - KeepEmailPrivate: util.OptionalBoolTrue, - EmailNotificationsPreference: &emailNotificationPreference, - } - if err := user_model.CreateUser(user, overwriteDefault); err != nil { + Name: username, + Email: email, + KeepEmailPrivate: true, + Passwd: gouuid.New().String(), + IsActive: cfg.AutoActivateUsers, + Language: cfg.DefaultLanguage, + UseCustomAvatar: true, + Avatar: avatars.DefaultAvatarLink(), + EmailNotificationsPreference: user_model.EmailNotificationsDisabled, + } + if err := user_model.CreateUser(user); err != nil { return nil, err } diff --git a/services/mailer/mail.go b/services/mailer/mail.go index bdd7e25cabd4..a5b60f71ec31 100644 --- a/services/mailer/mail.go +++ b/services/mailer/mail.go @@ -367,7 +367,6 @@ func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient //"List-Post": https://github.com/go-gitea/gitea/pull/13585 "List-Unsubscribe": ctx.Issue.HTMLURL(), - "X-Mailer": "Gitea", "X-Gitea-Reason": reason, "X-Gitea-Sender": ctx.Doer.DisplayName(), "X-Gitea-Recipient": recipient.DisplayName(), diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 6f67f36422ec..b7135de59fdb 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -39,7 +39,7 @@
  - {{.Name}} + {{.Name}} {{end}} {{if .Diff.IsIncomplete}} @@ -57,8 +57,7 @@ {{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}} {{$isCsv := (call $.IsCsvFile $file)}} {{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}} - {{$nameHash := Sha1 $file.Name}} -
+

- {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.i18n.Tr "repo.stored_lfs"}}){{end}} + {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.i18n.Tr "repo.stored_lfs"}}){{end}} {{if $file.IsGenerated}} {{$.i18n.Tr "repo.diff.generated"}} {{end}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 54df1c51fa5f..1b88ae73934b 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -508,13 +508,13 @@ {{ range $filename, $lines := .Review.CodeComments}} {{range $line, $comms := $lines}}
-
+
{{$invalid := (index $comms 0).Invalidated}} {{$resolved := (index $comms 0).IsResolved}} {{$resolveDoer := (index $comms 0).ResolveDoer}} {{$isNotPending := (not (eq (index $comms 0).Review.Type 0))}}
- {{$filename}} + {{$filename}} {{if $invalid }} {{$.i18n.Tr "repo.issues.review.outdated"}} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 20e80967bcee..d57a3a580b92 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3129,52 +3129,6 @@ } } }, - "/repos/{owner}/{repo}/collaborators/{collaborator}/permission": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "repository" - ], - "summary": "Get repository permissions for a user", - "operationId": "repoGetRepoPermissions", - "parameters": [ - { - "type": "string", - "description": "owner of the repo", - "name": "owner", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "name of the repo", - "name": "repo", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "username of the collaborator", - "name": "collaborator", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "$ref": "#/responses/RepoCollaboratorPermission" - }, - "403": { - "$ref": "#/responses/forbidden" - }, - "404": { - "$ref": "#/responses/notFound" - } - } - } - }, "/repos/{owner}/{repo}/commits": { "get": { "produces": [ @@ -14471,10 +14425,6 @@ "type": "string", "x-go-name": "Password" }, - "restricted": { - "type": "boolean", - "x-go-name": "Restricted" - }, "send_notify": { "type": "boolean", "x-go-name": "SendNotify" @@ -17501,24 +17451,6 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "RepoCollaboratorPermission": { - "description": "RepoCollaboratorPermission to get repository permission for a collaborator", - "type": "object", - "properties": { - "permission": { - "type": "string", - "x-go-name": "Permission" - }, - "role_name": { - "type": "string", - "x-go-name": "RoleName" - }, - "user": { - "$ref": "#/definitions/User" - } - }, - "x-go-package": "code.gitea.io/gitea/modules/structs" - }, "RepoCommit": { "type": "object", "title": "RepoCommit contains information of a commit in the context of a repository.", @@ -19194,12 +19126,6 @@ } } }, - "RepoCollaboratorPermission": { - "description": "RepoCollaboratorPermission", - "schema": { - "$ref": "#/definitions/RepoCollaboratorPermission" - } - }, "Repository": { "description": "Repository", "schema": { diff --git a/web_src/less/helpers.less b/web_src/less/helpers.less index 0c4bf1753af3..6904083da8b9 100644 --- a/web_src/less/helpers.less +++ b/web_src/less/helpers.less @@ -27,8 +27,6 @@ .word-break { word-wrap: break-word !important; - word-break: break-word; /* compat: Safari */ - overflow-wrap: anywhere; } .ellipsis { From 24d4f36d6028c91caedf7e97fe20ad3a12d9b0a4 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 30 Apr 2022 23:41:04 +0000 Subject: [PATCH 25/27] Add Poster check Co-authored-by: delvh --- templates/repo/issue/view_content/comments.tmpl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 54df1c51fa5f..984b706b3977 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -35,9 +35,11 @@ ({{$.i18n.Tr "repo.migrated_from" ($.Repository.OriginalURL|Escape) ($.Repository.GetOriginalURLHostname|Escape) | Safe }}){{end}} {{else}} - - {{avatar .Poster}} - + {{if gt .Poster.ID 0}} + + {{avatar .Poster}} + + {{end}} {{.Poster.GetDisplayName}} From 71fa53e718430ee68a847e866c3f6cf4de3b4cb0 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 1 May 2022 01:58:24 +0200 Subject: [PATCH 26/27] Fix idents --- templates/repo/issue/view_content/comments.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 984b706b3977..7ff7f247fca6 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -36,9 +36,9 @@ {{else}} {{if gt .Poster.ID 0}} - - {{avatar .Poster}} - + + {{avatar .Poster}} + {{end}} From 8e4fc2755e7f2d5ed138855e54b37078e176af5a Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 1 May 2022 14:25:27 +0000 Subject: [PATCH 27/27] Update comment Co-authored-by: wxiaoguang --- web_src/less/_repository.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 06b9b90544dd..13f9384ba063 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -861,7 +861,7 @@ } } - /* Don't show the inline timeline avatar on desktop. */ + /* Don't show the mobile oriented avatar ".inline-timeline-avatar" on desktop. Desktop uses the avatar with class ".timeline-avatar" */ .inline-timeline-avatar { display: none; }