Skip to content

Commit

Permalink
Fixes issues with shared with users, mostly defencive checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavle Jonoski authored and vladoohr committed May 14, 2020
1 parent 3b5ef12 commit c7de5fa
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions ckanext/knowledgehub/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,7 @@ def get_all_users():
if user.get('name') not in sysadmins:
users.append(
{
'id': user.get('id'),
'name': user.get('name'),
'display_name': user.get('fullname') or user.get('name')
}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/knowledgehub/logic/action/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ def _access_request_update(context, data_dict, granted=True):
'title': _('Request for access approved'),
'description': _('Your request for access has been approved.'),
'link': access_request.entity_link,
'recipient': access_request.user_id,
'recepient': access_request.user_id,
})
except Exception as e:
log.error('Failed to send notification for access granted. '
Expand Down
5 changes: 4 additions & 1 deletion ckanext/knowledgehub/model/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,13 @@ def load_related_data_visualization(cls, _id, related_data_ids):
def load_related_data_dashboard(cls, _id, related_data_ids):
dashboard = cls._call_action('dashboard_show', {'id': _id})

if not dashboard:
return

tags = cls._try_clean_list(dashboard, 'tags')
cls._load_tags_and_keywords(tags, related_data_ids)

indicators = dashboard.get('indicators', '').strip()
indicators = (dashboard.get('indicators', '') or '').strip()
if indicators:
indicators = json.loads(indicators)
for indicator in indicators:
Expand Down
5 changes: 3 additions & 2 deletions ckanext/knowledgehub/model/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def before_index(data):
{'ignore_auth': True},
{'id': data['package_id'], 'include_tracking': True})
if package:
data['organizations'] = package.get('organization', {}).get('name')
organization_id = package.get('organization', {}).get('id')
data['organizations'] = (package.get('organization',
{}) or {}).get('name')
organization_id = (package.get('organization', {}) or {}).get('id')
if organization_id:
permission_labels.append('member-%s' % organization_id)

Expand Down
10 changes: 7 additions & 3 deletions ckanext/knowledgehub/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,13 @@ def before_index(self, pkg_dict):
if resource_view.get('view_type') != 'recline_view':
rqs = resource_view.get('__extras', {}).\
get('research_questions', '')
if isinstance(rqs, str) or \
isinstance(rqs, unicode):
rqs = map(lambda r: r.strip(),
filter(lambda r: r and r.strip(),
rqs.split(',')))
if rqs:
for rq in map(lambda r: r.strip(),
filter(lambda r: r and r.strip(),
rqs.split(','))):
for rq in rqs:
try:
rq = toolkit.get_action(
'research_question_show')({
Expand Down Expand Up @@ -555,6 +558,7 @@ def get_user_dataset_labels(self, user_obj):

labels.append(u'creator-%s' % user_obj.id)
labels.append(u'user-%s' % user_obj.name)
labels.append(u'user-%s' % user_obj.id)

orgs = logic.get_action(u'organization_list_for_user')(
{u'user': user_obj.id}, {u'permission': u'read'})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ <h3>{{ _('Add visualizations based on Research Questions') }}</h3>
<h3>{{ _('Share with') }}</h3>

{% set users = h.get_all_users() %}
{% set shared_with_users = data.get('shared_with_users') or [] %}
<div class="control-group">
<label class="control-label" for="field_shared_with_users">{{ _("Users") }}</label>
<div class="controls">
<select id="field_shared_with_users" name="shared_with_users" data-module="autocomplete" multiple=False>
{% for user in users %}
<option value="{{ user.name }}" {% if user.name in (data.get('shared_with_users') or []) %} selected="selected"
<option value="{{ user.name }}" {% if (user.name in shared_with_users) or (user.id in shared_with_users) %} selected="selected"
{% endif %}>{{ user.display_name }}</option>
{% endfor %}
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ <h3>{{ _('Share with') }}</h3>
{% set users = h.get_all_users() %}
<div class="control-group">
<label class="control-label" for="field_shared_with_users">{{ _("Users") }}</label>
{% set shared_with_users = data.get('shared_with_users') or [] %}
<div class="controls">
<select id="field_shared_with_users" name="shared_with_users" data-module="autocomplete" multiple=False>
{% for user in users %}
<option value="{{ user.name }}" {% if user.name in (data.get('shared_with_users') or []) %} selected="selected"
<option value="{{ user.name }}" {% if (user.name in shared_with_users) or (user.id in shared_with_users) %} selected="selected"
{% endif %}>{{ user.display_name }}</option>
{% endfor %}
</select>
Expand Down

0 comments on commit c7de5fa

Please sign in to comment.