project -> application everywhere

This commit is contained in:
dandds
2019-01-10 16:38:00 -05:00
parent 9ad3c45200
commit 3fc323d785
67 changed files with 644 additions and 609 deletions

View File

@@ -67,7 +67,7 @@ def home():
)
else:
return redirect(
url_for("workspaces.workspace_projects", workspace_id=workspace_id)
url_for("workspaces.workspace_applications", workspace_id=workspace_id)
)
else:
return redirect(url_for("workspaces.workspaces"))

View File

@@ -250,7 +250,9 @@ def update_financial_verification(request_id):
if updated_request.legacy_task_order.verified:
workspace = Requests.auto_approve_and_create_workspace(updated_request)
flash("new_workspace")
return redirect(url_for("workspaces.new_project", workspace_id=workspace.id))
return redirect(
url_for("workspaces.new_application", workspace_id=workspace.id)
)
else:
return redirect(url_for("requests.requests_index", modal="pendingCCPOApproval"))

View File

@@ -66,7 +66,7 @@ class RequestsIndex(object):
def _workspace_link_for_request(self, request):
if request.is_approved:
return url_for(
"workspaces.workspace_projects", workspace_id=request.workspace.id
"workspaces.workspace_applications", workspace_id=request.workspace.id
)
else:
return None

View File

@@ -3,7 +3,7 @@ from flask import Blueprint, request as http_request, g, render_template
workspaces_bp = Blueprint("workspaces", __name__)
from . import index
from . import projects
from . import applications
from . import members
from . import invitations
from . import task_orders

View File

@@ -0,0 +1,102 @@
from flask import (
current_app as app,
g,
redirect,
render_template,
request as http_request,
url_for,
)
from . import workspaces_bp
from atst.domain.environment_roles import EnvironmentRoles
from atst.domain.exceptions import UnauthorizedError
from atst.domain.applications import Applications
from atst.domain.workspaces import Workspaces
from atst.forms.application import NewApplicationForm, ApplicationForm
@workspaces_bp.route("/workspaces/<workspace_id>/applications")
def workspace_applications(workspace_id):
workspace = Workspaces.get(g.current_user, workspace_id)
return render_template("workspaces/applications/index.html", workspace=workspace)
@workspaces_bp.route("/workspaces/<workspace_id>/applications/new")
def new_application(workspace_id):
workspace = Workspaces.get_for_update_applications(g.current_user, workspace_id)
form = NewApplicationForm()
return render_template(
"workspaces/applications/new.html", workspace=workspace, form=form
)
@workspaces_bp.route("/workspaces/<workspace_id>/applications/new", methods=["POST"])
def create_application(workspace_id):
workspace = Workspaces.get_for_update_applications(g.current_user, workspace_id)
form = NewApplicationForm(http_request.form)
if form.validate():
application_data = form.data
Applications.create(
g.current_user,
workspace,
application_data["name"],
application_data["description"],
application_data["environment_names"],
)
return redirect(
url_for("workspaces.workspace_applications", workspace_id=workspace.id)
)
else:
return render_template(
"workspaces/applications/new.html", workspace=workspace, form=form
)
@workspaces_bp.route("/workspaces/<workspace_id>/applications/<application_id>/edit")
def edit_application(workspace_id, application_id):
workspace = Workspaces.get_for_update_applications(g.current_user, workspace_id)
application = Applications.get(g.current_user, workspace, application_id)
form = ApplicationForm(name=application.name, description=application.description)
return render_template(
"workspaces/applications/edit.html",
workspace=workspace,
application=application,
form=form,
)
@workspaces_bp.route(
"/workspaces/<workspace_id>/applications/<application_id>/edit", methods=["POST"]
)
def update_application(workspace_id, application_id):
workspace = Workspaces.get_for_update_applications(g.current_user, workspace_id)
application = Applications.get(g.current_user, workspace, application_id)
form = ApplicationForm(http_request.form)
if form.validate():
application_data = form.data
Applications.update(g.current_user, workspace, application, application_data)
return redirect(
url_for("workspaces.workspace_applications", workspace_id=workspace.id)
)
else:
return render_template(
"workspaces/applications/edit.html",
workspace=workspace,
application=application,
form=form,
)
@workspaces_bp.route("/workspaces/<workspace_id>/environments/<environment_id>/access")
def access_environment(workspace_id, environment_id):
env_role = EnvironmentRoles.get(g.current_user.id, environment_id)
if not env_role:
raise UnauthorizedError(
g.current_user, "access environment {}".format(environment_id)
)
else:
token = app.csp.cloud.get_access_token(env_role)
return redirect(url_for("atst.csp_environment_access", token=token))

View File

