-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
hide issues from org private repos w/o team assignment #4034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hide issues from org private repos w/o team assignment #4034
Conversation
repo1 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 2, IsPrivate: false}).(*Repository) | ||
repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository) | ||
// A public repository owned by User 2 | ||
repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the IsPrivate: false
part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[13:16] lunny: JonasFranz because bool has default value false, Don’t know it means false or null
[13:16] lunny: Sess.Get has the same behavior
[13:16] JonasFranz: Okay, so we need to check it afterwards?
Since it is not supported to use bools in xorm, I propose to add an check if IsPrivate is set right:
assert.False(t, repo1.IsPrivate)
or
assert.True(t, repo1.IsPrivate)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it such that it really loads the expected repository. The resulting repository is the same, just an assurance.
That's applicable to the other changes in access_test.go
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it would be good to check that the repository is really private/public a comment does not ensure that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add it of course, just think that it's nothing that adds value since its predefined by the fixtures anyway.
models/access_test.go
Outdated
// A public repository owned by User 2 | ||
repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) | ||
// A private repository owned by Org 3 | ||
repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the IsPrivate: true
part?
models/access_test.go
Outdated
// A public repository owned by User 2 | ||
repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) | ||
// A private repository owned by Org 3 | ||
repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the IsPrivate: true
part?
repo1 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 2, IsPrivate: false}).(*Repository) | ||
repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository) | ||
// A public repository owned by User 2 | ||
repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the IsPrivate: false
part?
models/user.go
Outdated
@@ -557,7 +557,9 @@ func (u *User) GetOrgRepositoryIDs() ([]int64, error) { | |||
var ids []int64 | |||
return ids, x.Table("repository"). | |||
Cols("repository.id"). | |||
Join("INNER", "team_user", "repository.owner_id = team_user.org_id AND team_user.uid = ?", u.ID). | |||
Join("INNER", "team_user", "repository.owner_id = team_user.org_id"). | |||
Join("INNER", "team_repo", "(team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id) OR repository.is_private = 0"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check is_private = 0
first
models/user_test.go
Outdated
assert.NoError(t, err) | ||
// User 5's team has no access to any repo | ||
var emptyRepos []int64 | ||
assert.Equal(t, accessibleRepos, emptyRepos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use assert.Len
instead
Drone ci is failing. |
models/user_test.go
Outdated
accessibleRepos, err := user2.GetOrgRepositoryIDs() | ||
assert.NoError(t, err) | ||
// User 2's team has access to private repos 3, 5, repo 32 is a public repo of the organization | ||
assert.Equal(t, accessibleRepos, []int64{3, 5, 32}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second parameter should be the expected value and the third the actual value. (See https://godoc.org/github.com/stretchr/testify/assert#Equal)
models/user_test.go
Outdated
accessibleRepos, err = user4.GetOrgRepositoryIDs() | ||
assert.NoError(t, err) | ||
// User 4's team has access to private repo 3, repo 32 is a public repo of the organization | ||
assert.Equal(t, accessibleRepos, []int64{3, 32}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second parameter should be the expected value and the third the actual value. (See https://godoc.org/github.com/stretchr/testify/assert#Equal)
Codecov Report
@@ Coverage Diff @@
## master #4034 +/- ##
==========================================
+ Coverage 20% 20.09% +0.08%
==========================================
Files 153 153
Lines 30620 30660 +40
==========================================
+ Hits 6127 6160 +33
+ Misses 23565 23558 -7
- Partials 928 942 +14
Continue to review full report at Codecov.
|
models/user.go
Outdated
@@ -557,7 +557,9 @@ func (u *User) GetOrgRepositoryIDs() ([]int64, error) { | |||
var ids []int64 | |||
return ids, x.Table("repository"). | |||
Cols("repository.id"). | |||
Join("INNER", "team_user", "repository.owner_id = team_user.org_id AND team_user.uid = ?", u.ID). | |||
Join("INNER", "team_user", "repository.owner_id = team_user.org_id"). | |||
Join("INNER", "team_repo", "(team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id) OR repository.is_private != ?", true). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change it to:
repository.is_private = 0 OR (team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem with this is that it's not necessarily 0
if it is not private, because it could also be null
Also integration tests with pgsql fail on my pc
models/user.go
Outdated
@@ -558,7 +558,7 @@ func (u *User) GetOrgRepositoryIDs() ([]int64, error) { | |||
return ids, x.Table("repository"). | |||
Cols("repository.id"). | |||
Join("INNER", "team_user", "repository.owner_id = team_user.org_id"). | |||
Join("INNER", "team_repo", "(team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id) OR repository.is_private != ?", true). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove , true
since it is not used anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it is used. It's not possible to write != 0
because it doesn't work on all databases. You will see that pgsql fails if we use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be out of scope for this PR but if I create a team with permissions for Wiki only for example, the issues of the repository are shown in the issue list of the team members. But they shouldn't see them.
LGTM |
As @JonasFranzDEV said, team unit permissions are also need to be checked. |
@lunny @JonasFranzDEV Do you want me to make a more or less dirty fix by iterating over the selected repo ID's and check the unittype or do you favor a more solid solution by moving out the UnitType json into a new team_unit table? |
I would prefer team_unit table but than it can not be backported |
@lafriks I could backport the quick'n'dirty solution anyway ;-) |
@daviian it is not so critical bug to be worth it imho |
156fd84
to
3603861
Compare
Can you mark this PR as WIP? There is one thing missing I've not implemented yet. TODO
|
@lafriks There's one open issue though. What happens to existing actions on the dashboard that are linked to unallowed issues because of a change in the units afterwards? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conflicted but otherwise LGTM
@daviian please rebase and resolve conflicts |
e46702f
to
fc89ab6
Compare
@axifive Sry, didn't read your comment before rebasing. |
e69f332
to
f5a3465
Compare
@daviian, just wanted to warn against double rebase |
targets #4029
hides private organization repository issues from users that have no access to them.