Allow user to select 'No Access'

This commit is contained in:
richard-dds 2018-10-17 14:42:22 -04:00
parent fcd16c1b3c
commit c138df2b0f
6 changed files with 29 additions and 20 deletions

View File

@ -14,3 +14,10 @@ class EnvironmentRoles(object):
.one_or_none()
)
return existing_env_role
@classmethod
def delete(cls, user_id, environment_id):
existing_env_role = EnvironmentRoles.get(user_id, environment_id)
if existing_env_role:
db.session.delete(existing_env_role)
db.session.commit()

View File

@ -69,13 +69,17 @@ class Environments(object):
for id_and_role in ids_and_roles:
new_role = id_and_role["role"]
environment = Environments.get(id_and_role["id"])
env_role = EnvironmentRoles.get(workspace_user.user_id, id_and_role["id"])
if env_role:
env_role.role = new_role
if new_role is None:
EnvironmentRoles.delete(workspace_user.user.id, environment.id)
else:
env_role = EnvironmentRole(
user=workspace_user.user, environment=environment, role=new_role
)
db.session.add(env_role)
env_role = EnvironmentRoles.get(workspace_user.user_id, id_and_role["id"])
if env_role:
env_role.role = new_role
else:
env_role = EnvironmentRole(
user=workspace_user.user, environment=environment, role=new_role
)
db.session.add(env_role)
db.session.commit()

View File

@ -153,6 +153,10 @@ ENVIRONMENT_ROLES = [
"description": "Views cloud resource usage and budget reports.",
},
),
(
"",
{"name": "No Access", "description": "User has no access to this environment."},
),
]
ENV_ROLE_MODAL_DESCRIPTION = {

View File

@ -285,12 +285,10 @@ def update_member(workspace_id, member_id):
for entry in form_dict:
if re.match("env_", entry):
env_id = entry[4:]
env_role = form_dict[entry]
if env_role:
ids_and_roles.append({"id": env_id, "role": env_role})
env_role = form_dict[entry] or None
ids_and_roles.append({"id": env_id, "role": env_role})
form = EditMemberForm(http_request.form)
if form.validate():
new_role_name = None
if form.data["workspace_role"] != member.role:

View File

@ -38,26 +38,24 @@ export default {
this.new_role = this.initialData
},
actualRole: function () {
return this.revoke ? null : this.new_role
}
},
computed: {
displayName: function () {
const roleName = this.actualRole()
const newRole = this.newRole
for (var arr in this.choices) {
if (this.choices[arr][0] == roleName) {
if (this.choices[arr][0] == newRole) {
return this.choices[arr][1].name
}
}
return roleName ? roleName : "no access"
},
label_class: function () {
return this.displayName === "no access" ?
return this.displayName === "No Access" ?
"label" : "label label--success"
},
newRole: function () {
return this.actualRole()
return this.revoke ? "" : this.new_role
}
},
}

View File

@ -81,7 +81,7 @@
{% set role = EnvironmentRoles.get(member.user_id, env.id).role %}
<li class='block-list__item'>
<edit-environment-role inline-template initial-data='{{ role }}' v-bind:choices='{{ choices | tojson }}' v-bind:revoke='revoke'>
<edit-environment-role inline-template initial-data='{{ role or "" }}' v-bind:choices='{{ choices | tojson }}' v-bind:revoke='revoke'>
<div class='project-list-item__environment'>
<span class='project-list-item__environment__link'>
{{ env.name }}
@ -104,7 +104,6 @@
{% for choice in choices %}
<li class='block-list__item block-list__item--selectable'>
{% if choice[0] != "" %}
<input
name='radio_input_{{ env.id }}'
v-on:change='change'
@ -126,7 +125,6 @@
{{ choice[1].name }}
{% endif %}
</label>
{% endif %}
</li>
{% endfor %}
</ul>