Merge pull request #294 from dod-ccpo/edit-workspace-#160300728
Edit workspace #160300728
This commit is contained in:
@@ -27,7 +27,7 @@ class Workspaces(object):
|
||||
return ScopedWorkspace(user, workspace)
|
||||
|
||||
@classmethod
|
||||
def get_for_update(cls, user, workspace_id):
|
||||
def get_for_update_projects(cls, user, workspace_id):
|
||||
workspace = WorkspacesQuery.get(workspace_id)
|
||||
Authorization.check_workspace_permission(
|
||||
user, workspace, Permissions.ADD_APPLICATION_IN_WORKSPACE, "add project"
|
||||
@@ -35,6 +35,18 @@ class Workspaces(object):
|
||||
|
||||
return workspace
|
||||
|
||||
@classmethod
|
||||
def get_for_update_information(cls, user, workspace_id):
|
||||
workspace = WorkspacesQuery.get(workspace_id)
|
||||
Authorization.check_workspace_permission(
|
||||
user,
|
||||
workspace,
|
||||
Permissions.EDIT_WORKSPACE_INFORMATION,
|
||||
"update workspace information",
|
||||
)
|
||||
|
||||
return workspace
|
||||
|
||||
@classmethod
|
||||
def get_by_request(cls, request):
|
||||
return WorkspacesQuery.get_by_request(request)
|
||||
@@ -98,3 +110,10 @@ class Workspaces(object):
|
||||
workspace_role = WorkspacesQuery.create_workspace_role(user, role, workspace)
|
||||
WorkspacesQuery.add_and_commit(workspace_role)
|
||||
return workspace_role
|
||||
|
||||
@classmethod
|
||||
def update(cls, workspace, new_data):
|
||||
if "name" in new_data:
|
||||
workspace.name = new_data["name"]
|
||||
|
||||
WorkspacesQuery.add_and_commit(workspace)
|
||||
|
17
atst/forms/workspace.py
Normal file
17
atst/forms/workspace.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from wtforms.fields import StringField
|
||||
from wtforms.validators import Length
|
||||
|
||||
from .forms import ValidatedForm
|
||||
|
||||
|
||||
class WorkspaceForm(ValidatedForm):
|
||||
name = StringField(
|
||||
"Workspace Name",
|
||||
validators=[
|
||||
Length(
|
||||
min=4,
|
||||
max=50,
|
||||
message="Workspace names must be at least 4 and not more than 50 characters",
|
||||
)
|
||||
],
|
||||
)
|
@@ -20,6 +20,7 @@ class Permissions(object):
|
||||
VIEW_ASSIGNED_ATAT_ROLE_CONFIGURATIONS = "view_assigned_atat_role_configurations"
|
||||
VIEW_ASSIGNED_CSP_ROLE_CONFIGURATIONS = "view_assigned_csp_role_configurations"
|
||||
|
||||
EDIT_WORKSPACE_INFORMATION = "edit_workspace_information"
|
||||
DEACTIVATE_WORKSPACE = "deactivate_workspace"
|
||||
VIEW_ATAT_PERMISSIONS = "view_atat_permissions"
|
||||
TRANSFER_OWNERSHIP_OF_WORKSPACE = "transfer_ownership_of_workspace"
|
||||
|
@@ -17,6 +17,7 @@ from atst.domain.workspace_users import WorkspaceUsers
|
||||
from atst.forms.new_project import NewProjectForm
|
||||
from atst.forms.new_member import NewMemberForm
|
||||
from atst.forms.edit_member import EditMemberForm
|
||||
from atst.forms.workspace import WorkspaceForm
|
||||
from atst.domain.authz import Authorization
|
||||
from atst.models.permissions import Permissions
|
||||
|
||||
@@ -50,12 +51,32 @@ def workspaces():
|
||||
return render_template("workspaces/index.html", page=5, workspaces=workspaces)
|
||||
|
||||
|
||||
@bp.route("/workspaces/<workspace_id>/edit")
|
||||
def workspace(workspace_id):
|
||||
workspace = Workspaces.get_for_update_information(g.current_user, workspace_id)
|
||||
form = WorkspaceForm(data={"name": workspace.name})
|
||||
return render_template("workspaces/edit.html", form=form, workspace=workspace)
|
||||
|
||||
|
||||
@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)
|
||||
|
||||
|
||||
@bp.route("/workspaces/<workspace_id>/edit", methods=["POST"])
|
||||
def edit_workspace(workspace_id):
|
||||
workspace = Workspaces.get_for_update_information(g.current_user, workspace_id)
|
||||
form = WorkspaceForm(http_request.form)
|
||||
if form.validate():
|
||||
Workspaces.update(workspace, form.data)
|
||||
return redirect(
|
||||
url_for("workspaces.workspace_projects", workspace_id=workspace.id)
|
||||
)
|
||||
else:
|
||||
return render_template("workspaces/edit.html", form=form, workspace=workspace)
|
||||
|
||||
|
||||
@bp.route("/workspaces/<workspace_id>")
|
||||
def show_workspace(workspace_id):
|
||||
return redirect(url_for("workspaces.workspace_projects", workspace_id=workspace_id))
|
||||
@@ -98,7 +119,7 @@ def workspace_reports(workspace_id):
|
||||
|
||||
@bp.route("/workspaces/<workspace_id>/projects/new")
|
||||
def new_project(workspace_id):
|
||||
workspace = Workspaces.get_for_update(g.current_user, 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
|
||||
@@ -107,7 +128,7 @@ def new_project(workspace_id):
|
||||
|
||||
@bp.route("/workspaces/<workspace_id>/projects/new", methods=["POST"])
|
||||
def create_project(workspace_id):
|
||||
workspace = Workspaces.get_for_update(g.current_user, workspace_id)
|
||||
workspace = Workspaces.get_for_update_projects(g.current_user, workspace_id)
|
||||
form = NewProjectForm(http_request.form)
|
||||
|
||||
if form.validate():
|
||||
@@ -130,7 +151,7 @@ def create_project(workspace_id):
|
||||
|
||||
@bp.route("/workspaces/<workspace_id>/projects/<project_id>/edit")
|
||||
def edit_project(workspace_id, project_id):
|
||||
workspace = Workspaces.get_for_update(g.current_user, workspace_id)
|
||||
workspace = Workspaces.get_for_update_projects(g.current_user, workspace_id)
|
||||
project = Projects.get(g.current_user, workspace, project_id)
|
||||
form = NewProjectForm(
|
||||
name=project.name,
|
||||
|
Reference in New Issue
Block a user