From c235e519fa572e83813cb1c7160be630fcd9d938 Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Thu, 6 Sep 2018 11:48:24 -0400 Subject: [PATCH] Hook up Edit Project page --- atst/domain/projects.py | 11 ++- atst/routes/workspaces.py | 17 +++- templates/fragments/edit_project_form.html | 86 ++++++++++++++++ templates/workspaces/projects/edit.html | 17 ++++ templates/workspaces/projects/edit.html.to | 108 --------------------- templates/workspaces/projects/index.html | 2 +- templates/workspaces/projects/new.html | 81 +--------------- 7 files changed, 129 insertions(+), 193 deletions(-) create mode 100644 templates/fragments/edit_project_form.html create mode 100644 templates/workspaces/projects/edit.html delete mode 100644 templates/workspaces/projects/edit.html.to diff --git a/atst/domain/projects.py b/atst/domain/projects.py index ef966a5c..611ee2f9 100644 --- a/atst/domain/projects.py +++ b/atst/domain/projects.py @@ -1,7 +1,9 @@ from atst.database import db -from atst.domain.exceptions import NotFoundError -from atst.models.project import Project +from atst.domain.authz import Authorization from atst.domain.environments import Environments +from atst.domain.exceptions import NotFoundError +from atst.models.permissions import Permissions +from atst.models.project import Project class Projects(object): @@ -19,7 +21,10 @@ class Projects(object): def get(cls, user, workspace, project_id): # TODO: this should check permission for this particular project Authorization.check_workspace_permission( - user, workspace, Permissions.VIEW_APPLICATION_IN_WORKSPACE, + user, + workspace, + Permissions.VIEW_APPLICATION_IN_WORKSPACE, + "view project in workspace", ) try: diff --git a/atst/routes/workspaces.py b/atst/routes/workspaces.py index 594b8f99..0e18ed63 100644 --- a/atst/routes/workspaces.py +++ b/atst/routes/workspaces.py @@ -105,7 +105,7 @@ def new_project(workspace_id): @bp.route("/workspaces//projects/new", methods=["POST"]) -def update_project(workspace_id): +def create_project(workspace_id): workspace = Workspaces.get_for_update(g.current_user, workspace_id) form = NewProjectForm(http_request.form) @@ -126,6 +126,21 @@ def update_project(workspace_id): ) +@bp.route("/workspaces//projects//edit") +def edit_project(workspace_id, project_id): + workspace = Workspaces.get_for_update(g.current_user, workspace_id) + project = Projects.get(g.current_user, workspace, project_id) + form = NewProjectForm( + name=project.name, + environment_names=[env.name for env in project.environments], + description=project.description, + ) + + return render_template( + "workspaces/projects/edit.html", workspace=workspace, project=project, form=form + ) + + @bp.route("/workspaces//members/new") def new_member(workspace_id): workspace = Workspaces.get(g.current_user, workspace_id) diff --git a/templates/fragments/edit_project_form.html b/templates/fragments/edit_project_form.html new file mode 100644 index 00000000..6858604a --- /dev/null +++ b/templates/fragments/edit_project_form.html @@ -0,0 +1,86 @@ +{% from "components/icon.html" import Icon %} +{% from "components/modal.html" import Modal %} +{% from "components/text_input.html" import TextInput %} +{% from "components/alert.html" import Alert %} + + + {% set new_project = project is not defined %} + {% set form_action = url_for('workspaces.create_project', workspace_id=workspace.id) if new_project else url_for('workspaces.edit_project', workspace_id=workspace.id, project_id=project.id) %} + {% set action_text = 'Create' if new_project else 'Update' %} + {% set title_text = 'Add a new project' if new_project else 'Edit {} project'.format(project.name) %} + +
+ {% call Modal(name=modalName, dismissable=False) %} +

{{ action_text }} project !{ name }

+ +

+ When you click {{ action_text }} Project, the environments + + !{environment.name} + + will be created as individual cloud resource groups under !{ name } project. +

+ +
+ + +
+ {% endcall %} + + {{ form.csrf_token }} +
+
+

{{ title_text }}

+
+ +
+

+ AT-AT allows you to organize your workspace into multiple projects, each of which may have environments. +

