This commit is contained in:
jasquat 2023-01-04 16:15:15 -05:00
parent ac079f8815
commit f4907aeab4
11 changed files with 35 additions and 31 deletions

View File

@ -35,9 +35,9 @@ class HumanTaskModel(SpiffworkflowBaseDBModel):
ForeignKey(ProcessInstanceModel.id), nullable=False # type: ignore ForeignKey(ProcessInstanceModel.id), nullable=False # type: ignore
) )
lane_assignment_id: int | None = db.Column(ForeignKey(GroupModel.id)) lane_assignment_id: int | None = db.Column(ForeignKey(GroupModel.id))
completed_by_user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True) completed_by_user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True) # type: ignore
actual_owner_id: int = db.Column(ForeignKey(UserModel.id)) actual_owner_id: int = db.Column(ForeignKey(UserModel.id)) # type: ignore
# actual_owner: RelationshipProperty[UserModel] = relationship(UserModel) # actual_owner: RelationshipProperty[UserModel] = relationship(UserModel)
form_file_name: str | None = db.Column(db.String(50)) form_file_name: str | None = db.Column(db.String(50))

View File

@ -29,4 +29,4 @@ class HumanTaskUserModel(SpiffworkflowBaseDBModel):
human_task_id = db.Column( human_task_id = db.Column(
ForeignKey(HumanTaskModel.id), nullable=False, index=True # type: ignore ForeignKey(HumanTaskModel.id), nullable=False, index=True # type: ignore
) )
user_id = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) user_id = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) # type: ignore

View File

@ -27,7 +27,7 @@ class PrincipalModel(SpiffworkflowBaseDBModel):
__table_args__ = (CheckConstraint("NOT(user_id IS NULL AND group_id IS NULL)"),) __table_args__ = (CheckConstraint("NOT(user_id IS NULL AND group_id IS NULL)"),)
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(ForeignKey(UserModel.id), nullable=True, unique=True) user_id = db.Column(ForeignKey(UserModel.id), nullable=True, unique=True) # type: ignore
group_id = db.Column(ForeignKey(GroupModel.id), nullable=True, unique=True) group_id = db.Column(ForeignKey(GroupModel.id), nullable=True, unique=True)
user = relationship("UserModel", viewonly=True) user = relationship("UserModel", viewonly=True)

View File

@ -57,7 +57,7 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel):
process_model_display_name: str = db.Column( process_model_display_name: str = db.Column(
db.String(255), nullable=False, index=True db.String(255), nullable=False, index=True
) )
process_initiator_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) process_initiator_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) # type: ignore
process_initiator = relationship("UserModel") process_initiator = relationship("UserModel")
active_human_tasks = relationship( active_human_tasks = relationship(

View File

@ -70,7 +70,7 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
id: int = db.Column(db.Integer, primary_key=True) id: int = db.Column(db.Integer, primary_key=True)
identifier: str = db.Column(db.String(50), nullable=False, index=True) identifier: str = db.Column(db.String(50), nullable=False, index=True)
report_metadata: dict = deferred(db.Column(db.JSON)) # type: ignore report_metadata: dict = deferred(db.Column(db.JSON)) # type: ignore
created_by_id = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) created_by_id = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) # type: ignore
created_by = relationship("UserModel") created_by = relationship("UserModel")
created_at_in_seconds = db.Column(db.Integer) created_at_in_seconds = db.Column(db.Integer)
updated_at_in_seconds = db.Column(db.Integer) updated_at_in_seconds = db.Column(db.Integer)

View File

@ -17,7 +17,7 @@ class SecretModel(SpiffworkflowBaseDBModel):
id: int = db.Column(db.Integer, primary_key=True) id: int = db.Column(db.Integer, primary_key=True)
key: str = db.Column(db.String(50), unique=True, nullable=False) key: str = db.Column(db.String(50), unique=True, nullable=False)
value: str = db.Column(db.Text(), nullable=False) value: str = db.Column(db.Text(), nullable=False)
user_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) user_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) # type: ignore
updated_at_in_seconds: int = db.Column(db.Integer) updated_at_in_seconds: int = db.Column(db.Integer)
created_at_in_seconds: int = db.Column(db.Integer) created_at_in_seconds: int = db.Column(db.Integer)

View File

