Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add incident creation API endpoint #1056

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft

Conversation

noah-schechter
Copy link
Collaborator

@noah-schechter noah-schechter commented Dec 27, 2024

Note: This is my first change to Atlos that involves write access and permissions changes. While I've approached this feature thoughtfully, it involves changes to fairly high-risk code paths and so is deserving of an extra layer of scrutiny before merging.

Changes
This PR involves four main types of changes:

  • Changes to functions involved in creating media and assessing permissions to support an %APIToken{} instead of a %User{}.
  • Changes to the v2 API to handle a new api/v2/incidents/new endpoint.
  • Additions of several tests of basic functionality.
  • Updates to the API documentation.

Questions
A few implementation notes and questions:

  • The endpoint currently handles all attributes, all metadata other than deleted and assignments, and the urls field. A few questions:
    • I'd appreciate your guidance on what is going wrong with the deleted field; I'm not sure why the endpoint isn't handling these values.
    • Let me know if you think it's essential we include assignments; I think this requires a larger change to the cast() usage in Media.changeset/3. We also don't surface users' IDs so this would also require a smaller change to the in-platform API documentation on the Access page.
    • Unlike attributes' value validation, the urls list validation fails silently—an otherwise well-formed API call with "url" => ["foobar"] results in a successful incident creation, but the URL is not archived or added as a piece of source material. Let me know if it's ok to add validation for this at the APIV2Controller layer; I wasn't sure where to add this validation otherwise.

A Note on Regressions
In the course of developing this endpoint, I encountered two previously undocumented bugs. We should fix these, but it's worth noting, both for review of this PR and for root causing of these bugs, that they were not caused by this PR. The two bugs are:

  • The incident creation modal flashes for a moment when it initially loads.
  • The incident creation modal doesn't display an error message for invalid URLs, but the Create Incident button fails to allow the user to create an incident without invalid URLs, so the user becomes stuck on the incident creation modal.

Copy link

netlify bot commented Dec 27, 2024

Deploy Preview for atlos-docs ready!

Name Link
🔨 Latest commit 2ad6551
🔍 Latest deploy log https://app.netlify.com/sites/atlos-docs/deploys/67770405fcdba30008d9947e
😎 Deploy Preview https://deploy-preview-1056--atlos-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@milesmcc milesmcc left a comment

Choose a reason for hiding this comment

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

did not test live, but this approach looks good to me! see minor comments.

docs/content/docs/Technical/api.md Show resolved Hide resolved
docs/content/docs/Technical/api.md Outdated Show resolved Hide resolved
platform/lib/platform/material.ex Outdated Show resolved Hide resolved
platform/lib/platform/permissions.ex Show resolved Hide resolved
platform/lib/platform/updates.ex Outdated Show resolved Hide resolved
@@ -209,43 +238,50 @@ defmodule Platform.Material.Media do
changeset
end

def validate_project(changeset, user \\ nil, media \\ nil) do
def validate_project(changeset, media \\ [], opts) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function is confusing to me — so much is going on. what is the purpose of this function? to make sure that the user or token can edit media within a project?

Copy link
Collaborator

Choose a reason for hiding this comment

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

this function would benefit a lot from either a comment or a rename

Copy link
Collaborator

Choose a reason for hiding this comment

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

considering it doesn't operate on projects but media, the name seems confusing at best and wrong at worst

Copy link
Collaborator

Choose a reason for hiding this comment

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

👻

Copy link
Collaborator

Choose a reason for hiding this comment

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

(to be clear, I wrote this function)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree the name is cursed.💀 Just added a short comment to reflect that validate_project validates changes to an incident's project, not the project itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(Working on a deeper change to this function so that we actually do validate that the API Token is permitted to edit the incident's project.)

platform/lib/platform/material/media.ex Show resolved Hide resolved
@noah-schechter noah-schechter marked this pull request as draft January 2, 2025 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants