Compare commits

...

7 Commits

Author SHA1 Message Date
KN4CK3R 58d24f73be
Merge 2c742e320d into 26ae592234 2024-05-11 21:59:57 +03:00
Lunny Xiao 26ae592234
Move reverproxyauth before session so the header will not be ignored even if user has login (#27821)
When a user logout and then login another user, the reverseproxy auth
should be checked before session otherwise the old user is still login.
2024-05-11 14:55:49 +00:00
silverwind 3c2406a2f3
Use CSS `inset` shorthand (#30939)
Use [inset](https://developer.mozilla.org/en-US/docs/Web/CSS/inset)
shorthand instead of longhands. There may be more cases but these ones I
was able to definitely identify.
2024-05-11 14:28:56 +00:00
Lunny Xiao 40de54ece8
Remove If Exist check on migration for mssql because that syntax required SQL server 2016 (#30894)
Fix #30872

We will assume the database is consistent before executing the
migration. So the indexes should exist. Removing `IF EXIST` then is safe
enough.

---------

Co-authored-by: silverwind <me@silverwind.io>
2024-05-11 22:16:09 +08:00
KN4CK3R 2c742e320d Extract and display readme. 2024-05-09 20:43:09 +00:00
KN4CK3R d406ac025a Merge branch 'main' of https://github.com/go-gitea/gitea into enhancement-composer 2024-04-22 17:35:01 +00:00
KN4CK3R c3977fb558 Extract and display comments. 2024-04-05 22:13:44 +00:00
10 changed files with 109 additions and 54 deletions

View File

@ -1,3 +1,5 @@
-
id: 1
user_id: 1
pull_id: 1
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d

View File

@ -36,9 +36,9 @@ func expandHashReferencesToSha256(x *xorm.Engine) error {
if setting.Database.Type.IsMSSQL() {
// drop indexes that need to be re-created afterwards
droppedIndexes := []string{
"DROP INDEX IF EXISTS [IDX_commit_status_context_hash] ON [commit_status]",
"DROP INDEX IF EXISTS [UQE_review_state_pull_commit_user] ON [review_state]",
"DROP INDEX IF EXISTS [UQE_repo_archiver_s] ON [repo_archiver]",
"DROP INDEX [IDX_commit_status_context_hash] ON [commit_status]",
"DROP INDEX [UQE_review_state_pull_commit_user] ON [review_state]",
"DROP INDEX [UQE_repo_archiver_s] ON [repo_archiver]",
}
for _, s := range droppedIndexes {
_, err := db.Exec(s)

View File

@ -19,21 +19,21 @@ func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) {
type CommitStatus struct {
ID int64
ContextHash string
ContextHash string `xorm:"char(40) index"`
}
type RepoArchiver struct {
ID int64
RepoID int64
Type int
CommitID string
RepoID int64 `xorm:"index unique(s)"`
Type int `xorm:"unique(s)"`
CommitID string `xorm:"VARCHAR(40) unique(s)"`
}
type ReviewState struct {
ID int64
CommitSHA string
UserID int64
PullID int64
UserID int64 `xorm:"NOT NULL UNIQUE(pull_commit_user)"`
PullID int64 `xorm:"NOT NULL INDEX UNIQUE(pull_commit_user) DEFAULT 0"`
CommitSHA string `xorm:"NOT NULL VARCHAR(40) UNIQUE(pull_commit_user)"`
}
type Comment struct {

View File

@ -36,10 +36,14 @@ type Package struct {
Metadata *Metadata
}
// https://getcomposer.org/doc/04-schema.md
// Metadata represents the metadata of a Composer package
type Metadata struct {
Description string `json:"description,omitempty"`
Readme string `json:"readme,omitempty"`
Keywords []string `json:"keywords,omitempty"`
Comments Comments `json:"_comments,omitempty"`
Homepage string `json:"homepage,omitempty"`
License Licenses `json:"license,omitempty"`
Authors []Author `json:"authors,omitempty"`
@ -74,6 +78,28 @@ func (l *Licenses) UnmarshalJSON(data []byte) error {
return nil
}
// Comments represents the comments of a Composer package
type Comments []string
// UnmarshalJSON reads from a string or array
func (c *Comments) UnmarshalJSON(data []byte) error {
switch data[0] {
case '"':
var value string
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*c = Comments{value}
case '[':
values := make([]string, 0, 5)
if err := json.Unmarshal(data, &values); err != nil {
return err
}
*c = Comments(values)
}
return nil
}
// Author represents an author
type Author struct {
Name string `json:"name,omitempty"`
@ -101,14 +127,14 @@ func ParsePackage(r io.ReaderAt, size int64) (*Package, error) {
}
defer f.Close()
return ParseComposerFile(f)
return ParseComposerFile(archive, f)
}
}
return nil, ErrMissingComposerFile
}
// ParseComposerFile parses a composer.json file to retrieve the metadata of a Composer package
func ParseComposerFile(r io.Reader) (*Package, error) {
func ParseComposerFile(archive *zip.Reader, r io.Reader) (*Package, error) {
var cj struct {
Name string `json:"name"`
Version string `json:"version"`
@ -137,6 +163,18 @@ func ParseComposerFile(r io.Reader) (*Package, error) {
cj.Type = "library"
}
if cj.Readme == "" {
cj.Readme = "README.md"
}
f, err := archive.Open(cj.Readme)
if err == nil {
buf, _ := io.ReadAll(f)
cj.Readme = string(buf)
_ = f.Close()
} else {
cj.Readme = ""
}
return &Package{
Name: cj.Name,
Version: cj.Version,

View File

@ -17,6 +17,8 @@ import (
const (
name = "gitea/composer-package"
description = "Package Description"
readme = "Package Readme"
comments = "Package Comment"
packageType = "composer-plugin"
author = "Gitea Authors"
email = "no.reply@gitea.io"
@ -41,7 +43,8 @@ const composerContent = `{
},
"require": {
"php": ">=7.2 || ^8.0"
}
},
"_comments": "` + comments + `"
}`
func TestLicenseUnmarshal(t *testing.T) {
@ -54,18 +57,30 @@ func TestLicenseUnmarshal(t *testing.T) {
assert.Equal(t, "MIT", l[0])
}
func TestCommentsUnmarshal(t *testing.T) {
var c Comments
assert.NoError(t, json.NewDecoder(strings.NewReader(`["comment"]`)).Decode(&c))
assert.Len(t, c, 1)
assert.Equal(t, "comment", c[0])
assert.NoError(t, json.NewDecoder(strings.NewReader(`"comment"`)).Decode(&c))
assert.Len(t, c, 1)
assert.Equal(t, "comment", c[0])
}
func TestParsePackage(t *testing.T) {
createArchive := func(name, content string) []byte {
createArchive := func(files map[string]string) []byte {
var buf bytes.Buffer
archive := zip.NewWriter(&buf)
w, _ := archive.Create(name)
w.Write([]byte(content))
for name, content := range files {
w, _ := archive.Create(name)
w.Write([]byte(content))
}
archive.Close()
return buf.Bytes()
}
t.Run("MissingComposerFile", func(t *testing.T) {
data := createArchive("dummy.txt", "")
data := createArchive(map[string]string{"dummy.txt": ""})
cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
assert.Nil(t, cp)
@ -73,7 +88,7 @@ func TestParsePackage(t *testing.T) {
})
t.Run("MissingComposerFileInRoot", func(t *testing.T) {
data := createArchive("sub/sub/composer.json", "")
data := createArchive(map[string]string{"sub/sub/composer.json": ""})
cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
assert.Nil(t, cp)
@ -81,43 +96,52 @@ func TestParsePackage(t *testing.T) {
})
t.Run("InvalidComposerFile", func(t *testing.T) {
data := createArchive("composer.json", "")
data := createArchive(map[string]string{"composer.json": ""})
cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
assert.Nil(t, cp)
assert.Error(t, err)
})
t.Run("Valid", func(t *testing.T) {
data := createArchive("composer.json", composerContent)
t.Run("InvalidPackageName", func(t *testing.T) {
data := createArchive(map[string]string{"composer.json": "{}"})
cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
assert.NoError(t, err)
assert.NotNil(t, cp)
})
}
func TestParseComposerFile(t *testing.T) {
t.Run("InvalidPackageName", func(t *testing.T) {
cp, err := ParseComposerFile(strings.NewReader(`{}`))
assert.Nil(t, cp)
assert.ErrorIs(t, err, ErrInvalidName)
})
t.Run("InvalidPackageVersion", func(t *testing.T) {
cp, err := ParseComposerFile(strings.NewReader(`{"name": "gitea/composer-package", "version": "1.a.3"}`))
data := createArchive(map[string]string{"composer.json": `{"name": "gitea/composer-package", "version": "1.a.3"}`})
cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
assert.Nil(t, cp)
assert.ErrorIs(t, err, ErrInvalidVersion)
})
t.Run("InvalidReadmePath", func(t *testing.T) {
data := createArchive(map[string]string{"composer.json": `{"name": "gitea/composer-package", "readme": "sub/README.md"}`})
cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
assert.NoError(t, err)
assert.NotNil(t, cp)
assert.Empty(t, cp.Metadata.Readme)
})
t.Run("Valid", func(t *testing.T) {
cp, err := ParseComposerFile(strings.NewReader(composerContent))
data := createArchive(map[string]string{"composer.json": composerContent, "README.md": readme})
cp, err := ParsePackage(bytes.NewReader(data), int64(len(data)))
assert.NoError(t, err)
assert.NotNil(t, cp)
assert.Equal(t, name, cp.Name)
assert.Empty(t, cp.Version)
assert.Equal(t, description, cp.Metadata.Description)
assert.Equal(t, readme, cp.Metadata.Readme)
assert.Len(t, cp.Metadata.Comments, 1)
assert.Equal(t, comments, cp.Metadata.Comments[0])
assert.Len(t, cp.Metadata.Authors, 1)
assert.Equal(t, author, cp.Metadata.Authors[0].Name)
assert.Equal(t, email, cp.Metadata.Authors[0].Email)

View File

@ -98,14 +98,14 @@ func optionsCorsHandler() func(next http.Handler) http.Handler {
// The Session plugin is expected to be executed second, in order to skip authentication
// for users that have already signed in.
func buildAuthGroup() *auth_service.Group {
group := auth_service.NewGroup(
&auth_service.OAuth2{}, // FIXME: this should be removed and only applied in download and oauth related routers
&auth_service.Basic{}, // FIXME: this should be removed and only applied in download and git/lfs routers
&auth_service.Session{},
)
group := auth_service.NewGroup()
group.Add(&auth_service.OAuth2{}) // FIXME: this should be removed and only applied in download and oauth related routers
group.Add(&auth_service.Basic{}) // FIXME: this should be removed and only applied in download and git/lfs routers
if setting.Service.EnableReverseProxyAuth {
group.Add(&auth_service.ReverseProxy{})
group.Add(&auth_service.ReverseProxy{}) // reverseproxy should before Session, otherwise the header will be ignored if user has login
}
group.Add(&auth_service.Session{})
if setting.IsWindows && auth_model.IsSSPIEnabled(db.DefaultContext) {
group.Add(&auth_service.SSPI{}) // it MUST be the last, see the comment of SSPI

View File

@ -22,11 +22,11 @@
</div>
</div>
{{if .PackageDescriptor.Metadata.Description}}
{{if or .PackageDescriptor.Metadata.Description .PackageDescriptor.Metadata.Comments}}
<h4 class="ui top attached header">{{ctx.Locale.Tr "packages.about"}}</h4>
<div class="ui attached segment">
{{.PackageDescriptor.Metadata.Description}}
</div>
{{if .PackageDescriptor.Metadata.Description}}<div class="ui attached segment">{{.PackageDescriptor.Metadata.Description}}</div>{{end}}
{{if .PackageDescriptor.Metadata.Readme}}<div class="ui attached segment markup markdown">{{RenderMarkdownToHtml $.Context .PackageDescriptor.Metadata.Readme}}</div>{{end}}
{{if .PackageDescriptor.Metadata.Comments}}<div class="ui attached segment">{{StringUtils.Join .PackageDescriptor.Metadata.Comments " "}}</div>{{end}}
{{end}}
{{if or .PackageDescriptor.Metadata.Require .PackageDescriptor.Metadata.RequireDev}}
@ -39,7 +39,7 @@
</div>
{{end}}
{{if or .PackageDescriptor.Metadata.Keywords}}
{{if .PackageDescriptor.Metadata.Keywords}}
<h4 class="ui top attached header">{{ctx.Locale.Tr "packages.keywords"}}</h4>
<div class="ui attached segment">
{{range .PackageDescriptor.Metadata.Keywords}}

View File

@ -20,10 +20,7 @@ Gitea's private styles use `g-` prefix.
.g-table-auto-ellipsis td.auto-ellipsis span {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
inset: 0;
padding: inherit;
white-space: nowrap;
overflow: hidden;

View File

@ -204,10 +204,7 @@
.markup input[type="checkbox"]::after {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
inset: 0;
pointer-events: none;
background: var(--color-text);
mask-size: cover;

View File

@ -3,10 +3,7 @@
.ui.dimmer {
position: fixed;
display: none;
top: 0;
left: 0;
right: 0;
bottom: 0;
inset: 0;
background: var(--color-overlay-backdrop);
opacity: 0;
z-index: 1000;