diff --git a/atst/domain/environments.py b/atst/domain/environments.py index 2bb0e60f..e0bd3fdb 100644 --- a/atst/domain/environments.py +++ b/atst/domain/environments.py @@ -126,7 +126,7 @@ class Environments(object): for env_role in env_roles: members_list.append( { - "user_id": env_role.user_id, + "user_id": str(env_role.user_id), "user_name": env_role.user.full_name, "role": role, } diff --git a/atst/routes/applications/settings.py b/atst/routes/applications/settings.py index f363487e..f7198c54 100644 --- a/atst/routes/applications/settings.py +++ b/atst/routes/applications/settings.py @@ -31,7 +31,7 @@ def sort_env_users_by_role(env): users_list = [] no_access_users = env.application.users - env.users no_access_list = [ - {"user_id": user.id, "user_name": user.full_name, "role": "no_access"} + {"user_id": str(user.id), "user_name": user.full_name, "role": "no_access"} for user in no_access_users ] users_list.append({"role": "no_access", "members": no_access_list}) @@ -82,6 +82,8 @@ def settings(application_id): form=form, environments_obj=environments_obj, members_form=members_form, + active_toggler=http_request.args.get("active_toggler"), + active_toggler_section=http_request.args.get("active_toggler_section"), ) @@ -104,6 +106,8 @@ def update_environment(environment_id): application_id=application.id, fragment="application-environments", _anchor="application-environments", + active_toggler=environment.id, + active_toggler_section="edit", ) ) else: @@ -115,6 +119,11 @@ def update_environment(environment_id): 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", ), 400, ) @@ -182,6 +191,8 @@ def update_env_roles(environment_id): application_id=application.id, fragment="application-environments", _anchor="application-environments", + active_toggler=environment.id, + active_toggler_section="members", ) ) else: @@ -195,6 +206,8 @@ def update_env_roles(environment_id): name=application.name, description=application.description ), environments_obj=get_environments_obj_for_app(application=application), + active_toggler=environment.id, + active_toggler_section="edit", ) diff --git a/js/components/forms/edit_environment_role.js b/js/components/forms/edit_environment_role.js index e9919f29..376fb039 100644 --- a/js/components/forms/edit_environment_role.js +++ b/js/components/forms/edit_environment_role.js @@ -1,63 +1,88 @@ import FormMixin from '../../mixins/form' -import textinput from '../text_input' -import Selector from '../selector' import Modal from '../../mixins/modal' -import toggler from '../toggler' export default { name: 'edit-environment-role', - mixins: [FormMixin, Modal], - - components: { - toggler, - Modal, - Selector, - textinput, - }, + mixins: [FormMixin], props: { - choices: Array, - initialData: String, - applicationId: String, + initialRoles: Array, }, data: function() { return { - new_role: this.initialData, + selectedSection: null, + roles: this.sanitizeValues(this.initialRoles), } }, - mounted: function() { - this.$root.$on('revoke-' + this.applicationId, this.revoke) - }, - methods: { - change: function(e) { - this.new_role = e.target.value + sanitizeValues: function(roles) { + roles.forEach(role => { + role.members.forEach(member => { + if (member.role === null) { + member.role = 'no_access' + } + }) + }) + return roles }, - cancel: function() { - this.new_role = this.initialData - }, - revoke: function() { - this.new_role = '' - }, - }, - computed: { - displayName: function() { - const newRole = this.newRole - for (var arr in this.choices) { - if (this.choices[arr][0] == newRole) { - return this.choices[arr][1].name + checkNoAccess: function(role) { + return role === 'no_access' + }, + + toggleSection: function(sectionName) { + if (this.selectedSection === sectionName) { + this.selectedSection = null + } else { + this.selectedSection = sectionName + } + }, + + onInput: function(e) { + this.changed = true + this.updateRoles(e.target.attributes['user-id'].value, e.target.value) + this.showError = false + this.showValid = true + }, + + getUserInfo: function(userId) { + for (let role of this.roles) { + for (let member of role.members) { + if (member.user_id === userId) { + return member + } } } }, - label_class: function() { - return this.newRole === '' ? 'label' : 'label label--success' + + removeUser: function(userId) { + for (let role of this.roles) { + role.members = role.members.filter(member => { + return member.user_id !== userId + }) + if (!role.members) { + role.members = [] + } + } }, - newRole: function() { - return this.new_role + + addUser: function(userInfo, newRole) { + this.roles.forEach(role => { + if (role.role === newRole) { + userInfo.role = newRole + role.members.push(userInfo) + } + }) + }, + + updateRoles: function(userId, newRole) { + var userInfo = this.getUserInfo(userId) + this.removeUser(userId) + this.addUser(userInfo, newRole) + this.toggleSection() }, }, } diff --git a/js/components/toggler.js b/js/components/toggler.js index 2f1c1f0b..e433b294 100644 --- a/js/components/toggler.js +++ b/js/components/toggler.js @@ -1,3 +1,4 @@ +import editEnvironmentRole from './forms/edit_environment_role' import FormMixin from '../mixins/form' import optionsinput from './options_input' import textinput from './text_input' @@ -7,7 +8,15 @@ export default { mixins: [FormMixin], + props: { + initialSelectedSection: { + type: String, + default: null, + }, + }, + components: { + editEnvironmentRole, optionsinput, textinput, optionsinput, diff --git a/styles/sections/_application_edit.scss b/styles/sections/_application_edit.scss index 73a32c7e..75027e93 100644 --- a/styles/sections/_application_edit.scss +++ b/styles/sections/_application_edit.scss @@ -77,7 +77,7 @@ margin: 0; li { - background-color: white; + background-color: $color-white; border: none; } } diff --git a/templates/fragments/applications/edit_environments.html b/templates/fragments/applications/edit_environments.html index 2d64a0f2..fe25d41b 100644 --- a/templates/fragments/applications/edit_environments.html +++ b/templates/fragments/applications/edit_environments.html @@ -72,8 +72,9 @@