abs-auth-rbac-core 0.3.5__tar.gz → 0.3.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of abs-auth-rbac-core might be problematic. Click here for more details.

Files changed (33) hide show
  1. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/PKG-INFO +1 -1
  2. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/rbac/service.py +38 -51
  3. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/pyproject.toml +1 -1
  4. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/README.md +0 -0
  5. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/__init__.py +0 -0
  6. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/auth/__init__.py +0 -0
  7. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/auth/auth_functions.py +0 -0
  8. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/auth/jwt_functions.py +0 -0
  9. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/auth/middleware.py +0 -0
  10. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/__init__.py +0 -0
  11. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/base_model.py +0 -0
  12. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/gov_casbin_rule.py +0 -0
  13. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/permissions.py +0 -0
  14. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/rbac_model.py +0 -0
  15. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/role_permission.py +0 -0
  16. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/roles.py +0 -0
  17. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/seeder/permission_seeder.py +0 -0
  18. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/user.py +0 -0
  19. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/user_permission.py +0 -0
  20. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/models/user_role.py +0 -0
  21. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/rbac/__init__.py +0 -0
  22. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/rbac/decorator.py +0 -0
  23. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/rbac/policy.conf +0 -0
  24. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/repository/__init__.py +0 -0
  25. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/repository/permission_repository.py +0 -0
  26. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/repository/role_repository.py +0 -0
  27. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/schema/__init__.py +0 -0
  28. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/schema/permission.py +0 -0
  29. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/service/__init__.py +0 -0
  30. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/service/permission_service.py +0 -0
  31. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/service/role_service.py +0 -0
  32. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/util/__init__.py +0 -0
  33. {abs_auth_rbac_core-0.3.5 → abs_auth_rbac_core-0.3.6}/abs_auth_rbac_core/util/permission_constants.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abs-auth-rbac-core
3
- Version: 0.3.5
3
+ Version: 0.3.6
4
4
  Summary: RBAC and Auth core utilities including JWT token management.
5
5
  License-Expression: MIT
6
6
  Author: AutoBridgeSystems
@@ -392,8 +392,7 @@ class RBACService:
392
392
  if not role:
393
393
  raise NotFoundError(detail="Requested role does not exist")
394
394
 
395
- return role
396
-
395
+ return role
397
396
 
398
397
  def update_role_permissions(
399
398
  self,
@@ -402,12 +401,14 @@ class RBACService:
402
401
  name: Optional[str] = None,
403
402
  description: Optional[str] = None,
404
403
  ) -> Any:
405
- """Update role permissions"""
404
+ """Update role permissions by replacing all existing permissions with new ones"""
405
+
406
406
  with self.db() as session:
407
407
  try:
408
408
  if not session.is_active:
409
409
  session.begin()
410
410
 
