Skip to content

Commit

Permalink
[CPNHUB-110] fix: Email notifications not working for non-admin users (
Browse files Browse the repository at this point in the history
…#125)

* [CPNHUB-110] fix: Email notifications not working for non-admin users

* fix: Unit tests using ObjectId instead of str for companies
  • Loading branch information
MarkLark86 authored Apr 26, 2022
1 parent d7ed111 commit 83b9dfc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions newsroom/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def get_matching_topics_for_item(self, item_id, topics, users, companies, query)

search.user = user
search.is_admin = is_admin(user)
search.company = companies.get(user.get('company', ''))
search.company = companies.get(str(user.get('company', '')))

search.query = deepcopy(query)
search.section = topic.get('topic_type')
Expand Down Expand Up @@ -700,12 +700,13 @@ def get_matching_topics_for_item(self, item_id, topics, users, companies, query)
self.apply_company_filter(search)
self.apply_time_limit_filter(search)
self.apply_products_filter(search)
except Forbidden:
except Forbidden as exc:
logger.info(
'Notification for user:{} and topic:{} is skipped'.format(
user.get('_id'),
topic.get('_id')
)
),
exc_info=exc
)
continue

Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def test_matching_topics_for_public_user(client, app):
search = get_resource_service('wire_search')

users = {'foo': {'company': COMPANY_1_ID, 'user_type': 'public'}}
companies = {COMPANY_1_ID: {'_id': COMPANY_1_ID, 'name': 'test-comp'}}
companies = {str(COMPANY_1_ID): {'_id': COMPANY_1_ID, 'name': 'test-comp'}}
topics = [
{'_id': 'created_to_old', 'created': {'to': '2017-01-01'}, 'user': 'foo'},
{'_id': 'created_from_future', 'created': {'from': 'now/d'}, 'user': 'foo', 'timezone_offset': 60 * 28},
Expand Down Expand Up @@ -659,7 +659,7 @@ def test_matching_topics_for_user_with_inactive_company(client, app):
'foo': {'company': COMPANY_1_ID, 'user_type': 'public'},
'bar': {'company': COMPANY_2_ID, 'user_type': 'public'},
}
companies = {COMPANY_1_ID: {'_id': COMPANY_1_ID, 'name': 'test-comp'}}
companies = {str(COMPANY_1_ID): {'_id': COMPANY_1_ID, 'name': 'test-comp'}}
topics = [
{'_id': 'created_to_old', 'created': {'to': '2017-01-01'}, 'user': 'bar'},
{'_id': 'created_from_future', 'created': {'from': 'now/d'}, 'user': 'foo', 'timezone_offset': 60 * 28},
Expand Down

0 comments on commit 83b9dfc

Please sign in to comment.