44from mock import Mock
55
66from sentry .auth import access
7- from sentry .models import AuthProvider
7+ from sentry .models import AuthProvider , Organization
88from sentry .testutils import TestCase
99
1010
@@ -18,7 +18,8 @@ def test_no_access(self):
1818 assert not result .is_active
1919 assert result .sso_is_valid
2020 assert not result .scopes
21- assert not result .has_team (team )
21+ assert not result .has_team_access (team )
22+ assert not result .has_team_membership (team )
2223
2324 def test_owner_all_teams (self ):
2425 user = self .create_user ()
@@ -33,11 +34,15 @@ def test_owner_all_teams(self):
3334 assert result .is_active
3435 assert result .sso_is_valid
3536 assert result .scopes == member .get_scopes ()
36- assert result .has_team (team )
37+ assert result .has_team_access (team )
38+ assert result .has_team_membership (team )
3739
38- def test_member_no_teams (self ):
40+ def test_member_no_teams_closed_membership (self ):
3941 user = self .create_user ()
40- organization = self .create_organization (owner = self .user )
42+ organization = self .create_organization (
43+ owner = self .user ,
44+ flags = 0 , # disable default allow_joinleave
45+ )
4146 member = self .create_member (
4247 organization = organization , user = user ,
4348 role = 'member' ,
@@ -48,7 +53,27 @@ def test_member_no_teams(self):
4853 assert result .is_active
4954 assert result .sso_is_valid
5055 assert result .scopes == member .get_scopes ()
51- assert not result .has_team (team )
56+ assert not result .has_team_access (team )
57+ assert not result .has_team_membership (team )
58+
59+ def test_member_no_teams_open_membership (self ):
60+ user = self .create_user ()
61+ organization = self .create_organization (
62+ owner = self .user ,
63+ flags = Organization .flags .allow_joinleave ,
64+ )
65+ member = self .create_member (
66+ organization = organization , user = user ,
67+ role = 'member' , teams = (),
68+ )
69+ team = self .create_team (organization = organization )
70+
71+ result = access .from_user (user , organization )
72+ assert result .is_active
73+ assert result .sso_is_valid
74+ assert result .scopes == member .get_scopes ()
75+ assert result .has_team_access (team )
76+ assert not result .has_team_membership (team )
5277
5378 def test_team_restricted_org_member_access (self ):
5479 user = self .create_user ()
@@ -64,7 +89,8 @@ def test_team_restricted_org_member_access(self):
6489 assert result .is_active
6590 assert result .sso_is_valid
6691 assert result .scopes == member .get_scopes ()
67- assert result .has_team (team )
92+ assert result .has_team_access (team )
93+ assert result .has_team_membership (team )
6894
6995 def test_unlinked_sso (self ):
7096 user = self .create_user ()
@@ -106,4 +132,5 @@ def test_no_access(self):
106132 assert not result .is_active
107133 assert result .sso_is_valid
108134 assert not result .scopes
109- assert not result .has_team (Mock ())
135+ assert not result .has_team_access (Mock ())
136+ assert not result .has_team_membership (Mock ())
0 commit comments