Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  Fix issue overview for teams (go-gitea#19652)
  Fix nodeinfo caching and prevent NPE if cache non-existent (go-gitea#19721)
  Update go-chi/cache to utilize Ping() (go-gitea#19719)
  Disable blank issues (go-gitea#19717)
  clarify what session provider 'db' does (go-gitea#19713)
  [skip ci] Updated translations via Crowdin
  • Loading branch information
zjjhot committed May 16, 2022
2 parents 79092b0 + 71ca131 commit afa2c2a
Show file tree
Hide file tree
Showing 25 changed files with 174 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
blank_issues_enabled: true
blank_issues_enabled: false
contact_links:
- name: Security Concern
url: https://tinyurl.com/security-gitea
Expand Down
3 changes: 2 additions & 1 deletion custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,8 @@ PATH =
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Either "memory", "file", or "redis", default is "memory"
;; Either "memory", "file", "redis", "db", "mysql", "couchbase", "memcache" or "postgres"
;; Default is "memory". "db" will reuse the configuration in [database]
;PROVIDER = memory
;;
;; Provider config options
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type

## Session (`session`)

- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, db, mysql, couchbase, memcache, postgres\].
- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, db, mysql, couchbase, memcache, postgres\]. Setting `db` will reuse the configuration in `[database]`
- `PROVIDER_CONFIG`: **data/sessions**: For file, the root path; for db, empty (database config will be used); for others, the connection string.
- `COOKIE_SECURE`: **false**: Enable this to force using HTTPS for all session access.
- `COOKIE_NAME`: **i\_like\_gitea**: The name of the cookie used for the session ID.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b
code.gitea.io/sdk/gitea v0.15.1
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb
gitea.com/go-chi/cache v0.0.0-20211201020628-dcb774c4ffea
gitea.com/go-chi/cache v0.2.0
gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5
gitea.com/go-chi/session v0.0.0-20211218221615-e3605d8b28b8
gitea.com/lunny/levelqueue v0.4.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb h1:Yy0Bxzc8R2wxiwXoG/rECGplJUSpXqCsog9PuJFgiHs=
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb/go.mod h1:77TZu701zMXWJFvB8gvTbQ92zQ3DQq/H7l5wAEjQRKc=
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0=
gitea.com/go-chi/cache v0.0.0-20211201020628-dcb774c4ffea h1:Fq/f4hjigb5v5WpA5TfBCZOSavpHPBiB4Wkj/WsITYM=
gitea.com/go-chi/cache v0.0.0-20211201020628-dcb774c4ffea/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0=
gitea.com/go-chi/cache v0.2.0 h1:E0npuTfDW6CT1yD8NMDVc1SK6IeRjfmRL2zlEsCEd7w=
gitea.com/go-chi/cache v0.2.0/go.mod h1:iQlVK2aKTZ/rE9UcHyz9pQWGvdP9i1eI2spOpzgCrtE=
gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5 h1:J/1i8u40TbcLP/w2w2KCkgW2PelIqYkD5UOwu8IOvVU=
gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5/go.mod h1:hQ9SYHKdOX968wJglb/NMQ+UqpOKwW4L+EYdvkWjHSo=
gitea.com/go-chi/session v0.0.0-20211218221615-e3605d8b28b8 h1:tJQRXgZigkLeeW9LPlps9G9aMoE6LAmqigLA+wxmd1Q=
Expand Down
8 changes: 4 additions & 4 deletions integrations/api_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,22 @@ func TestAPISearchIssues(t *testing.T) {
req = NewRequest(t, "GET", link.String())
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.EqualValues(t, "15", resp.Header().Get("X-Total-Count"))
assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count"))
assert.Len(t, apiIssues, 10) // there are more but 10 is page item limit

query.Add("limit", "20")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 15)
assert.Len(t, apiIssues, 17)

query = url.Values{"assigned": {"true"}, "state": {"all"}, "token": {token}}
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 1)
assert.Len(t, apiIssues, 2)

query = url.Values{"milestones": {"milestone1"}, "state": {"all"}, "token": {token}}
link.RawQuery = query.Encode()
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestAPISearchIssues(t *testing.T) {
req = NewRequest(t, "GET", link.String())
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 3)
assert.Len(t, apiIssues, 5)

query = url.Values{"owner": {"user3"}, "team": {"team1"}, "token": {token}} // organization + team
link.RawQuery = query.Encode()
Expand Down
2 changes: 1 addition & 1 deletion integrations/api_nodeinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestNodeinfo(t *testing.T) {
assert.True(t, nodeinfo.OpenRegistrations)
assert.Equal(t, "gitea", nodeinfo.Software.Name)
assert.Equal(t, 23, nodeinfo.Usage.Users.Total)
assert.Equal(t, 15, nodeinfo.Usage.LocalPosts)
assert.Equal(t, 17, nodeinfo.Usage.LocalPosts)
assert.Equal(t, 2, nodeinfo.Usage.LocalComments)
})
}
8 changes: 4 additions & 4 deletions integrations/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,22 +392,22 @@ func TestSearchIssues(t *testing.T) {
req = NewRequest(t, "GET", link.String())
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.EqualValues(t, "15", resp.Header().Get("X-Total-Count"))
assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count"))
assert.Len(t, apiIssues, 10) // there are more but 10 is page item limit

query.Add("limit", "20")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 15)
assert.Len(t, apiIssues, 17)

