Skip to content

Commit 8fbc813

Browse files
committed
Revert "Fix/user permissions (#461)"
This reverts commit bd1f7b5.
1 parent 03a2000 commit 8fbc813

File tree

14 files changed

+22
-1074
lines changed

14 files changed

+22
-1074
lines changed

ckanext/querytool/controllers/querytool.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,12 @@ def querytool_edit(self, querytool=None, data=None,
153153
}
154154

155155
context = _get_context()
156+
try:
157+
check_access('querytool_update', context, data_dict)
158+
except NotAuthorized:
159+
abort(403, _('Not authorized to see this page'))
156160

157161
_querytool = _get_action('querytool_get', data_dict)
158-
user_type = helpers.get_user_permission_type(c.userobj, _querytool.get('group')) if _querytool else []
159-
160-
if _querytool and user_type in ['member', None] and c.userobj.sysadmin is False and data_dict.get('name') != '':
161-
abort(403, _('Not authorized to see this page'))
162-
else:
163-
if user_type not in ['admin', 'editor'] and data_dict.get('name') != '':
164-
try:
165-
check_access('querytool_update', context, data_dict)
166-
except NotAuthorized:
167-
abort(403, _('Not authorized to see this page'))
168162

169163
if _querytool is None and len(querytool) > 0:
170164
abort(404, _('Report not found.'))
@@ -318,17 +312,12 @@ def edit_visualizations(self, querytool=None, data=None,
318312

319313
context = _get_context()
320314

321-
_querytool = _get_action('querytool_get', data_dict)
322-
user_type = helpers.get_user_permission_type(c.userobj, _querytool.get('group')) if _querytool else []
323-
324-
if _querytool and user_type in ['member', None] and c.userobj.sysadmin is False:
315+
try:
316+
check_access('querytool_update', context, data_dict)
317+
except NotAuthorized:
325318
abort(403, _('Not authorized to see this page'))
326-
else:
327-
if user_type not in ['admin', 'editor']:
328-
try:
329-
check_access('querytool_update', context, data_dict)
330-
except NotAuthorized:
331-
abort(403, _('Not authorized to see this page'))
319+
320+
_querytool = _get_action('querytool_get', data_dict)
332321

333322
if _querytool is None and len(querytool) > 0:
334323
abort(404, _('Report not found.'))

ckanext/querytool/helpers.py

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,9 @@ def get_map_data(geojson_url, map_key_field, data_key_field,
502502

503503
@functools32.lru_cache(maxsize=128)
504504
def get_resource_data(sql_string):
505-
context = {}
506-
507-
if get_is_admin_or_editor_of_any_group(c.userobj):
508-
context['ignore_auth'] = True
509505

510506
response = toolkit.get_action('datastore_search_sql')(
511-
context, {'sql': sql_string}
507+
{}, {'sql': sql_string}
512508
)
513509
records_to_lower = []
514510
for record in response['records']:
@@ -650,40 +646,6 @@ def get_user_permission(userobj):
650646
return True
651647

652648

653-
def get_orgs_for_user(userobj, org):
654-
orgs = _get_action('organization_list_for_user', {'id': userobj.id})
655-
org_names = [o['name'] for o in orgs]
656-
657-
if org in org_names:
658-
return True
659-
else:
660-
return False
661-
662-
663-
def get_all_orgs_for_user(userobj):
664-
orgs = _get_action('organization_list_for_user', {'id': userobj.id})
665-
666-
if orgs:
667-
return orgs
668-
669-
670-
def get_organization(org_id):
671-
return _get_action('organization_show', {'id': org_id}) if org_id else []
672-
673-
674-
def get_datasets_for_user(userobj, package_name):
675-
package = _get_action('package_show', {'name_or_id': package_name})
676-
org_access = get_orgs_for_user(userobj, package['organization']['name'])
677-
678-
for group in package.get('groups'):
679-
group_access = get_groups_for_user(userobj, group['name'])
680-
681-
if group_access or org_access:
682-
return True
683-
684-
return False
685-
686-
687649
def get_groups_for_user(userobj, group):
688650
groups = _get_action('group_list_authz', {'id': userobj.id})
689651
group_names = [g['name'] for g in groups]
@@ -694,37 +656,6 @@ def get_groups_for_user(userobj, group):
694656
return False
695657

696658

697-
def get_is_admin_or_editor_of_any_group(userobj):
698-
groups = _get_action('group_list_authz', {'id': userobj.id})
699-
is_admin_or_editor = [get_user_permission_type(userobj, group['id']) for group in groups]
700-
701-
if len(groups) != 0 and any(t in ['admin', 'editor'] for t in is_admin_or_editor):
702-
return True
703-
else:
704-
return False
705-
706-
707-
def get_edit_permission_for_user(userobj, group):
708-
member_list = toolkit.get_action('member_list')({}, {'id': group})
709-
710-
if c.userobj.id in member_list:
711-
return True
712-
return False
713-
714-
715-
def get_user_permission_type(userobj, group):
716-
member_list = toolkit.get_action('member_list')({}, {'id': group})
717-
718-
for m in member_list:
719-
if userobj.id in m:
720-
if 'Admin' in m:
721-
return 'admin'
722-
if 'Member' in m:
723-
return 'member'
724-
if 'Editor' in m:
725-
return 'editor'
726-
727-
728659
def get_querytool_get_chart_colors(data):
729660
try:
730661
data = json.loads(data)

0 commit comments

Comments
 (0)