411
+ # Get role with eager loading of permissions
411
412
  role = (
412
413
  session.query(Role)
413
414
  .options(joinedload(Role.permissions))
@@ -418,91 +419,77 @@ class RBACService:
418
419
  if not role:
419
420
  raise NotFoundError(detail="Requested role does not exist")
420
421
 
422
+ # Update role information if provided
421
423
  if name is not None or description is not None:
422
424
  if name:
425
+ # Check if new name already exists for a different role
423
426
  existing_role = (
424
427
  session.query(Role)
425
428
  .filter(Role.name == name, Role.uuid != role_uuid)
426
429
  .first()
427
430
  )
431
+
428
432
  if existing_role:
429
433
  raise DuplicatedError(detail="Role already exists")
434
+
430
435
  if role.name != "super_admin":
431
436
  role.name = name
437
+
432
438
  if description is not None:
433
439
  role.description = description
434
440
 
435
441
  if permissions is not None:
436
- existing_permissions = role.permissions
437
- existing_permission = {p.uuid for p in existing_permissions}
438
- new_permission = set(permissions) if permissions else set()
439
-
440
- permissions_to_remove = existing_permission - new_permission
441
- permissions_to_add = new_permission - existing_permission
442
-
443
- if permissions_to_remove:
444
- session.query(RolePermission).filter(
445
- RolePermission.role_uuid == role_uuid,
446
- RolePermission.permission_uuid.in_(permissions_to_remove)
447
- ).delete(synchronize_session=False)
442
+ # Remove ALL existing policies for this role from Casbin
443
+ self.enforcer.remove_filtered_policy(0, str(role_uuid))
444
+
445
+ # Delete existing role permissions from database
446
+ session.query(RolePermission).filter(
447
+ RolePermission.role_uuid == role_uuid
448
+ ).delete(synchronize_session=False)
448
449
 
449
- if permissions_to_add:
450
- new_permissions = (
450
+ # Add new permissions if provided
451
+ if permissions:
452
+ # Fetch all permissions in a single query
453
+ permissions_objs = (
451
454
  session.query(Permission)
452
- .filter(Permission.uuid.in_(permissions_to_add))
455
+ .filter(Permission.uuid.in_(permissions))
453
456
  .all()
454
457
  )
455
458
 
456
- found_permission = {p.uuid for p in new_permissions}
457
- missing_permission = permissions_to_add - found_permission
458
- if missing_permission:
459
+ found_permission_ids = {p.uuid for p in permissions_objs}
460
+ missing_permission_ids = set(permissions) - found_permission_ids
461
+ if missing_permission_ids:
459
462
  raise NotFoundError(
460
- detail=f"Permissions with UUIDs '{', '.join(missing_permission)}' not found"
463
+ detail=f"Permissions with UUIDs '{', '.join(missing_permission_ids)}' not found"
461
464
  )
462
465
 
466
+ # Bulk insert role permissions
463
467
  role_permissions = [
464
468
  {"role_uuid": role_uuid, "permission_uuid": permission.uuid}
465
- for permission in new_permissions
469
+ for permission in permissions_objs
466
470
  ]
467
471
  session.bulk_insert_mappings(RolePermission, role_permissions)
468
472
 
469
- session.commit()
470
- casbin_updated = False
471
-
472
- if permissions is not None:
473
- existing_permissions_dict = {p.uuid: p for p in existing_permissions}
474
-
475
- if permissions_to_remove:
476
- remove_policies = [
477
- [role_uuid, existing_permissions_dict[perm_id].resource,
478
- existing_permissions_dict[perm_id].action,
479
- existing_permissions_dict[perm_id].module]
480
- for perm_id in permissions_to_remove
481
- ]
482
-
483
- self.enforcer.remove_policies(remove_policies)
484
- casbin_updated = True
485
-
486
-
487
- if permissions_to_add:
488
- add_policies = [
489
- [role_uuid, p.resource, p.action, p.module]
490
- for p in new_permissions
473
+ # Add new Casbin policies
474
+ policies = [
475
+ [role_uuid, permission.resource, permission.action, permission.module]
476
+ for permission in permissions_objs
491
477
  ]
492
-
493
- self.enforcer.add_policies(add_policies)
494
- casbin_updated = True
495
-
496
- if casbin_updated:
478
+ self.enforcer.add_policies(policies)
479
+
480
+ # Save all Casbin changes
497
481
  self.enforcer.save_policy()
498
482
 
483
+ session.commit()
484
+
485
+ # Refresh the role to get the updated permissions
499
486
  session.refresh(role)
500
487
 
488
+ # Return the updated role with permissions
501
489
  return role
502
490
 
503
491
  except Exception as e:
504
492
  raise e
505
-
506
493
 
507
494
  def delete_role(self, role_uuid: str,exception_roles:List[str]=None):
508
495
  """Delete a role and its associated permissions"""
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "abs-auth-rbac-core"
3
- version = "0.3.5"
3
+ version = "0.3.6"
4
4
  description = "RBAC and Auth core utilities including JWT token management."
5
5
  authors = [
6
6
  {name = "AutoBridgeSystems", email = "info@autobridgesystems.com"}