abs-auth-rbac-core 0.1.0__tar.gz → 0.1.2__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.
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/PKG-INFO +1 -1
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/rbac/service.py +20 -33
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/pyproject.toml +1 -1
- abs_auth_rbac_core-0.1.0/abs_auth_rbac_core/rbac/database.py +0 -52
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/README.md +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/__init__.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/auth/__init__.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/auth/auth_functions.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/auth/jwt_functions.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/auth/middleware.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/__init__.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/base_model.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/gov_casbin_rule.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/permissions.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/rbac_model.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/role_permission.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/roles.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/seeder/permission_seeder.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/user.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/user_role.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/rbac/__init__.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/rbac/decorator.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/rbac/policy.conf +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/util/__init__.py +0 -0
- {abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/util/permission_constants.py +0 -0
|
@@ -275,46 +275,32 @@ class RBACService:
|
|
|
275
275
|
if not session.is_active:
|
|
276
276
|
session.begin()
|
|
277
277
|
|
|
278
|
-
role
|
|
278
|
+
# Get role with permissions eagerly loaded
|
|
279
|
+
role = (
|
|
280
|
+
session.query(Role)
|
|
281
|
+
.options(joinedload(Role.permissions))
|
|
282
|
+
.filter(Role.uuid == role_uuid)
|
|
283
|
+
.first()
|
|
284
|
+
)
|
|
285
|
+
if not role:
|
|
286
|
+
raise NotFoundError(detail="Requested role does not exist")
|
|
279
287
|
|
|
280
288
|
if exception_roles and len(exception_roles) > 0 and role.name in exception_roles:
|
|
281
289
|
raise PermissionDeniedError(detail="You are not allowed to delete the requested role.")
|
|
282
|
-
|
|
283
|
-
# Get role name for Casbin policy removal
|
|
284
|
-
role_name = role.name
|
|
285
|
-
|
|
286
|
-
# Delete role permissions
|
|
287
|
-
role_permissions = (
|
|
288
|
-
session.query(RolePermission)
|
|
289
|
-
.filter(RolePermission.role_uuid == role_uuid)
|
|
290
|
-
.all()
|
|
291
|
-
)
|
|
292
|
-
|
|
293
|
-
# Remove Casbin policies for each permission
|
|
294
|
-
remove_policies =[]
|
|
295
|
-
for role_permission in role_permissions:
|
|
296
|
-
permission = (
|
|
297
|
-
session.query(Permission)
|
|
298
|
-
.filter(Permission.uuid == role_permission.permission_uuid)
|
|
299
|
-
.first()
|
|
300
|
-
)
|
|
301
|
-
if permission:
|
|
302
|
-
remove_policies.append(
|
|
303
|
-
(role_name, permission.resource, permission.action, permission.module)
|
|
304
|
-
)
|
|
305
290
|
|
|
306
|
-
|
|
307
|
-
|
|
291
|
+
# Collect all policies to remove from the eagerly loaded permissions
|
|
292
|
+
remove_policies = [
|
|
293
|
+
[role.name, permission.resource, permission.action, permission.module]
|
|
294
|
+
for permission in role.permissions
|
|
295
|
+
]
|
|
308
296
|
|
|
309
|
-
#
|
|
310
|
-
|
|
311
|
-
RolePermission.role_uuid == role_uuid
|
|
312
|
-
).delete()
|
|
297
|
+
# Remove all policies at once
|
|
298
|
+
if remove_policies:
|
|
313
299
|
|
|
314
|
-
|
|
315
|
-
|
|
300
|
+
self.enforcer.remove_policies(remove_policies)
|
|
301
|
+
self.enforcer.save_policy()
|
|
316
302
|
|
|
317
|
-
# Delete role
|
|
303
|
+
# Delete role (cascade will handle role_permissions and user_roles)
|
|
318
304
|
session.delete(role)
|
|
319
305
|
session.commit()
|
|
320
306
|
|
|
@@ -363,6 +349,7 @@ class RBACService:
|
|
|
363
349
|
"name": permission.name,
|
|
364
350
|
"resource": permission.resource,
|
|
365
351
|
"action": permission.action,
|
|
352
|
+
"module": permission.module
|
|
366
353
|
}
|
|
367
354
|
)
|
|
368
355
|
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
from contextlib import AbstractContextManager, contextmanager
|
|
2
|
-
from typing import Any, Generator
|
|
3
|
-
from loguru import logger
|
|
4
|
-
|
|
5
|
-
from sqlalchemy import create_engine, orm
|
|
6
|
-
from sqlalchemy.orm import Session
|
|
7
|
-
from abs_repository_core.models import BaseModel
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Database:
|
|
11
|
-
def __init__(self, db_url: str) -> None:
|
|
12
|
-
"""
|
|
13
|
-
Initialize the database engine and session factory
|
|
14
|
-
"""
|
|
15
|
-
self._engine = create_engine(
|
|
16
|
-
db_url,
|
|
17
|
-
echo=False,
|
|
18
|
-
echo_pool=False,
|
|
19
|
-
pool_pre_ping=True,
|
|
20
|
-
pool_recycle=3600,
|
|
21
|
-
query_cache_size=0,
|
|
22
|
-
)
|
|
23
|
-
self._session_factory = orm.scoped_session(
|
|
24
|
-
orm.sessionmaker(
|
|
25
|
-
autocommit=False,
|
|
26
|
-
autoflush=False,
|
|
27
|
-
bind=self._engine,
|
|
28
|
-
),
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
def create_database(self) -> None:
|
|
32
|
-
"""
|
|
33
|
-
Create all the tables in the database
|
|
34
|
-
"""
|
|
35
|
-
BaseModel.metadata.create_all(self._engine)
|
|
36
|
-
|
|
37
|
-
@contextmanager
|
|
38
|
-
def session(self) -> Generator[Any, Any, AbstractContextManager[Session]]:
|
|
39
|
-
"""
|
|
40
|
-
Provides a database session for the request
|
|
41
|
-
"""
|
|
42
|
-
session: Session = self._session_factory()
|
|
43
|
-
try:
|
|
44
|
-
yield session
|
|
45
|
-
except Exception as e:
|
|
46
|
-
session.rollback()
|
|
47
|
-
import traceback
|
|
48
|
-
|
|
49
|
-
logger.error(f"Exception: {e}\n{traceback.format_exc()}")
|
|
50
|
-
raise e
|
|
51
|
-
finally:
|
|
52
|
-
session.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/auth/auth_functions.py
RENAMED
|
File without changes
|
{abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/auth/jwt_functions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/base_model.py
RENAMED
|
File without changes
|
{abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/gov_casbin_rule.py
RENAMED
|
File without changes
|
{abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/permissions.py
RENAMED
|
File without changes
|
{abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/rbac_model.py
RENAMED
|
File without changes
|
{abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/role_permission.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{abs_auth_rbac_core-0.1.0 → abs_auth_rbac_core-0.1.2}/abs_auth_rbac_core/models/user_role.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|