Skip to content

Commit 4211fb8

Browse files
authored
Merge branch 'master' into rm-com
2 parents 0628e08 + cd607b5 commit 4211fb8

20 files changed

+148
-82
lines changed

integrations/privateactivity_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func TestPrivateActivityYesHeatmapHasNoContentForUserItself(t *testing.T) {
388388
session := loginUser(t, privateActivityTestUser)
389389
hasContent := testPrivateActivityHelperHasHeatmapContentFromSession(t, session)
390390

391-
assert.False(t, hasContent, "user should have no heatmap content")
391+
assert.True(t, hasContent, "user should see their own heatmap content")
392392
}
393393

394394
func TestPrivateActivityYesHeatmapHasNoContentForOtherUser(t *testing.T) {
@@ -399,7 +399,7 @@ func TestPrivateActivityYesHeatmapHasNoContentForOtherUser(t *testing.T) {
399399
session := loginUser(t, privateActivityTestOtherUser)
400400
hasContent := testPrivateActivityHelperHasHeatmapContentFromSession(t, session)
401401

402-
assert.False(t, hasContent, "user should have no heatmap content")
402+
assert.False(t, hasContent, "other user should not see heatmap content")
403403
}
404404

405405
func TestPrivateActivityYesHeatmapHasNoContentForAdmin(t *testing.T) {
@@ -410,5 +410,5 @@ func TestPrivateActivityYesHeatmapHasNoContentForAdmin(t *testing.T) {
410410
session := loginUser(t, privateActivityTestAdmin)
411411
hasContent := testPrivateActivityHelperHasHeatmapContentFromSession(t, session)
412412

413-
assert.False(t, hasContent, "user should have no heatmap content")
413+
assert.True(t, hasContent, "heatmap should show content for admin")
414414
}

models/action.go

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -297,32 +297,63 @@ type GetFeedsOptions struct {
297297

298298
// GetFeeds returns actions according to the provided options
299299
func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
300-
cond := builder.NewCond()
300+
if !activityReadable(opts.RequestedUser, opts.Actor) {
301+
return make([]*Action, 0), nil
302+
}
301303

302-
var repoIDs []int64
303-
var actorID int64
304+
cond, err := activityQueryCondition(opts)
305+
if err != nil {
306+
return nil, err
307+
}
304308

305-
if opts.Actor != nil {
306-
actorID = opts.Actor.ID
309+
actions := make([]*Action, 0, setting.UI.FeedPagingNum)
310+
311+
if err := x.Limit(setting.UI.FeedPagingNum).Desc("id").Where(cond).Find(&actions); err != nil {
312+
return nil, fmt.Errorf("Find: %v", err)
307313
}
308314

309-
if opts.RequestedUser.IsOrganization() {
310-
env, err := opts.RequestedUser.AccessibleReposEnv(actorID)
311-
if err != nil {
312-
return nil, fmt.Errorf("AccessibleReposEnv: %v", err)
313-
}
314-
if repoIDs, err = env.RepoIDs(1, opts.RequestedUser.NumRepos); err != nil {
315-
return nil, fmt.Errorf("GetUserRepositories: %v", err)
315+
if err := ActionList(actions).LoadAttributes(); err != nil {
316+
return nil, fmt.Errorf("LoadAttributes: %v", err)
317+
}
318+
319+
return actions, nil
320+
}
321+
322+
func activityReadable(user *User, doer *User) bool {
323+
var doerID int64
324+
if doer != nil {
325+
doerID = doer.ID
326+
}
327+
if doer == nil || !doer.IsAdmin {
328+
if user.KeepActivityPrivate && doerID != user.ID {
329+
return false
316330
}
331+
}
332+
return true
333+
}
317334

318-
cond = cond.And(builder.In("repo_id", repoIDs))
319-
} else {
320-
cond = cond.And(builder.In("repo_id", AccessibleRepoIDsQuery(opts.Actor)))
335+
func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
336+
cond := builder.NewCond()
337+
338+
var repoIDs []int64
339+
var actorID int64
340+
if opts.Actor != nil {
341+
actorID = opts.Actor.ID
321342
}
322343

344+
// check readable repositories by doer/actor
323345
if opts.Actor == nil || !opts.Actor.IsAdmin {
324-
if opts.RequestedUser.KeepActivityPrivate && actorID != opts.RequestedUser.ID {
325-
return make([]*Action, 0), nil
346+
if opts.RequestedUser.IsOrganization() {
347+
env, err := opts.RequestedUser.AccessibleReposEnv(actorID)
348+
if err != nil {
349+
return nil, fmt.Errorf("AccessibleReposEnv: %v", err)
350+
}
351+
if repoIDs, err = env.RepoIDs(1, opts.RequestedUser.NumRepos); err != nil {
352+
return nil, fmt.Errorf("GetUserRepositories: %v", err)
353+
}
354+
cond = cond.And(builder.In("repo_id", repoIDs))
355+
} else {
356+
cond = cond.And(builder.In("repo_id", AccessibleRepoIDsQuery(opts.Actor)))
326357
}
327358
}
328359

@@ -334,20 +365,9 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
334365
if !opts.IncludePrivate {
335366
cond = cond.And(builder.Eq{"is_private": false})
336367
}
337-
338368
if !opts.IncludeDeleted {
339369
cond = cond.And(builder.Eq{"is_deleted": false})
340370
}
341371

342-
actions := make([]*Action, 0, setting.UI.FeedPagingNum)
343-
344-
if err := x.Limit(setting.UI.FeedPagingNum).Desc("id").Where(cond).Find(&actions); err != nil {
345-
return nil, fmt.Errorf("Find: %v", err)
346-
}
347-
348-
if err := ActionList(actions).LoadAttributes(); err != nil {
349-
return nil, fmt.Errorf("LoadAttributes: %v", err)
350-
}
351-
352-
return actions, nil
372+
return cond, nil
353373
}

models/fixtures/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@
2323
act_user_id: 11
2424
repo_id: 9
2525
is_private: false
26+
27+
-
28+
id: 4
29+
user_id: 16
30+
op_type: 12 # close issue
31+
act_user_id: 16
32+
repo_id: 22
33+
is_private: true
34+
created_unix: 1603267920

models/user_heatmap.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ type UserHeatmapData struct {
1616
}
1717

1818
// GetUserHeatmapDataByUser returns an array of UserHeatmapData
19-
func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
19+
func GetUserHeatmapDataByUser(user *User, doer *User) ([]*UserHeatmapData, error) {
2020
hdata := make([]*UserHeatmapData, 0)
2121

22-
if user.KeepActivityPrivate {
22+
if !activityReadable(user, doer) {
2323
return hdata, nil
2424
}
2525

@@ -37,22 +37,26 @@ func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
3737
groupByName = groupBy
3838
}
3939

40-
sess := x.Select(groupBy+" AS timestamp, count(user_id) as contributions").
41-
Table("action").
42-
Where("user_id = ?", user.ID).
43-
And("created_unix > ?", (timeutil.TimeStampNow() - 31536000))
44-
45-
// * Heatmaps for individual users only include actions that the user themself
46-
// did.
47-
// * For organizations actions by all users that were made in owned
48-
// repositories are counted.
49-
if user.Type == UserTypeIndividual {
50-
sess = sess.And("act_user_id = ?", user.ID)
40+
cond, err := activityQueryCondition(GetFeedsOptions{
41+
RequestedUser: user,
42+
Actor: doer,
43+
IncludePrivate: true, // don't filter by private, as we already filter by repo access
44+
IncludeDeleted: true,
45+
// * Heatmaps for individual users only include actions that the user themself did.
46+
// * For organizations actions by all users that were made in owned
47+
// repositories are counted.
48+
OnlyPerformedBy: !user.IsOrganization(),
49+
})
50+
if err != nil {
51+
return nil, err
5152
}
5253

53-
err := sess.GroupBy(groupByName).
54+
return hdata, x.
55+
Select(groupBy+" AS timestamp, count(user_id) as contributions").
56+
Table("action").
57+
Where(cond).
58+
And("created_unix > ?", (timeutil.TimeStampNow() - 31536000)).
59+
GroupBy(groupByName).
5460
OrderBy("timestamp").
5561
Find(&hdata)
56-
57-
return hdata, err
5862
}

models/user_heatmap_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package models
66

77
import (
88
"encoding/json"
9+
"fmt"
910
"testing"
1011

1112
"github.com/stretchr/testify/assert"
@@ -14,35 +15,45 @@ import (
1415
func TestGetUserHeatmapDataByUser(t *testing.T) {
1516
testCases := []struct {
1617
userID int64
18+
doerID int64
1719
CountResult int
1820
JSONResult string
1921
}{
20-
{2, 1, `[{"timestamp":1603152000,"contributions":1}]`},
21-
{3, 0, `[]`},
22+
{2, 2, 1, `[{"timestamp":1603152000,"contributions":1}]`}, // self looks at action in private repo
23+
{2, 1, 1, `[{"timestamp":1603152000,"contributions":1}]`}, // admin looks at action in private repo
24+
{2, 3, 0, `[]`}, // other user looks at action in private repo
25+
{2, 0, 0, `[]`}, // nobody looks at action in private repo
26+
{16, 15, 1, `[{"timestamp":1603238400,"contributions":1}]`}, // collaborator looks at action in private repo
27+
{3, 3, 0, `[]`}, // no action action not performed by target user
2228
}
2329
// Prepare
2430
assert.NoError(t, PrepareTestDatabase())
2531

26-
for _, tc := range testCases {
27-
28-
// Insert some action
32+
for i, tc := range testCases {
2933
user := AssertExistsAndLoadBean(t, &User{ID: tc.userID}).(*User)
3034

35+
doer := &User{ID: tc.doerID}
36+
_, err := loadBeanIfExists(doer)
37+
assert.NoError(t, err)
38+
if tc.doerID == 0 {
39+
doer = nil
40+
}
41+
3142
// get the action for comparison
3243
actions, err := GetFeeds(GetFeedsOptions{
3344
RequestedUser: user,
34-
Actor: user,
45+
Actor: doer,
3546
IncludePrivate: true,
36-
OnlyPerformedBy: false,
47+
OnlyPerformedBy: true,
3748
IncludeDeleted: true,
3849
})
3950
assert.NoError(t, err)
4051

4152
// Get the heatmap and compare
42-
heatmap, err := GetUserHeatmapDataByUser(user)
53+
heatmap, err := GetUserHeatmapDataByUser(user, doer)
4354
assert.NoError(t, err)
4455
assert.Equal(t, len(actions), len(heatmap), "invalid action count: did the test data became too old?")
45-
assert.Equal(t, tc.CountResult, len(heatmap))
56+
assert.Equal(t, tc.CountResult, len(heatmap), fmt.Sprintf("testcase %d", i))
4657

4758
//Test JSON rendering
4859
jsonData, err := json.Marshal(heatmap)

options/locale/locale_cs-CZ.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,6 @@ settings.trust_model.collaborator.long=Spolupracovník: Důvěřovat podpisům s
15231523
settings.trust_model.collaborator.desc=Platné podpisy spolupracovníků tohoto repozitáře budou označeny jako „důvěryhodné“ - (ať se shodují s autorem, či nikoli). V opačném případě budou platné podpisy označeny jako „nedůvěryhodné“, pokud se podpis shoduje s autorem a „neodpovídající“, pokud ne.
15241524
settings.trust_model.committer=Tvůrce revize
15251525
settings.trust_model.committer.long=Tvůrce revize: Důvěřovat podpisům, které odpovídají autorům (což odpovídá GitHub a přinutí Giteu nastavit jako tvůrce pro Giteou podepsané revize)
1526-
settings.trust_model.committer.desc=Platné podpisy budou označeny pouze jako „důvěryhodné“, pokud se shodují s autorem, jinak budou označeny jako „neodpovídající“. To přinutí Giteu, aby byla autorem podepsaných revizí se skutečným autorem označeným jako Co-Authored-By: a Co-Committed-By: na konci revize. Výchozí klíč Gitea musí odpovídat uživateli v databázi.
15271526
settings.trust_model.collaboratorcommitter=Spolupracovník+Tvůrce revize
15281527
settings.trust_model.collaboratorcommitter.long=Spolupracovník+Tvůrce revize: Důvěřovat podpisům od spolupracovníků, které odpovídají tvůrci revize
15291528
settings.trust_model.collaboratorcommitter.desc=Platné podpisy spolupracovníků tohoto repozitáře budou označeny jako „důvěryhodné“, pokud se shodují s autorem. V opačném případě budou platné podpisy označeny jako "nedůvěryhodné", pokud se podpis shoduje s autorem a „neodpovídajícím“ v opačném případě. To přinutí Giteu, aby byla označena jako autor podepsaných revizí se skutečným autorem označeným jako Co-Authored-By: a Co-Committed-By: na konci revize. Výchozí klíč Gitea musí odpovídat uživateli v databázi.

options/locale/locale_de-DE.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,6 @@ settings.trust_model.collaborator.long=Mitarbeiter: Vertraue Signaturen von Mita
15021502
settings.trust_model.collaborator.desc=Gültige Signaturen von Mitarbeitern dieses Projekts werden als "vertrauenswürdig" markiert - ( egal ob sie mit dem Committer übereinstimmen oder nicht). Andernfalls werden gültige Signaturen als "nicht vertrauenswürdig" markiert, unabhängig ob die Signatur mit dem Committer übereinstimmt oder nicht.
15031503
settings.trust_model.committer=Committer
15041504
settings.trust_model.committer.long=Committer: Vertraue Signaturen, die zu Committern passen (Dies stimmt mit GitHub überein und zwingt signierte Commits von Gitea dazu, Gitea als Committer zu haben)
1505-
settings.trust_model.committer.desc=Gültige Signaturen werden nur dann als "vertrauenswürdig" markiert, wenn sie mit dem Committer übereinstimmen, andernfalls werden sie als "nicht übereinstimmend" markiert. Dies zwingt Gitea dazu, der Committer bei signierten Commits zu sein, wobei der eigentliche Committer als Co-Authored-By: und Co-Committed-By: Trailer im Commit markiert ist. Der Standard-Gitea-Schlüssel muss mit einem Benutzer in der Datenbank übereinstimmen.
15061505
settings.trust_model.collaboratorcommitter=Mitarbeiter+Committer
15071506
settings.trust_model.collaboratorcommitter.long=Mitarbeiter+Committer: Signaturen der Mitarbeiter vertrauen die mit dem Committer übereinstimmen
15081507
settings.trust_model.collaboratorcommitter.desc=Gültige Signaturen von Mitarbeitern dieses Projekts werden als "vertrauenswürdig" markiert, wenn sie mit dem Committer übereinstimmen. Andernfalls werden gültige Signaturen als "nicht vertrauenswürdig" markiert, wenn die Signatur mit dem Committer übereinstimmt als "nicht übereinstimmend". Dies zwingt Gitea als Committer bei signierten Commits mit dem tatsächlichen Committer als Co-Authored-By: und Co-Committed-By: Trailer im Commit. Der Standard-Gitea-Schlüssel muss mit einem Benutzer in der Datenbank übereinstimmen.

options/locale/locale_es-ES.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,6 @@ settings.trust_model.collaborator.long=Colaborador: Confiar en firmas de colabor
15171517
settings.trust_model.collaborator.desc=Las firmas válidas de los colaboradores de este repositorio serán marcadas como "confiables" - (coincidan o no con el committer). De lo contrario, las firmas válidas serán marcadas como "no confiables" si la firma coincide con el committer y "no coincidente" si no lo es.
15181518
settings.trust_model.committer=Committer
15191519
settings.trust_model.committer.long=Committer: Firmas de confianza que coinciden con los committers (Esto coincide con GitHub y obligará a Gitea a firmar los commits a tener a Gitea como el committer)
1520-
settings.trust_model.committer.desc=Las firmas válidas solo se marcarán como "confiables" si coinciden con el autor de la confirmación; de lo contrario, se marcarán como "no coincidentes". Esto obligará a Gitea a ser el confirmador en los compromisos firmados con el confirmador real marcado como Co-Authored-By: y Co-Committed-By: tráiler en el commit. La clave Gitea predeterminada debe coincidir con un usuario en la base de datos.
15211520
settings.trust_model.collaboratorcommitter=Colaborador+Comitter
15221521
settings.trust_model.collaboratorcommitter.long=Colaborador+Comitter: Confiar en firmas de colaboradores que coincidan con el committer
15231522
settings.trust_model.collaboratorcommitter.desc=Las firmas válidas de los colaboradores de este repositorio se marcarán como "de confianza" si coinciden con el confirmador. De lo contrario, las firmas válidas se marcarán como "no confiables" si la firma coincide con el autor de la confirmación y como "no coincidentes" en caso contrario. Esto obligará a Gitea a ser marcado como el confirmador en los compromisos firmados con el confirmador real marcado como Coautor por: y Cocommitido por: tráiler en el compromiso. La clave Gitea predeterminada debe coincidir con un usuario en la base de datos.

options/locale/locale_ja-JP.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,6 @@ settings.trust_model.collaborator.long=共同作業者: 共同作業者による
15231523
settings.trust_model.collaborator.desc=このリポジトリの共同作業者による正常な署名は、(署名がコミッターのものかどうかにかかわらず)「信頼済み」とみなします。 署名が共同作業者ではないコミッターのものであれば「信頼不可」、それ以外は「不一致」となります。
15241524
settings.trust_model.committer=コミッター
15251525
settings.trust_model.committer.long=コミッター: コミッターによる署名を信頼します (これはGitHub方式であり、Giteaの署名が付いたコミットはコミッターがGitea自身であることが強制されます)
1526-
settings.trust_model.committer.desc=正常な署名は、コミッターに一致する場合のみ「信頼済み」とみなし、それ以外は「不一致」となります。 Giteaが署名付きコミットのコミッターであることが強制され、本来のコミッターはコミットの最後に Co-Authored-By: と Co-Committed-By: で追加されます。 Giteaのデフォルト鍵はデータベース内のユーザー1人とマッチしなければなりません。
15271526
settings.trust_model.collaboratorcommitter=共同作業者+コミッター
15281527
settings.trust_model.collaboratorcommitter.long=共同作業者+コミッター: コミッターと一致する共同作業者による署名を信頼します
15291528
settings.trust_model.collaboratorcommitter.desc=このリポジトリの共同作業者による正常な署名は、コミッターと一致する場合に「信頼済み」とみなします。 それ以外の正常な署名のうち、コミッターに一致するものは「信頼不可」、他は「不一致」となります。 Giteaが署名付きコミットのコミッターであることが強制され、本来のコミッターはコミットの最後に Co-Authored-By: と Co-Committed-By: で追加されます。 Giteaのデフォルト鍵はデータベース内のユーザー1人とマッチしなければなりません。

options/locale/locale_lv-LV.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,6 @@ settings.trust_model.collaborator.long=Līdzstrādnieka: Uzticēties līdzstrād
14881488
settings.trust_model.collaborator.desc=Ticami līdzstrādnieku paraksti tiks atzīmēti kā "uzticami" (neatkarīgi no tā vai tie atbilst revīzijas iesūtītājam vai nē). Citos gadījumos ticami paraksti tiks atzīmēti kā "neuzticami", ja paraksts atbilst revīzijas iesūtītājam vai "nesakrītošs", ja neatbilst.
14891489
settings.trust_model.committer=Revīzijas iesūtītāja
14901490
settings.trust_model.committer.long=Revīzijas iesūtītāja: Uzticēties parakstiem, kas atbilst revīzijas iesūtītājiem (Šis atbilst GitHub uzvedībai un piespiedīs Gitea parakstītām revīzijām būt Gitea kā revīzijas iesūtītājam)
1491-
settings.trust_model.committer.desc=Ticami paraksti tiks atzīmēti kā "uzticami", ja tie atbilst revīzijas iesūtītājam, citos gadījumos tie tiks atzīmēti kā "nesakrītoši". Šis nozīmē, ka Gitea būs kā revīzijas iesūtītājs parakstītām revīzijām, kur īstais revīzijas iesūtītājs tiks atīzmēts revīzijas komentāra beigās ar tekstu Co-Authored-By: un Co-Committed-By:. Noklusētajai Gitea atslēgai ir jāatbilst lietotājam datu bāzē.
14921491
settings.trust_model.collaboratorcommitter=Līdzstrādnieka un revīzijas iesūtītāja
14931492
settings.trust_model.collaboratorcommitter.long=Līdzstrādnieka un revīzijas iesūtītāja: Uzticēties līdzstrādnieku parakstiem, kas atbilst revīzijas iesūtītājam
14941493
settings.trust_model.collaboratorcommitter.desc=Ticami līdzstrādnieku paraksti tiks atzīmēti kā "uzticami", ja tie atbilst revīzijas iesūtītājam, citos gadījumos tie tiks atzīmēti kā "neuzticami", ja paraksts atbilst revīzijas iesūtītajam, vai "nesakrītoši", ja neatbilst. Šis nozīmē, ka Gitea būs kā revīzijas iesūtītājs parakstītām revīzijām, kur īstais revīzijas iesūtītājs tiks atīzmēts revīzijas komentāra beigās ar tekstu Co-Authored-By: un Co-Committed-By:. Noklusētajai Gitea atslēgai ir jāatbilst lietotājam datu bāzē.

options/locale/locale_nl-NL.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,6 @@ settings.trust_model.collaborator.long=Medewerker: Vertrouw handtekeningen door
14951495
settings.trust_model.collaborator.desc=Geldige handtekeningen door medewerkers van deze repository worden gemarkeerd als "vertrouwd" - (ongeacht of ze overeenkomen met de committer of niet). Anders worden geldige handtekeningen gemarkeerd als "niet vertrouwd" als de handtekening overeenkomt met de committer en "niet overeenkomend" als dat niet het geval is.
14961496
settings.trust_model.committer=Committer
14971497
settings.trust_model.committer.long=Committer: Vertrouw handtekeningen die overeenkomen met committers (Dit komt overeen met GitHub en zal Gitea ondertekende commits dwingen om Gitea als de committer te hebben)
1498-
settings.trust_model.committer.desc=Geldige handtekeningen worden alleen gemarkeerd als "vertrouwd" als ze overeenkomen met de committer, anders worden ze gemarkeerd als "niet overeenkomend". Dit zal Gitea dwingen om de committer te zijn aan ondertekende commits met de eigenlijke committer gemarkeerd als Co-Authored-By: en Co-Committed-By: trailer in de commit. De standaard Gitea-sleutel moet overeenkomen met een gebruiker in de database.
14991498
settings.trust_model.collaboratorcommitter=Medewerker+Committer
15001499
settings.trust_model.collaboratorcommitter.long=Medewerker+Committer: Vertrouw handtekeningen door medewerkers die overeenkomen met de committer
15011500
settings.wiki_delete=Uncyclo-gegevens verwijderen

0 commit comments

Comments
 (0)