Beispiel #1
0
def validate_type(
        type: str,
        context: Optional[List[str]] = None) -> NotificationSettingTypes:
    try:
        return NotificationSettingTypes(type)
    except ValueError:
        raise ParameterValidationError(f"Unknown type: {type}", context)
Beispiel #2
0
def get_legacy_object(
    notification_setting: Any,
    actor_mapping: Mapping[int, Any],
    parent_mapping: Mapping[int, Any],
    organization_mapping: Mapping[int, Any],
) -> Any:
    type = NotificationSettingTypes(notification_setting.type)
    value = NotificationSettingOptionValues(notification_setting.value)
    scope_type = NotificationScopeType(notification_setting.scope_type)
    key = get_legacy_key(type, scope_type)

    data = {
        "key": key,
        "value": get_legacy_value(type, value),
        "user": actor_mapping.get(notification_setting.target_id),
        "project": None,
        "organization": None,
    }

    if scope_type == NotificationScopeType.PROJECT:
        data["project"] = parent_mapping.get(
            notification_setting.scope_identifier)
    if scope_type == NotificationScopeType.ORGANIZATION:
        data["organization"] = organization_mapping.get(
            notification_setting.scope_identifier)

    return LegacyUserOptionClone(**data)