diff options
author | guillep2k <18600385+guillep2k@users.noreply.github.com> | 2019-10-10 13:45:11 -0300 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-10-10 19:45:11 +0300 |
commit | df2c11a878719719b8600745888c570af93827be (patch) | |
tree | 4dd527c9538a748483ee8c1467bd88ef8001a380 /models/issue_test.go | |
parent | 57b0d9a38ba7d8dcc05a74fe39ab9f9e765ed8b3 (diff) | |
download | gitea-df2c11a878719719b8600745888c570af93827be.tar.gz gitea-df2c11a878719719b8600745888c570af93827be.zip |
Ignore mentions for users with no access (#8395)
* Draft for ResolveMentionsByVisibility()
* Correct typo
* Resolve teams instead of orgs for mentions
* Create test for ResolveMentionsByVisibility
* Fix check for individual users and doer
* Test and fix team mentions
* Run all mentions through visibility filter
* Fix error check
* Simplify code, fix doer included in teams
* Simplify team id list build
Diffstat (limited to 'models/issue_test.go')
-rw-r--r-- | models/issue_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/models/issue_test.go b/models/issue_test.go index 9cd9ff0ad9..5b039bc1d5 100644 --- a/models/issue_test.go +++ b/models/issue_test.go @@ -366,3 +366,35 @@ func TestIssue_InsertIssue(t *testing.T) { testInsertIssue(t, "my issue1", "special issue's comments?") testInsertIssue(t, `my issue2, this is my son's love \n \r \ `, "special issue's '' comments?") } + +func TestIssue_ResolveMentions(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + testSuccess := func(owner, repo, doer string, mentions []string, expected []int64) { + o := AssertExistsAndLoadBean(t, &User{LowerName: owner}).(*User) + r := AssertExistsAndLoadBean(t, &Repository{OwnerID: o.ID, LowerName: repo}).(*Repository) + issue := &Issue{RepoID: r.ID} + d := AssertExistsAndLoadBean(t, &User{LowerName: doer}).(*User) + resolved, err := issue.ResolveMentionsByVisibility(DefaultDBContext(), d, mentions) + assert.NoError(t, err) + ids := make([]int64, len(resolved)) + for i, user := range resolved { + ids[i] = user.ID + } + sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] }) + assert.EqualValues(t, expected, ids) + } + + // Public repo, existing user + testSuccess("user2", "repo1", "user1", []string{"user5"}, []int64{5}) + // Public repo, non-existing user + testSuccess("user2", "repo1", "user1", []string{"nonexisting"}, []int64{}) + // Public repo, doer + testSuccess("user2", "repo1", "user1", []string{"user1"}, []int64{}) + // Private repo, team member + testSuccess("user17", "big_test_private_4", "user20", []string{"user2"}, []int64{2}) + // Private repo, not a team member + testSuccess("user17", "big_test_private_4", "user20", []string{"user5"}, []int64{}) + // Private repo, whole team + testSuccess("user17", "big_test_private_4", "user15", []string{"owners"}, []int64{18}) +} |