Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/release-freeze' into release-can…
Browse files Browse the repository at this point in the history
…didate
  • Loading branch information
wajeeha-khalid committed Mar 28, 2019
2 parents 9cf6ba8 + 0114f42 commit 4ddaf7b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
3 changes: 3 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,9 @@
# Completion
'completion',
'completion_aggregator',

# Profile image
'openedx.core.djangoapps.profile_images',
)


Expand Down
3 changes: 3 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,9 @@

# User Manager API
'user_manager',

# Profile image
'openedx.core.djangoapps.profile_images',
)

######################### CSRF #########################################
Expand Down
20 changes: 20 additions & 0 deletions lms/lib/comment_client/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ def _retrieve(self, *args, **kwargs):
raise
self._update_from_response(response)

def retire(self, retired_username):
url = _url_for_retire(self.id)
params = {'retired_username': retired_username}

perform_request(
'post',
url,
params,
raw=True,
metric_action='user.retire',
metric_tags=self._metric_tags
)


def get_user_social_stats(user_id, course_id, end_date=None, thread_type=None, thread_ids=None):
""" Queries cs_comments_service for social_stats """
Expand Down Expand Up @@ -266,3 +279,10 @@ def _url_for_read(user_id):
Returns cs_comments_service url endpoint to mark thread as read for given user_id
"""
return "{prefix}/users/{user_id}/read".format(prefix=settings.PREFIX, user_id=user_id)


def _url_for_retire(user_id):
"""
Returns cs_comments_service url endpoint to retire a user (remove all post content, etc.)
"""
return "{prefix}/users/{user_id}/retire".format(prefix=settings.PREFIX, user_id=user_id)
38 changes: 31 additions & 7 deletions openedx/core/djangoapps/user_api/accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@
from django.utils.translation import override as override_language, ugettext as _
from django.db import transaction, IntegrityError
import datetime

from pytz import UTC
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from django.core.validators import validate_email, ValidationError
from django.http import HttpResponseForbidden
from openedx.core.djangoapps.profile_images.tasks import delete_profile_images
from openedx.core.djangoapps.user_api.preferences.api import update_user_preferences
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.user_api.errors import PreferenceValidationError
from openedx.core.lib.api.view_utils import add_serializer_errors

from student.models import User, UserProfile, Registration
from student import forms as student_forms
from student import views as student_views
from util.model_utils import emit_setting_changed_event
from lms.lib.comment_client.user import User as CCUser
from lms.lib.comment_client.utils import CommentClientRequestError

from openedx.core.lib.api.view_utils import add_serializer_errors
from edx_notifications.lib import admin as notification_admin

from ..errors import (
AccountUpdateError, AccountValidationError, AccountUsernameInvalid, AccountPasswordInvalid,
Expand All @@ -38,7 +40,6 @@
AccountLegacyProfileSerializer, AccountUserSerializer,
UserReadOnlySerializer, _visible_fields # pylint: disable=invalid-name
)
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers


# Public access point for this function.
Expand Down Expand Up @@ -559,19 +560,42 @@ def delete_users(users):
1. models with a ForeignKey relationship to User (with on_delete=CASCADE).
2. models with indirect relationship to User (i.e. through another model, or with on_delete other than CASCADE)
3. files belonging to the user.
4. user notifications in edx-notification models
Arguments:
users: An iterable of 'User' objects.
Returns:
None
results array of dictionaries with user email and error message or None in case of success
Raises:
UserAPIInternalError
"""
failed = {}
for user in users:
retire_user_comments(user)
try:
retire_user_comments(user)
except Exception as e:
failed[user.email] = str(e)

# Delete user profile images in background task
usernames = list(users.values_list('username', flat=True))
delete_profile_images.delay(usernames)

delete_profile_images.delay(users)
# Delete notifications
user_ids = users.values_list('id', flat=True)
notification_admin.purge_user_data(user_ids)

# Delete notifications that mention the users, e.g. group work
for username in usernames:
payload = '"action_username": "{}"'.format(username)
notification_admin.purge_notifications_with_payload(payload)

# Finally delete user and related models
for user in users.exclude(email__in=failed):
try:
user.delete()
except Exception as e:
failed[user.email] = str(e)

users.delete()
return failed
5 changes: 3 additions & 2 deletions openedx/core/djangoapps/user_api/accounts/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ def test_delete_user(self, mock_delete_profile_images, mock_ccuser):
user1 = UserFactory.create(password='secret')
user2 = UserFactory.create(password='secret')

users_qs = User.objects.filter(username__in=[user1.username, user2.username])
usernames = [user1.username, user2.username]
users_qs = User.objects.filter(username__in=usernames)

# Delete the users
delete_users(users_qs)
Expand All @@ -521,7 +522,7 @@ def test_delete_user(self, mock_delete_profile_images, mock_ccuser):
])

# Verify that the delete_profile_images task is called
mock_delete_profile_images.delay.assert_called_with(users_qs)
mock_delete_profile_images.delay.assert_called_with(usernames)

# Verify that the user objects have been deleted
self.assertEqual(User.objects.filter(username__in=[user1.username, user2.username]).count(), 0)
14 changes: 7 additions & 7 deletions requirements/edx/custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# When updating a hash of an XBlock that uses xblock-utils, please update its version hash in github.txt.
-e git+https://github.com/edx-solutions/xblock-mentoring.git@8837eb5d91fed05ec4758dfd9b9e7adc5c906210#egg=xblock-mentoring
-e git+https://github.com/edx-solutions/[email protected].2#egg=xblock-image-explorer==1.1.2
-e git+https://github.com/edx-solutions/[email protected].3#egg=xblock-image-explorer==1.1.3
-e git+https://github.com/edx-solutions/xblock-drag-and-drop.git@92ee2055a16899090a073e1df81e35d5293ad767#egg=xblock-drag-and-drop
# FIXME: temp hash, until a proper solution is findout (ref ticket: https://edx-wiki.atlassian.net/browse/MCKIN-8249)
-e git+https://github.com/edx-solutions/xblock-drag-and-drop-v2.git@15d0d797c8bf8590ca39dec88fcc3f315058d565#egg=xblock-drag-and-drop-v2==2.2.1
Expand All @@ -13,22 +13,22 @@
git+https://github.com/edx-solutions/[email protected]#egg=xblock-group-project==0.1.1
-e git+https://github.com/edx-solutions/xblock-adventure.git@7bdeb62b1055377dc04a7b503f7eea8264f5847b#egg=xblock-adventure
-e git+https://github.com/open-craft/[email protected]#egg=xblock-poll==1.8.2
-e git+https://github.com/edx/edx-notifications.git@0.8.3#egg=edx-notifications==0.8.3
-e git+https://github.com/open-craft/edx-notifications.git@9930a7069dd496e3229145d0dee8f750c9d1d7cc#egg=edx-notifications==0.8.4
-e git+https://github.com/open-craft/[email protected]#egg=xblock-problem-builder==3.3.2
-e git+https://github.com/OfficeDev/xblock-officemix.git@86238f5968a08db005717dbddc346808f1ed3716#egg=xblock-officemix
-e git+https://github.com/open-craft/[email protected]#egg=xblock-chat==0.2.3
-e git+https://github.com/open-craft/xblock-eoc-journal.git@53c6b6e4e8764627ed352e30fe2c60755e91d262#egg=xblock-eoc-journal
-e git+https://github.com/mckinseyacademy/[email protected].23#egg=xblock-scorm==2.0.23
-e git+https://github.com/mckinseyacademy/[email protected].24#egg=xblock-scorm==2.0.24
-e git+https://github.com/mckinseyacademy/[email protected]#egg=xblock-diagnostic-feedback==0.2.4
-e git+https://github.com/open-craft/[email protected].10#egg=xblock-group-project-v2==0.4.10
-e git+https://github.com/open-craft/[email protected].14#egg=xblock-group-project-v2==0.4.14
-e git+https://github.com/open-craft/[email protected]#egg=xblock-virtualreality==0.1.1
git+https://github.com/edx-solutions/[email protected].11#egg=api-integration==2.5.11
git+https://github.com/edx-solutions/[email protected].13#egg=api-integration==2.5.13
git+https://github.com/edx-solutions/[email protected]#egg=organizations-edx-platform-extensions==1.2.7
git+https://github.com/edx-solutions/[email protected]#egg=gradebook-edx-platform-extensions==1.1.14
git+https://github.com/edx-solutions/[email protected].6#egg=projects-edx-platform-extensions==1.1.6
git+https://github.com/edx-solutions/[email protected].8#egg=projects-edx-platform-extensions==1.1.8
git+https://github.com/edx-solutions/[email protected]#egg=discussion-edx-platform-extensions==1.2.13
git+https://github.com/edx-solutions/[email protected]#egg=course-edx-platform-extensions==1.1.1
git+https://github.com/edx-solutions/mobileapps-edx-platform-extensions.git@v1.2.2#egg=mobileapps-edx-platform-extensions==1.2.2
git+https://github.com/edx-solutions/mobileapps-edx-platform-extensions.git@v1.3.0#egg=mobileapps-edx-platform-extensions==1.3.0
git+https://github.com/edx-solutions/[email protected]#egg=progress-edx-platform-extensions==1.0.8
openedx-completion-aggregator==1.5.21
git+https://github.com/mckinseyacademy/[email protected]#egg=openedx-user-manager-api==1.1.0

0 comments on commit 4ddaf7b

Please sign in to comment.