From b212524e6105a28be0ef20b0292392f4d30655ee Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 21 Nov 2022 16:58:39 -0500 Subject: [PATCH] added a script to add a user to a group w/ burnettk --- .../scripts/add_user_to_group.py | 40 +++++++++++++++++++ .../cypress/e2e/process_groups.cy.js | 4 +- .../src/components/ProcessGroupForm.tsx | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 spiffworkflow-backend/src/spiffworkflow_backend/scripts/add_user_to_group.py diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/add_user_to_group.py b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/add_user_to_group.py new file mode 100644 index 00000000..b07095e3 --- /dev/null +++ b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/add_user_to_group.py @@ -0,0 +1,40 @@ +"""Get_env.""" +from typing import Any + +from spiffworkflow_backend.models.group import GroupModel +from spiffworkflow_backend.models.group import GroupNotFoundError +from spiffworkflow_backend.models.script_attributes_context import ( + ScriptAttributesContext, +) +from spiffworkflow_backend.models.user import UserModel, UserNotFoundError +from spiffworkflow_backend.scripts.script import Script +from spiffworkflow_backend.services.user_service import UserService + + +class AddUserToGroup(Script): + """AddUserToGroup.""" + + def get_description(self) -> str: + """Get_description.""" + return """Add a given user to a given group.""" + + def run( + self, + script_attributes_context: ScriptAttributesContext, + *args: Any, + **kwargs: Any, + ) -> Any: + """Run.""" + username = args[0] + group_identifier = args[1] + user = UserModel.query.filter_by(username=username).first() + if user is None: + raise UserNotFoundError(f"Script 'add_user_to_group' could not find a user with username: {username}") + + group = GroupModel.query.filter_by(identifier=group_identifier).first() + if group is None: + raise GroupNotFoundError( + f"Script 'add_user_to_group' could not find group with identifier '{group_identifier}'." + ) + + UserService.add_user_to_group(user, group) diff --git a/spiffworkflow-frontend/cypress/e2e/process_groups.cy.js b/spiffworkflow-frontend/cypress/e2e/process_groups.cy.js index 450d2689..85ab9b82 100644 --- a/spiffworkflow-frontend/cypress/e2e/process_groups.cy.js +++ b/spiffworkflow-frontend/cypress/e2e/process_groups.cy.js @@ -32,7 +32,9 @@ describe('process-groups', () => { cy.contains('Delete').click(); cy.contains('Are you sure'); - cy.getBySel('modal-confirmation-dialog').find('.cds--btn--danger').click(); + cy.getBySel('delete-process-group-button-modal-confirmation-dialog') + .find('.cds--btn--danger') + .click(); cy.url().should('include', `process-groups`); cy.contains(groupId).should('not.exist'); }); diff --git a/spiffworkflow-frontend/src/components/ProcessGroupForm.tsx b/spiffworkflow-frontend/src/components/ProcessGroupForm.tsx index e427f43b..26f64253 100644 --- a/spiffworkflow-frontend/src/components/ProcessGroupForm.tsx +++ b/spiffworkflow-frontend/src/components/ProcessGroupForm.tsx @@ -169,6 +169,7 @@ export default function ProcessGroupForm({ if (mode === 'edit') { buttons.push(