def get_participants_for_release( projects: Iterable[Project], organization: Organization, user_ids: Set[int]) -> Mapping[ExternalProviders, Mapping[User, int]]: # Collect all users with verified emails on a team in the related projects. users = list( User.objects.get_team_members_with_verified_email_for_projects( projects)) # Get all the involved users' settings for deploy-emails (including # users' organization-independent settings.) notification_settings = NotificationSetting.objects.get_for_users_by_parent( NotificationSettingTypes.DEPLOY, users=users, parent=organization, ) notification_settings_by_user = transform_to_notification_settings_by_user( notification_settings, users) # Map users to their setting value. Prioritize user/org specific, then # user default, then product default. users_to_reasons_by_provider: MutableMapping[ ExternalProviders, MutableMapping[User, int]] = defaultdict(dict) for user in users: notification_settings_by_scope = notification_settings_by_user.get( user, {}) values_by_provider = get_deploy_values_by_provider( notification_settings_by_scope, notification_providers()) for provider, value in values_by_provider.items(): reason_option = get_reason(user, value, user_ids) if reason_option: users_to_reasons_by_provider[provider][user] = reason_option return users_to_reasons_by_provider
def test_get_deploy_values_by_provider(self): notification_settings_by_scope = { NotificationScopeType.ORGANIZATION: { ExternalProviders.EMAIL: NotificationSettingOptionValues.COMMITTED_ONLY }, NotificationScopeType.USER: { ExternalProviders.EMAIL: NotificationSettingOptionValues.ALWAYS }, } values_by_provider = get_deploy_values_by_provider( notification_settings_by_scope, notification_providers()) assert values_by_provider == { ExternalProviders.EMAIL: NotificationSettingOptionValues.COMMITTED_ONLY, ExternalProviders.SLACK: NotificationSettingOptionValues.COMMITTED_ONLY, }