query = url.Values{"assigned": {"true"}, "state": {"all"}}
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 1)
assert.Len(t, apiIssues, 2)

query = url.Values{"milestones": {"milestone1"}, "state": {"all"}}
link.RawQuery = query.Encode()
Expand Down Expand Up @@ -435,7 +435,7 @@ func TestSearchIssues(t *testing.T) {
req = NewRequest(t, "GET", link.String())
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 3)
assert.Len(t, apiIssues, 5)

query = url.Values{"owner": {"user3"}, "team": {"team1"}} // organization + team
link.RawQuery = query.Encode()
Expand Down
24 changes: 24 additions & 0 deletions models/fixtures/issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,27 @@
is_pull: false
created_unix: 1602935696
updated_unix: 1602935696

-
id: 16
repo_id: 32
index: 1
poster_id: 2
name: just a normal issue
content: content
is_closed: false
is_pull: false
created_unix: 1602935696
updated_unix: 1602935696

-
id: 17
repo_id: 32
index: 2
poster_id: 15
name: a issue with a assignment
content: content
is_closed: false
is_pull: false
created_unix: 1602935696
updated_unix: 1602935696
4 changes: 4 additions & 0 deletions models/fixtures/issue_assignees.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
id: 3
assignee_id: 2
issue_id: 6
-
id: 4
assignee_id: 2
issue_id: 17
5 changes: 4 additions & 1 deletion models/fixtures/issue_index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
-
group_id: 10
max_index: 1
-
group_id: 32
max_index: 2
-
group_id: 48
max_index: 1
Expand All @@ -21,4 +24,4 @@
max_index: 1
-
group_id: 51
max_index: 1
max_index: 1
2 changes: 1 addition & 1 deletion models/fixtures/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@
is_private: false
num_stars: 0
num_forks: 0
num_issues: 0
num_issues: 2
is_mirror: false
status: 0

Expand Down
1 change: 1 addition & 0 deletions models/fixtures/team_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@

-
id: 43
org_id: 3
team_id: 7
type: 2 # issues
access_mode: 2
Expand Down
6 changes: 3 additions & 3 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,7 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
}

if opts.User != nil {
sess.And(
issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.IsTrue()),
)
sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.IsTrue()))
}
}

Expand Down Expand Up @@ -1463,6 +1461,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {

sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
opts.setupSessionWithLimit(sess)

sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID)

issues := make([]*Issue, 0, opts.ListOptions.PageSize)
Expand All @@ -1484,6 +1483,7 @@ func CountIssues(opts *IssuesOptions) (int64, error) {
sess := e.Select("COUNT(issue.id) AS count").Table("issue")
sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
opts.setupSessionNoLimit(sess)

return sess.Count()
}

