route, form, and domain methods for updating workspace name
This commit is contained in:
parent
fbdf8b0ee6
commit
021871ec16
@ -27,7 +27,7 @@ class Workspaces(object):
|
|||||||
return ScopedWorkspace(user, workspace)
|
return ScopedWorkspace(user, workspace)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_for_update(cls, user, workspace_id):
|
def get_for_update_projects(cls, user, workspace_id):
|
||||||
workspace = WorkspacesQuery.get(workspace_id)
|
workspace = WorkspacesQuery.get(workspace_id)
|
||||||
Authorization.check_workspace_permission(
|
Authorization.check_workspace_permission(
|
||||||
user, workspace, Permissions.ADD_APPLICATION_IN_WORKSPACE, "add project"
|
user, workspace, Permissions.ADD_APPLICATION_IN_WORKSPACE, "add project"
|
||||||
@ -35,6 +35,15 @@ class Workspaces(object):
|
|||||||
|
|
||||||
return workspace
|
return workspace
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_for_update_information(cls, user, workspace_id):
|
||||||
|
workspace = WorkspacesQuery.get(workspace_id)
|
||||||
|
# Authorization.check_workspace_permission(
|
||||||
|
# user, workspace, TBD, "update workspace information"
|
||||||
|
# )
|
||||||
|
|
||||||
|
return workspace
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_request(cls, request):
|
def get_by_request(cls, request):
|
||||||
return WorkspacesQuery.get_by_request(request)
|
return WorkspacesQuery.get_by_request(request)
|
||||||
@ -98,3 +107,10 @@ class Workspaces(object):
|
|||||||
workspace_role = WorkspacesQuery.create_workspace_role(user, role, workspace)
|
workspace_role = WorkspacesQuery.create_workspace_role(user, role, workspace)
|
||||||
WorkspacesQuery.add_and_commit(workspace_role)
|
WorkspacesQuery.add_and_commit(workspace_role)
|
||||||
return 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)
|
||||||
|
8
atst/forms/workspace.py
Normal file
8
atst/forms/workspace.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
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)])
|
@ -17,6 +17,7 @@ from atst.domain.workspace_users import WorkspaceUsers
|
|||||||
from atst.forms.new_project import NewProjectForm
|
from atst.forms.new_project import NewProjectForm
|
||||||
from atst.forms.new_member import NewMemberForm
|
from atst.forms.new_member import NewMemberForm
|
||||||
from atst.forms.edit_member import EditMemberForm
|
from atst.forms.edit_member import EditMemberForm
|
||||||
|
from atst.forms.workspace import WorkspaceForm
|
||||||
from atst.domain.authz import Authorization
|
from atst.domain.authz import Authorization
|
||||||
from atst.models.permissions import Permissions
|
from atst.models.permissions import Permissions
|
||||||
|
|
||||||
@ -50,6 +51,20 @@ def workspaces():
|
|||||||
return render_template("workspaces/index.html", page=5, workspaces=workspaces)
|
return render_template("workspaces/index.html", page=5, workspaces=workspaces)
|
||||||
|
|
||||||
|
|
||||||
|
@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)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/workspaces/<workspace_id>/projects")
|
@bp.route("/workspaces/<workspace_id>/projects")
|
||||||
def workspace_projects(workspace_id):
|
def workspace_projects(workspace_id):
|
||||||
workspace = Workspaces.get(g.current_user, workspace_id)
|
workspace = Workspaces.get(g.current_user, workspace_id)
|
||||||
@ -98,7 +113,7 @@ def workspace_reports(workspace_id):
|
|||||||
|
|
||||||
@bp.route("/workspaces/<workspace_id>/projects/new")
|
@bp.route("/workspaces/<workspace_id>/projects/new")
|
||||||
def new_project(workspace_id):
|
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()
|
form = NewProjectForm()
|
||||||
return render_template(
|
return render_template(
|
||||||
"workspaces/projects/new.html", workspace=workspace, form=form
|
"workspaces/projects/new.html", workspace=workspace, form=form
|
||||||
@ -107,7 +122,7 @@ def new_project(workspace_id):
|
|||||||
|
|
||||||
@bp.route("/workspaces/<workspace_id>/projects/new", methods=["POST"])
|
@bp.route("/workspaces/<workspace_id>/projects/new", methods=["POST"])
|
||||||
def create_project(workspace_id):
|
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)
|
form = NewProjectForm(http_request.form)
|
||||||
|
|
||||||
if form.validate():
|
if form.validate():
|
||||||
@ -130,7 +145,7 @@ def create_project(workspace_id):
|
|||||||
|
|
||||||
@bp.route("/workspaces/<workspace_id>/projects/<project_id>/edit")
|
@bp.route("/workspaces/<workspace_id>/projects/<project_id>/edit")
|
||||||
def edit_project(workspace_id, project_id):
|
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)
|
project = Projects.get(g.current_user, workspace, project_id)
|
||||||
form = NewProjectForm(
|
form = NewProjectForm(
|
||||||
name=project.name,
|
name=project.name,
|
||||||
|
@ -63,16 +63,16 @@ def test_workspaces_get_ensures_user_is_in_workspace(workspace, workspace_owner)
|
|||||||
Workspaces.get(outside_user, workspace.id)
|
Workspaces.get(outside_user, workspace.id)
|
||||||
|
|
||||||
|
|
||||||
def test_get_for_update_allows_owner(workspace, workspace_owner):
|
def test_get_for_update_projects_allows_owner(workspace, workspace_owner):
|
||||||
Workspaces.get_for_update(workspace_owner, workspace.id)
|
Workspaces.get_for_update_projects(workspace_owner, workspace.id)
|
||||||
|
|
||||||
|
|
||||||
def test_get_for_update_blocks_developer(workspace):
|
def test_get_for_update_projects_blocks_developer(workspace):
|
||||||
developer = UserFactory.create()
|
developer = UserFactory.create()
|
||||||
WorkspaceUsers.add(developer, workspace.id, "developer")
|
WorkspaceUsers.add(developer, workspace.id, "developer")
|
||||||
|
|
||||||
with pytest.raises(UnauthorizedError):
|
with pytest.raises(UnauthorizedError):
|
||||||
Workspaces.get_for_update(developer, workspace.id)
|
Workspaces.get_for_update_projects(developer, workspace.id)
|
||||||
|
|
||||||
|
|
||||||
def test_can_create_workspace_user(workspace, workspace_owner):
|
def test_can_create_workspace_user(workspace, workspace_owner):
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from flask import url_for
|
||||||
|
|
||||||
from tests.factories import UserFactory, WorkspaceFactory
|
from tests.factories import UserFactory, WorkspaceFactory
|
||||||
from atst.domain.workspaces import Workspaces
|
from atst.domain.workspaces import Workspaces
|
||||||
from atst.models.workspace_user import WorkspaceUser
|
from atst.models.workspace_user import WorkspaceUser
|
||||||
@ -51,3 +53,17 @@ def test_user_without_permission_has_no_add_member_link(client, user_session):
|
|||||||
'href="/workspaces/{}/members/new"'.format(workspace.id).encode()
|
'href="/workspaces/{}/members/new"'.format(workspace.id).encode()
|
||||||
not in response.data
|
not in response.data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_workspace_name(client, user_session):
|
||||||
|
user = UserFactory.create()
|
||||||
|
workspace = WorkspaceFactory.create()
|
||||||
|
Workspaces._create_workspace_role(user, workspace, "admin")
|
||||||
|
user_session(user)
|
||||||
|
response = client.post(
|
||||||
|
url_for("workspaces.edit_workspace", workspace_id=workspace.id),
|
||||||
|
data={"name": "a cool new name"},
|
||||||
|
follow_redirects=True,
|
||||||
|
)
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert workspace.name == "a cool new name"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user