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

v2 API: add endpoint to activate and deactivate users #1007

Merged
merged 5 commits into from
Dec 4, 2024

Conversation

JerrySentry
Copy link
Contributor

Introduce endpoint
PATCH /api/v2/{service}/{owner_username}/users/{user_username_or_ownerid}/
to activate or deactivate the specified user via request body:
{activated: boolean}

closes: codecov/feedback#559

Screenshot 2024-11-28 at 2 58 42 PM

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.00%. Comparing base (591a7ab) to head (da38239).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1007   +/-   ##
=======================================
  Coverage   96.00%   96.00%           
=======================================
  Files         828      828           
  Lines       19353    19373   +20     
=======================================
+ Hits        18579    18599   +20     
  Misses        774      774           
Flag Coverage Δ
unit 92.26% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 92.26% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

codecov-notifications bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@JerrySentry JerrySentry marked this pull request as ready for review November 28, 2024 20:21
Copy link
Contributor

@suejung-sentry suejung-sentry left a comment

Choose a reason for hiding this comment

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

I'm probably missing it but where do we do the check that only an admin is allowed to perform this action?

EDIT - oh I see, we didn't intend to restrict this to admins only (same as in our existing UI). Sounds good then - approved this!

Updates a user for the specified owner_username or ownerid

Allowed fields
- activated: boolean value to activate or deactivate the use
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo "deactivate the user"


if serializer.validated_data["activated"]:
if self.owner.can_activate_user(instance):
print("can activate")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: stray print

self.owner.activate_user(instance)
else:
raise PermissionDenied(
f"Cannot activate user {self.owner.username} -- not enough seats left."
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this is lifted from the existing internal PATCH endpoint but seems like 403 Permission Denied is a weird status code if the reason is "not enough seats". What do you think of like 409 conflict or 400 invalid request?

Also pet peeve that the can_activate_user function should be named like has_enough_seats if we intend to tie error messages to be tied to that specific condition (or emit the various reasons for the error from can_activate_user). But probably not much gain for a lot of work so can just leave as is.

@JerrySentry JerrySentry added this pull request to the merge queue Dec 4, 2024
Merged via the queue into main with commit 6b47a93 Dec 4, 2024
19 checks passed
@JerrySentry JerrySentry deleted the nov_28_activate_api branch December 4, 2024 17:27
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.

Feature Request: Enable User Activation/Deactivation via API
2 participants