Merge pull request #213 from dod-ccpo/fix-new-workspace-redirect

Redirect to projects/new after FV-related request approval
This commit is contained in:
richard-dds 2018-08-24 16:09:06 -04:00 committed by GitHub
commit 7ecc836033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 64 additions and 25 deletions

View File

@ -1,7 +1,7 @@
from flask_wtf import Form from flask_wtf import Form
from wtforms.fields import StringField, TextAreaField, FieldList from wtforms.fields import StringField, TextAreaField, FieldList
from wtforms.validators import Required from wtforms.validators import Required
from atst.forms.validators import ListItemRequired from atst.forms.validators import ListItemRequired, ListItemsUnique
class NewProjectForm(Form): class NewProjectForm(Form):
@ -12,7 +12,10 @@ class NewProjectForm(Form):
description = TextAreaField(label="Description", validators=[Required()]) description = TextAreaField(label="Description", validators=[Required()])
environment_names = FieldList( environment_names = FieldList(
StringField(label="Environment Name"), StringField(label="Environment Name"),
validators=[ListItemRequired(message="Provide at least one environment name.")], validators=[
ListItemRequired(message="Provide at least one environment name."),
ListItemsUnique(message="Environment names must be unique."),
],
) )
@property @property

View File

@ -60,3 +60,11 @@ def ListItemRequired(message="Please provide at least one.", empty_values=("", N
raise ValidationError(message) raise ValidationError(message)
return _list_item_required return _list_item_required
def ListItemsUnique(message="Items must be unique"):
def _list_items_unique(form, field):
if len(field.data) > len(set(field.data)):
raise ValidationError(message)
return _list_items_unique

View File

@ -45,7 +45,7 @@ def update_financial_verification(request_id):
new_workspace = Requests.approve_and_create_workspace(updated_request) new_workspace = Requests.approve_and_create_workspace(updated_request)
return redirect( return redirect(
url_for( url_for(
"workspaces.workspace_projects", "workspaces.new_project",
workspace_id=new_workspace.id, workspace_id=new_workspace.id,
newWorkspace=True, newWorkspace=True,
) )

View File

@ -18,7 +18,14 @@
.icon-tooltip { .icon-tooltip {
margin: -$gap; margin: -$gap;
}
&--grow {
display: inline-block;
width: 100%;
p {
margin-bottom: 0;
}
} }
} }

View File

@ -31,6 +31,10 @@
<div class='alert__message'>{{ message | safe }}</div> <div class='alert__message'>{{ message | safe }}</div>
{% endif %} {% endif %}
{% if caller %}
<div class='alert__message'>{{ caller() }}</div>
{% endif %}
{% if fragment %} {% if fragment %}
<div class='alert__message'> <div class='alert__message'>
{% include fragment %} {% include fragment %}

View File

@ -9,6 +9,14 @@
{% block workspace_content %} {% block workspace_content %}
{% set modalName = "newProjectConfirmation" %} {% set modalName = "newProjectConfirmation" %}
{% if request.args.get("newWorkspace") %}
{{ Alert('Workspace created!',
message="\
<p>You are now ready to create projects and environments within the JEDI Cloud.</p>
",
level='success'
) }}
{% endif %}
<new-project inline-template v-bind:initial-data='{{ form.data|tojson }}'> <new-project inline-template v-bind:initial-data='{{ form.data|tojson }}'>
<form method="POST" action="{{ url_for('workspaces.update_project', workspace_id=workspace.id) }}" > <form method="POST" action="{{ url_for('workspaces.update_project', workspace_id=workspace.id) }}" >
@ -32,30 +40,29 @@
<div class="panel"> <div class="panel">
<div class="panel__heading panel__heading--grow"> <div class="panel__heading panel__heading--grow">
<h1>Add a new project</h1> <h1>Add a new project</h1>
{{ Tooltip(
"AT-AT allows you to organize your workspace into multiple projects, each of which may have environments.",
title="learn more"
)}}
</div> </div>
<div class="panel__content"> <div class="panel__content">
<p>
AT-AT allows you to organize your workspace into multiple projects, each of which may have environments.
</p>
{{ TextInput(form.name) }} {{ TextInput(form.name) }}
{{ TextInput(form.description, paragraph=True) }} {{ TextInput(form.description, paragraph=True) }}
</div> </div>
</div> </div>
{% if form.environment_names.errors %} {% if form.environment_names.errors %}
{{ Alert("Missing Environments", message="Provide at least one environment name.", level="error") }} {% for error in form.environment_names.errors %}
{{ Alert(error, level="error") }}
{% endfor %}
{% endif %} {% endif %}
<div class="block-list project-list-item"> <div class="block-list project-list-item">
<header class="block-list__header"> <header class="block-list__header block-list__header--grow">
<h2 class="block-list__title">Project Environments</h2> <h2 class="block-list__title">Project Environments</h2>
{{ Tooltip( <p>
"Each environment created within a project is an enclave of cloud resources that is logically separated from each other for increased security.", Each environment created within a project is an enclave of cloud resources that is logically separated from each other for increased security.
title="learn more" </p>
)}}
</header> </header>
<ul> <ul>

View File

@ -5,15 +5,6 @@
{% block workspace_content %} {% block workspace_content %}
{% if request.args.get("newWorkspace") %}
{{ Alert('Workspace created!',
message="\
<p>You are now ready to create projects and environments within the JEDI Cloud.</p>
",
level='success'
) }}
{% endif %}
{% for project in workspace.projects %} {% for project in workspace.projects %}
<div class='block-list project-list-item'> <div class='block-list project-list-item'>
<header class='block-list__header'> <header class='block-list__header'>

View File

@ -1,7 +1,7 @@
from wtforms.validators import ValidationError from wtforms.validators import ValidationError
import pytest import pytest
from atst.forms.validators import Alphabet, IsNumber, PhoneNumber from atst.forms.validators import Alphabet, IsNumber, PhoneNumber, ListItemsUnique
class TestIsNumber: class TestIsNumber:
@ -51,3 +51,22 @@ class TestAlphabet:
dummy_field.data = invalid dummy_field.data = invalid
with pytest.raises(ValidationError): with pytest.raises(ValidationError):
validator(dummy_form, dummy_field) validator(dummy_form, dummy_field)
class TestListItemsUnique:
@pytest.mark.parametrize("valid", [["a", "aa", "aaa"], ["one", "two", "three"]])
def test_ListItemsUnique_allows_unique_items(self, valid, dummy_form, dummy_field):
validator = ListItemsUnique()
dummy_field.data = valid
validator(dummy_form, dummy_field)
@pytest.mark.parametrize(
"invalid", [["a", "a", "a"], ["one", "two", "two", "three"]]
)
def test_ListItemsUnique_rejects_duplicate_names(
self, invalid, dummy_form, dummy_field
):
validator = ListItemsUnique()
dummy_field.data = invalid
with pytest.raises(ValidationError):
validator(dummy_form, dummy_field)

View File

@ -137,4 +137,4 @@ class TestPENumberInForm:
response = self.submit_data(client, data, extended=True) response = self.submit_data(client, data, extended=True)
assert response.status_code == 302 assert response.status_code == 302
assert "/workspaces" in response.headers.get("Location") assert "/projects/new" in response.headers.get("Location")