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

feat: add new endpoint to unlink the logged in user #2279

Merged
merged 1 commit into from
Nov 1, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Unreleased
----------
* nothing unreleased

[4.31.0]
--------
* feat: add new endpoint to unlink the logged in user.

[4.30.1]
--------
* fix: serialize best_mode_for_course_run field in DefaultEnterpriseEnrollmentIntentionSerializer.
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.30.1"
__version__ = "4.31.0"
26 changes: 25 additions & 1 deletion enterprise/api/v1/views/enterprise_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
HTTP_202_ACCEPTED,
HTTP_400_BAD_REQUEST,
HTTP_409_CONFLICT,
HTTP_422_UNPROCESSABLE_ENTITY,
)

from django.contrib import auth
Expand Down Expand Up @@ -460,7 +461,6 @@
"""
Unlinks users with the given emails from the enterprise.
"""

serializer = serializers.EnterpriseCustomerUnlinkUsersSerializer(
data=request.data
)
Expand All @@ -487,3 +487,27 @@
raise UnlinkUserFromEnterpriseError(msg) from exc

return Response(status=HTTP_200_OK)

@action(methods=['post'], detail=True, permission_classes=[permissions.IsAuthenticated])
def unlink_self(self, request, pk=None): # pylint: disable=unused-argument
"""
Unlink request user from the enterprise.
"""
user_email = request.user.email
enterprise_customer = self.get_object()

Check warning on line 497 in enterprise/api/v1/views/enterprise_customer.py

View check run for this annotation

Codecov / codecov/patch

enterprise/api/v1/views/enterprise_customer.py#L496-L497

Added lines #L496 - L497 were not covered by tests

try:
models.EnterpriseCustomerUser.objects.unlink_user(

Check warning on line 500 in enterprise/api/v1/views/enterprise_customer.py

View check run for this annotation

Codecov / codecov/patch

enterprise/api/v1/views/enterprise_customer.py#L499-L500

Added lines #L499 - L500 were not covered by tests
enterprise_customer=enterprise_customer, user_email=user_email, is_relinkable=True
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to never relink?

)
except (models.EnterpriseCustomerUser.DoesNotExist, models.PendingEnterpriseCustomerUser.DoesNotExist):
msg = "[UNLINK_SELF] User with email {} does not exist in enterprise {}.".format(

Check warning on line 504 in enterprise/api/v1/views/enterprise_customer.py

View check run for this annotation

Codecov / codecov/patch

enterprise/api/v1/views/enterprise_customer.py#L504

Added line #L504 was not covered by tests
user_email, enterprise_customer
)
LOGGER.warning(msg)
jajjibhai008 marked this conversation as resolved.
Show resolved Hide resolved
return Response(status=HTTP_422_UNPROCESSABLE_ENTITY)
except Exception as exc:
msg = "[UNLINK_SELF] Could not unlink {} from {}".format(user_email, enterprise_customer)
raise UnlinkUserFromEnterpriseError(msg) from exc

Check warning on line 511 in enterprise/api/v1/views/enterprise_customer.py

View check run for this annotation

Codecov / codecov/patch

enterprise/api/v1/views/enterprise_customer.py#L507-L511

Added lines #L507 - L511 were not covered by tests

return Response(status=HTTP_200_OK)

Check warning on line 513 in enterprise/api/v1/views/enterprise_customer.py

View check run for this annotation

Codecov / codecov/patch

enterprise/api/v1/views/enterprise_customer.py#L513

Added line #L513 was not covered by tests
Loading