-
Notifications
You must be signed in to change notification settings - Fork 2k
/
auth.py
44 lines (28 loc) · 1.15 KB
/
auth.py
1
2
3
4
5
6
7
8
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
import ckan.plugins as p
def datastore_auth(context, data_dict, privilege='resource_update'):
if not 'id' in data_dict:
data_dict['id'] = data_dict.get('resource_id')
user = context.get('user')
authorized = p.toolkit.check_access(privilege, context, data_dict)
if not authorized:
return {
'success': False,
'msg': p.toolkit._('User {0} not authorized to update resource {1}'
.format(str(user), data_dict['id']))
}
else:
return {'success': True}
def datastore_create(context, data_dict):
return datastore_auth(context, data_dict)
def datastore_upsert(context, data_dict):
return datastore_auth(context, data_dict)
def datastore_delete(context, data_dict):
return datastore_auth(context, data_dict)
@p.toolkit.auth_allow_anonymous_access
def datastore_search(context, data_dict):
return datastore_auth(context, data_dict, 'resource_show')
@p.toolkit.auth_allow_anonymous_access
def datastore_search_sql(context, data_dict):
return {'success': True}
def datastore_change_permissions(context, data_dict):
return datastore_auth(context, data_dict)