Skip to content

Commit 0b3ea42

Browse files
daviiantechknowlogick
authored andcommitted
hide issues from org private repos w/o team assignment (#4034)
1 parent 46d19c4 commit 0b3ea42

24 files changed

+545
-72
lines changed

integrations/api_repo_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func TestAPISearchRepo(t *testing.T) {
6767
expectedResults
6868
}{
6969
{name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50", expectedResults: expectedResults{
70-
nil: {count: 15},
71-
user: {count: 15},
72-
user2: {count: 15}},
70+
nil: {count: 16},
71+
user: {count: 16},
72+
user2: {count: 16}},
7373
},
7474
{name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10", expectedResults: expectedResults{
7575
nil: {count: 10},

models/access_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ func TestAccessLevel(t *testing.T) {
2222

2323
user1 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
2424
user2 := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
25-
repo1 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 2, IsPrivate: false}).(*Repository)
26-
repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository)
25+
// A public repository owned by User 2
26+
repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
27+
assert.False(t, repo1.IsPrivate)
28+
// A private repository owned by Org 3
29+
repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
30+
assert.True(t, repo2.IsPrivate)
2731

2832
level, err := AccessLevel(user1.ID, repo1)
2933
assert.NoError(t, err)
@@ -47,8 +51,12 @@ func TestHasAccess(t *testing.T) {
4751

4852
user1 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
4953
user2 := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
50-
repo1 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 2, IsPrivate: false}).(*Repository)
51-
repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository)
54+
// A public repository owned by User 2
55+
repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
56+
assert.False(t, repo1.IsPrivate)
57+
// A private repository owned by Org 3
58+
repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
59+
assert.True(t, repo2.IsPrivate)
5260

5361
for _, accessMode := range accessModes {
5462
has, err := HasAccess(user1.ID, repo1, accessMode)

models/fixtures/repository.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
is_mirror: true
352352
num_forks: 1
353353
is_fork: false
354-
354+
355355
-
356356
id: 29
357357
fork_id: 27
@@ -365,7 +365,7 @@
365365
num_closed_pulls: 0
366366
is_mirror: false
367367
is_fork: true
368-
368+
369369
-
370370
id: 30
371371
fork_id: 28
@@ -389,3 +389,14 @@
389389
num_forks: 0
390390
num_issues: 0
391391
is_mirror: false
392+
393+
-
394+
id: 32
395+
owner_id: 3
396+
lower_name: repo21
397+
name: repo21
398+
is_private: false
399+
num_stars: 0
400+
num_forks: 0
401+
num_issues: 0
402+
is_mirror: false

models/fixtures/team.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
lower_name: owners
55
name: Owners
66
authorize: 4 # owner
7-
num_repos: 2
7+
num_repos: 3
88
num_members: 1
9-
unit_types: '[1,2,3,4,5,6,7]'
109

1110
-
1211
id: 2
@@ -16,7 +15,6 @@
1615
authorize: 2 # write
1716
num_repos: 1
1817
num_members: 2
19-
unit_types: '[1,2,3,4,5,6,7]'
2018

2119
-
2220
id: 3
@@ -26,7 +24,6 @@
2624
authorize: 4 # owner
2725
num_repos: 0
2826
num_members: 1
29-
unit_types: '[1,2,3,4,5,6,7]'
3027

3128
-
3229
id: 4
@@ -36,7 +33,6 @@
3633
authorize: 4 # owner
3734
num_repos: 0
3835
num_members: 1
39-
unit_types: '[1,2,3,4,5,6,7]'
4036

4137
-
4238
id: 5
@@ -46,7 +42,6 @@
4642
authorize: 4 # owner
4743
num_repos: 2
4844
num_members: 2
49-
unit_types: '[1,2,3,4,5,6,7]'
5045

5146
-
5247
id: 6
@@ -56,4 +51,3 @@
5651
authorize: 4 # owner
5752
num_repos: 2
5853
num_members: 1
59-
unit_types: '[1,2,3,4,5,6,7]'

models/fixtures/team_repo.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@
3333
org_id: 19
3434
team_id: 6
3535
repo_id: 27
36-
36+
3737
-
3838
id: 7
3939
org_id: 19
4040
team_id: 6
41-
repo_id: 28
41+
repo_id: 28
42+
43+
-
44+
id: 8
45+
org_id: 3
46+
team_id: 1
47+
repo_id: 32

models/fixtures/team_unit.yml

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
-
2+
id: 1
3+
team_id: 1
4+
type: 1
5+
6+
-
7+
id: 2
8+
team_id: 1
9+
type: 2
10+
11+
-
12+
id: 3
13+
team_id: 1
14+
type: 3
15+
16+
-
17+
id: 4
18+
team_id: 1
19+
type: 4
20+
21+
-
22+
id: 5
23+
team_id: 1
24+
type: 5
25+
26+
-
27+
id: 6
28+
team_id: 1
29+
type: 6
30+
31+
-
32+
id: 7
33+
team_id: 1
34+
type: 7
35+
36+
-
37+
id: 8
38+
team_id: 2
39+
type: 1
40+
41+
-
42+
id: 9
43+
team_id: 2
44+
type: 2
45+
46+
-
47+
id: 10
48+
team_id: 2
49+
type: 3
50+
51+
-
52+
id: 11
53+
team_id: 2
54+
type: 4
55+
56+
-
57+
id: 12
58+
team_id: 2
59+
type: 5
60+
61+
-
62+
id: 13
63+
team_id: 2
64+
type: 6
65+
66+
-
67+
id: 14
68+
team_id: 2
69+
type: 7
70+
71+
-
72+
id: 15
73+
team_id: 3
74+
type: 1
75+
76+
-
77+
id: 16
78+
team_id: 3
79+
type: 2
80+
81+
-
82+
id: 17
83+
team_id: 3
84+
type: 3
85+
86+
-
87+
id: 18
88+
team_id: 3
89+
type: 4
90+
91+
-
92+
id: 19
93+
team_id: 3
94+
type: 5
95+
96+
-
97+
id: 20
98+
team_id: 3
99+
type: 6
100+
101+
-
102+
id: 21
103+
team_id: 3
104+
type: 7
105+
106+
-
107+
id: 22
108+
team_id: 4
109+
type: 1
110+
111+
-
112+
id: 23
113+
team_id: 4
114+
type: 2
115+
116+
-
117+
id: 24
118+
team_id: 4
119+
type: 3
120+
121+
-
122+
id: 25
123+
team_id: 4
124+
type: 4
125+
126+
-
127+
id: 26
128+
team_id: 4
129+
type: 5
130+
131+
-
132+
id: 27
133+
team_id: 4
134+
type: 6
135+
136+
-
137+
id: 28
138+
team_id: 4
139+
type: 7
140+
141+
-
142+
id: 29
143+
team_id: 5
144+
type: 1
145+
146+
-
147+
id: 30
148+
team_id: 5
149+
type: 2
150+
151+
-
152+
id: 31
153+
team_id: 5
154+
type: 3
155+
156+
-
157+
id: 32
158+
team_id: 5
159+
type: 4
160+
161+
-
162+
id: 33
163+
team_id: 5
164+
type: 5
165+
166+
-
167+
id: 34
168+
team_id: 5
169+
type: 6
170+
171+
-
172+
id: 35
173+
team_id: 5
174+
type: 7
175+
176+
-
177+
id: 36
178+
team_id: 6
179+
type: 1
180+
181+
-
182+
id: 37
183+
team_id: 6
184+
type: 2
185+
186+
-
187+
id: 38
188+
team_id: 6
189+
type: 3
190+
191+
-
192+
id: 39
193+
team_id: 6
194+
type: 4
195+
196+
-
197+
id: 40
198+
team_id: 6
199+
type: 5
200+
201+
-
202+
id: 41
203+
team_id: 6
204+
type: 6
205+
206+
-
207+
id: 42
208+
team_id: 6
209+
type: 7

models/fixtures/user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
is_admin: false
4646
avatar: avatar3
4747
avatar_email: [email protected]
48-
num_repos: 2
48+
num_repos: 3
4949
num_members: 2
5050
num_teams: 2
5151

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ var migrations = []Migration{
190190
NewMigration("remove stale watches", removeStaleWatches),
191191
// v68 -> V69
192192
NewMigration("Reformat and remove incorrect topics", reformatAndRemoveIncorrectTopics),
193+
// v69 -> v70
194+
NewMigration("move team units to team_unit table", moveTeamUnitsToTeamUnitTable),
193195
}
194196

195197
// Migrate database to current version

models/migrations/v38.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ func removeCommitsUnitType(x *xorm.Engine) (err error) {
2525
Created time.Time `xorm:"-"`
2626
}
2727

28+
type Team struct {
29+
ID int64
30+
UnitTypes []int `xorm:"json"`
31+
}
32+
2833
// Update team unit types
2934
const batchSize = 100
3035
for start := 0; ; start += batchSize {
31-
teams := make([]*models.Team, 0, batchSize)
36+
teams := make([]*Team, 0, batchSize)
3237
if err := x.Limit(batchSize, start).Find(&teams); err != nil {
3338
return err
3439
}
3540
if len(teams) == 0 {
3641
break
3742
}
3843
for _, team := range teams {
39-
ut := make([]models.UnitType, 0, len(team.UnitTypes))
44+
ut := make([]int, 0, len(team.UnitTypes))
4045
for _, u := range team.UnitTypes {
4146
if u < V16UnitTypeCommits {
4247
ut = append(ut, u)

0 commit comments

Comments
 (0)