def test_get_most_specific_notification_setting_value(self): project_id = 1 notification_settings_by_scope = { NotificationScopeType.USER: { self.user.id: { ExternalProviders.SLACK: NotificationSettingOptionValues.NEVER, ExternalProviders.EMAIL: NotificationSettingOptionValues.ALWAYS, }, }, NotificationScopeType.PROJECT: { project_id: { ExternalProviders.SLACK: NotificationSettingOptionValues.NEVER, ExternalProviders.EMAIL: NotificationSettingOptionValues.NEVER, }, }, } value = get_most_specific_notification_setting_value( notification_settings_by_scope, recipient=self.user, parent_id=project_id, type=NotificationSettingTypes.ISSUE_ALERTS, ) assert value == NotificationSettingOptionValues.NEVER
def test_get_most_specific_notification_setting_value_empty_workflow(self): value = get_most_specific_notification_setting_value( notification_settings_by_scope={}, recipient=self.user, parent_id=1, type=NotificationSettingTypes.WORKFLOW, ) assert value == NotificationSettingOptionValues.SUBSCRIBE_ONLY
def test_get_most_specific_notification_setting_value_empty_alerts(self): value = get_most_specific_notification_setting_value( notification_settings_by_scope={}, recipient=self.user, parent_id=1, type=NotificationSettingTypes.ISSUE_ALERTS, ) assert value == NotificationSettingOptionValues.ALWAYS
def get_attrs( self, item_list: Sequence[Project], user: User, **kwargs: Any ) -> MutableMapping[Project, MutableMapping[str, Any]]: def measure_span(op_tag): span = sentry_sdk.start_span(op=f"serialize.get_attrs.project.{op_tag}") span.set_data("Object Count", len(item_list)) return span with measure_span("preamble"): project_ids = [i.id for i in item_list] if user.is_authenticated and item_list: bookmarks = set( ProjectBookmark.objects.filter( user=user, project_id__in=project_ids ).values_list("project_id", flat=True) ) notification_settings_by_scope = transform_to_notification_settings_by_scope( NotificationSetting.objects.get_for_user_by_projects( NotificationSettingTypes.ISSUE_ALERTS, user, item_list, ) ) else: bookmarks = set() notification_settings_by_scope = {} with measure_span("stats"): stats = None transaction_stats = None session_stats = None project_ids = [o.id for o in item_list] if self.transaction_stats and self.stats_period: stats = self.get_stats(project_ids, "!event.type:transaction") transaction_stats = self.get_stats(project_ids, "event.type:transaction") elif self.stats_period: stats = self.get_stats(project_ids, "!event.type:transaction") if self.session_stats: session_stats = self.get_session_stats(project_ids) avatars = {a.project_id: a for a in ProjectAvatar.objects.filter(project__in=item_list)} project_ids = [i.id for i in item_list] platforms = ProjectPlatform.objects.filter(project_id__in=project_ids).values_list( "project_id", "platform" ) platforms_by_project = defaultdict(list) for project_id, platform in platforms: platforms_by_project[project_id].append(platform) with measure_span("access"): result = get_access_by_project(item_list, user) with measure_span("features"): features_by_project = get_features_for_projects(item_list, user) for project, serialized in result.items(): serialized["features"] = features_by_project[project] with measure_span("other"): for project, serialized in result.items(): value = get_most_specific_notification_setting_value( notification_settings_by_scope, recipient=user, parent_id=project.id, type=NotificationSettingTypes.ISSUE_ALERTS, ) is_subscribed = value == NotificationSettingOptionValues.ALWAYS serialized.update( { "is_bookmarked": project.id in bookmarks, "is_subscribed": is_subscribed, "avatar": avatars.get(project.id), "platforms": platforms_by_project[project.id], } ) if stats: serialized["stats"] = stats[project.id] if transaction_stats: serialized["transactionStats"] = transaction_stats[project.id] if session_stats: serialized["sessionStats"] = session_stats[project.id] return result