@@ -32,7 +32,7 @@ def edit_workspace(workspace_id):
if form.validate():
Workspaces.update(workspace, form.data)
return redirect(
url_for("workspaces.workspace_projects", workspace_id=workspace.id)
url_for("workspaces.workspace_applications", workspace_id=workspace.id)
)
else:
return render_template("workspaces/edit.html", form=form, workspace=workspace)
@@ -40,7 +40,9 @@ def edit_workspace(workspace_id):
@workspaces_bp.route("/workspaces/<workspace_id>")
def show_workspace(workspace_id):
return redirect(url_for("workspaces.workspace_projects", workspace_id=workspace_id))
return redirect(
url_for("workspaces.workspace_applications", workspace_id=workspace_id)
)
@workspaces_bp.route("/workspaces/<workspace_id>/reports")

View File

@@ -4,7 +4,7 @@ from flask import render_template, request as http_request, g, redirect, url_for
from . import workspaces_bp
from atst.domain.exceptions import AlreadyExistsError
from atst.domain.projects import Projects
from atst.domain.applications import Applications
from atst.domain.workspaces import Workspaces
from atst.domain.workspace_roles import WorkspaceRoles, MEMBER_STATUS_CHOICES
from atst.domain.environments import Environments
@@ -101,7 +101,7 @@ def view_member(workspace_id, member_id):
"edit this workspace user",
)
member = WorkspaceRoles.get(workspace_id, member_id)
projects = Projects.get_all(g.current_user, member, workspace)
applications = Applications.get_all(g.current_user, member, workspace)
form = EditMemberForm(workspace_role=member.role_name)
editable = g.current_user == member.user
can_revoke_access = Workspaces.can_revoke_access_for(workspace, member)
@@ -113,7 +113,7 @@ def view_member(workspace_id, member_id):
"workspaces/members/edit.html",
workspace=workspace,
member=member,
projects=projects,
applications=applications,
form=form,
choices=ENVIRONMENT_ROLES,
env_role_modal_description=ENV_ROLE_MODAL_DESCRIPTION,

View File

@@ -1,99 +0,0 @@
from flask import (
current_app as app,
g,
redirect,
render_template,
request as http_request,
url_for,
)
from . import workspaces_bp
from atst.domain.environment_roles import EnvironmentRoles
from atst.domain.exceptions import UnauthorizedError
from atst.domain.projects import Projects
from atst.domain.workspaces import Workspaces
from atst.forms.project import NewProjectForm, ProjectForm
@workspaces_bp.route("/workspaces/<workspace_id>/projects")
def workspace_projects(workspace_id):
workspace = Workspaces.get(g.current_user, workspace_id)
return render_template("workspaces/projects/index.html", workspace=workspace)
@workspaces_bp.route("/workspaces/<workspace_id>/projects/new")
def new_project(workspace_id):
workspace = Workspaces.get_for_update_projects(g.current_user, workspace_id)
form = NewProjectForm()
return render_template(
"workspaces/projects/new.html", workspace=workspace, form=form
)
@workspaces_bp.route("/workspaces/<workspace_id>/projects/new", methods=["POST"])
def create_project(workspace_id):
workspace = Workspaces.get_for_update_projects(g.current_user, workspace_id)
form = NewProjectForm(http_request.form)
if form.validate():
project_data = form.data
Projects.create(
g.current_user,
workspace,
project_data["name"],
project_data["description"],
project_data["environment_names"],
)
return redirect(
url_for("workspaces.workspace_projects", workspace_id=workspace.id)
)
else:
return render_template(
"workspaces/projects/new.html", workspace=workspace, form=form
)
@workspaces_bp.route("/workspaces/<workspace_id>/projects/<project_id>/edit")
def edit_project(workspace_id, project_id):
workspace = Workspaces.get_for_update_projects(g.current_user, workspace_id)
project = Projects.get(g.current_user, workspace, project_id)
form = ProjectForm(name=project.name, description=project.description)
return render_template(
"workspaces/projects/edit.html", workspace=workspace, project=project, form=form
)
@workspaces_bp.route(
"/workspaces/<workspace_id>/projects/<project_id>/edit", methods=["POST"]
)
def update_project(workspace_id, project_id):
workspace = Workspaces.get_for_update_projects(g.current_user, workspace_id)
project = Projects.get(g.current_user, workspace, project_id)
form = ProjectForm(http_request.form)
if form.validate():
project_data = form.data
Projects.update(g.current_user, workspace, project, project_data)
return redirect(
url_for("workspaces.workspace_projects", workspace_id=workspace.id)
)
else:
return render_template(
"workspaces/projects/edit.html",
workspace=workspace,
project=project,
form=form,
)
@workspaces_bp.route("/workspaces/<workspace_id>/environments/<environment_id>/access")
def access_environment(workspace_id, environment_id):
env_role = EnvironmentRoles.get(g.current_user.id, environment_id)
if not env_role:
raise UnauthorizedError(
g.current_user, "access environment {}".format(environment_id)
)
else:
token = app.csp.cloud.get_access_token(env_role)
return redirect(url_for("atst.csp_environment_access", token=token))