Update the template to show real data

This commit is contained in:
Montana 2018-09-13 15:20:34 -04:00
parent 79c357dcab
commit 5a5d81eb7f
4 changed files with 43 additions and 65 deletions

View File

@ -4,7 +4,6 @@ from atst.database import db
from atst.models.environment import Environment
from atst.models.environment_role import EnvironmentRole, CSPRole
from atst.models.project import Project
from atst.domain.users import Users
from .exceptions import NotFoundError
@ -59,13 +58,13 @@ class Environments(object):
new_role = environment_data["user_role_name"]
environment = Environments.get(cls=cls, environment_id=environment_data["id"])
if workspace_user.has_environment_roles:
env_role = EnvironmentRole.get(workspace_user.user_id, environment.id)
env_role = EnvironmentRole.get(
workspace_user.user_id, environment_data["id"]
)
env_role.role = new_role
else:
env_role = EnvironmentRole(
user=workspace_user.user,
environment=environment,
role=new_role
user=workspace_user.user, environment=environment, role=new_role
)
db.session.add(env_role)
db.session.commit()

View File

@ -49,3 +49,21 @@ class Projects(object):
.filter(EnvironmentRole.user_id == user.id)
.all()
)
@classmethod
def get_all(cls, workspace_user, workspace):
Authorization.check_workspace_permission(
workspace_user.user,
workspace,
Permissions.VIEW_APPLICATION_IN_WORKSPACE,
"view project in workspace",
)
try:
projects = (
db.session.query(Project).filter_by(workspace_id=workspace.id).all()
)
except NoResultFound:
raise NotFoundError("projects")
return projects

View File

@ -214,9 +214,14 @@ def view_member(workspace_id, member_id):
"edit this workspace user",
)
member = WorkspaceUsers.get(workspace_id, member_id)
projects = Projects.get_all(member, workspace)
form = EditMemberForm(workspace_role=member.role, environment_role="")
return render_template(
"workspaces/members/edit.html", form=form, workspace=workspace, member=member
"workspaces/members/edit.html",
workspace=workspace,
member=member,
projects=projects,
form=form,
)

View File

@ -88,83 +88,39 @@
</div>
{% endcall %}
{% for project in projects %}
<div is='toggler' default-visible class='block-list project-list-item'>
<template slot-scope='{ isVisible, toggle }'>
<header class='block-list__header'>
<button v-on:click='toggle' class='icon-link icon-link--large icon-link--default spend-table__project__toggler'>
<template v-if='isVisible'>{{ Icon('caret_down') }}</template>
<template v-else>{{ Icon('caret_right') }}</template>
<h3 class="block-list__title">Code.mil</h3>
<h3 class="block-list__title">{{ project.name }}</h3>
</button>
<span><a href="#" class="icon-link icon-link--danger">revoke all access</a></span>
</header>
<ul v-show='isVisible'>
{% for env in project.environments %}
<li class='block-list__item project-list-item__environment'>
<span class='project-list-item__environment'>
Development
{{ env.name }}
</span>
<div class='project-list-item__environment__actions'>
<span class="label">no access </span><button v-on:click="openModal('rolesModal')" type="button" class="icon-link">set role</button>
{% set role = 'no access' %}
{% set label = 'label' %}
{% for er in member.user.environment_roles %}
{% if er.get(member.user_id, env.id) %}
{% set role = er.get(member.user_id, env.id).role %}
{% set label = 'label label--success' %}
{% endif %}
{% endfor %}
<span class="{{ label }}">{{ role }}</span><button v-on:click="openModal('rolesModal')" type="button" class="icon-link">set role</button>
</div>
</li>
<li class='block-list__item project-list-item__environment'>
<span class='project-list-item__environment'>
Sandbox
</span>
<div class='project-list-item__environment__actions'>
<span class="label">no access</span><button v-on:click="openModal('rolesModal')" type="button" class="icon-link">set role</button>
</div>
</li>
<li class='block-list__item project-list-item__environment'>
<span class='project-list-item__environment'>
Production
</span>
<div class='project-list-item__environment__actions'>
<span class="label label--success">Billing</span><button v-on:click="openModal('rolesModal')" type="button" class="icon-link">set role</button>
</div>
</li>
</ul>
</template>
</div>
<div is="toggler" class='block-list project-list-item'>
<template slot-scope='{ isVisible, toggle }'>
<header class='block-list__header'>
<button v-on:click='toggle' class='icon-link icon-link--large icon-link--default spend-table__project__toggler'>
<template v-if='isVisible'>{{ Icon('caret_down') }}</template>
<template v-else>{{ Icon('caret_right') }}</template>
<h3 class="block-list__title">Digital Dojo</h3>
</button>
<span class="label">no access</span>
</header>
<ul v-show='isVisible'>
<li class='block-list__item project-list-item__environment'>
<span class='project-list-item__environment'>
Development
</span>
<div class='project-list-item__environment__actions'>
<span class="label">no access </span><button v-on:click="openModal('rolesModal')" type="button" class="icon-link">set role</button>
</div>
</li>
<li class='block-list__item project-list-item__environment'>
<span class='project-list-item__environment'>
Sandbox
</span>
<div class='project-list-item__environment__actions'>
<span class="label">no access</span><button v-on:click="openModal('rolesModal')" type="button" class="icon-link">set role</button>
</div>
</li>
<li class='block-list__item project-list-item__environment'>
<span class='project-list-item__environment'>
Production
</span>
<div class='project-list-item__environment__actions'>
<span class="label">no access</span><button v-on:click="openModal('rolesModal')" type="button" class="icon-link">set role</button>
</div>
</li>
{% endfor %}
</ul>
</template>
</div>
{% endfor %}
<div class='action-group'>
<button class='action-group__action usa-button usa-button-big'>