Skip to content

Commit

Permalink
Merge branch 'master' into ryan953/replay-a11y-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan953 authored Nov 27, 2023
2 parents 427047d + 72ac7ce commit 707144e
Show file tree
Hide file tree
Showing 55 changed files with 1,948 additions and 399 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
"style-loader": "^3.3.1",
"ts-node": "^10.9.1",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"u2f-api": "1.0.10",
"url-loader": "^4.1.0",
"webpack": "5.87.0",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ module = [
"sentry.api.endpoints.user_identity_config",
"sentry.api.endpoints.user_index",
"sentry.api.endpoints.user_notification_details",
"sentry.api.endpoints.user_notification_fine_tuning",
"sentry.api.endpoints.user_permission_details",
"sentry.api.endpoints.user_permissions",
"sentry.api.endpoints.user_permissions_config",
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ sortedcontainers==2.4.0
soupsieve==2.3.2.post1
sqlparse==0.4.4
statsd==3.3
stripe==2.61.0
stripe==3.1.0
structlog==22.1.0
symbolic==12.7.0
time-machine==2.13.0
Expand Down
2 changes: 1 addition & 1 deletion requirements-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ snuba-sdk==2.0.9
soupsieve==2.3.2.post1
sqlparse==0.4.4
statsd==3.3
stripe==2.61.0
stripe==3.1.0
structlog==22.1.0
symbolic==12.7.0
toronado==0.1.0
Expand Down
2 changes: 1 addition & 1 deletion requirements-getsentry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ PlanOut==0.6.0
pycountry==17.5.14
pyvat==1.3.15
reportlab==3.6.13
stripe==2.61.0
stripe==3.1.0
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
from rest_framework.request import Request
from rest_framework.response import Response

from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import control_silo_endpoint
from sentry.api.bases import SentryAppInstallationsBaseEndpoint
from sentry.api.fields.sentry_slug import SentrySlugField
from sentry.api.paginator import OffsetPaginator
from sentry.api.serializers import serialize
from sentry.constants import SENTRY_APP_SLUG_MAX_LENGTH
Expand All @@ -14,21 +14,7 @@


class SentryAppInstallationsSerializer(serializers.Serializer):
slug = serializers.RegexField(
r"^[a-z0-9_\-]+$",
max_length=SENTRY_APP_SLUG_MAX_LENGTH,
error_messages={
"invalid": _(
"Enter a valid slug consisting of lowercase letters, "
"numbers, underscores or hyphens."
)
},
)

def validate(self, attrs):
if not attrs.get("slug"):
raise serializers.ValidationError("Sentry App slug is required")
return attrs
slug = SentrySlugField(required=True, max_length=SENTRY_APP_SLUG_MAX_LENGTH)


@control_silo_endpoint
Expand Down
71 changes: 49 additions & 22 deletions src/sentry/api/endpoints/user_notification_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import control_silo_endpoint
from sentry.api.bases.user import UserEndpoint
from sentry.api.fields.empty_integer import EmptyIntegerField
from sentry.api.serializers import Serializer, serialize
from sentry.models.notificationsetting import NotificationSetting
from sentry.models.options.user_option import UserOption
from sentry.notifications.types import UserOptionsSettingsKey

USER_OPTION_SETTINGS = {
UserOptionsSettingsKey.SELF_ACTIVITY: {
"key": "self_notifications",
"default": "0",
"type": bool,
},
UserOptionsSettingsKey.SELF_ASSIGN: {
"key": "self_assign_issue",
"default": "0",
"type": bool,
},
}
from sentry.notifications.types import NotificationScopeType, UserOptionsSettingsKey
from sentry.notifications.utils.legacy_mappings import (
USER_OPTION_SETTINGS,
get_option_value_from_int,
get_type_from_user_option_settings_key,
map_notification_settings_to_legacy,
)
from sentry.types.integrations import ExternalProviders


class UserNotificationsSerializer(Serializer):
Expand All @@ -32,6 +28,19 @@ def get_attrs(self, item_list, user, *args, **kwargs):
).select_related("user")
keys_to_user_option_objects = {user_option.key: user_option for user_option in user_options}

notification_settings = NotificationSetting.objects._filter(
ExternalProviders.EMAIL,
scope_type=NotificationScopeType.USER,
user_ids=[user.id for user in item_list],
)
notification_settings_as_user_options = map_notification_settings_to_legacy(
notification_settings, user_mapping={user.id: user for user in item_list}
)

# Override deprecated UserOption rows with NotificationSettings.
for user_option in notification_settings_as_user_options:
keys_to_user_option_objects[user_option.key] = user_option

results = defaultdict(list)
for user_option in keys_to_user_option_objects.values():
results[user_option.user].append(user_option)
Expand All @@ -48,13 +57,21 @@ def serialize(self, obj, attrs, user, *args, **kwargs):
elif uo["type"] == int:
data[key.value] = int(val)

data["weeklyReports"] = True # This cannot be overridden

return data


# only expose legacy options
class UserNotificationDetailsSerializer(serializers.Serializer):
deployNotifications = EmptyIntegerField(
required=False, min_value=2, max_value=4, allow_null=True
)
personalActivityNotifications = serializers.BooleanField(required=False)
selfAssignOnResolve = serializers.BooleanField(required=False)
subscribeByDefault = serializers.BooleanField(required=False)
workflowNotifications = EmptyIntegerField(
required=False, min_value=0, max_value=2, allow_null=True
)


@control_silo_endpoint
Expand Down Expand Up @@ -83,12 +100,22 @@ def put(self, request: Request, user) -> Response:
status=status.HTTP_400_BAD_REQUEST,
)

user_option, _ = UserOption.objects.get_or_create(
key=USER_OPTION_SETTINGS[key]["key"],
user=user,
project_id=None,
organization_id=None,
)
user_option.update(value=str(int(value)))
type = get_type_from_user_option_settings_key(key)
if type:
NotificationSetting.objects.update_settings(
ExternalProviders.EMAIL,
type,
get_option_value_from_int(type, int(value)),
user_id=user.id,
)
else:
# Legacy user options which does not include weekly report
user_option, _ = UserOption.objects.get_or_create(
key=USER_OPTION_SETTINGS[key]["key"],
user=user,
project_id=None,
organization_id=None,
)
user_option.update(value=str(int(value)))

return self.get(request, user)
66 changes: 0 additions & 66 deletions src/sentry/api/endpoints/user_notification_email.py

This file was deleted.

Loading

0 comments on commit 707144e

Please sign in to comment.