Skip to content

Commit

Permalink
Merge pull request #80 from edx/bseverino/rest-api
Browse files Browse the repository at this point in the history
[MST-1361] Add patch and delete to VerifiedNameView
  • Loading branch information
bseverino authored Mar 1, 2022
2 parents 6e416cb + a890073 commit c5ba5ee
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 63 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Change Log
Unreleased
~~~~~~~~~~

[2.3.0] - 2022-02-28
~~~~~~~~~~~~~~~~~~~~
* Add REST API functionality to update verified name status, and to delete verified names.

[2.2.1] - 2022-02-23
~~~~~~~~~~~~~~~~~~~~
* Update verified name status to `denied` if proctoring `error` status is received
Expand Down
2 changes: 1 addition & 1 deletion edx_name_affirmation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Django app housing name affirmation logic.
"""

__version__ = '2.2.1'
__version__ = '2.3.0'

default_app_config = 'edx_name_affirmation.apps.EdxNameAffirmationConfig' # pylint: disable=invalid-name
21 changes: 20 additions & 1 deletion edx_name_affirmation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import logging

from django.core.exceptions import ObjectDoesNotExist

from edx_name_affirmation.exceptions import (
VerifiedNameAttemptIdNotGiven,
VerifiedNameDoesNotExist,
Expand Down Expand Up @@ -100,6 +102,21 @@ def get_verified_name(user, is_verified=False, statuses_to_exclude=None):
return verified_name_qs.first()


def delete_verified_name(verified_name_id):
"""
Delete a VerifiedName.
"""
try:
verified_name = VerifiedName.objects.get(id=verified_name_id)
verified_name.delete()
except ObjectDoesNotExist as exc:
err_msg = (
'Attempted to delete verified_name_id={verified_name_id}'
'but it does not exist'.format(verified_name_id=verified_name_id)
)
raise VerifiedNameDoesNotExist(err_msg) from exc


def get_verified_name_history(user):
"""
Return a QuerySet of all VerifiedNames for a given user, ordered by the date created from
Expand Down Expand Up @@ -215,7 +232,7 @@ def update_verified_name_status(
)
raise VerifiedNameDoesNotExist(err_msg)

verified_name_obj.status = status.value
verified_name_obj.status = status
verified_name_obj.save()

log_msg = (
Expand All @@ -230,6 +247,8 @@ def update_verified_name_status(
)
log.info(log_msg)

return verified_name_obj


def create_verified_name_config(user, use_verified_name_for_certs=None):
"""
Expand Down
12 changes: 11 additions & 1 deletion edx_name_affirmation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Meta:
model = VerifiedName

fields = (
"created", "username", "verified_name", "profile_name", "verification_attempt_id",
"id", "created", "username", "verified_name", "profile_name", "verification_attempt_id",
"proctored_exam_attempt_id", "status"
)

Expand All @@ -54,6 +54,16 @@ def _contains_url(self, string):
return bool(regex)


class UpdateVerifiedNameSerializer(VerifiedNameSerializer):
"""
Serializer for updates to the VerifiedName Model.
"""
username = serializers.CharField(source='user.username', required=True)
verified_name = serializers.CharField(required=False)
profile_name = serializers.CharField(required=False)
status = serializers.CharField(required=True)


class VerifiedNameConfigSerializer(serializers.ModelSerializer):
"""
Serializer for the VerifiedNameConfig Model.
Expand Down
Loading

0 comments on commit c5ba5ee

Please sign in to comment.