Merge pull request #822 from dod-ccpo/app-members-edit
App members edit
This commit is contained in:
@@ -2,18 +2,18 @@ from flask_wtf import FlaskForm
|
||||
from wtforms.fields import FieldList, FormField, HiddenField, RadioField, StringField
|
||||
|
||||
from .forms import BaseForm
|
||||
from .data import ENV_ROLES
|
||||
from .data import ENV_ROLES, ENV_ROLE_NO_ACCESS as NO_ACCESS
|
||||
|
||||
|
||||
class MemberForm(FlaskForm):
|
||||
user_id = HiddenField()
|
||||
user_name = StringField()
|
||||
role_name = RadioField(choices=ENV_ROLES, default="no_access")
|
||||
role_name = RadioField(choices=ENV_ROLES, default=NO_ACCESS)
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
_data = super().data
|
||||
if "role_name" in _data and _data["role_name"] == "no_access":
|
||||
if "role_name" in _data and _data["role_name"] == NO_ACCESS:
|
||||
_data["role_name"] = None
|
||||
return _data
|
||||
|
||||
|
@@ -217,6 +217,7 @@ REQUIRED_DISTRIBUTIONS = [
|
||||
("other", "Other as necessary"),
|
||||
]
|
||||
|
||||
ENV_ROLE_NO_ACCESS = "No Access"
|
||||
ENV_ROLES = [(role.value, role.value) for role in CSPRole] + [
|
||||
("no_access", "No access")
|
||||
(ENV_ROLE_NO_ACCESS, "No access")
|
||||
]
|
||||
|
@@ -1,14 +1,31 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms.fields import FormField, FieldList, HiddenField, StringField
|
||||
from wtforms.fields import FormField, FieldList, HiddenField, RadioField, StringField
|
||||
from wtforms.validators import Required
|
||||
|
||||
from .application_member import EnvironmentForm
|
||||
from .application_member import EnvironmentForm as BaseEnvironmentForm
|
||||
from .data import ENV_ROLES, ENV_ROLE_NO_ACCESS as NO_ACCESS
|
||||
from .forms import BaseForm
|
||||
from atst.forms.fields import SelectField
|
||||
from atst.domain.permission_sets import PermissionSets
|
||||
from atst.utils.localization import translate
|
||||
|
||||
|
||||
class EnvironmentForm(BaseEnvironmentForm):
|
||||
role = RadioField(
|
||||
"Role",
|
||||
choices=ENV_ROLES,
|
||||
default=None,
|
||||
filters=[lambda x: None if x == "None" else x],
|
||||
)
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
_data = super().data
|
||||
if "role" in _data and _data["role"] == NO_ACCESS:
|
||||
_data["role"] = None
|
||||
return _data
|
||||
|
||||
|
||||
class PermissionsForm(FlaskForm):
|
||||
perms_team_mgmt = SelectField(
|
||||
translate("portfolios.applications.members.new.manage_team"),
|
||||
|
@@ -5,6 +5,7 @@ from atst.domain.environments import Environments
|
||||
from atst.domain.applications import Applications
|
||||
from atst.forms.app_settings import AppEnvRolesForm
|
||||
from atst.forms.application import ApplicationForm, EditEnvironmentForm
|
||||
from atst.forms.data import ENV_ROLE_NO_ACCESS as NO_ACCESS
|
||||
from atst.domain.authz.decorator import user_can_access_decorator as user_can
|
||||
from atst.models.environment_role import CSPRole
|
||||
from atst.domain.exceptions import NotFoundError
|
||||
@@ -46,10 +47,10 @@ def sort_env_users_by_role(env):
|
||||
users_list = []
|
||||
no_access_users = env.application.users - env.users
|
||||
no_access_list = [
|
||||
{"user_id": str(user.id), "user_name": user.full_name, "role_name": "no_access"}
|
||||
{"user_id": str(user.id), "user_name": user.full_name, "role_name": NO_ACCESS}
|
||||
for user in no_access_users
|
||||
]
|
||||
users_list.append({"role": "no_access", "members": no_access_list})
|
||||
users_list.append({"role": NO_ACCESS, "members": no_access_list})
|
||||
|
||||
for role in CSPRole:
|
||||
users_list.append(
|
||||
|
@@ -6,6 +6,7 @@ from atst.domain.applications import Applications
|
||||
from atst.domain.application_roles import ApplicationRoles
|
||||
from atst.domain.authz.decorator import user_can_access_decorator as user_can
|
||||
from atst.domain.environment_roles import EnvironmentRoles
|
||||
from atst.domain.environments import Environments
|
||||
from atst.domain.exceptions import AlreadyExistsError
|
||||
from atst.domain.permission_sets import PermissionSets
|
||||
from atst.domain.users import Users
|
||||
@@ -97,15 +98,25 @@ def update_team(application_id):
|
||||
form = TeamForm(http_request.form)
|
||||
|
||||
if form.validate():
|
||||
for member in form.members:
|
||||
app_role = ApplicationRoles.get(member.data["user_id"], application.id)
|
||||
for member_form in form.members:
|
||||
app_role = ApplicationRoles.get(member_form.user_id.data, application.id)
|
||||
new_perms = [
|
||||
perm
|
||||
for perm in member.data["permission_sets"]
|
||||
for perm in member_form.data["permission_sets"]
|
||||
if perm != PermissionSets.VIEW_APPLICATION
|
||||
]
|
||||
ApplicationRoles.update_permission_sets(app_role, new_perms)
|
||||
flash("updated_application_members_permissions")
|
||||
|
||||
for environment_role_form in member_form.environment_roles:
|
||||
user = Users.get(member_form.user_id.data)
|
||||
environment = Environments.get(
|
||||
environment_role_form.environment_id.data
|
||||
)
|
||||
Environments.update_env_role(
|
||||
environment, user, environment_role_form.data.get("role")
|
||||
)
|
||||
|
||||
flash("updated_application_team_settings", application_name=application.name)
|
||||
|
||||
return redirect(
|
||||
url_for(
|
||||
|
@@ -186,10 +186,10 @@ MESSAGES = {
|
||||
""",
|
||||
"category": "success",
|
||||
},
|
||||
"updated_application_members_permissions": {
|
||||
"updated_application_team_settings": {
|
||||
"title_template": translate("flash.success"),
|
||||
"message_template": """
|
||||
<p>{{ "flash.updated_application_members_permissions" | translate }}</p>
|
||||
<p>{{ "flash.updated_application_team_settings" | translate({"application_name": application_name}) }}</p>
|
||||
""",
|
||||
"category": "success",
|
||||
},
|
||||
|
Reference in New Issue
Block a user