Merge pull request #815 from dod-ccpo/add-new-env-app-settings
Add New Environment via app settings
This commit is contained in:
@@ -85,20 +85,33 @@ def check_users_are_in_application(user_ids, application):
|
||||
return True
|
||||
|
||||
|
||||
@applications_bp.route("/applications/<application_id>/settings")
|
||||
@user_can(Permissions.VIEW_APPLICATION, message="view application edit form")
|
||||
def settings(application_id):
|
||||
application = Applications.get(application_id)
|
||||
form = ApplicationForm(name=application.name, description=application.description)
|
||||
def render_settings_page(application, **kwargs):
|
||||
environments_obj = get_environments_obj_for_app(application=application)
|
||||
members_form = AppEnvRolesForm(data=data_for_app_env_roles_form(application))
|
||||
new_env_form = EditEnvironmentForm()
|
||||
|
||||
if "application_form" not in kwargs:
|
||||
kwargs["application_form"] = ApplicationForm(
|
||||
name=application.name, description=application.description
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"portfolios/applications/settings.html",
|
||||
application=application,
|
||||
form=form,
|
||||
environments_obj=environments_obj,
|
||||
members_form=members_form,
|
||||
new_env_form=new_env_form,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
@applications_bp.route("/applications/<application_id>/settings")
|
||||
@user_can(Permissions.VIEW_APPLICATION, message="view application edit form")
|
||||
def settings(application_id):
|
||||
application = Applications.get(application_id)
|
||||
|
||||
return render_settings_page(
|
||||
application=application,
|
||||
active_toggler=http_request.args.get("active_toggler"),
|
||||
active_toggler_section=http_request.args.get("active_toggler_section"),
|
||||
)
|
||||
@@ -129,16 +142,8 @@ def update_environment(environment_id):
|
||||
)
|
||||
else:
|
||||
return (
|
||||
render_template(
|
||||
"portfolios/applications/settings.html",
|
||||
render_settings_page(
|
||||
application=application,
|
||||
form=ApplicationForm(
|
||||
name=application.name, description=application.description
|
||||
),
|
||||
environments_obj=get_environments_obj_for_app(application=application),
|
||||
members_form=AppEnvRolesForm(
|
||||
data=data_for_app_env_roles_form(application)
|
||||
),
|
||||
active_toggler=environment.id,
|
||||
active_toggler_section="edit",
|
||||
),
|
||||
@@ -146,6 +151,31 @@ def update_environment(environment_id):
|
||||
)
|
||||
|
||||
|
||||
@applications_bp.route(
|
||||
"/applications/<application_id>/environments/new", methods=["POST"]
|
||||
)
|
||||
@user_can(Permissions.CREATE_ENVIRONMENT, message="create application environment")
|
||||
def new_environment(application_id):
|
||||
application = Applications.get(application_id)
|
||||
env_form = EditEnvironmentForm(formdata=http_request.form)
|
||||
|
||||
if env_form.validate():
|
||||
Environments.create(application=application, name=env_form.name.data)
|
||||
|
||||
flash("environment_added", environment_name=env_form.data["name"])
|
||||
|
||||
return redirect(
|
||||
url_for(
|
||||
"applications.settings",
|
||||
application_id=application.id,
|
||||
fragment="application-environments",
|
||||
_anchor="application-environments",
|
||||
)
|
||||
)
|
||||
else:
|
||||
return (render_settings_page(application=application), 400)
|
||||
|
||||
|
||||
@applications_bp.route("/applications/<application_id>/edit", methods=["POST"])
|
||||
@user_can(Permissions.EDIT_APPLICATION, message="update application")
|
||||
def update(application_id):
|
||||
@@ -162,12 +192,7 @@ def update(application_id):
|
||||
)
|
||||
)
|
||||
else:
|
||||
return render_template(
|
||||
"portfolios/applications/settings.html",
|
||||
application=application,
|
||||
form=form,
|
||||
environments_obj=get_environments_obj_for_app(application=application),
|
||||
)
|
||||
return render_settings_page(application=application, application_form=form)
|
||||
|
||||
|
||||
@applications_bp.route("/environments/<environment_id>/roles", methods=["POST"])
|
||||
@@ -214,13 +239,8 @@ def update_env_roles(environment_id):
|
||||
)
|
||||
else:
|
||||
return (
|
||||
render_template(
|
||||
"portfolios/applications/settings.html",
|
||||
render_settings_page(
|
||||
application=application,
|
||||
form=ApplicationForm(
|
||||
name=application.name, description=application.description
|
||||
),
|
||||
environments_obj=get_environments_obj_for_app(application=application),
|
||||
active_toggler=environment.id,
|
||||
active_toggler_section="edit",
|
||||
),
|
||||
|
@@ -5,6 +5,7 @@ from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from atst.database import db
|
||||
from atst.domain.authz import Authorization
|
||||
from atst.domain.exceptions import NotFoundError
|
||||
from atst.domain.portfolios.scopes import ScopedPortfolio
|
||||
from atst.models import (
|
||||
Application,
|
||||
|
@@ -17,6 +17,13 @@ MESSAGES = {
|
||||
"message_template": "Application environment members have been updated",
|
||||
"category": "success",
|
||||
},
|
||||
"environment_added": {
|
||||
"title_template": translate("flash.success"),
|
||||
"message_template": """
|
||||
{{ "flash.environment_added" | translate({ "env_name": environment_name }) }}
|
||||
""",
|
||||
"category": "success",
|
||||
},
|
||||
"application_environments_updated": {
|
||||
"title_template": "Application environments updated",
|
||||
"message_template": "Application environments have been updated",
|
||||
@@ -29,7 +36,7 @@ MESSAGES = {
|
||||
},
|
||||
"invitation_resent": {
|
||||
"title_template": "Invitation resent",
|
||||
"message_template": "The {{ officer_type }} has been resent instructions to join this portfolio.",
|
||||
"message_template": "The {{ officer_type }} has been resent instructions to join this portfolio.",
|
||||
"category": "success",
|
||||
},
|
||||
"task_order_draft": {
|
||||
|
Reference in New Issue
Block a user