Skip to content

Commit

Permalink
Merge pull request #1519 from ckan/1519-fix-orgs-in-dashboard
Browse files Browse the repository at this point in the history
Activity Stream from: Organization Error group not found
  • Loading branch information
nigelbabu committed Apr 10, 2014
2 parents 3e54a65 + 94521e2 commit 1c86590
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ckan/controllers/user.py
Expand Up @@ -567,7 +567,8 @@ def display_name(followee):
action_functions = {
'dataset': 'package_show',
'user': 'user_show',
'group': 'group_show'
'group': 'group_show',
'organization': 'organization_show',
}
action_function = logic.get_action(
action_functions.get(filter_type))
Expand Down
3 changes: 2 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -1430,7 +1430,8 @@ def dashboard_activity_stream(user_id, filter_type=None, filter_id=None,
action_functions = {
'dataset': 'package_activity_list_html',
'user': 'user_activity_list_html',
'group': 'group_activity_list_html'
'group': 'group_activity_list_html',
'organization': 'organization_activity_list_html',
}
action_function = logic.get_action(action_functions.get(filter_type))
return action_function(context, {'id': filter_id, 'offset': offset})
Expand Down
53 changes: 51 additions & 2 deletions ckan/logic/action/get.py
Expand Up @@ -2564,6 +2564,18 @@ def group_follower_count(context, data_dict):
context['model'].UserFollowingGroup)


def organization_follower_count(context, data_dict):
'''Return the number of followers of an organization.
:param id: the id or name of the organization
:type id: string
:rtype: int
'''
return group_follower_count(context, data_dict)


def _follower_list(context, data_dict, default_schema, FollowerClass):
schema = context.get('schema', default_schema)
data_dict, errors = _validate(data_dict, schema, context)
Expand Down Expand Up @@ -2631,6 +2643,21 @@ def group_follower_list(context, data_dict):
context['model'].UserFollowingGroup)


def organization_follower_list(context, data_dict):
'''Return the list of users that are following the given organization.
:param id: the id or name of the organization
:type id: string
:rtype: list of dictionaries
'''
_check_access('organization_follower_list', context, data_dict)
return _follower_list(
context, data_dict,
ckan.logic.schema.default_follow_group_schema(),
context['model'].UserFollowingGroup)

def _am_following(context, data_dict, default_schema, FollowerClass):
schema = context.get('schema', default_schema)
data_dict, errors = _validate(data_dict, schema, context)
Expand Down Expand Up @@ -2818,7 +2845,8 @@ def display_name(followee):
for followee_list_function, followee_type in (
(user_followee_list, 'user'),
(dataset_followee_list, 'dataset'),
(group_followee_list, 'group')):
(group_followee_list, 'group'),
(organization_followee_list, 'organization')):
dicts = followee_list_function(context, data_dict)
for d in dicts:
followee_dicts.append(
Expand Down Expand Up @@ -2915,6 +2943,26 @@ def group_followee_list(context, data_dict):
'''
_check_access('group_followee_list', context, data_dict)

return _group_or_org_followee_list(context, data_dict, is_org=False)


def organization_followee_list(context, data_dict):
'''Return the list of organizations that are followed by the given user.
:param id: the id or name of the user
:type id: string
:rtype: list of dictionaries
'''

_check_access('organization_followee_list', context, data_dict)

return _group_or_org_followee_list(context, data_dict, is_org=True)


def _group_or_org_followee_list(context, data_dict, is_org=False):

if not context.get('skip_validation'):
schema = context.get('schema',
ckan.logic.schema.default_follow_user_schema())
Expand All @@ -2929,7 +2977,8 @@ def group_followee_list(context, data_dict):

# Convert the UserFollowingGroup objects to a list of Group objects.
groups = [model.Group.get(followee.object_id) for followee in followees]
groups = [group for group in groups if group is not None]
groups = [group for group in groups
if group is not None and group.is_organization == is_org]

# Dictize the list of Group objects.
return [model_dictize.group_dictize(group, context) for group in groups]
Expand Down
7 changes: 7 additions & 0 deletions ckan/logic/auth/get.py
Expand Up @@ -236,6 +236,10 @@ def group_follower_list(context, data_dict):
return sysadmin(context, data_dict)


def organization_follower_list(context, data_dict):
return sysadmin(context, data_dict)


def _followee_list(context, data_dict):
model = context['model']

Expand Down Expand Up @@ -271,6 +275,9 @@ def dataset_followee_list(context, data_dict):
def group_followee_list(context, data_dict):
return _followee_list(context, data_dict)

@logic.auth_audit_exempt
def organization_followee_list(context, data_dict):
return _followee_list(context, data_dict)

def user_reset(context, data_dict):
return {'success': True}
Expand Down
2 changes: 2 additions & 0 deletions ckan/templates/user/snippets/followee_dropdown.html
Expand Up @@ -5,6 +5,8 @@
<i class="icon-user"></i>
{% elif type == 'group' %}
<i class="icon-group"></i>
{% elif type == 'organization' %}
<i class="icon-building"></i>
{% endif %}
{%- endmacro %}

Expand Down
1 change: 1 addition & 0 deletions ckan/tests/test_coding_standards.py
Expand Up @@ -927,6 +927,7 @@ class TestActionAuth(object):
'get: member_list',
'get: organization_activity_list',
'get: organization_activity_list_html',
'get: organization_follower_count',
'get: package_activity_list',
'get: package_activity_list_html',
'get: recently_changed_packages_activity_list',
Expand Down

0 comments on commit 1c86590

Please sign in to comment.