pyl fixed w/ burnettk

This commit is contained in:
jasquat 2022-12-20 16:14:55 -05:00
parent 92258c6f9a
commit 3e4ab0145e
7 changed files with 17 additions and 16 deletions

View File

@ -27,7 +27,7 @@ class GroupModel(FlaskBpmnGroupModel):
identifier = db.Column(db.String(255)) identifier = db.Column(db.String(255))
user_group_assignments = relationship("UserGroupAssignmentModel", cascade="delete") user_group_assignments = relationship("UserGroupAssignmentModel", cascade="delete")
user_group_assignments_waiting = relationship( user_group_assignments_waiting = relationship( # type: ignore
"UserGroupAssignmentWaitingModel", cascade="delete" "UserGroupAssignmentWaitingModel", cascade="delete"
) )
users = relationship( # type: ignore users = relationship( # type: ignore

View File

@ -8,8 +8,9 @@ from spiffworkflow_backend.models.group import GroupModel
class UserGroupAssignmentWaitingModel(SpiffworkflowBaseDBModel): class UserGroupAssignmentWaitingModel(SpiffworkflowBaseDBModel):
"""UserGroupAssignmentsWaitingModel - When a user is assinged to a group, but that username does not exist, """When a user is assigned to a group, but that username does not exist.
we cache it here to be applied in the event the user does log into the system.
We cache it here to be applied in the event the user does log in to the system.
""" """
MATCH_ALL_USERS = "*" MATCH_ALL_USERS = "*"
@ -24,9 +25,9 @@ class UserGroupAssignmentWaitingModel(SpiffworkflowBaseDBModel):
username = db.Column(db.String(255), nullable=False) username = db.Column(db.String(255), nullable=False)
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_assignment_waiting,users") # type: ignore group = relationship("GroupModel", overlaps="groups,user_group_assignments_waiting,users") # type: ignore
def is_match_all(self): def is_match_all(self) -> bool:
"""Is_match_all.""" """Is_match_all."""
if self.username == self.MATCH_ALL_USERS: if self.username == self.MATCH_ALL_USERS:
return True return True

View File

@ -218,12 +218,12 @@ class AuthorizationService:
cls.associate_user_with_group(user, default_group) cls.associate_user_with_group(user, default_group)
@classmethod @classmethod
def find_or_create_permission_target(cls, uri): def find_or_create_permission_target(cls, uri: str) -> PermissionTargetModel:
"""Find_or_create_permission_target.""" """Find_or_create_permission_target."""
uri_with_percent = re.sub(r"\*", "%", uri) uri_with_percent = re.sub(r"\*", "%", uri)
permission_target = PermissionTargetModel.query.filter_by( permission_target: Optional[
uri=uri_with_percent PermissionTargetModel
).first() ] = PermissionTargetModel.query.filter_by(uri=uri_with_percent).first()
if permission_target is None: if permission_target is None:
permission_target = PermissionTargetModel(uri=uri_with_percent) permission_target = PermissionTargetModel(uri=uri_with_percent)
db.session.add(permission_target) db.session.add(permission_target)

View File

@ -43,7 +43,7 @@ class TestAddPermission(BaseTest):
assert group is None assert group is None
assert permission_target is None assert permission_target is None
result = AddPermission().run( AddPermission().run(
script_attributes_context, "read", "/test_add_permission/*", "my_test_group" script_attributes_context, "read", "/test_add_permission/*", "my_test_group"
) )
group = GroupModel.query.filter( group = GroupModel.query.filter(

View File

@ -35,7 +35,7 @@ class TestAddUserToGroup(BaseTest):
process_instance_id=1, process_instance_id=1,
process_model_identifier="my_test_user", process_model_identifier="my_test_user",
) )
result = AddUserToGroup().run( AddUserToGroup().run(
script_attributes_context, my_user.username, my_group.identifier script_attributes_context, my_user.username, my_group.identifier
) )
assert my_user in my_group.users assert my_user in my_group.users
@ -54,7 +54,7 @@ class TestAddUserToGroup(BaseTest):
process_instance_id=1, process_instance_id=1,
process_model_identifier="my_test_user", process_model_identifier="my_test_user",
) )
result = AddUserToGroup().run( AddUserToGroup().run(
script_attributes_context, "dan@sartography.com", "competent-joes" script_attributes_context, "dan@sartography.com", "competent-joes"
) )
my_group = GroupModel.query.filter( my_group = GroupModel.query.filter(

View File

@ -53,7 +53,7 @@ class TestDeletePermissions(BaseTest):
process_instance_id=1, process_instance_id=1,
process_model_identifier="my_test_user", process_model_identifier="my_test_user",
) )
result = ClearPermissions().run(script_attributes_context) ClearPermissions().run(script_attributes_context)
groups = GroupModel.query.all() groups = GroupModel.query.all()
assert 0 == len(groups) assert 0 == len(groups)

View File

@ -20,10 +20,10 @@ class TestUserService(BaseTest):
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
) -> None: ) -> None:
"""Test_waiting_group_assignments.""" """Test_waiting_group_assignments."""
aTestGroup = GroupService.find_or_create_group("aTestGroup") a_test_group = GroupService.find_or_create_group("aTestGroup")
UserService.add_waiting_group_assignment("initiator_user", aTestGroup) UserService.add_waiting_group_assignment("initiator_user", a_test_group)
initiator_user = self.find_or_create_user("initiator_user") initiator_user = self.find_or_create_user("initiator_user")
assert initiator_user.groups[0] == aTestGroup assert initiator_user.groups[0] == a_test_group
def test_assigning_a_group_to_all_users_updates_new_users( def test_assigning_a_group_to_all_users_updates_new_users(
self, self,