Auth
auth(proxy=None, keymapping=None, anon=False)
¶
Decorator that indicates that the function being decorated is an auth function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proxy
|
a name or list of names of auth functions that should be called before this one (optional) |
None
|
|
keymapping
|
a dict remapping names of keys from this data_dict to the proxy function(s) data_dict; e.g. if the parameter 'id' is called 'resource_id' in the proxy function, the keymapping would be {'id': 'resource_id'} (optional) |
None
|
|
anon
|
allow anonymous access (optional) |
False
|
Returns:
| Type | Description |
|---|---|
|
a wrapper function |
Source code in ckantools/decorators/auth.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
check(proxy, context, data_dict, keymapping=None)
¶
Check that the current user has the given access in the given context. The resource id is extracted from the data dict and therefore must be present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proxy
|
the name of the other auth function to check |
required | |
context
|
the context dict |
required | |
data_dict
|
the data dict |
required | |
keymapping
|
a dict of data_dict key to auth function key, e.g. if the proxied function requires 'id' but the data_dict contains that value as 'resource_id' |
None
|
Returns:
| Type | Description |
|---|---|
|
a dict containing a "success" key with a boolean value indicating whether the current user has the required access. If the user does not then an additional "msg" key is returned in this dict which contains a user-friendly message. |
Source code in ckantools/decorators/auth.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
is_auth(function)
¶
Determines whether the given function is an auth function or not. This is simply based on the existance of the is_auth attribute which is set in the decorator above.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
the function to check |
required |
Returns:
| Type | Description |
|---|---|
|
True if the function is an auth function, False if not |
Source code in ckantools/decorators/auth.py
84 85 86 87 88 89 90 91 92 | |