Skip to content

Commit f59862b

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Update bluemonday (go-gitea#21281) Add support for authentication based on reverse proxy email (go-gitea#19949) Do not allow organisation owners add themselves as collaborator (go-gitea#20043) Feature: Case-insensitive "find files in repo" (go-gitea#21269) Better repo API unit checks (go-gitea#21130) Fix empty container layer history and UI (go-gitea#21251) Add filetree on left of diff view (go-gitea#21012)
2 parents 1ead6aa + 5a3b9ac commit f59862b

28 files changed

+736
-218
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ require (
6868
github.com/mattn/go-isatty v0.0.16
6969
github.com/mattn/go-sqlite3 v1.14.13
7070
github.com/mholt/archiver/v3 v3.5.1
71-
github.com/microcosm-cc/bluemonday v1.0.19
71+
github.com/microcosm-cc/bluemonday v1.0.20
7272
github.com/minio/minio-go/v7 v7.0.35
7373
github.com/msteinert/pam v1.0.0
7474
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
@@ -95,7 +95,7 @@ require (
9595
go.jolheiser.com/hcaptcha v0.0.4
9696
go.jolheiser.com/pwn v0.0.3
9797
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
98-
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b
98+
golang.org/x/net v0.0.0-20220927171203-f486391704dc
9999
golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094
100100
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261
101101
golang.org/x/text v0.3.7

go.sum

+4-3
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,8 @@ github.com/mholt/acmez v1.0.4 h1:N3cE4Pek+dSolbsofIkAYz6H1d3pE+2G0os7QHslf80=
10691069
github.com/mholt/acmez v1.0.4/go.mod h1:qFGLZ4u+ehWINeJZjzPlsnjJBCPAADWTcIqE/7DAYQY=
10701070
github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Clwo=
10711071
github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4=
1072-
github.com/microcosm-cc/bluemonday v1.0.19 h1:OI7hoF5FY4pFz2VA//RN8TfM0YJ2dJcl4P4APrCWy6c=
1073-
github.com/microcosm-cc/bluemonday v1.0.19/go.mod h1:QNzV2UbLK2/53oIIwTOyLUSABMkjZ4tqiyC1g/DyqxE=
1072+
github.com/microcosm-cc/bluemonday v1.0.20 h1:flpzsq4KU3QIYAYGV/szUat7H+GPOXR0B2JU5A1Wp8Y=
1073+
github.com/microcosm-cc/bluemonday v1.0.20/go.mod h1:yfBmMi8mxvaZut3Yytv+jTXRY8mxyjJ0/kQBTElld50=
10741074
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
10751075
github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
10761076
github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
@@ -1710,8 +1710,9 @@ golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su
17101710
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
17111711
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
17121712
golang.org/x/net v0.0.0-20220630215102-69896b714898/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
1713-
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b h1:ZmngSVLe/wycRns9MKikG9OWIEjGcGAkacif7oYQaUY=
17141713
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
1714+
golang.org/x/net v0.0.0-20220927171203-f486391704dc h1:FxpXZdoBqT8RjqTy6i1E8nXHhW21wK7ptQ/EPIGxzPQ=
1715+
golang.org/x/net v0.0.0-20220927171203-f486391704dc/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
17151716
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
17161717
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
17171718
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

modules/packages/container/metadata.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ func parseOCIImageConfig(r io.Reader) (*Metadata, error) {
9595
if i := strings.Index(cmd, "#(nop) "); i != -1 {
9696
cmd = strings.TrimSpace(cmd[i+7:])
9797
}
98-
imageLayers = append(imageLayers, cmd)
98+
if cmd != "" {
99+
imageLayers = append(imageLayers, cmd)
100+
}
99101
}
100102

101103
metadata := &Metadata{

modules/structs/repo.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -151,39 +151,39 @@ type EditRepoOption struct {
151151
Template *bool `json:"template,omitempty"`
152152
// either `true` to enable issues for this repository or `false` to disable them.
153153
HasIssues *bool `json:"has_issues,omitempty"`
154-
// set this structure to configure internal issue tracker (requires has_issues)
154+
// set this structure to configure internal issue tracker
155155
InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
156-
// set this structure to use external issue tracker (requires has_issues)
156+
// set this structure to use external issue tracker
157157
ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
158158
// either `true` to enable the wiki for this repository or `false` to disable it.
159159
HasWiki *bool `json:"has_wiki,omitempty"`
160-
// set this structure to use external wiki instead of internal (requires has_wiki)
160+
// set this structure to use external wiki instead of internal
161161
ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
162162
// sets the default branch for this repository.
163163
DefaultBranch *string `json:"default_branch,omitempty"`
164164
// either `true` to allow pull requests, or `false` to prevent pull request.
165165
HasPullRequests *bool `json:"has_pull_requests,omitempty"`
166166
// either `true` to enable project unit, or `false` to disable them.
167167
HasProjects *bool `json:"has_projects,omitempty"`
168-
// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace. `has_pull_requests` must be `true`.
168+
// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
169169
IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
170-
// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits. `has_pull_requests` must be `true`.
170+
// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
171171
AllowMerge *bool `json:"allow_merge_commits,omitempty"`
172-
// either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging. `has_pull_requests` must be `true`.
172+
// either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.
173173
AllowRebase *bool `json:"allow_rebase,omitempty"`
174-
// either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits. `has_pull_requests` must be `true`.
174+
// either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits.
175175
AllowRebaseMerge *bool `json:"allow_rebase_explicit,omitempty"`
176-
// either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging. `has_pull_requests` must be `true`.
176+
// either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging.
177177
AllowSquash *bool `json:"allow_squash_merge,omitempty"`
178-
// either `true` to allow mark pr as merged manually, or `false` to prevent it. `has_pull_requests` must be `true`.
178+
// either `true` to allow mark pr as merged manually, or `false` to prevent it.
179179
AllowManualMerge *bool `json:"allow_manual_merge,omitempty"`
180-
// either `true` to enable AutodetectManualMerge, or `false` to prevent it. `has_pull_requests` must be `true`, Note: In some special cases, misjudgments can occur.
180+
// either `true` to enable AutodetectManualMerge, or `false` to prevent it. Note: In some special cases, misjudgments can occur.
181181
AutodetectManualMerge *bool `json:"autodetect_manual_merge,omitempty"`
182-
// either `true` to allow updating pull request branch by rebase, or `false` to prevent it. `has_pull_requests` must be `true`.
182+
// either `true` to allow updating pull request branch by rebase, or `false` to prevent it.
183183
AllowRebaseUpdate *bool `json:"allow_rebase_update,omitempty"`
184184
// set to `true` to delete pr branch after merge by default
185185
DefaultDeleteBranchAfterMerge *bool `json:"default_delete_branch_after_merge,omitempty"`
186-
// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", or "squash". `has_pull_requests` must be `true`.
186+
// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", or "squash".
187187
DefaultMergeStyle *string `json:"default_merge_style,omitempty"`
188188
// set to `true` to archive this repository.
189189
Archived *bool `json:"archived,omitempty"`

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,7 @@ settings.confirm_delete = Delete Repository
18981898
settings.add_collaborator = Add Collaborator
18991899
settings.add_collaborator_success = The collaborator has been added.
19001900
settings.add_collaborator_inactive_user = Can not add an inactive user as a collaborator.
1901+
settings.add_collaborator_owner = Can not add an owner as a collaborator.
19011902
settings.add_collaborator_duplicate = The collaborator is already added to this repository.
19021903
settings.delete_collaborator = Remove
19031904
settings.collaborator_deletion = Remove Collaborator

routers/api/v1/repo/repo.go

+23-8
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
732732
var units []repo_model.RepoUnit
733733
var deleteUnitTypes []unit_model.Type
734734

735+
currHasIssues := repo.UnitEnabledCtx(ctx, unit_model.TypeIssues)
736+
newHasIssues := currHasIssues
735737
if opts.HasIssues != nil {
736-
if *opts.HasIssues && opts.ExternalTracker != nil && !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
738+
newHasIssues = *opts.HasIssues
739+
}
740+
if currHasIssues || newHasIssues {
741+
if newHasIssues && opts.ExternalTracker != nil && !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
737742
// Check that values are valid
738743
if !validation.IsValidExternalURL(opts.ExternalTracker.ExternalTrackerURL) {
739744
err := fmt.Errorf("External tracker URL not valid")
@@ -756,7 +761,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
756761
},
757762
})
758763
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues)
759-
} else if *opts.HasIssues && opts.ExternalTracker == nil && !unit_model.TypeIssues.UnitGlobalDisabled() {
764+
} else if newHasIssues && opts.ExternalTracker == nil && !unit_model.TypeIssues.UnitGlobalDisabled() {
760765
// Default to built-in tracker
761766
var config *repo_model.IssuesConfig
762767

@@ -783,7 +788,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
783788
Config: config,
784789
})
785790
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker)
786-
} else if !*opts.HasIssues {
791+
} else if !newHasIssues {
787792
if !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
788793
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker)
789794
}
@@ -793,8 +798,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
793798
}
794799
}
795800

