Add property to get number of users in an application
This commit is contained in:
parent
85de20c175
commit
c3157596be
@ -17,6 +17,14 @@ class Application(Base, mixins.TimestampsMixin, mixins.AuditableMixin):
|
|||||||
portfolio = relationship("Portfolio")
|
portfolio = relationship("Portfolio")
|
||||||
environments = relationship("Environment", back_populates="application")
|
environments = relationship("Environment", back_populates="application")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def users(self):
|
||||||
|
return set([user for env in self.environments for user in env.users])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def num_users(self):
|
||||||
|
return len(self.users)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def displayname(self):
|
def displayname(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<a class='icon-link' href='{{ url_for("portfolios.edit_application", portfolio_id=portfolio.id, application_id=application.id) }}'>
|
<a class='icon-link' href='{{ url_for("portfolios.edit_application", portfolio_id=portfolio.id, application_id=application.id) }}'>
|
||||||
<span>Team</span>
|
<span>Team</span>
|
||||||
<span class='counter'>11</span>
|
<span class='counter'>{{ application.num_users }}</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
22
tests/models/test_application.py
Normal file
22
tests/models/test_application.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from atst.domain.environments import Environments
|
||||||
|
from tests.factories import ApplicationFactory, UserFactory
|
||||||
|
|
||||||
|
|
||||||
|
def test_application_num_users():
|
||||||
|
application = ApplicationFactory.create(
|
||||||
|
environments=[{"name": "dev"}, {"name": "staging"}, {"name": "prod"}]
|
||||||
|
)
|
||||||
|
assert application.num_users == 0
|
||||||
|
|
||||||
|
first_env = application.environments[0]
|
||||||
|
user1 = UserFactory()
|
||||||
|
Environments.add_member(first_env, user1, "developer")
|
||||||
|
assert application.num_users == 1
|
||||||
|
|
||||||
|
second_env = application.environments[-1]
|
||||||
|
Environments.add_member(second_env, user1, "developer")
|
||||||
|
assert application.num_users == 1
|
||||||
|
|
||||||
|
user2 = UserFactory()
|
||||||
|
Environments.add_member(second_env, user2, "developer")
|
||||||
|
assert application.num_users == 2
|
Loading…
x
Reference in New Issue
Block a user