Display users env role if they have environment access
This commit is contained in:
parent
7671269b7f
commit
02efa33e49
@ -3,9 +3,10 @@ from flask import current_app as app
|
|||||||
|
|
||||||
from atst.database import db
|
from atst.database import db
|
||||||
from atst.models import (
|
from atst.models import (
|
||||||
EnvironmentRole,
|
|
||||||
ApplicationRole,
|
|
||||||
Environment,
|
Environment,
|
||||||
|
EnvironmentRole,
|
||||||
|
Application,
|
||||||
|
ApplicationRole,
|
||||||
ApplicationRoleStatus,
|
ApplicationRoleStatus,
|
||||||
)
|
)
|
||||||
from atst.domain.exceptions import NotFoundError
|
from atst.domain.exceptions import NotFoundError
|
||||||
@ -126,3 +127,15 @@ class EnvironmentRoles(object):
|
|||||||
.one_or_none()
|
.one_or_none()
|
||||||
)
|
)
|
||||||
return existing_env_role
|
return existing_env_role
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def for_user(cls, user_id, portfolio_id):
|
||||||
|
return (
|
||||||
|
db.session.query(EnvironmentRole)
|
||||||
|
.join(ApplicationRole)
|
||||||
|
.join(Application)
|
||||||
|
.filter(Application.portfolio_id == portfolio_id)
|
||||||
|
.filter(ApplicationRole.application_id == Application.id)
|
||||||
|
.filter(ApplicationRole.user_id == user_id)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
from flask import render_template
|
from flask import render_template, g
|
||||||
|
|
||||||
from .blueprint import applications_bp
|
from .blueprint import applications_bp
|
||||||
from atst.domain.authz.decorator import user_can_access_decorator as user_can
|
from atst.domain.authz.decorator import user_can_access_decorator as user_can
|
||||||
|
from atst.domain.environment_roles import EnvironmentRoles
|
||||||
from atst.models.permissions import Permissions
|
from atst.models.permissions import Permissions
|
||||||
|
|
||||||
|
|
||||||
@ -23,4 +24,11 @@ def has_portfolio_applications(_user, portfolio=None, **_kwargs):
|
|||||||
message="view portfolio applications",
|
message="view portfolio applications",
|
||||||
)
|
)
|
||||||
def portfolio_applications(portfolio_id):
|
def portfolio_applications(portfolio_id):
|
||||||
return render_template("applications/index.html")
|
user_env_roles = EnvironmentRoles.for_user(g.current_user.id, portfolio_id)
|
||||||
|
environment_access = {}
|
||||||
|
for env_role in user_env_roles:
|
||||||
|
environment_access[env_role.environment_id] = env_role.role
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"applications/index.html", environment_access=environment_access
|
||||||
|
)
|
||||||
|
@ -52,11 +52,11 @@
|
|||||||
heading_tag="h4"
|
heading_tag="h4"
|
||||||
) %}
|
) %}
|
||||||
{% for environment in application.environments %}
|
{% for environment in application.environments %}
|
||||||
{{ environment.id }}
|
{% set env_access = environment_access[environment.id] %}
|
||||||
<div class="accordion__content--list-item">
|
<div class="accordion__content--list-item">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col col--grow">
|
<div class="col col--grow">
|
||||||
{% if g.current_user in environment.users %}
|
{% if env_access %}
|
||||||
<a href='{{ url_for("applications.access_environment", environment_id=environment.id)}}' target='_blank' rel='noopener noreferrer'>
|
<a href='{{ url_for("applications.access_environment", environment_id=environment.id)}}' target='_blank' rel='noopener noreferrer'>
|
||||||
{{ environment.displayname }} {{ Icon('link', classes='icon--medium icon--primary') }}
|
{{ environment.displayname }} {{ Icon('link', classes='icon--medium icon--primary') }}
|
||||||
</a>
|
</a>
|
||||||
@ -64,9 +64,9 @@
|
|||||||
{{ environment.displayname }}
|
{{ environment.displayname }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if g.current_user in environment.users %}
|
{% if env_access %}
|
||||||
<div class="col">
|
<div class="col">
|
||||||
Your env role here!
|
{{ env_access }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -136,3 +136,21 @@ def test_get_for_update(application_role, environment):
|
|||||||
assert role.application_role == application_role
|
assert role.application_role == application_role
|
||||||
assert role.environment == environment
|
assert role.environment == environment
|
||||||
assert role.deleted
|
assert role.deleted
|
||||||
|
|
||||||
|
|
||||||
|
def test_for_user(application_role, environment):
|
||||||
|
portfolio = application_role.application.portfolio
|
||||||
|
user = application_role.user
|
||||||
|
# create roles for 2 environments
|
||||||
|
env_role = EnvironmentRoleFactory.create(
|
||||||
|
application_role=application_role, environment=environment
|
||||||
|
)
|
||||||
|
env_role1 = EnvironmentRoleFactory.create(application_role=application_role)
|
||||||
|
# create role for environment in a different app in same portfolio
|
||||||
|
app2 = ApplicationFactory.create(portfolio=portfolio)
|
||||||
|
app_role2 = ApplicationRoleFactory.create(application=app2, user=user)
|
||||||
|
env_role2 = EnvironmentRoleFactory.create(application_role=app_role2)
|
||||||
|
env_roles = EnvironmentRoles.for_user(user.id, portfolio.id)
|
||||||
|
assert len(env_roles) == 3
|
||||||
|
for role in [env_role, env_role1, env_role2]:
|
||||||
|
assert role in env_roles
|
||||||
|
Loading…
x
Reference in New Issue
Block a user