Upsearch api (#1259)
* Run partial tests, add sqlite var * Add upsearch api * Getting ./bin/pyl to pass * Getting ./bin/pyl to pass * Clean up fixtures * Revert this change * PR feedback - use actual schema for api.yml * Hopefully fix the permissions
This commit is contained in:
parent
f8a104cb2d
commit
e8d2396b38
13
Makefile
13
Makefile
|
@ -20,6 +20,9 @@ IN_FRONTEND ?= $(DOCKER_COMPOSE) run $(FRONTEND_CONTAINER)
|
||||||
|
|
||||||
SPIFFWORKFLOW_BACKEND_ENV ?= local_development
|
SPIFFWORKFLOW_BACKEND_ENV ?= local_development
|
||||||
|
|
||||||
|
BACKEND_SQLITE_FILE ?= src/instance/db_$(SPIFFWORKFLOW_BACKEND_ENV).sqlite3
|
||||||
|
JUST ?=
|
||||||
|
|
||||||
YML_FILES := -f docker-compose.yml \
|
YML_FILES := -f docker-compose.yml \
|
||||||
-f $(BACKEND_DEV_OVERLAY) \
|
-f $(BACKEND_DEV_OVERLAY) \
|
||||||
-f $(FRONTEND_DEV_OVERLAY) \
|
-f $(FRONTEND_DEV_OVERLAY) \
|
||||||
|
@ -67,17 +70,17 @@ be-sh:
|
||||||
$(IN_BACKEND) /bin/bash
|
$(IN_BACKEND) /bin/bash
|
||||||
|
|
||||||
be-sqlite:
|
be-sqlite:
|
||||||
@if [ ! -f "$(BACKEND_CONTAINER)/src/instance/db_$(SPIFFWORKFLOW_BACKEND_ENV).sqlite3" ]; then \
|
@if [ ! -f "$(BACKEND_CONTAINER)/$(BACKEND_SQLITE_FILE)" ]; then \
|
||||||
echo "SQLite database file does not exist: $(BACKEND_CONTAINER)/src/instance/db_$(SPIFFWORKFLOW_BACKEND_ENV).sqlite3"; \
|
echo "SQLite database file does not exist: $(BACKEND_CONTAINER)/$(BACKEND_SQLITE_FILE)"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
$(IN_BACKEND) sqlite3 src/instance/db_$(SPIFFWORKFLOW_BACKEND_ENV).sqlite3
|
$(IN_BACKEND) sqlite3 $(BACKEND_SQLITE_FILE)
|
||||||
|
|
||||||
be-tests: be-clear-log-file
|
be-tests: be-clear-log-file
|
||||||
$(IN_BACKEND) poetry run pytest
|
$(IN_BACKEND) poetry run pytest tests/spiffworkflow_backend/$(JUST)
|
||||||
|
|
||||||
be-tests-par: be-clear-log-file
|
be-tests-par: be-clear-log-file
|
||||||
$(IN_BACKEND) poetry run pytest -n auto -x --random-order
|
$(IN_BACKEND) poetry run pytest -n auto -x --random-order tests/spiffworkflow_backend/$(JUST)
|
||||||
|
|
||||||
fe-lint-fix:
|
fe-lint-fix:
|
||||||
$(IN_FRONTEND) npm run lint:fix
|
$(IN_FRONTEND) npm run lint:fix
|
||||||
|
|
|
@ -457,6 +457,27 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/ProcessGroup"
|
$ref: "#/components/schemas/ProcessGroup"
|
||||||
|
|
||||||
|
/upsearch-locations:
|
||||||
|
parameters:
|
||||||
|
- name: location
|
||||||
|
in: query
|
||||||
|
required: false
|
||||||
|
description: The location to perform the upsearch
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
get:
|
||||||
|
operationId: spiffworkflow_backend.routes.upsearch_controller.upsearch_locations
|
||||||
|
summary: Returns upsearch locations for the given location
|
||||||
|
tags:
|
||||||
|
- Upsearch
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Upsearch Locations.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Locations"
|
||||||
|
|
||||||
/process-models:
|
/process-models:
|
||||||
parameters:
|
parameters:
|
||||||
- name: process_group_identifier
|
- name: process_group_identifier
|
||||||
|
@ -3159,6 +3180,10 @@ components:
|
||||||
ok:
|
ok:
|
||||||
type: boolean
|
type: boolean
|
||||||
example: true
|
example: true
|
||||||
|
Locations:
|
||||||
|
properties:
|
||||||
|
locations:
|
||||||
|
type: array
|
||||||
User:
|
User:
|
||||||
properties:
|
properties:
|
||||||
uid:
|
uid:
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from flask import jsonify
|
||||||
|
from flask import make_response
|
||||||
|
|
||||||
|
from spiffworkflow_backend.services.upsearch_service import UpsearchService
|
||||||
|
|
||||||
|
|
||||||
|
def upsearch_locations(
|
||||||
|
location: str | None,
|
||||||
|
) -> Any:
|
||||||
|
upsearch_locations = UpsearchService.upsearch_locations(location)
|
||||||
|
|
||||||
|
return make_response(jsonify({"locations": upsearch_locations}), 200)
|
|
@ -542,6 +542,8 @@ class AuthorizationService:
|
||||||
permissions_to_assign.append(PermissionToAssign(permission="read", target_uri="/script-assist/enabled"))
|
permissions_to_assign.append(PermissionToAssign(permission="read", target_uri="/script-assist/enabled"))
|
||||||
permissions_to_assign.append(PermissionToAssign(permission="create", target_uri="/script-assist/process-message"))
|
permissions_to_assign.append(PermissionToAssign(permission="create", target_uri="/script-assist/process-message"))
|
||||||
|
|
||||||
|
permissions_to_assign.append(PermissionToAssign(permission="read", target_uri="/upsearch-locations"))
|
||||||
|
|
||||||
for permission in ["create", "read", "update", "delete"]:
|
for permission in ["create", "read", "update", "delete"]:
|
||||||
permissions_to_assign.append(PermissionToAssign(permission=permission, target_uri="/process-instances/reports/*"))
|
permissions_to_assign.append(PermissionToAssign(permission=permission, target_uri="/process-instances/reports/*"))
|
||||||
permissions_to_assign.append(PermissionToAssign(permission=permission, target_uri="/public/*"))
|
permissions_to_assign.append(PermissionToAssign(permission=permission, target_uri="/public/*"))
|
||||||
|
|
|
@ -3,8 +3,8 @@ import os
|
||||||
|
|
||||||
class UpsearchService:
|
class UpsearchService:
|
||||||
@classmethod
|
@classmethod
|
||||||
def upsearch_locations(cls, process_model_identifier: str) -> list[str]:
|
def upsearch_locations(cls, process_model_identifier: str | None) -> list[str]:
|
||||||
location = process_model_identifier
|
location = process_model_identifier or ""
|
||||||
locations = []
|
locations = []
|
||||||
|
|
||||||
while location != "":
|
while location != "":
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import pytest
|
||||||
|
from flask.app import Flask
|
||||||
|
from flask.testing import FlaskClient
|
||||||
|
from spiffworkflow_backend.models.user import UserModel
|
||||||
|
|
||||||
|
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class TestUpsearchControllerController(BaseTest):
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"location,expected",
|
||||||
|
[
|
||||||
|
("a/b/c/d", ["a/b/c/d", "a/b/c", "a/b", "a", ""]),
|
||||||
|
("a", ["a", ""]),
|
||||||
|
("", [""]),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_return_upsearch_locations_for_path(
|
||||||
|
self,
|
||||||
|
app: Flask,
|
||||||
|
client: FlaskClient,
|
||||||
|
with_db_and_bpmn_file_cleanup: None,
|
||||||
|
with_super_admin_user: UserModel,
|
||||||
|
location: str,
|
||||||
|
expected: list[str],
|
||||||
|
) -> None:
|
||||||
|
response = client.get(
|
||||||
|
f"/v1.0/upsearch-locations?location={location}", headers=self.logged_in_headers(with_super_admin_user)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert "locations" in response.json
|
||||||
|
assert response.json["locations"] == expected
|
|
@ -474,6 +474,7 @@ class TestAuthorizationService(BaseTest):
|
||||||
("/user-groups/for-current-user", "read"),
|
("/user-groups/for-current-user", "read"),
|
||||||
("/users/exists/by-username", "create"),
|
("/users/exists/by-username", "create"),
|
||||||
("/users/search", "read"),
|
("/users/search", "read"),
|
||||||
|
("/upsearch-locations", "read"),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue