Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions src/sentry/api/endpoints/project_rule_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ def put(self, request: Request, project, rule) -> Response:
)
rule_data_before["label"] = rule.label

for action in request.data.get("actions", []):
if action["id"] == "sentry.integrations.slack.notify_action.SlackNotifyServiceAction":
if not action["channel_id"] and not action["channel"]:
continue

for old_action in rule_data_before.get("actions", []):
if (
old_action["id"]
== "sentry.integrations.slack.notify_action.SlackNotifyServiceAction"
):
if (
action["channel_id"] == old_action["channel_id"]
and action["channel"] != old_action["channel"]
):
del action["channel_id"]

elif (
action["channel"] == old_action["channel"]
and action["channel_id"] != old_action["channel_id"]
):
del action["channel"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might not work as intended. iirc, we actually just fetch channel_id from slack, never the channel so this might just permanently leave channel empty


serializer = DrfRuleSerializer(
context={"project": project, "organization": project.organization},
data=request.data,
Expand Down
15 changes: 11 additions & 4 deletions tests/sentry/api/endpoints/test_project_rule_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from sentry.constants import ObjectStatus
from sentry.deletions.tasks.scheduled import run_scheduled_deletions
from sentry.integrations.slack.utils.channel import strip_channel_name
from sentry.integrations.slack.utils.channel import SlackChannelIdData, strip_channel_name
from sentry.models.environment import Environment
from sentry.models.rule import NeglectedRule, Rule, RuleActivity, RuleActivityType
from sentry.models.rulefirehistory import RuleFireHistory
Expand Down Expand Up @@ -1076,7 +1076,10 @@ def test_with_null_environment(self):
assert response.data["environment"] is None
assert_rule_from_payload(self.rule, payload)

def test_update_channel_slack_workspace_fail_sdk(self):
@patch(
"sentry.integrations.slack.utils.channel.get_channel_id_with_timeout",
)
def test_update_channel_slack_workspace_saved(self, mock_get_channel_id_with_timeout):
conditions = [{"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition"}]
actions = [
{
Expand All @@ -1095,6 +1098,9 @@ def test_update_channel_slack_workspace_fail_sdk(self):
{"name": "new_channel_name", "id": "new_channel_id"},
],
}
mock_get_channel_id_with_timeout.return_value = SlackChannelIdData(
prefix="#", channel_id="new_channel_id", timed_out=False
)

with self.mock_conversations_list(channels["channels"]):
with self.mock_conversations_info(channels["channels"][0]):
Expand All @@ -1107,11 +1113,12 @@ def test_update_channel_slack_workspace_fail_sdk(self):
"conditions": conditions,
"frequency": 30,
}
self.get_error_response(

self.get_success_response(
self.organization.slug,
self.project.slug,
self.rule.id,
status_code=400,
status_code=200,
**payload,
)

Expand Down
Loading