|
53 | 53 | _text = sqlalchemy.text |
54 | 54 |
|
55 | 55 |
|
56 | | -def _filter_activity_by_user(activity_list, users=[]): |
57 | | - ''' |
58 | | - Return the given ``activity_list`` but with activities from the specified |
59 | | - users removed. The users parameters should be a list of ids. |
60 | | -
|
61 | | - A *new* filtered list is returned, the given ``activity_list`` itself is |
62 | | - not modified. |
63 | | - ''' |
64 | | - if not len(users): |
65 | | - return activity_list |
66 | | - new_list = [] |
67 | | - for activity in activity_list: |
68 | | - if activity.user_id not in users: |
69 | | - new_list.append(activity) |
70 | | - return new_list |
71 | | - |
72 | | - |
73 | 56 | def _activity_stream_get_filtered_users(): |
74 | 57 | ''' |
75 | 58 | Get the list of users from the :ref:`ckan.hide_activity_from_users` config |
@@ -2499,10 +2482,8 @@ def user_activity_list(context, data_dict): |
2499 | 2482 | offset = data_dict.get('offset', 0) |
2500 | 2483 | limit = data_dict['limit'] # defaulted, limited & made an int by schema |
2501 | 2484 |
|
2502 | | - _activity_objects = model.activity.user_activity_list( |
| 2485 | + activity_objects = model.activity.user_activity_list( |
2503 | 2486 | user.id, limit=limit, offset=offset) |
2504 | | - activity_objects = _filter_activity_by_user( |
2505 | | - _activity_objects, _activity_stream_get_filtered_users()) |
2506 | 2487 |
|
2507 | 2488 | return model_dictize.activity_list_dictize( |
2508 | 2489 | activity_objects, context, |
@@ -2553,13 +2534,10 @@ def package_activity_list(context, data_dict): |
2553 | 2534 | offset = int(data_dict.get('offset', 0)) |
2554 | 2535 | limit = data_dict['limit'] # defaulted, limited & made an int by schema |
2555 | 2536 |
|
2556 | | - _activity_objects = model.activity.package_activity_list( |
2557 | | - package.id, limit=limit, offset=offset) |
2558 | | - if not include_hidden_activity: |
2559 | | - activity_objects = _filter_activity_by_user( |
2560 | | - _activity_objects, _activity_stream_get_filtered_users()) |
2561 | | - else: |
2562 | | - activity_objects = _activity_objects |
| 2537 | + activity_objects = model.activity.package_activity_list( |
| 2538 | + package.id, limit=limit, offset=offset, |
| 2539 | + include_hidden_activity=include_hidden_activity, |
| 2540 | + ) |
2563 | 2541 |
|
2564 | 2542 | return model_dictize.activity_list_dictize( |
2565 | 2543 | activity_objects, context, include_data=data_dict['include_data']) |
@@ -2608,13 +2586,10 @@ def group_activity_list(context, data_dict): |
2608 | 2586 | group_show = logic.get_action('group_show') |
2609 | 2587 | group_id = group_show(context, {'id': group_id})['id'] |
2610 | 2588 |
|
2611 | | - _activity_objects = model.activity.group_activity_list( |
2612 | | - group_id, limit=limit, offset=offset) |
2613 | | - if not include_hidden_activity: |
2614 | | - activity_objects = _filter_activity_by_user( |
2615 | | - _activity_objects, _activity_stream_get_filtered_users()) |
2616 | | - else: |
2617 | | - activity_objects = _activity_objects |
| 2589 | + activity_objects = model.activity.group_activity_list( |
| 2590 | + group_id, limit=limit, offset=offset, |
| 2591 | + include_hidden_activity=include_hidden_activity, |
| 2592 | + ) |
2618 | 2593 |
|
2619 | 2594 | return model_dictize.activity_list_dictize( |
2620 | 2595 | activity_objects, context, |
@@ -2662,13 +2637,10 @@ def organization_activity_list(context, data_dict): |
2662 | 2637 | org_show = logic.get_action('organization_show') |
2663 | 2638 | org_id = org_show(context, {'id': org_id})['id'] |
2664 | 2639 |
|
2665 | | - _activity_objects = model.activity.organization_activity_list( |
2666 | | - org_id, limit=limit, offset=offset) |
2667 | | - if not include_hidden_activity: |
2668 | | - activity_objects = _filter_activity_by_user( |
2669 | | - _activity_objects, _activity_stream_get_filtered_users()) |
2670 | | - else: |
2671 | | - activity_objects = _activity_objects |
| 2640 | + activity_objects = model.activity.organization_activity_list( |
| 2641 | + org_id, limit=limit, offset=offset, |
| 2642 | + include_hidden_activity=include_hidden_activity, |
| 2643 | + ) |
2672 | 2644 |
|
2673 | 2645 | return model_dictize.activity_list_dictize( |
2674 | 2646 | activity_objects, context, |
@@ -2698,12 +2670,9 @@ def recently_changed_packages_activity_list(context, data_dict): |
2698 | 2670 | data_dict['include_data'] = False |
2699 | 2671 | limit = data_dict['limit'] # defaulted, limited & made an int by schema |
2700 | 2672 |
|
2701 | | - _activity_objects = \ |
| 2673 | + activity_objects = \ |
2702 | 2674 | model.activity.recently_changed_packages_activity_list( |
2703 | 2675 | limit=limit, offset=offset) |
2704 | | - activity_objects = _filter_activity_by_user( |
2705 | | - _activity_objects, |
2706 | | - _activity_stream_get_filtered_users()) |
2707 | 2676 |
|
2708 | 2677 | return model_dictize.activity_list_dictize( |
2709 | 2678 | activity_objects, context, |
@@ -3216,13 +3185,11 @@ def dashboard_activity_list(context, data_dict): |
3216 | 3185 |
|
3217 | 3186 | # FIXME: Filter out activities whose subject or object the user is not |
3218 | 3187 | # authorized to read. |
3219 | | - _activity_tuple_objects = model.activity.dashboard_activity_list( |
| 3188 | + activity_objects = model.activity.dashboard_activity_list( |
3220 | 3189 | user_id, limit=limit, offset=offset) |
3221 | 3190 |
|
3222 | | - activity_tuple_list = _filter_activity_by_user( |
3223 | | - _activity_tuple_objects, _activity_stream_get_filtered_users()) |
3224 | 3191 | activity_dicts = model_dictize.activity_list_dictize( |
3225 | | - activity_tuple_list, context) |
| 3192 | + activity_objects, context) |
3226 | 3193 |
|
3227 | 3194 | # Mark the new (not yet seen by user) activities. |
3228 | 3195 | strptime = datetime.datetime.strptime |
|
0 commit comments