Repository: privacera/paig (language: python)

Issue:
[ENH]: Fix the warnings on startup
### Contact Details

pravin.bansod@privacera.com

### Feature Description

Below warnings are harmless, however its better to evaluate and fix these.


```
/usr/local/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'schema_extra' has been renamed to 'json_schema_extra'
  warnings.warn(message, UserWarning)
/usr/local/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'orm_mode' has been renamed to 'from_attributes'
* 'schema_extra' has been renamed to 'json_schema_extra'
  warnings.warn(message, UserWarning)
/usr/local/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'orm_mode' has been renamed to 'from_attributes'
  warnings.warn(message, UserWarning)
/usr/local/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'allow_population_by_field_name' has been renamed to 'populate_by_name'
  warnings.warn(message, UserWarning)
```

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
[ENH]: Fix the warnings on startup
### Contact Details

pravin.bansod@privacera.com

### Feature Description

Below warnings are harmless, however its better to evaluate and fix these.


```
/usr/local/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'schema_extra' has been renamed to 'json_schema_extra'
  warnings.warn(message, UserWarning)
/usr/local/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'orm_mode' has been renamed to 'from_attributes'
* 'schema_extra' has been renamed to 'json_schema_extra'
  warnings.warn(message, UserWarning)
/usr/local/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'orm_mode' has been renamed to 'from_attributes'
  warnings.warn(message, UserWarning)
/usr/local/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'allow_population_by_field_name' has been renamed to 'populate_by_name'
  warnings.warn(message, UserWarning)
```

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct


Discussion / hints:

Fix patch:
diff --git a/backend/paig/api/audit/api_schemas/access_audit_schema.py b/backend/paig/api/audit/api_schemas/access_audit_schema.py
index c9960c50..8b98c3ba 100644
--- a/backend/paig/api/audit/api_schemas/access_audit_schema.py
+++ b/backend/paig/api/audit/api_schemas/access_audit_schema.py
@@ -36,7 +36,6 @@ class BaseAccessAuditView(BaseModel):
 
     class Config:
         from_attributes = True
-        orm_mode = True
         populate_by_name = True
 
 
diff --git a/backend/paig/api/authz/authorizer/paig_authorizer.py b/backend/paig/api/authz/authorizer/paig_authorizer.py
index 0c201d7a..64e90686 100644
--- a/backend/paig/api/authz/authorizer/paig_authorizer.py
+++ b/backend/paig/api/authz/authorizer/paig_authorizer.py
@@ -45,7 +45,7 @@ class AuthzRequest(BaseModel):
     request_date_time: datetime = Field(current_utc_time(), alias="requestDateTime")
 
     class Config:
-        allow_population_by_field_name = True
+        populate_by_name = True
 
 
 class AuthzResponse(BaseModel):
@@ -81,7 +81,7 @@ class AuthzResponse(BaseModel):
     paig_policy_ids: List[int] = Field([], alias="paigPolicyIds")
 
     class Config:
-        allow_population_by_field_name = True
+        populate_by_name = True
 
 
 class VectorDBAuthzRequest(BaseModel):
@@ -97,7 +97,7 @@ class VectorDBAuthzRequest(BaseModel):
     application_key: str = Field(None, alias="applicationKey")
 
     class Config:
-        allow_population_by_field_name = True
+        populate_by_name = True
 
 
 class VectorDBAuthzResponse(BaseModel):
@@ -125,7 +125,7 @@ class VectorDBAuthzResponse(BaseModel):
     reason: str = Field(None, alias="reason")
 
     class Config:
-        allow_population_by_field_name = True
+        populate_by_name = True
 
 
 class PAIGAuthorizer(ABC):
