2022-10-31 11:39:54 -04:00
|
|
|
"""Get_env."""
|
|
|
|
from typing import Any
|
|
|
|
from spiffworkflow_backend.models.group import GroupModel, GroupNotFoundError
|
|
|
|
|
|
|
|
from spiffworkflow_backend.models.script_attributes_context import (
|
|
|
|
ScriptAttributesContext,
|
|
|
|
)
|
|
|
|
from spiffworkflow_backend.scripts.script import Script
|
|
|
|
|
|
|
|
|
|
|
|
class GetGroupMembers(Script):
|
|
|
|
"""GetGroupMembers."""
|
|
|
|
|
|
|
|
def get_description(self) -> str:
|
|
|
|
"""Get_description."""
|
2022-10-31 08:41:05 -07:00
|
|
|
return """Return the list of usernames of the users in the given group."""
|
2022-10-31 11:39:54 -04:00
|
|
|
|
|
|
|
def run(
|
|
|
|
self,
|
|
|
|
script_attributes_context: ScriptAttributesContext,
|
|
|
|
*args: Any,
|
|
|
|
**kwargs: Any
|
|
|
|
) -> Any:
|
|
|
|
"""Run."""
|
|
|
|
group_identifier = args[0]
|
|
|
|
group = GroupModel.query.filter_by(identifier=group_identifier).first()
|
|
|
|
if group is None:
|
|
|
|
raise GroupNotFoundError(
|
|
|
|
f"Script 'get_group_members' could not find group with identifier '{group_identifier}'.")
|
|
|
|
|
|
|
|
usernames = [u.username for u in group.users]
|
|
|
|
return usernames
|