Repository navigation
feat(admin): create and delete alerts and reports on behalf of a user - #10232
nishantmonu51 wants to merge 10 commits into
Conversation
Adds CreateAlertForUser, DeleteAlertForUser, CreateReportForUser and DeleteReportForUser, and exposes them to the runtime through the admin service driver, for the AI tools that create alerts and reports from the chat. - Only the project's primary deployment can call them, for a user of the project, as it does for GetAlertMeta, GetReportMeta and GetConnectorOAuthToken. - They write the same managed YAML as CreateAlert and CreateReport, owned by the user, through shared helpers. - What they create only reaches project members: recipients default to the user, other recipients must be members of the project, and Slack channels and webhooks are rejected. - Delete only deletes the user's own alerts and reports, even for users who can manage others'. - The runtime's AdminService takes the admin proto's AlertOptions and ReportOptions, instead of a copy of them. Based on the reviewed design of #10121, which also listed and edited alerts and reports; editing from the chat is out of scope for now. Co-authored-by: dfliess <dfliess@gmail.com>
…ment config causes
…e a deployed runtime's repo
nishantmonu51
left a comment
There was a problem hiding this comment.
A couple of API details and a small cleanup inline.
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| return user, projPerms, nil |
There was a problem hiding this comment.
Could we check projPerms.ReadProd here? The regular DeleteAlert and DeleteReport endpoints both check current production access before checking ownership. The new delete handlers only check ownership, so their behavior diverges after a user's project access is revoked.
There was a problem hiding this comment.
Fixed in 8883105: userForPrimaryDeployment now rejects users without ReadProd, so all four RPCs, deletes included, match the regular endpoints; a new subtest covers a user removed from the project.
| return nil, err | ||
| } | ||
|
|
||
| org, err := s.admin.DB.FindOrganization(ctx, proj.OrganizationID) |
There was a problem hiding this comment.
Both create RPCs fetch the organization after writing and reconciling the resource. If that lookup fails, chat reports a failed create even though the alert or report exists. A retry uses a fresh name and can schedule duplicate notifications. Could we move FindOrganization above createManagedAlert and createManagedReport?
There was a problem hiding this comment.
Fixed in 8883105: both create RPCs look up the organization before creating the alert or report.
| return []string{user.Email}, nil | ||
| } | ||
|
|
||
| for _, recipient := range append(append([]string{}, emails...), slackUsers...) { |
There was a problem hiding this comment.
Could we use slices.Concat(emails, slackUsers) here? It gives the same iteration order and leaves the caller's slices alone without the nested appends.
There was a problem hiding this comment.
Fixed in 8883105: uses slices.Concat(emails, slackUsers).
|
This is the shape we wanted: four RPCs that share their helpers with Allow Slack channels. "Alert me in #sales-ops" is a common request, and a channel sits inside the Slack workspace that the project's admin configured. Please let The Developed in collaboration with Claude Code |
… and drop the url response field after review - recipientsForUser allows Slack channels, which are in the workspace the project's admin configured, and still rejects webhooks. The user's email is only the default when there are no recipients at all. - CreateAlertForUserResponse and CreateReportForUserResponse no longer return a url, so the handlers skip the organization lookup; the runtime builds the page URL from the instance's frontend URL.
|
@pjain1 Thanks, both done in b6c94e0 (after merging #10231 in 2459b49):
|
nishantmonu51
left a comment
There was a problem hiding this comment.
Two things on Slack delivery.
| // Slack channels are allowed, since they're in the Slack workspace the project's admin configured, | ||
| // and Slack webhooks, which can be any URL, are rejected. | ||
| func (s *Server) recipientsForUser(ctx context.Context, proj *database.Project, user *database.User, emails, slackUsers, slackChannels, slackWebhooks []string) ([]string, error) { | ||
| if len(slackWebhooks) > 0 { |
There was a problem hiding this comment.
Can recipientsForUser require a verified internal Slack channel here? sendTextToChannels passes the destination straight to chat.postMessage, which also accepts DM destinations, and Slack Connect channels can have readers outside the workspace. That can send an alert’s rows or a report’s summary beyond the intended audience. Resolve the destination to a channel ID and check its conversation type and external-sharing status before accepting it. Posting destinations · Slack Connect channel flags
There was a problem hiding this comment.
Partly fixed in 7f91a46: @name and user or DM IDs (U/W/D) are now rejected as channels, so people are only reached as Slack users who are project members; ruling out Slack Connect channels needs a conversations.info call with the project's Slack token, which only the runtime has, so I've left that for a decision (the regular create endpoints and the form don't check channels either).
| if len(slackWebhooks) > 0 { | ||
| return nil, status.Error(codes.InvalidArgument, "the AI can't send to Slack webhooks, since they can be any URL") | ||
| } | ||
| if len(emails) == 0 && len(slackUsers) == 0 && len(slackChannels) == 0 { |
There was a problem hiding this comment.
A Slack-only alert or report can now be created in a project with no Slack setup, with no email fallback. The user gets a success response and delivery fails later in sendTextToChannels. Could the for-user create path check notifier availability before saving and tell the user to configure Slack or choose email? The web form already checks ListNotifierConnectors in FormMetadataProvider.
…a user after review chat.postMessage also takes "@name" and user or direct message IDs as a channel, which would reach people who aren't members of the project.
Takes over #10121, reduced to create and delete as its review asked. Stacked on #10231.
CreateAlertForUser,DeleteAlertForUser,CreateReportForUserandDeleteReportForUserlet the runtime act for the user of its AI session. They write the same managed YAML asCreateAlertandCreateReport, through shared helpers.GetAlertMeta,GetReportMetaandGetConnectorOAuthToken. The trust-model decision for feat(ai): let the analyst create and edit the user's personal dashboards #10030 is still open; this follows whatever is decided there.save_alert,list_alerts) #10122 review: recipients default to the user, other email and Slack-user recipients must be project members, and Slack channels and webhooks are rejected. What the AI creates can't send data outside the project.AdminServicetakesadminv1.AlertOptionsandadminv1.ReportOptions, so there's no third copy of the options.Checklist: