Skip to content

Commit 3f19768

Browse files
committed
Fix datastore main auth function
1 parent 36f72e6 commit 3f19768

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

changes/9021.misc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Auth functions are expected to return a dictionary with a 'success' key,
2+
not raise exceptions.

ckanext/datastore/logic/auth.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ def datastore_auth(context: Context,
1212

1313
user = context.get('user')
1414

15-
authorized = p.toolkit.check_access(privilege, context, data_dict)
16-
if not authorized:
15+
try:
16+
p.toolkit.check_access(privilege, context, data_dict)
17+
except p.toolkit.NotAuthorized:
1718
return {
1819
'success': False,
1920
'msg': p.toolkit._(
20-
'User {0} not authorized to update resource {1}'
21-
.format(str(user), data_dict['id'])
21+
'User {0} not authorized to perform {1} on resource {2}'
22+
.format(str(user), privilege, data_dict['id'])
2223
)
2324
}
24-
else:
25-
return {'success': True}
25+
return {'success': True}
2626

2727

2828
def datastore_create(context: Context, data_dict: DataDict):

0 commit comments

Comments
 (0)