Skip to content

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

Merged
merged 16 commits into from
Jun 21, 2018

Conversation

daviian
Copy link
Member

@daviian daviian commented May 24, 2018

targets #4029

hides private organization repository issues from users that have no access to them.

@lunny lunny added the type/bug label May 24, 2018
@lunny lunny added this to the 1.5.0 milestone May 24, 2018
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)
Copy link
Member

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?

Copy link
Member

@jonasfranz jonasfranz May 24, 2018

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)

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

// 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)
Copy link
Member

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?

// 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)
Copy link
Member

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)
Copy link
Member

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").
Copy link
Member

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

assert.NoError(t, err)
// User 5's team has no access to any repo
var emptyRepos []int64
assert.Equal(t, accessibleRepos, emptyRepos)
Copy link
Member

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

@bkcsoft bkcsoft added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 24, 2018
@jonasfranz
Copy link
Member

Drone ci is failing.

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})
Copy link
Member

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)

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})
Copy link
Member

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-io
Copy link

codecov-io commented May 24, 2018

Codecov Report

Merging #4034 into master will increase coverage by 0.08%.
The diff coverage is 29.24%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
models/repo.go 18.4% <0%> (+0.61%) ⬆️
models/models.go 33.33% <100%> (+0.28%) ⬆️
models/user.go 22.33% <33.33%> (+0.73%) ⬆️
routers/user/home.go 24.92% <40%> (ø) ⬆️
models/notification.go 66.84% <42.85%> (-0.95%) ⬇️
models/org_team.go 47.22% <5%> (-3.01%) ⬇️
models/repo_watch.go 61.62% <50%> (-1.89%) ⬇️
models/org.go 68.18% <69.23%> (-0.04%) ⬇️
modules/process/manager.go 69.56% <0%> (-4.35%) ⬇️
models/topic.go 54.12% <0%> (-0.58%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46d19c4...f5a3465. Read the comment docs.

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).
Copy link
Member

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)

Copy link
Member Author

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).
Copy link
Member

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

Copy link
Member Author

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.

@bkcsoft bkcsoft added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 24, 2018
Copy link
Member

@jonasfranz jonasfranz left a 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.

@lunny
Copy link
Member

lunny commented May 29, 2018

LGTM

@bkcsoft bkcsoft added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 29, 2018
@lunny
Copy link
Member

lunny commented May 29, 2018

As @JonasFranzDEV said, team unit permissions are also need to be checked.

@daviian
Copy link
Member Author

daviian commented Jun 2, 2018

@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?

@lafriks
Copy link
Member

lafriks commented Jun 2, 2018

I would prefer team_unit table but than it can not be backported

@daviian
Copy link
Member Author

daviian commented Jun 2, 2018

@lafriks I could backport the quick'n'dirty solution anyway ;-)

@lafriks
Copy link
Member

lafriks commented Jun 2, 2018

@daviian it is not so critical bug to be worth it imho

@daviian daviian force-pushed the bugfix/unallowed-issue-listing branch from 156fd84 to 3603861 Compare June 3, 2018 18:52
@daviian
Copy link
Member Author

daviian commented Jun 3, 2018

Can you mark this PR as WIP? There is one thing missing I've not implemented yet.

TODO

  • Migrate team unit types into new team_unit table
  • Filter Issues by team access and unit type
  • Don't notify users about certain actions that lack the required unit type.
  • Remove link to issue in actions on dashboard if user is not allowed to access

@techknowlogick techknowlogick added the pr/wip This PR is not ready for review label Jun 3, 2018
@daviian
Copy link
Member Author

daviian commented Jun 5, 2018

@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?

Copy link
Member

@jonasfranz jonasfranz left a 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

@lafriks
Copy link
Member

lafriks commented Jun 20, 2018

@daviian please rebase and resolve conflicts

@axifive
Copy link
Member

axifive commented Jun 20, 2018

@daviian, Please use v69 migration name for conflict resolving. Because I already resolved #4258 with v68

@daviian daviian force-pushed the bugfix/unallowed-issue-listing branch from e46702f to fc89ab6 Compare June 20, 2018 20:22
@daviian
Copy link
Member Author

daviian commented Jun 20, 2018

@axifive Sry, didn't read your comment before rebasing.

@daviian daviian force-pushed the bugfix/unallowed-issue-listing branch from e69f332 to f5a3465 Compare June 21, 2018 10:02
@axifive
Copy link
Member

axifive commented Jun 21, 2018

@daviian, just wanted to warn against double rebase

@techknowlogick techknowlogick merged commit 0b3ea42 into go-gitea:master Jun 21, 2018
@daviian daviian deleted the bugfix/unallowed-issue-listing branch June 21, 2018 20:00
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants