Skip to content

Conversation

@scefali
Copy link
Contributor

@scefali scefali commented Jul 17, 2019

This PR adds a route to mark a sentry app as installed after receiving an access token from the grant. Here's what the request object should look like in JS:

 {
     url: `api/0/sentry-app-installations/${installationId}/`,
     method: 'PUT',
     data: { status: 'installed'  }
}

There is validation on the value of status. It must either be installed or pending. And there is validation to make sure we never go from installed to pending.

I had to make a hack in has_permission in SentryAppInstallationPermission to ignore the usual permission checks for marking the sentry app as installed. This is because a sentry app that has no permissions should still be able to be marked as installed by the proxy hack.

@scefali scefali requested review from MeredithAnya and mnoble July 17, 2019 17:35
def has_permission(self, request, *args, **kwargs):
# To let the app mark the installation as installed, we don't care about permissions
if request.user.is_sentry_app:
if request.method == 'PUT':
Copy link
Contributor

Choose a reason for hiding this comment

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

Can probably combine the two above conditions into one.

),
)
# convert status to str for comparison
last_status = SentryAppInstallationStatus.as_str(self.instance.status)
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is used when creating a new SentryAppInstallation, self.instance is going to be None, so we should probably wrap this whole part in if self.instance.

serializer = SentryAppInstallationSerializer(
installation,
data=request.data,
partial=True,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need the partial=True here since we expect the status to be in the request.data and that's the only thing you are validating

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be good to keep it, though. Updating is almost always going to allow only a portion of the required data (opposed to requiring all fields).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put it back

def validate_status(self, new_status):
# make sure the status in in our defined list
try:
SentryAppInstallationStatus.STATUS_MAP[new_status]
Copy link
Member

@MeredithAnya MeredithAnya Jul 17, 2019

Choose a reason for hiding this comment

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

so I don't think we necessarily need the STATUS_MAP - if we only allow for updating to be installed we can probs just do that explicitly

if new_status != SentryAppInstallationStatus.INSTALLED:
    raise ValidationError(u"Invalid value '{}' for status".format(new_status))

That way we don't have to worry about the check below since we don't let anyone explicitly set an installation's status to pending

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MeredithAnya I talked to @mnoble about this and he said we should let our APIs be idempotent (see https://restfulapi.net/idempotent-rest-apis/). In other words, if the installation is pending we shouldn't throw an error if the request sets it to pending.

Copy link
Member

Choose a reason for hiding this comment

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

They can write client code in such a way that there can be duplicate requests as well.

To me that's not what we are saying here imo. It seems like pending is a state that is never set directly by the developer. Like they should never be trying to set the status to pending.

Copy link
Contributor Author

@scefali scefali Jul 17, 2019

Choose a reason for hiding this comment

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

@MeredithAnya I am OK with either approach but I'd like to know what @mnoble thinks before making the change

Copy link
Contributor

@mnoble mnoble left a comment

Choose a reason for hiding this comment

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

🚀

@scefali scefali merged commit 6d320b1 into master Jul 17, 2019
@scefali scefali deleted the feat/mark-sentry-app-installed-put-route branch July 17, 2019 23:15
HazAT added a commit that referenced this pull request Jul 19, 2019
* master:
  ref(admin): Convert user edit page to react (#14074)
  ref: Remove unused Group.get_oldest_event and legacy events behavior (#14038)
  ref(api): Update DELETE users/ to support hard deleting (#14068)
  test(OrganizationDiscoverSavedQueryDetailTest): Stabilize put test (#14077)
  meta(readme): Sentry logo should link to sentry.io (#14076)
  ref: Remove duplicate column (#14073)
  App platform/update permissions token auth (#14046)
  feat: Support issue IDs as canonical parameters
  ref: Change to new traceparent header for Python SDK (#14070)
  feat: Use option to force-disable transaction events (#14056)
  feat(apm): Register option to force-disable transaction events (#14055)
  Feat/mark sentry app installed put route (#14060)
  ref: Remove unused Group.event_set property  (#14036)
  fix: Filter out groups that are pending deletion/merge from `by_qualified_short_id` (SEN-849)
  fix(ui): Fix resolve/ignore actions for accounts without multi… (#14058)
  Fix: Remove extra $.param introduced in GH-14051 (#14061)
  feat: Use Snuba for Group.from_event_id (#14034)
  fix(ui) Display implicit default sort and default to descending (#14042)
  fix(github) Fix 404s not being handled in repository search (#14030)
  fix: Pass an empty array to $.param instead of an empty string when options.query is falsey (#14051)

# Conflicts:
#	src/sentry/utils/sdk.py
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants