Check for member in application function, not user function
This commit is contained in:
parent
6822680bc8
commit
fec4687c02
@ -7,7 +7,7 @@ from atst.models import EnvironmentRole
|
|||||||
class EnvironmentRoles(object):
|
class EnvironmentRoles(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, user, environment, role):
|
def create(cls, user, environment, role):
|
||||||
if user.is_app_member(environment.application):
|
if environment.application.has_member(user):
|
||||||
env_role = EnvironmentRole(user=user, environment=environment, role=role)
|
env_role = EnvironmentRole(user=user, environment=environment, role=role)
|
||||||
if not user.cloud_id:
|
if not user.cloud_id:
|
||||||
user.cloud_id = app.csp.cloud.create_user(user)
|
user.cloud_id = app.csp.cloud.create_user(user)
|
||||||
|
@ -68,7 +68,7 @@ class Environments(object):
|
|||||||
def update_env_role(cls, environment, user, new_role):
|
def update_env_role(cls, environment, user, new_role):
|
||||||
updated = False
|
updated = False
|
||||||
|
|
||||||
if user.is_app_member(environment.application):
|
if environment.application.has_member(user):
|
||||||
if new_role is None:
|
if new_role is None:
|
||||||
updated = EnvironmentRoles.delete(user.id, environment.id)
|
updated = EnvironmentRoles.delete(user.id, environment.id)
|
||||||
else:
|
else:
|
||||||
|
@ -52,6 +52,9 @@ class Application(
|
|||||||
def displayname(self):
|
def displayname(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def has_member(self, user):
|
||||||
|
return user in self.users
|
||||||
|
|
||||||
def __repr__(self): # pragma: no cover
|
def __repr__(self): # pragma: no cover
|
||||||
return "<Application(name='{}', description='{}', portfolio='{}', id='{}')>".format(
|
return "<Application(name='{}', description='{}', portfolio='{}', id='{}')>".format(
|
||||||
self.name, self.description, self.portfolio.name, self.id
|
self.name, self.description, self.portfolio.name, self.id
|
||||||
|
@ -80,9 +80,6 @@ class User(
|
|||||||
def displayname(self):
|
def displayname(self):
|
||||||
return self.full_name
|
return self.full_name
|
||||||
|
|
||||||
def is_app_member(self, application):
|
|
||||||
return self in application.users
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<User(name='{}', dod_id='{}', email='{}', has_portfolios='{}', id='{}')>".format(
|
return "<User(name='{}', dod_id='{}', email='{}', has_portfolios='{}', id='{}')>".format(
|
||||||
self.full_name, self.dod_id, self.email, self.has_portfolios, self.id
|
self.full_name, self.dod_id, self.email, self.has_portfolios, self.id
|
||||||
|
@ -4,6 +4,7 @@ from tests.factories import (
|
|||||||
ApplicationFactory,
|
ApplicationFactory,
|
||||||
ApplicationRoleFactory,
|
ApplicationRoleFactory,
|
||||||
EnvironmentFactory,
|
EnvironmentFactory,
|
||||||
|
UserFactory,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -38,3 +39,16 @@ def test_audit_event_for_application_deletion(session):
|
|||||||
)
|
)
|
||||||
assert update_event.changed_state.get("deleted")
|
assert update_event.changed_state.get("deleted")
|
||||||
assert update_event.changed_state["deleted"] == [False, True]
|
assert update_event.changed_state["deleted"] == [False, True]
|
||||||
|
|
||||||
|
|
||||||
|
def test_has_app_member():
|
||||||
|
user = UserFactory.create()
|
||||||
|
app = ApplicationFactory.create()
|
||||||
|
ApplicationRoleFactory.create(user=user, application=app)
|
||||||
|
assert app.has_member(user)
|
||||||
|
|
||||||
|
|
||||||
|
def test_does_not_have_app_member():
|
||||||
|
user = UserFactory.create()
|
||||||
|
app = ApplicationFactory.create()
|
||||||
|
assert not app.has_member(user)
|
||||||
|
@ -26,19 +26,6 @@ def test_cannot_update_dod_id(session):
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def test_is_app_member():
|
|
||||||
user = UserFactory.create()
|
|
||||||
app = ApplicationFactory.create()
|
|
||||||
ApplicationRoleFactory.create(user=user, application=app)
|
|
||||||
assert user.is_app_member(app)
|
|
||||||
|
|
||||||
|
|
||||||
def test_is_not_app_member():
|
|
||||||
user = UserFactory.create()
|
|
||||||
app = ApplicationFactory.create()
|
|
||||||
assert not user.is_app_member(app)
|
|
||||||
|
|
||||||
|
|
||||||
def test_deleted_application_roles_are_ignored(session):
|
def test_deleted_application_roles_are_ignored(session):
|
||||||
user = UserFactory.create()
|
user = UserFactory.create()
|
||||||
app = ApplicationFactory.create()
|
app = ApplicationFactory.create()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user