+ {{ TextInput(form.name) }} + {{ TextInput(form.description, paragraph=True) }} +
+
+ + {% if form.environment_names.errors %} + {% for error in form.environment_names.errors %} + {{ Alert(error, level="error") }} + {% endfor %} + {% endif %} + +
+
+

Project Environments

+

+ Each environment created within a project is an enclave of cloud resources that is logically separated from each other for increased security. +

+
+ +
    +
  • +
    + + +
    + +
  • +
+ + +
+ + +
+ +
+ + + +
+
+ diff --git a/templates/workspaces/projects/edit.html b/templates/workspaces/projects/edit.html new file mode 100644 index 00000000..0a504091 --- /dev/null +++ b/templates/workspaces/projects/edit.html @@ -0,0 +1,17 @@ +{% extends "workspaces/base.html" %} + +{% from "components/alert.html" import Alert %} +{% from "components/icon.html" import Icon %} + +{% block workspace_content %} + +{{ Alert( + "UI Mock", + message="

Please note, this screen is a non-functional UI mockup.

", + level="warning" +) }} + +{% set modalName = "updateProjectConfirmation" %} +{% include "fragments/edit_project_form.html" %} + +{% endblock %} diff --git a/templates/workspaces/projects/edit.html.to b/templates/workspaces/projects/edit.html.to deleted file mode 100644 index 58c18bed..00000000 --- a/templates/workspaces/projects/edit.html.to +++ /dev/null @@ -1,108 +0,0 @@ -{% extends "base_workspace.html.to" %} - -{% from "components/alert.html" import Alert %} - -{% block template_vars %} - {% set is_new_project = False %} - {% set project_name = "Code.mil" %} - {% set project_id = "789" %} -{% end %} - -{% block workspace_content %} - -{{ Alert( - "UI Mock", - message="

Please note, this screen is a non-functional UI mockup.

", - level="warning" -) }} - -
-
-
-

- {% if is_new_project %} - Add a new project - {% else %} - {{ project_name }} - Edit project - {% end %} -

-
- -
-
- - -
- -
- - -
-
-
- -
-
-

Project Environments

-
- - {# All instances of .usa-input groups here should be replaced with {% module TextInput(wtforms.fields.Field) %} #} - -
    -
  • -
    - - -
    - -
  • - -
  • -
    - - -
    - -
  • - -
  • -
    - - -
    - -
  • - -
- - -
- - -
- -{% end %} - diff --git a/templates/workspaces/projects/index.html b/templates/workspaces/projects/index.html index 99b00d7f..8dfaf373 100644 --- a/templates/workspaces/projects/index.html +++ b/templates/workspaces/projects/index.html @@ -25,7 +25,7 @@

{{ project.name }} ({{ project.environments|length }} environments)

- + {{ Icon('edit') }} edit diff --git a/templates/workspaces/projects/new.html b/templates/workspaces/projects/new.html index 69914ea3..765ff7d2 100644 --- a/templates/workspaces/projects/new.html +++ b/templates/workspaces/projects/new.html @@ -1,9 +1,3 @@ -{% from "components/icon.html" import Icon %} -{% from "components/modal.html" import Modal %} -{% from "components/text_input.html" import TextInput %} -{% from "components/tooltip.html" import Tooltip %} -{% from "components/alert.html" import Alert %} - {% extends "workspaces/base.html" %} {% block workspace_content %} @@ -18,79 +12,6 @@ ) }} {% endif %} - -
- {% call Modal(name=modalName, dismissable=False) %} -

Create project !{ name }

+{% include "fragments/edit_project_form.html" %} -

- When you click Create Project, the environments - - !{environment.name} - - will be created as individual cloud resource groups under !{ name } project. -

- -
- - -
- {% endcall %} - - {{ form.csrf_token }} -
-
-

Add a new project

-
- -
-

- AT-AT allows you to organize your workspace into multiple projects, each of which may have environments. -

- {{ TextInput(form.name) }} - {{ TextInput(form.description, paragraph=True) }} -
-
- - {% if form.environment_names.errors %} - {% for error in form.environment_names.errors %} - {{ Alert(error, level="error") }} - {% endfor %} - {% endif %} - -
-
-

Project Environments

-

- Each environment created within a project is an enclave of cloud resources that is logically separated from each other for increased security. -

-
- -
    -
  • -
    - - -
    - -
  • -
- - -
- - -
- -
- -
- - - {% endblock %}