diff --git a/backend/paig/api/governance/api_schemas/ai_app_config.py b/backend/paig/api/governance/api_schemas/ai_app_config.py
index 9beceadb..3f48c198 100644
--- a/backend/paig/api/governance/api_schemas/ai_app_config.py
+++ b/backend/paig/api/governance/api_schemas/ai_app_config.py
@@ -38,7 +38,7 @@ class AIApplicationConfigView(BaseView):
     application_id: Optional[int] = Field(None, description="The application ID", alias="applicationId")
 
     class Config:
-        schema_extra = {
+        json_schema_extra = {
             "example": {
                 "allowedUsers": ["user1", "user2"],
                 "allowedGroups": ["group1", "group2"],
diff --git a/backend/paig/core/api_schemas/base_view.py b/backend/paig/core/api_schemas/base_view.py
index f3f351ed..b59cd64e 100644
--- a/backend/paig/core/api_schemas/base_view.py
+++ b/backend/paig/core/api_schemas/base_view.py
@@ -20,7 +20,6 @@ class BaseView(BaseModel):
     update_time: Optional[datetime] = Field(None, description="The last update time of the resource", alias="updateTime")
 
     class Config:
-        orm_mode = True
         from_attributes = True
         json_encoders = {
             datetime: lambda v: v.strftime('%Y-%m-%dT%H:%M:%S.%f%z')


Test patch:
diff --git a/backend/paig/tests/api/authz/authorizer/utils/test_authorizer_utils.py b/backend/paig/tests/api/authz/authorizer/utils/test_authorizer_utils.py
index 3114e0a7..1fcedb0a 100644
--- a/backend/paig/tests/api/authz/authorizer/utils/test_authorizer_utils.py
+++ b/backend/paig/tests/api/authz/authorizer/utils/test_authorizer_utils.py
@@ -70,7 +70,26 @@ def app_policies():
     ]
 
 
-def test_check_explicit_application_access_allowed(authz_request, app_config):
+def test_allowed_access_for_user(authz_request, app_config):
+    authz_request.user_id = "test_user"
+    user_groups = ["some_other_group"]
+    access_type = "allowed"
+
+    result = check_explicit_application_access(authz_request, app_config, user_groups, access_type)
+    assert result is True
+
+
+def test_denied_access_for_user(authz_request, app_config):
+    authz_request.user_id = "denied_user"
+    user_groups = ["some_other_group"]
+    access_type = "denied"
+
+    result = check_explicit_application_access(authz_request, app_config, user_groups, access_type)
+    assert result is True
+
+
+def test_allowed_access_for_group(authz_request, app_config):
+    authz_request.user_id = "some_other_user"
     user_groups = ["group1"]
     access_type = "allowed"
 
@@ -79,7 +98,8 @@ def test_check_explicit_application_access_allowed(authz_request, app_config):
     assert result is True
 
 
-def test_check_explicit_application_access_denied(authz_request, app_config):
+def test_denied_access_for_group(authz_request, app_config):
+    authz_request.user_id = "some_other_user"
     user_groups = ["denied_group"]
     access_type = "denied"
 
@@ -88,7 +108,8 @@ def test_check_explicit_application_access_denied(authz_request, app_config):
     assert result is True
 
 
-def test_check_explicit_application_access_none(authz_request, app_config):
+def test_allowed_access_for_invalid_user_and_group(authz_request, app_config):
+    authz_request.user_id = "some_other_user"
     user_groups = ["some_other_group"]
     access_type = "allowed"
 
@@ -97,6 +118,16 @@ def test_check_explicit_application_access_none(authz_request, app_config):
     assert result is False
 
 
+def test_denied_access_denied_for_invalid_user_and_group(authz_request, app_config):
+    authz_request.user_id = "some_other_user"
+    user_groups = ["some_other_group"]
+    access_type = "denied"
+
+    result = check_explicit_application_access(authz_request, app_config, user_groups, access_type)
+
+    assert result is False
+
+
 def test_find_first_deny_policy(authz_request, app_policies):
     authz_request.request_type = "prompt"
     result = find_first_deny_policy(app_policies, authz_request)