spiff-arena/tests/spiffworkflow_backend/helpers/base_test.py

364 lines
13 KiB
Python
Raw Normal View History

"""Base_test."""
import io
import json
import os
import time
from typing import Any
from typing import Dict
from typing import Optional
from flask import current_app
from flask.app import Flask
from flask.testing import FlaskClient
from flask_bpmn.api.api_error import ApiError
from flask_bpmn.models.db import db
from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
from werkzeug.test import TestResponse # type: ignore
Squashed 'spiffworkflow-backend/' changes from f9c2fa21e..5225a8b4c 5225a8b4c pyl 259f74a1e Merge branch 'main' into bug/refresh-token d452208ef Merge pull request #135 from sartography/feature/permissions3 8e1075406 Merge branch 'main' into bug/refresh-token 2b01d2fe7 fixed authentication_callback and getting the user w/ burnettk 476e36c7d mypy changes 6403e62c0 Fix migration after merging main 594a32b67 merged in main and resolved conflicts w/ burnettk b285ba1a1 added updated columns to secrets and updated flask-bpmn 7c53fc9fa Merge remote-tracking branch 'origin/main' into feature/permissions3 201a6918a pyl changes a6112f7fb Merge branch 'main' into bug/refresh-token 87f65a6c6 auth_token should be dictionary, not string f163de61c pyl 1f443bb94 PublicAuthenticationService -> AuthenticationService 6c491a3df Don't refresh token here. They just logged in. We are validating the returned token. If it is bad, raise an error. 91b8649f8 id_token -> auth_token fc94774bb Move `store_refresh_token` to authentication_service 00d66e9c5 mypy c4e415dbe mypy 1e75716eb Pre commit a72b03e09 Rename method. We pass it auth_tokens, not id_tokens 9a6700a6d Too many things expect g.token. Reverting my change 74883fb23 Noe store refresh_token, and try to use it if auth_token is expired Renamed some methods to use correct token type be0557013 Cleanup - remove unused code cf01f0d51 Add refresh_token model 1c0c937af added method to delete all permissions so we can recreate them w/ burnettk aaeaac879 Merge remote-tracking branch 'origin/main' into feature/permissions3 44856fce2 added api endpoint to check if user has permissions based on given target uris w/ burnettk ae830054d precommit w/ burnettk 94d50efb1 created common method to check whether an api method should have auth w/ burnettk c955335d0 precommit w/ burnettk 37caf1a69 added a finance user to keycloak and fixed up the staging permission yml w/ burnettk 93c456294 merged in main and resolved conflicts w/ burnettk 06a7c6485 remaining tests are now passing w/ burnettk 50529d04c added test to make sure api gives a 403 if a permission is not found w/ burnettk 6a9d0a68a api calls are somewhat respecting permissions now and the process api tests are passing d07fbbeff attempting to respect permissions w/ burnettk git-subtree-dir: spiffworkflow-backend git-subtree-split: 5225a8b4c101133567d4f7efa33632d36c29c81d
2022-10-20 20:00:12 +00:00
from spiffworkflow_backend.models.permission_assignment import Permission
from spiffworkflow_backend.models.permission_target import PermissionTargetModel
from spiffworkflow_backend.models.process_group import ProcessGroup
from spiffworkflow_backend.models.process_group import ProcessGroupSchema
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
from spiffworkflow_backend.models.process_model import NotificationType
from spiffworkflow_backend.models.process_model import ProcessModelInfo
from spiffworkflow_backend.models.process_model import ProcessModelInfoSchema
from spiffworkflow_backend.models.user import UserModel
Squashed 'spiffworkflow-backend/' changes from 03bf7a61..10c443a2 10c443a2 Merge pull request #130 from sartography/feature/data 71c803aa allow passing in the log level into the app w/ burnettk daeb82d9 Merge pull request #126 from sartography/dependabot/pip/typing-extensions-4.4.0 14c8f52c Merge pull request #123 from sartography/dependabot/pip/dot-github/workflows/poetry-1.2.2 92d204e6 Merge remote-tracking branch 'origin/main' into feature/data 1cb77901 run the save all bpmn script on server boot w/ burnettk 16a6f476 Bump typing-extensions from 4.3.0 to 4.4.0 d8ac61fc Bump poetry from 1.2.1 to 1.2.2 in /.github/workflows 3be27786 Merge pull request #131 from sartography/feature/permissions2 1fd8fc78 Merge remote-tracking branch 'origin/main' into feature/permissions2 d29621ae data setup on app boot 0b21a5d4 refactor bin/save_all_bpmn.py into service code 02fb9d61 lint c95db461 refactor scripts 98628fc2 This caused a problem with scopes when token timed out. d8b2323b merged in main and resolved conflicts d01b4fc7 updated sentry-sdk to resolve deprecation warnings 5851ddf5 update for mypy in python 3.9 508f9900 merged in main and resolved conflicts 68d69978 precommit w/ burnettk 85a4ee16 removed debug print statements w/ burnettk 93eb91f4 added keycloak configs and user perms for staging w/ burnettk e4ded8fc added method to import permissions from yml file w/ burnettk 22ba89ae use percents instead of asterisks to better support db syntax w/ burnettk 0c116ae8 postgres does not use backticks w/ burnettk 621ad3ef attempting to see if sql like statement works in other dbs as well w/ burnettk git-subtree-dir: spiffworkflow-backend git-subtree-split: 10c443a2d82752e8ed9d1679afe6409d81029006
2022-10-12 19:28:52 +00:00
from spiffworkflow_backend.services.authorization_service import AuthorizationService
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
from spiffworkflow_backend.services.file_system_service import FileSystemService
from spiffworkflow_backend.services.process_model_service import ProcessModelService
from spiffworkflow_backend.services.user_service import UserService
# from tests.spiffworkflow_backend.helpers.test_data import logged_in_headers
class BaseTest:
"""BaseTest."""
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
def basic_test_setup(
self,
client: FlaskClient,
user: UserModel,
process_group_id: Optional[str] = "test_group",
process_model_id: Optional[str] = "random_fact",
bpmn_file_name: Optional[str] = None,
bpmn_file_location: Optional[str] = None,
) -> str:
"""Creates a process group.
Creates a process model
Adds a bpmn file to the model.
"""
process_group_display_name = process_group_id or ""
process_group_description = process_group_id or ""
process_model_identifier = f"{process_group_id}/{process_model_id}"
if bpmn_file_location is None:
bpmn_file_location = process_model_id
self.create_process_group(
client, user, process_group_description, process_group_display_name
)
self.create_process_model_with_api(
client,
process_model_id=process_model_identifier,
process_model_display_name=process_group_display_name,
process_model_description=process_group_description,
user=user,
)
load_test_spec(
process_model_id=process_model_identifier,
bpmn_file_name=bpmn_file_name,
process_model_source_directory=bpmn_file_location,
)
return process_model_identifier
@staticmethod
def find_or_create_user(username: str = "test_user_1") -> UserModel:
"""Find_or_create_user."""
user = UserModel.query.filter_by(username=username).first()
if isinstance(user, UserModel):
return user
user = UserService.create_user("internal", username, username=username)
if isinstance(user, UserModel):
return user
raise ApiError(
error_code="create_user_error",
message=f"Cannot find or create user: {username}",
)
@staticmethod
def get_open_id_constants(app: Flask) -> tuple:
"""Get_open_id_constants."""
open_id_server_url = app.config["OPEN_ID_SERVER_URL"]
open_id_client_id = app.config["OPEN_ID_CLIENT_ID"]
open_id_realm_name = app.config["OPEN_ID_REALM_NAME"]
open_id_client_secret_key = app.config[
"OPEN_ID_CLIENT_SECRET_KEY"
] # noqa: S105
return (
open_id_server_url,
open_id_client_id,
open_id_realm_name,
open_id_client_secret_key,
)
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
@staticmethod
def create_process_instance(
client: FlaskClient,
test_process_model_id: str,
headers: Dict[str, str],
) -> TestResponse:
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
"""Create_process_instance.
There must be an existing process model to instantiate.
"""
modified_process_model_id = test_process_model_id.replace("/", ":")
response = client.post(
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
f"/v1.0/process-models/{modified_process_model_id}/process-instances",
headers=headers,
)
assert response.status_code == 201
return response
def create_process_model_with_api(
self,
client: FlaskClient,
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
process_model_id: Optional[str] = None,
process_model_display_name: str = "Cooooookies",
process_model_description: str = "Om nom nom delicious cookies",
fault_or_suspend_on_exception: str = NotificationType.suspend.value,
exception_notification_addresses: Optional[list] = None,
primary_process_id: Optional[str] = None,
primary_file_name: Optional[str] = None,
Squashed 'spiffworkflow-backend/' changes from f9c2fa21e..5225a8b4c 5225a8b4c pyl 259f74a1e Merge branch 'main' into bug/refresh-token d452208ef Merge pull request #135 from sartography/feature/permissions3 8e1075406 Merge branch 'main' into bug/refresh-token 2b01d2fe7 fixed authentication_callback and getting the user w/ burnettk 476e36c7d mypy changes 6403e62c0 Fix migration after merging main 594a32b67 merged in main and resolved conflicts w/ burnettk b285ba1a1 added updated columns to secrets and updated flask-bpmn 7c53fc9fa Merge remote-tracking branch 'origin/main' into feature/permissions3 201a6918a pyl changes a6112f7fb Merge branch 'main' into bug/refresh-token 87f65a6c6 auth_token should be dictionary, not string f163de61c pyl 1f443bb94 PublicAuthenticationService -> AuthenticationService 6c491a3df Don't refresh token here. They just logged in. We are validating the returned token. If it is bad, raise an error. 91b8649f8 id_token -> auth_token fc94774bb Move `store_refresh_token` to authentication_service 00d66e9c5 mypy c4e415dbe mypy 1e75716eb Pre commit a72b03e09 Rename method. We pass it auth_tokens, not id_tokens 9a6700a6d Too many things expect g.token. Reverting my change 74883fb23 Noe store refresh_token, and try to use it if auth_token is expired Renamed some methods to use correct token type be0557013 Cleanup - remove unused code cf01f0d51 Add refresh_token model 1c0c937af added method to delete all permissions so we can recreate them w/ burnettk aaeaac879 Merge remote-tracking branch 'origin/main' into feature/permissions3 44856fce2 added api endpoint to check if user has permissions based on given target uris w/ burnettk ae830054d precommit w/ burnettk 94d50efb1 created common method to check whether an api method should have auth w/ burnettk c955335d0 precommit w/ burnettk 37caf1a69 added a finance user to keycloak and fixed up the staging permission yml w/ burnettk 93c456294 merged in main and resolved conflicts w/ burnettk 06a7c6485 remaining tests are now passing w/ burnettk 50529d04c added test to make sure api gives a 403 if a permission is not found w/ burnettk 6a9d0a68a api calls are somewhat respecting permissions now and the process api tests are passing d07fbbeff attempting to respect permissions w/ burnettk git-subtree-dir: spiffworkflow-backend git-subtree-split: 5225a8b4c101133567d4f7efa33632d36c29c81d
2022-10-20 20:00:12 +00:00
user: Optional[UserModel] = None,
) -> TestResponse:
"""Create_process_model."""
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
if process_model_id is not None:
Squashed 'spiffworkflow-backend/' changes from f9c2fa21e..5225a8b4c 5225a8b4c pyl 259f74a1e Merge branch 'main' into bug/refresh-token d452208ef Merge pull request #135 from sartography/feature/permissions3 8e1075406 Merge branch 'main' into bug/refresh-token 2b01d2fe7 fixed authentication_callback and getting the user w/ burnettk 476e36c7d mypy changes 6403e62c0 Fix migration after merging main 594a32b67 merged in main and resolved conflicts w/ burnettk b285ba1a1 added updated columns to secrets and updated flask-bpmn 7c53fc9fa Merge remote-tracking branch 'origin/main' into feature/permissions3 201a6918a pyl changes a6112f7fb Merge branch 'main' into bug/refresh-token 87f65a6c6 auth_token should be dictionary, not string f163de61c pyl 1f443bb94 PublicAuthenticationService -> AuthenticationService 6c491a3df Don't refresh token here. They just logged in. We are validating the returned token. If it is bad, raise an error. 91b8649f8 id_token -> auth_token fc94774bb Move `store_refresh_token` to authentication_service 00d66e9c5 mypy c4e415dbe mypy 1e75716eb Pre commit a72b03e09 Rename method. We pass it auth_tokens, not id_tokens 9a6700a6d Too many things expect g.token. Reverting my change 74883fb23 Noe store refresh_token, and try to use it if auth_token is expired Renamed some methods to use correct token type be0557013 Cleanup - remove unused code cf01f0d51 Add refresh_token model 1c0c937af added method to delete all permissions so we can recreate them w/ burnettk aaeaac879 Merge remote-tracking branch 'origin/main' into feature/permissions3 44856fce2 added api endpoint to check if user has permissions based on given target uris w/ burnettk ae830054d precommit w/ burnettk 94d50efb1 created common method to check whether an api method should have auth w/ burnettk c955335d0 precommit w/ burnettk 37caf1a69 added a finance user to keycloak and fixed up the staging permission yml w/ burnettk 93c456294 merged in main and resolved conflicts w/ burnettk 06a7c6485 remaining tests are now passing w/ burnettk 50529d04c added test to make sure api gives a 403 if a permission is not found w/ burnettk 6a9d0a68a api calls are somewhat respecting permissions now and the process api tests are passing d07fbbeff attempting to respect permissions w/ burnettk git-subtree-dir: spiffworkflow-backend git-subtree-split: 5225a8b4c101133567d4f7efa33632d36c29c81d
2022-10-20 20:00:12 +00:00
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
# make sure we have a group
process_group_id, _ = os.path.split(process_model_id)
process_group_path = f"{FileSystemService.root_path()}/{process_group_id}"
if ProcessModelService().is_group(process_group_path):
if exception_notification_addresses is None:
exception_notification_addresses = []
model = ProcessModelInfo(
id=process_model_id,
display_name=process_model_display_name,
description=process_model_description,
is_review=False,
primary_process_id=primary_process_id,
primary_file_name=primary_file_name,
fault_or_suspend_on_exception=fault_or_suspend_on_exception,
exception_notification_addresses=exception_notification_addresses,
)
if user is None:
user = self.find_or_create_user()
response = client.post(
"/v1.0/process-models",
content_type="application/json",
data=json.dumps(ProcessModelInfoSchema().dump(model)),
headers=self.logged_in_headers(user),
)
assert response.status_code == 201
return response
else:
raise Exception("You must create the group first")
else:
raise Exception(
"You must include the process_model_id, which must be a path to the model"
)
def create_spec_file(
self,
client: FlaskClient,
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
process_model_id: str,
process_model_location: Optional[str] = None,
process_model: Optional[ProcessModelInfo] = None,
file_name: str = "random_fact.svg",
file_data: bytes = b"abcdef",
Squashed 'spiffworkflow-backend/' changes from f9c2fa21e..5225a8b4c 5225a8b4c pyl 259f74a1e Merge branch 'main' into bug/refresh-token d452208ef Merge pull request #135 from sartography/feature/permissions3 8e1075406 Merge branch 'main' into bug/refresh-token 2b01d2fe7 fixed authentication_callback and getting the user w/ burnettk 476e36c7d mypy changes 6403e62c0 Fix migration after merging main 594a32b67 merged in main and resolved conflicts w/ burnettk b285ba1a1 added updated columns to secrets and updated flask-bpmn 7c53fc9fa Merge remote-tracking branch 'origin/main' into feature/permissions3 201a6918a pyl changes a6112f7fb Merge branch 'main' into bug/refresh-token 87f65a6c6 auth_token should be dictionary, not string f163de61c pyl 1f443bb94 PublicAuthenticationService -> AuthenticationService 6c491a3df Don't refresh token here. They just logged in. We are validating the returned token. If it is bad, raise an error. 91b8649f8 id_token -> auth_token fc94774bb Move `store_refresh_token` to authentication_service 00d66e9c5 mypy c4e415dbe mypy 1e75716eb Pre commit a72b03e09 Rename method. We pass it auth_tokens, not id_tokens 9a6700a6d Too many things expect g.token. Reverting my change 74883fb23 Noe store refresh_token, and try to use it if auth_token is expired Renamed some methods to use correct token type be0557013 Cleanup - remove unused code cf01f0d51 Add refresh_token model 1c0c937af added method to delete all permissions so we can recreate them w/ burnettk aaeaac879 Merge remote-tracking branch 'origin/main' into feature/permissions3 44856fce2 added api endpoint to check if user has permissions based on given target uris w/ burnettk ae830054d precommit w/ burnettk 94d50efb1 created common method to check whether an api method should have auth w/ burnettk c955335d0 precommit w/ burnettk 37caf1a69 added a finance user to keycloak and fixed up the staging permission yml w/ burnettk 93c456294 merged in main and resolved conflicts w/ burnettk 06a7c6485 remaining tests are now passing w/ burnettk 50529d04c added test to make sure api gives a 403 if a permission is not found w/ burnettk 6a9d0a68a api calls are somewhat respecting permissions now and the process api tests are passing d07fbbeff attempting to respect permissions w/ burnettk git-subtree-dir: spiffworkflow-backend git-subtree-split: 5225a8b4c101133567d4f7efa33632d36c29c81d
2022-10-20 20:00:12 +00:00
user: Optional[UserModel] = None,
) -> Any:
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
"""Test_create_spec_file.
Adds a bpmn file to the model.
process_model_id is the destination path
process_model_location is the source path
because of permissions, user might be required now..., not sure yet.
"""
if process_model_location is None:
process_model_location = file_name.split(".")[0]
if process_model is None:
process_model = load_test_spec(
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
process_model_id=process_model_id,
bpmn_file_name=file_name,
process_model_source_directory=process_model_location,
)
data = {"file": (io.BytesIO(file_data), file_name)}
Squashed 'spiffworkflow-backend/' changes from f9c2fa21e..5225a8b4c 5225a8b4c pyl 259f74a1e Merge branch 'main' into bug/refresh-token d452208ef Merge pull request #135 from sartography/feature/permissions3 8e1075406 Merge branch 'main' into bug/refresh-token 2b01d2fe7 fixed authentication_callback and getting the user w/ burnettk 476e36c7d mypy changes 6403e62c0 Fix migration after merging main 594a32b67 merged in main and resolved conflicts w/ burnettk b285ba1a1 added updated columns to secrets and updated flask-bpmn 7c53fc9fa Merge remote-tracking branch 'origin/main' into feature/permissions3 201a6918a pyl changes a6112f7fb Merge branch 'main' into bug/refresh-token 87f65a6c6 auth_token should be dictionary, not string f163de61c pyl 1f443bb94 PublicAuthenticationService -> AuthenticationService 6c491a3df Don't refresh token here. They just logged in. We are validating the returned token. If it is bad, raise an error. 91b8649f8 id_token -> auth_token fc94774bb Move `store_refresh_token` to authentication_service 00d66e9c5 mypy c4e415dbe mypy 1e75716eb Pre commit a72b03e09 Rename method. We pass it auth_tokens, not id_tokens 9a6700a6d Too many things expect g.token. Reverting my change 74883fb23 Noe store refresh_token, and try to use it if auth_token is expired Renamed some methods to use correct token type be0557013 Cleanup - remove unused code cf01f0d51 Add refresh_token model 1c0c937af added method to delete all permissions so we can recreate them w/ burnettk aaeaac879 Merge remote-tracking branch 'origin/main' into feature/permissions3 44856fce2 added api endpoint to check if user has permissions based on given target uris w/ burnettk ae830054d precommit w/ burnettk 94d50efb1 created common method to check whether an api method should have auth w/ burnettk c955335d0 precommit w/ burnettk 37caf1a69 added a finance user to keycloak and fixed up the staging permission yml w/ burnettk 93c456294 merged in main and resolved conflicts w/ burnettk 06a7c6485 remaining tests are now passing w/ burnettk 50529d04c added test to make sure api gives a 403 if a permission is not found w/ burnettk 6a9d0a68a api calls are somewhat respecting permissions now and the process api tests are passing d07fbbeff attempting to respect permissions w/ burnettk git-subtree-dir: spiffworkflow-backend git-subtree-split: 5225a8b4c101133567d4f7efa33632d36c29c81d
2022-10-20 20:00:12 +00:00
if user is None:
user = self.find_or_create_user()
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
modified_process_model_id = process_model.id.replace("/", ":")
response = client.post(
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
f"/v1.0/process-models/{modified_process_model_id}/files",
data=data,
follow_redirects=True,
content_type="multipart/form-data",
headers=self.logged_in_headers(user),
)
assert response.status_code == 201
assert response.get_data() is not None
file = json.loads(response.get_data(as_text=True))
# assert FileType.svg.value == file["type"]
# assert "image/svg+xml" == file["content_type"]
response = client.get(
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
f"/v1.0/process-models/{modified_process_model_id}/files/{file_name}",
headers=self.logged_in_headers(user),
)
assert response.status_code == 200
file2 = json.loads(response.get_data(as_text=True))
assert file["file_contents"] == file2["file_contents"]
return file
def create_process_group(
self,
client: FlaskClient,
user: Any,
process_group_id: str,
display_name: str = "",
) -> str:
"""Create_process_group."""
process_group = ProcessGroup(
id=process_group_id, display_name=display_name, display_order=0, admin=False
)
response = client.post(
"/v1.0/process-groups",
headers=self.logged_in_headers(user),
content_type="application/json",
data=json.dumps(ProcessGroupSchema().dump(process_group)),
)
assert response.status_code == 201
assert response.json is not None
assert response.json["id"] == process_group_id
return process_group_id
# @staticmethod
# def get_public_access_token(username: str, password: str) -> dict:
# """Get_public_access_token."""
Squashed 'spiffworkflow-backend/' changes from f9c2fa21e..5225a8b4c 5225a8b4c pyl 259f74a1e Merge branch 'main' into bug/refresh-token d452208ef Merge pull request #135 from sartography/feature/permissions3 8e1075406 Merge branch 'main' into bug/refresh-token 2b01d2fe7 fixed authentication_callback and getting the user w/ burnettk 476e36c7d mypy changes 6403e62c0 Fix migration after merging main 594a32b67 merged in main and resolved conflicts w/ burnettk b285ba1a1 added updated columns to secrets and updated flask-bpmn 7c53fc9fa Merge remote-tracking branch 'origin/main' into feature/permissions3 201a6918a pyl changes a6112f7fb Merge branch 'main' into bug/refresh-token 87f65a6c6 auth_token should be dictionary, not string f163de61c pyl 1f443bb94 PublicAuthenticationService -> AuthenticationService 6c491a3df Don't refresh token here. They just logged in. We are validating the returned token. If it is bad, raise an error. 91b8649f8 id_token -> auth_token fc94774bb Move `store_refresh_token` to authentication_service 00d66e9c5 mypy c4e415dbe mypy 1e75716eb Pre commit a72b03e09 Rename method. We pass it auth_tokens, not id_tokens 9a6700a6d Too many things expect g.token. Reverting my change 74883fb23 Noe store refresh_token, and try to use it if auth_token is expired Renamed some methods to use correct token type be0557013 Cleanup - remove unused code cf01f0d51 Add refresh_token model 1c0c937af added method to delete all permissions so we can recreate them w/ burnettk aaeaac879 Merge remote-tracking branch 'origin/main' into feature/permissions3 44856fce2 added api endpoint to check if user has permissions based on given target uris w/ burnettk ae830054d precommit w/ burnettk 94d50efb1 created common method to check whether an api method should have auth w/ burnettk c955335d0 precommit w/ burnettk 37caf1a69 added a finance user to keycloak and fixed up the staging permission yml w/ burnettk 93c456294 merged in main and resolved conflicts w/ burnettk 06a7c6485 remaining tests are now passing w/ burnettk 50529d04c added test to make sure api gives a 403 if a permission is not found w/ burnettk 6a9d0a68a api calls are somewhat respecting permissions now and the process api tests are passing d07fbbeff attempting to respect permissions w/ burnettk git-subtree-dir: spiffworkflow-backend git-subtree-split: 5225a8b4c101133567d4f7efa33632d36c29c81d
2022-10-20 20:00:12 +00:00
# public_access_token = AuthenticationService().get_public_access_token(
# username, password
# )
# return public_access_token
def create_process_instance_from_process_model(
self,
process_model: ProcessModelInfo,
status: Optional[str] = "not_started",
user: Optional[UserModel] = None,
) -> ProcessInstanceModel:
"""Create_process_instance_from_process_model."""
if user is None:
user = self.find_or_create_user()
current_time = round(time.time())
process_instance = ProcessInstanceModel(
status=status,
process_initiator=user,
process_model_identifier=process_model.id,
Squashed 'spiffworkflow-backend/' changes from b8924100d..64ac70428 64ac70428 Move to Python 3.11 (#27) 167851df1 remove leading slash from model identifiers 3503fe400 one instance test left for cypress w/ burnettk 7e09363c4 merged in main and resolved conflicts w/ burnettk cullerton afbc3157d fixed some acceptance tests w/ burnettk cullerton 96e7b63c6 made a process model form w/ burnettk c19aac25f Somethings up w/authentication. Maybe the stored token is bad d17007eaa Merge branch 'main' into feature/nested-groups 729b13881 script to modify all model json files to use full path for model id. Also removes process_group_id 7856b8caa return next task when running an instance w/ burnettk d183b961c First pass at custom report/perspective for Process Instance List (#23) f303c0f77 remove process_group_identifier from process-instances endpoint 207de9ab8 Merge branch 'main' into feature/nested-groups fec8d06b8 started test for test_script_unit_test_run ea31c7a12 fixed process_model_identifier in script_unit_test_create 5d058cbea Fix url in test f8afd7bdd Remove the `_2` methods 7c13ec802 Fix urls for uspend and resume endpoints 19158d7b0 Get testing bpmn files out of the config directory 5f1ee7f16 fixed failing test de3b4b81d Merge branch 'main' into feature/nested-groups 440871d57 First stab at nested folders. Added temp endpoints Changes to tests and test helpers 1bd6a199f Don't need parent. Just use the whole path for the group id a2ab420b2 Committing so Jon can view code git-subtree-dir: spiffworkflow-backend git-subtree-split: 64ac7042887af80869963bc103c01f56404727f2
2022-11-09 20:02:19 +00:00
process_group_identifier="",
updated_at_in_seconds=round(time.time()),
start_in_seconds=current_time - (3600 * 1),
end_in_seconds=current_time - (3600 * 1 - 20),
)
db.session.add(process_instance)
db.session.commit()
return process_instance
Squashed 'spiffworkflow-backend/' changes from f9c2fa21e..5225a8b4c 5225a8b4c pyl 259f74a1e Merge branch 'main' into bug/refresh-token d452208ef Merge pull request #135 from sartography/feature/permissions3 8e1075406 Merge branch 'main' into bug/refresh-token 2b01d2fe7 fixed authentication_callback and getting the user w/ burnettk 476e36c7d mypy changes 6403e62c0 Fix migration after merging main 594a32b67 merged in main and resolved conflicts w/ burnettk b285ba1a1 added updated columns to secrets and updated flask-bpmn 7c53fc9fa Merge remote-tracking branch 'origin/main' into feature/permissions3 201a6918a pyl changes a6112f7fb Merge branch 'main' into bug/refresh-token 87f65a6c6 auth_token should be dictionary, not string f163de61c pyl 1f443bb94 PublicAuthenticationService -> AuthenticationService 6c491a3df Don't refresh token here. They just logged in. We are validating the returned token. If it is bad, raise an error. 91b8649f8 id_token -> auth_token fc94774bb Move `store_refresh_token` to authentication_service 00d66e9c5 mypy c4e415dbe mypy 1e75716eb Pre commit a72b03e09 Rename method. We pass it auth_tokens, not id_tokens 9a6700a6d Too many things expect g.token. Reverting my change 74883fb23 Noe store refresh_token, and try to use it if auth_token is expired Renamed some methods to use correct token type be0557013 Cleanup - remove unused code cf01f0d51 Add refresh_token model 1c0c937af added method to delete all permissions so we can recreate them w/ burnettk aaeaac879 Merge remote-tracking branch 'origin/main' into feature/permissions3 44856fce2 added api endpoint to check if user has permissions based on given target uris w/ burnettk ae830054d precommit w/ burnettk 94d50efb1 created common method to check whether an api method should have auth w/ burnettk c955335d0 precommit w/ burnettk 37caf1a69 added a finance user to keycloak and fixed up the staging permission yml w/ burnettk 93c456294 merged in main and resolved conflicts w/ burnettk 06a7c6485 remaining tests are now passing w/ burnettk 50529d04c added test to make sure api gives a 403 if a permission is not found w/ burnettk 6a9d0a68a api calls are somewhat respecting permissions now and the process api tests are passing d07fbbeff attempting to respect permissions w/ burnettk git-subtree-dir: spiffworkflow-backend git-subtree-split: 5225a8b4c101133567d4f7efa33632d36c29c81d
2022-10-20 20:00:12 +00:00
@classmethod
def create_user_with_permission(
cls,
username: str,
target_uri: str = PermissionTargetModel.URI_ALL,
permission_names: Optional[list[str]] = None,
) -> UserModel:
"""Create_user_with_permission."""
user = BaseTest.find_or_create_user(username=username)
return cls.add_permissions_to_user(
user, target_uri=target_uri, permission_names=permission_names
)
@classmethod
def add_permissions_to_user(
cls,
user: UserModel,
target_uri: str = PermissionTargetModel.URI_ALL,
permission_names: Optional[list[str]] = None,
) -> UserModel:
"""Add_permissions_to_user."""
permission_target = PermissionTargetModel.query.filter_by(
uri=target_uri
).first()
if permission_target is None:
permission_target = PermissionTargetModel(uri=target_uri)
db.session.add(permission_target)
db.session.commit()
if permission_names is None:
permission_names = [member.name for member in Permission]
for permission in permission_names:
AuthorizationService.create_permission_for_principal(
principal=user.principal,
permission_target=permission_target,
permission=permission,
)
return user
@staticmethod
def logged_in_headers(
user: UserModel, _redirect_url: str = "http://some/frontend/url"
) -> Dict[str, str]:
"""Logged_in_headers."""
return dict(Authorization="Bearer " + user.encode_auth_token())
def get_test_data_file_contents(
self, file_name: str, process_model_test_data_dir: str
) -> bytes:
"""Get_test_data_file_contents."""
file_full_path = os.path.join(
current_app.instance_path,
"..",
"..",
"tests",
"data",
process_model_test_data_dir,
file_name,
)
with open(file_full_path, "rb") as file:
return file.read()
Squashed 'spiffworkflow-backend/' changes from 03bf7a61..10c443a2 10c443a2 Merge pull request #130 from sartography/feature/data 71c803aa allow passing in the log level into the app w/ burnettk daeb82d9 Merge pull request #126 from sartography/dependabot/pip/typing-extensions-4.4.0 14c8f52c Merge pull request #123 from sartography/dependabot/pip/dot-github/workflows/poetry-1.2.2 92d204e6 Merge remote-tracking branch 'origin/main' into feature/data 1cb77901 run the save all bpmn script on server boot w/ burnettk 16a6f476 Bump typing-extensions from 4.3.0 to 4.4.0 d8ac61fc Bump poetry from 1.2.1 to 1.2.2 in /.github/workflows 3be27786 Merge pull request #131 from sartography/feature/permissions2 1fd8fc78 Merge remote-tracking branch 'origin/main' into feature/permissions2 d29621ae data setup on app boot 0b21a5d4 refactor bin/save_all_bpmn.py into service code 02fb9d61 lint c95db461 refactor scripts 98628fc2 This caused a problem with scopes when token timed out. d8b2323b merged in main and resolved conflicts d01b4fc7 updated sentry-sdk to resolve deprecation warnings 5851ddf5 update for mypy in python 3.9 508f9900 merged in main and resolved conflicts 68d69978 precommit w/ burnettk 85a4ee16 removed debug print statements w/ burnettk 93eb91f4 added keycloak configs and user perms for staging w/ burnettk e4ded8fc added method to import permissions from yml file w/ burnettk 22ba89ae use percents instead of asterisks to better support db syntax w/ burnettk 0c116ae8 postgres does not use backticks w/ burnettk 621ad3ef attempting to see if sql like statement works in other dbs as well w/ burnettk git-subtree-dir: spiffworkflow-backend git-subtree-split: 10c443a2d82752e8ed9d1679afe6409d81029006
2022-10-12 19:28:52 +00:00
def assert_user_has_permission(
self,
user: UserModel,
permission: str,
target_uri: str,
expected_result: bool = True,
) -> None:
"""Assert_user_has_permission."""
has_permission = AuthorizationService.user_has_permission(
user=user,
permission=permission,
target_uri=target_uri,
)
assert has_permission is expected_result