@ -26,9 +26,7 @@ class UserModel(SpiffworkflowBaseDBModel):
__table_args__ = (db.UniqueConstraint("service", "service_id", name="service_key"),) __table_args__ = (db.UniqueConstraint("service", "service_id", name="service_key"),)
id: int = db.Column(db.Integer, primary_key=True) id: int = db.Column(db.Integer, primary_key=True)
username: str = db.Column( username: str = db.Column(db.String(255), nullable=False, unique=True)
db.String(255), nullable=False, unique=True
)
service = db.Column( service = db.Column(
db.String(255), nullable=False, unique=False db.String(255), nullable=False, unique=False

View File

@ -17,7 +17,7 @@ class UserGroupAssignmentModel(SpiffworkflowBaseDBModel):
) )
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(ForeignKey(UserModel.id), nullable=False) user_id = db.Column(ForeignKey(UserModel.id), nullable=False) # type: ignore
group_id = db.Column(ForeignKey(GroupModel.id), nullable=False) group_id = db.Column(ForeignKey(GroupModel.id), nullable=False)
group = relationship("GroupModel", overlaps="groups,user_group_assignments,users") # type: ignore group = relationship("GroupModel", overlaps="groups,user_group_assignments,users") # type: ignore

View File

@ -434,7 +434,7 @@ def _get_tasks(
ProcessInstanceModel.status.label("process_instance_status"), # type: ignore ProcessInstanceModel.status.label("process_instance_status"), # type: ignore
ProcessInstanceModel.updated_at_in_seconds, ProcessInstanceModel.updated_at_in_seconds,
ProcessInstanceModel.created_at_in_seconds, ProcessInstanceModel.created_at_in_seconds,
UserModel.username.label("process_initiator_username"), UserModel.username.label("process_initiator_username"), # type: ignore
GroupModel.identifier.label("assigned_user_group_identifier"), GroupModel.identifier.label("assigned_user_group_identifier"),
HumanTaskModel.task_name, HumanTaskModel.task_name,
HumanTaskModel.task_title, HumanTaskModel.task_title,

View File

@ -1,10 +1,10 @@
"""users_controller.""" """Users_controller."""
import flask import flask
from spiffworkflow_backend.models.user import UserModel
from flask import make_response
from flask import jsonify
from flask import g from flask import g
from flask import jsonify
from flask import make_response
from spiffworkflow_backend.models.user import UserModel
def user_search(username_prefix: str) -> flask.wrappers.Response: def user_search(username_prefix: str) -> flask.wrappers.Response:

View File

@ -1,9 +1,9 @@
"""test_users_controller.""" """Test_users_controller."""
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
from spiffworkflow_backend.models.user import UserModel
from flask.testing import FlaskClient
from flask.app import Flask from flask.app import Flask
from flask.testing import FlaskClient
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
from spiffworkflow_backend.models.user import UserModel
class TestUsersController(BaseTest): class TestUsersController(BaseTest):
@ -22,13 +22,19 @@ class TestUsersController(BaseTest):
self.find_or_create_user(username="abc") self.find_or_create_user(username="abc")
self.find_or_create_user(username="ac") self.find_or_create_user(username="ac")
self._assert_search_has_count(client, with_super_admin_user, 'aa', 1) self._assert_search_has_count(client, with_super_admin_user, "aa", 1)
self._assert_search_has_count(client, with_super_admin_user, 'ab', 2) self._assert_search_has_count(client, with_super_admin_user, "ab", 2)
self._assert_search_has_count(client, with_super_admin_user, 'ac', 1) self._assert_search_has_count(client, with_super_admin_user, "ac", 1)
self._assert_search_has_count(client, with_super_admin_user, 'ad', 0) self._assert_search_has_count(client, with_super_admin_user, "ad", 0)
self._assert_search_has_count(client, with_super_admin_user, 'a', 4) self._assert_search_has_count(client, with_super_admin_user, "a", 4)
def _assert_search_has_count(self, client: FlaskClient, with_super_admin_user: UserModel, username_prefix: str, expected_count: int) -> None: def _assert_search_has_count(
self,
client: FlaskClient,
with_super_admin_user: UserModel,
username_prefix: str,
expected_count: int,
) -> None:
"""_assert_search_has_count.""" """_assert_search_has_count."""
response = client.get( response = client.get(
f"/v1.0/users/search?username_prefix={username_prefix}", f"/v1.0/users/search?username_prefix={username_prefix}",
@ -36,6 +42,6 @@ class TestUsersController(BaseTest):
) )
assert response.status_code == 200 assert response.status_code == 200
assert response.json assert response.json
assert response.json['users'] is not None assert response.json["users"] is not None
assert response.json['username_prefix'] == username_prefix assert response.json["username_prefix"] == username_prefix
assert len(response.json['users']) == expected_count assert len(response.json["users"]) == expected_count