801+
currHasWiki := repo.UnitEnabledCtx(ctx, unit_model.TypeWiki)
802+
newHasWiki := currHasWiki
796803
if opts.HasWiki != nil {
797-
if *opts.HasWiki && opts.ExternalWiki != nil && !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
804+
newHasWiki = *opts.HasWiki
805+
}
806+
if currHasWiki || newHasWiki {
807+
if newHasWiki && opts.ExternalWiki != nil && !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
798808
// Check that values are valid
799809
if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) {
800810
err := fmt.Errorf("External wiki URL not valid")
@@ -810,15 +820,15 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
810820
},
811821
})
812822
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeWiki)
813-
} else if *opts.HasWiki && opts.ExternalWiki == nil && !unit_model.TypeWiki.UnitGlobalDisabled() {
823+
} else if newHasWiki && opts.ExternalWiki == nil && !unit_model.TypeWiki.UnitGlobalDisabled() {
814824
config := &repo_model.UnitConfig{}
815825
units = append(units, repo_model.RepoUnit{
816826
RepoID: repo.ID,
817827
Type: unit_model.TypeWiki,
818828
Config: config,
819829
})
820830
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki)
821-
} else if !*opts.HasWiki {
831+
} else if !newHasWiki {
822832
if !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
823833
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki)
824834
}
@@ -828,8 +838,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
828838
}
829839
}
830840

841+
currHasPullRequests := repo.UnitEnabledCtx(ctx, unit_model.TypePullRequests)
842+
newHasPullRequests := currHasPullRequests
831843
if opts.HasPullRequests != nil {
832-
if *opts.HasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
844+
newHasPullRequests = *opts.HasPullRequests
845+
}
846+
if currHasPullRequests || newHasPullRequests {
847+
if newHasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
833848
// We do allow setting individual PR settings through the API, so
834849
// we get the config settings and then set them
835850
// if those settings were provided in the opts.
@@ -889,7 +904,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
889904
Type: unit_model.TypePullRequests,
890905
Config: config,
891906
})
892-
} else if !*opts.HasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
907+
} else if !newHasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
893908
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePullRequests)
894909
}
895910
}

routers/web/repo/setting.go

+13
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,19 @@ func CollaborationPost(ctx *context.Context) {
917917
return
918918
}
919919

920+
// find the owner team of the organization the repo belongs too and
921+
// check if the user we're trying to add is an owner.
922+
if ctx.Repo.Repository.Owner.IsOrganization() {
923+
if isOwner, err := organization.IsOrganizationOwner(ctx, ctx.Repo.Repository.Owner.ID, u.ID); err != nil {
924+
ctx.ServerError("IsOrganizationOwner", err)
925+
return
926+
} else if isOwner {
927+
ctx.Flash.Error(ctx.Tr("repo.settings.add_collaborator_owner"))
928+
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath())
929+
return
930+
}
931+
}
932+
920933
if err = repo_module.AddCollaborator(ctx.Repo.Repository, u); err != nil {
921934
ctx.ServerError("AddCollaborator", err)
922935
return

services/auth/reverseproxy.go

+52-8
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,22 @@ type ReverseProxy struct{}
3737

3838
// getUserName extracts the username from the "setting.ReverseProxyAuthUser" header
3939
func (r *ReverseProxy) getUserName(req *http.Request) string {
40-
webAuthUser := strings.TrimSpace(req.Header.Get(setting.ReverseProxyAuthUser))
41-
if len(webAuthUser) == 0 {
42-
return ""
43-
}
44-
return webAuthUser
40+
return strings.TrimSpace(req.Header.Get(setting.ReverseProxyAuthUser))
4541
}
4642

4743
// Name represents the name of auth method
4844
func (r *ReverseProxy) Name() string {
4945
return ReverseProxyMethodName
5046
}
5147

52-
// Verify extracts the username from the "setting.ReverseProxyAuthUser" header
48+
// getUserFromAuthUser extracts the username from the "setting.ReverseProxyAuthUser" header
5349
// of the request and returns the corresponding user object for that name.
5450
// Verification of header data is not performed as it should have already been done by
55-
// the revese proxy.
51+
// the reverse proxy.
5652
// If a username is available in the "setting.ReverseProxyAuthUser" header an existing
5753
// user object is returned (populated with username or email found in header).
5854
// Returns nil if header is empty.
59-
func (r *ReverseProxy) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User {
55+
func (r *ReverseProxy) getUserFromAuthUser(req *http.Request) *user_model.User {
6056
username := r.getUserName(req)
6157
if len(username) == 0 {
6258
return nil
@@ -71,6 +67,54 @@ func (r *ReverseProxy) Verify(req *http.Request, w http.ResponseWriter, store Da
7167
}
7268
user = r.newUser(req)
7369
}
70+
return user
71+
}
72+
73+
// getEmail extracts the email from the "setting.ReverseProxyAuthEmail" header
74+
func (r *ReverseProxy) getEmail(req *http.Request) string {
75+
return strings.TrimSpace(req.Header.Get(setting.ReverseProxyAuthEmail))
76+
}
77+
78+
// getUserFromAuthEmail extracts the username from the "setting.ReverseProxyAuthEmail" header
79+
// of the request and returns the corresponding user object for that email.
80+
// Verification of header data is not performed as it should have already been done by
81+
// the reverse proxy.
82+
// If an email is available in the "setting.ReverseProxyAuthEmail" header an existing
83+
// user object is returned (populated with the email found in header).
84+
// Returns nil if header is empty or if "setting.EnableReverseProxyEmail" is disabled.
85+
func (r *ReverseProxy) getUserFromAuthEmail(req *http.Request) *user_model.User {
86+
if !setting.Service.EnableReverseProxyEmail {
87+
return nil
88+
}
89+
email := r.getEmail(req)
90+
if len(email) == 0 {
91+
return nil
92+
}
93+
log.Trace("ReverseProxy Authorization: Found email: %s", email)
94+
95+
user, err := user_model.GetUserByEmail(email)
96+
if err != nil {
97+
// Do not allow auto-registration, we don't have a username here
98+
if !user_model.IsErrUserNotExist(err) {
99+
log.Error("GetUserByEmail: %v", err)
100+
}
101+
return nil
102+
}
103+
return user
104+
}
105+
106+
// Verify attempts to load a user object based on headers sent by the reverse proxy.
107+
// First it will attempt to load it based on the username (see docs for getUserFromAuthUser),
108+
// and failing that it will attempt to load it based on the email (see docs for getUserFromAuthEmail).
109+
// Returns nil if the headers are empty or the user is not found.
110+
func (r *ReverseProxy) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *user_model.User {
111+
user := r.getUserFromAuthUser(req)
112+
if user == nil {
113+
user = r.getUserFromAuthEmail(req)
114+
if user == nil {
115+
return nil
116+
}
117+
}
74118

75119
// Make sure requests to API paths, attachment downloads, git and LFS do not create a new session
76120
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawReleaseOrLFSPath(req) {

templates/package/content/container.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
{{if .PackageDescriptor.Metadata.ImageLayers}}
4848
<h4 class="ui top attached header">{{.locale.Tr "packages.container.layers"}}</h4>
4949
<div class="ui attached segment">
50-
<table id="notice-table" class="ui very basic compact table">
50+
<table class="ui very basic compact table">
5151
<tbody>
5252
{{range .PackageDescriptor.Metadata.ImageLayers}}
5353
<tr>
@@ -61,7 +61,7 @@
6161
{{if .PackageDescriptor.Metadata.Labels}}
6262
<h4 class="ui top attached header">{{.locale.Tr "packages.container.labels"}}</h4>
6363
<div class="ui attached segment">
64-
<table id="notice-table" class="ui very basic compact table">
64+
<table class="ui very basic compact table container-labels">
6565
<thead>
6666
<tr>
6767
<th>{{.locale.Tr "packages.container.labels.key"}}</th>

templates/repo/commit_page.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{template "base/head" .}}
22
<div class="page-content repository diff">
33
{{template "repo/header" .}}
4-
<div class="ui container {{if .IsSplitStyle}}fluid padded{{end}}">
4+
<div class="ui container fluid padded">
55
{{$class := ""}}
66
{{if .Commit.Signature}}
77
{{$class = (printf "%s%s" $class " isSigned")}}

0 commit comments

Comments
 (0)