Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hiding importance filter from clients that have restricted coverage information [STTNHUB-327] #900

Merged
merged 6 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion newsroom/agenda/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
get_public_contacts,
get_links,
get_vocabulary,
get_groups,
)
from newsroom.wire.utils import update_action_list
from newsroom.wire.views import set_item_permission
Expand Down Expand Up @@ -143,7 +144,7 @@ def get_view_data() -> Dict:
"restrict_coverage_info": company.get("restrict_coverage_info", False) if company else False,
"locators": get_vocabulary("locators"),
"ui_config": get_resource_service("ui_config").get_section_config("agenda"),
"groups": app.config.get("AGENDA_GROUPS", []),
"groups": get_groups(company, app.config.get("AGENDA_GROUPS", [])),
"has_agenda_featured_items": get_resource_service("agenda_featured").find_one(req=None) is not None,
"user_folders": get_user_folders(user, "agenda") if user else [],
"company_folders": get_company_folders(company, "agenda") if company else [],
Expand Down
8 changes: 8 additions & 0 deletions newsroom/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def assert_never(value: NoReturn) -> NoReturn:
NavigationIds = List[Union[str, ObjectId]]
Section = Literal["wire", "agenda", "monitoring", "news_api", "media_releases", "factcheck", "am_news", "aapX"]
SectionAllowedMap = Dict[Section, bool]
Permissions = Literal["restrict_coverage_info"]


class Group(TypedDict):
field: str
label: str
nested: dict
permissions: List[Permissions]


class Country(TypedDict):
Expand Down
19 changes: 18 additions & 1 deletion newsroom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from flask import current_app as app, json, abort, request, g, flash, session, url_for
from flask_babel import gettext

from newsroom.types import PublicUserData, User, Company
from newsroom.types import PublicUserData, User, Company, Group
from newsroom.template_filters import (
time_short,
parse_date as parse_short_date,
Expand Down Expand Up @@ -664,3 +664,20 @@ def parse_objectid(value: Union[str, ObjectId]) -> Union[str, ObjectId]:
return ObjectId(value)
except InvalidId:
return value


def get_groups(company: Optional[Company], groups: List[Group]) -> List[Group]:
"""
filter agenda groups based on restrict_coverage_info permission
"""
return [group for group in groups if has_permissions(group, company)]


def has_permissions(group: Group, company: Optional[Company]) -> bool:
group_permissions = group.get("permissions", [])
if group_permissions:
for permission in group_permissions:
if company and company.get(permission):
return False
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
return True
return True
Loading