1
1
"""Methods to manage permission management configuration"""
2
2
3
3
import logging
4
- from connexion import App
5
- from connexion .exceptions import Forbidden
6
- from flask_authz import CasbinEnforcer
4
+ from functools import wraps
7
5
from pkg_resources import resource_filename
6
+ from pathlib import Path
8
7
from typing import (Callable , Optional , Tuple )
9
- from functools import wraps
8
+
9
+ from connexion import App
10
+ from connexion .exceptions import Forbidden
10
11
from flask import current_app
11
12
from flask .wrappers import Response
13
+ from flask_authz import CasbinEnforcer
12
14
13
15
from foca .models .config import (
14
16
DBConfig ,
@@ -50,7 +52,7 @@ def register_access_control(
50
52
access_db_conf = DBConfig (
51
53
collections = {
52
54
access_control_config .collection_name : CollectionConfig ()
53
- },
55
+ } if access_control_config . collection_name is not None else {} ,
54
56
client = None
55
57
)
56
58
@@ -113,7 +115,7 @@ def register_permission_specs(
113
115
spec_path = access_control_config .api_specs
114
116
115
117
spec = SpecConfig (
116
- path = spec_path ,
118
+ path = Path ( spec_path ) ,
117
119
add_operation_fields = {
118
120
"x-openapi-router-controller" : (
119
121
access_control_config .api_controllers
@@ -191,7 +193,9 @@ def check_permissions(
191
193
"""
192
194
193
195
def _decorator_check_permissions (fn ):
194
- """User access decorator. Used to facilitate optional decorator arguments.
196
+ """User access decorator.
197
+
198
+ Used to facilitate optional decorator arguments.
195
199
196
200
Args:
197
201
fn: The function to be decorated.
@@ -200,7 +204,7 @@ def _decorator_check_permissions(fn):
200
204
The response returned from the input function.
201
205
"""
202
206
@wraps (fn )
203
- def _wrapper (* args , ** kwargs ):
207
+ def _wrapper (* args , ** kwargs ) -> Tuple [ Response , int ] :
204
208
"""Wrapper for permissions decorator.
205
209
206
210
Args:
0 commit comments