mirror of
https://github.com/sartography/spiffworkflow-backend.git
synced 2025-02-23 04:48:09 +00:00
added method to delete all permissions so we can recreate them w/ burnettk
This commit is contained in:
parent
aaeaac879a
commit
1c0c937af7
14
bin/delete_and_import_all_permissions.py
Normal file
14
bin/delete_and_import_all_permissions.py
Normal file
@ -0,0 +1,14 @@
|
||||
"""Deletes all permissions and then re-imports from yaml file."""
|
||||
from spiffworkflow_backend import get_hacked_up_app_for_script
|
||||
from spiffworkflow_backend.services.authorization_service import AuthorizationService
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Main."""
|
||||
app = get_hacked_up_app_for_script()
|
||||
with app.app_context():
|
||||
AuthorizationService.delete_all_permissions_and_recreate()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -58,6 +58,7 @@ def with_db_and_bpmn_file_cleanup() -> None:
|
||||
"""Process_group_resource."""
|
||||
for model in SpiffworkflowBaseDBModel._all_subclasses():
|
||||
db.session.query(model).delete()
|
||||
db.session.commit()
|
||||
|
||||
try:
|
||||
yield
|
||||
|
@ -29,4 +29,4 @@ class GroupModel(FlaskBpmnGroupModel):
|
||||
secondary="user_group_assignment",
|
||||
overlaps="user_group_assignments,users",
|
||||
)
|
||||
principal = relationship("PrincipalModel", uselist=False) # type: ignore
|
||||
principal = relationship("PrincipalModel", uselist=False, cascade="all, delete") # type: ignore
|
||||
|
@ -80,6 +80,18 @@ class AuthorizationService:
|
||||
|
||||
return cls.has_permission(principals, permission, target_uri)
|
||||
|
||||
@classmethod
|
||||
def delete_all_permissions_and_recreate(cls) -> None:
|
||||
for model in [PermissionAssignmentModel, PermissionTargetModel]:
|
||||
db.session.query(model).delete()
|
||||
|
||||
# cascading to principals doesn't seem to work when attempting to delete all so do it like this instead
|
||||
for group in GroupModel.query.all():
|
||||
db.session.delete(group)
|
||||
|
||||
db.session.commit()
|
||||
cls.import_permissions_from_yaml_file()
|
||||
|
||||
@classmethod
|
||||
def import_permissions_from_yaml_file(
|
||||
cls, raise_if_missing_user: bool = False
|
||||
|
Loading…
x
Reference in New Issue
Block a user