Expand Down
19 changes: 17 additions & 2 deletions models/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/foreignreference"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/organization"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -287,6 +288,20 @@ func TestGetUserIssueStats(t *testing.T) {
ClosedCount: 0,
},
},
{
UserIssueStatsOptions{
UserID: 2,
Org: unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}).(*organization.Organization),
Team: unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 7}).(*organization.Team),
FilterMode: FilterModeAll,
},
IssueStats{
YourRepositoriesCount: 2,
AssignCount: 1,
CreateCount: 1,
OpenCount: 2,
},
},
} {
t.Run(fmt.Sprintf("%#v", test.Opts), func(t *testing.T) {
stats, err := GetUserIssueStats(test.Opts)
Expand Down Expand Up @@ -341,7 +356,7 @@ func TestGetRepoIDsForIssuesOptions(t *testing.T) {
IssuesOptions{
AssigneeID: 2,
},
[]int64{3},
[]int64{3, 32},
},
{
IssuesOptions{
Expand Down Expand Up @@ -595,5 +610,5 @@ func TestCountIssues(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
count, err := CountIssues(&IssuesOptions{})
assert.NoError(t, err)
assert.EqualValues(t, 15, count)
assert.EqualValues(t, 17, count)
}
24 changes: 20 additions & 4 deletions models/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
Expand Down Expand Up @@ -246,11 +247,26 @@ func teamUnitsRepoCond(id string, userID, orgID, teamID int64, units ...unit.Typ
builder.Eq{
"team_id": teamID,
}.And(
builder.In(
"team_id", builder.Select("team_id").From("team_user").Where(
builder.Eq{
builder.Or(
// Check if the user is member of the team.
builder.In(
"team_id", builder.Select("team_id").From("team_user").Where(
builder.Eq{
"uid": userID,
},
),
),
// Check if the user is in the owner team of the organisation.
builder.Exists(builder.Select("team_id").From("team_user").
Where(builder.Eq{
"org_id": orgID,
"team_id": builder.Select("id").From("team").Where(
builder.Eq{
"org_id": orgID,
"lower_name": strings.ToLower(organization.OwnerTeamName),
}),
"uid": userID,
},
}),
),
)).And(
builder.In(
Expand Down
27 changes: 1 addition & 26 deletions modules/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
package cache

import (
"errors"
"fmt"
"strconv"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"

mc "gitea.com/go-chi/cache"
Expand All @@ -35,37 +33,14 @@ func NewContext() error {
if conn, err = newCache(setting.CacheService.Cache); err != nil {
return err
}
if err = Ping(); err != nil {
if err = conn.Ping(); err != nil {
return err
}
}

return err
}

// Ping checks if the cache service works or not, it not, it returns an error
func Ping() error {
if conn == nil {
return errors.New("cache not available")
}
var err error
const testKey = "__gitea_cache_test"
const testVal = "test-value"
if err = conn.Put(testKey, testVal, 10); err != nil {
return err
}
val := conn.Get(testKey)
if valStr, ok := val.(string); !ok || valStr != testVal {
// If the cache is full, the Get may not read the expected value stored by Put.
// Since we have checked that Put can success, so we just show a warning here, do not return an error to panic.
log.Warn("cache (adapter:%s, config:%s) doesn't seem to work correctly, set test value '%v' but get '%v'",
setting.CacheService.Cache.Adapter, setting.CacheService.Cache.Conn,
testVal, val,
)
}
return nil
}

// GetCache returns the currently configured cache
func GetCache() mc.Cache {
return conn
Expand Down
5 changes: 5 additions & 0 deletions modules/cache/cache_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func (c *RedisCacher) StartAndGC(opts cache.Options) error {
return c.c.Ping(graceful.GetManager().HammerContext()).Err()
}

// Ping tests if the cache is alive.
func (c *RedisCacher) Ping() error {
return c.c.Ping(graceful.GetManager().HammerContext()).Err()
}

func init() {
cache.Register("redis", &RedisCacher{})
}
5 changes: 5 additions & 0 deletions modules/cache/cache_twoqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ func (c *TwoQueueCache) StartAndGC(opts mc.Options) error {
return err
}

// Ping tests if the cache is alive.
func (c *TwoQueueCache) Ping() error {
return mc.GenericPing(c)
}

func init() {
mc.Register("twoqueue", &TwoQueueCache{})
}
2 changes: 1 addition & 1 deletion options/locale/locale_de-DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ sign_up_successful=Konto wurde erfolgreich erstellt.
confirmation_mail_sent_prompt=Eine neue Bestätigungs-E-Mail wurde an <b>%s</b> gesendet. Bitte überprüfe dein Postfach innerhalb der nächsten %s, um die Registrierung abzuschließen.
must_change_password=Aktualisiere dein Passwort
allow_password_change=Verlange vom Benutzer das Passwort zu ändern (empfohlen)
reset_password_mail_sent_prompt=Eine Bestätigungs-E-Mail wurde an<b>%s</b> gesendet. Bitte überprüfe dein Postfach innerhalb von %s um den Wiederherstellungsprozess abzuschließen.
reset_password_mail_sent_prompt=Eine Bestätigungs-E-Mail wurde an <b>%s</b> gesendet. Bitte überprüfe dein Postfach innerhalb von %s, um den Wiederherstellungsprozess abzuschließen.
active_your_account=Aktiviere dein Konto
account_activated=Konto wurde aktiviert
prohibit_login=Anmelden verboten
Expand Down
Loading

0 comments on commit afa2c2a

Please sign in to comment.