added a script to add a user to a group w/ burnettk
This commit is contained in:
parent
de392c9fd1
commit
b212524e61
|
@ -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)
|
|
@ -32,7 +32,9 @@ describe('process-groups', () => {
|
||||||
|
|
||||||
cy.contains('Delete').click();
|
cy.contains('Delete').click();
|
||||||
cy.contains('Are you sure');
|
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.url().should('include', `process-groups`);
|
||||||
cy.contains(groupId).should('not.exist');
|
cy.contains(groupId).should('not.exist');
|
||||||
});
|
});
|
||||||
|
|
|
@ -169,6 +169,7 @@ export default function ProcessGroupForm({
|
||||||
if (mode === 'edit') {
|
if (mode === 'edit') {
|
||||||
buttons.push(
|
buttons.push(
|
||||||
<ButtonWithConfirmation
|
<ButtonWithConfirmation
|
||||||
|
data-qa="delete-process-group-button"
|
||||||
description={`Delete Process Group ${processGroup.id}?`}
|
description={`Delete Process Group ${processGroup.id}?`}
|
||||||
onConfirmation={deleteProcessGroup}
|
onConfirmation={deleteProcessGroup}
|
||||||
buttonLabel="Delete"
|
buttonLabel="Delete"
|
||||||
|
|
Loading…
Reference in New Issue