{"action":"created","comment":{"url":"https://api.github.com/repos/raccoongang/edx-platform/pulls/comments/216598483","pull_request_review_id":154111659,"id":216598483,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNjU5ODQ4Mw==","diff_hunk":"@@ -0,0 +1,132 @@\n+import logging\n+from uuid import uuid4\n+from django.conf import settings\n+from django.core.exceptions import NON_FIELD_ERRORS, ValidationError\n+from django.contrib.auth.models import User\n+from rest_framework.views import APIView\n+from rest_framework import status\n+from rest_framework.response import Response\n+from openedx.core.djangoapps.user_api.accounts.api import check_account_exists\n+from student.views import create_account_with_params\n+from student.models import CourseEnrollment, EnrollmentClosedError, CourseFullError, AlreadyEnrolledError, UserProfile\n+from enrollment.views import EnrollmentCrossDomainSessionAuth, EnrollmentUserThrottle, ApiKeyPermissionMixIn\n+from django.core.validators import validate_slug\n+from opaque_keys.edx.locations import SlashSeparatedCourseKey\n+from openedx.core.lib.api.permissions import ApiKeyHeaderPermission\n+from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers\n+from student.forms import PasswordResetFormNoActive\n+from openedx.core.lib.api.authentication import OAuth2AuthenticationAllowInactiveUser\n+\n+log = logging.getLogger(__name__)\n+\n+def string_to_boolean(string):\n+    return str(string).lower() in ['true',]\n+\n+\n+class CreateUserAccountWithoutPasswordView(APIView):\n+    authentication_classes = (OAuth2AuthenticationAllowInactiveUser,)\n+    permission_classes = ApiKeyHeaderPermission,\n+\n+    def post(self, request):\n+        \"\"\"\n+        Create user account without password\n+\n+        Creates a user using mail, login and also name and surname.\n+        Sets a random password and sends a user a message to change it.\n+        \"\"\"\n+        data = request.data\n+        data['honor_code'] = \"True\"\n+        data['terms_of_service'] = \"True\"\n+        data['name'] = request.data.get('prename')\n+        email = request.data.get('email')\n+        username = request.data.get('username')\n+        try:\n+            validate_slug(username)\n+        except ValidationError as err:\n+            return Response(\n+                data={\n+                    \"user_message\": \"Enter a valid 'username' consisting of letters, numbers, underscores or hyphens.\"\n+                },\n+                status=400\n+            )\n+\n+        if check_account_exists(username=username, email=email):\n+            return Response(data={\"user_message\": \"User already exists\"}, status=409)\n+\n+        try:\n+            data['password'] = uuid4().hex\n+            user = create_account_with_params(request, data)\n+            user.is_active = True\n+            user.first_name = request.data.get('prename')\n+            user.last_name = request.data.get('surname')\n+            user.save()\n+            self.send_activation_email(request)\n+        except ValidationError as err:\n+            # Should only get non-field errors from this function\n+            assert NON_FIELD_ERRORS not in err.message_dict\n+            # Only return first error for each field\n+            return Response(data={\"user_message\": \"Wrong parameters on user creation\"}, status=400)\n+        except ValueError as err:\n+            return Response(data={\"user_message\": \"Wrong email format\"}, status=400)\n+\n+        return Response(data={'user_id': user.id}, status=200)\n+\n+    @staticmethod\n+    def send_activation_email(request):\n+        form = PasswordResetFormNoActive(request.data)\n+        if form.is_valid():\n+            form.save(use_https=request.is_secure(),\n+                      from_email=configuration_helpers.get_value(\n+                          'email_from_address', settings.DEFAULT_FROM_EMAIL),\n+                      request=request,\n+                      subject_template_name='etc_api/set_password_subject.txt',\n+                      email_template_name='etc_api/set_password_email.html'\n+                      )\n+\n+\n+class SetActivateUserStatus(APIView):\n+    authentication_classes = (OAuth2AuthenticationAllowInactiveUser,)\n+    permission_classes = ApiKeyHeaderPermission,\n+\n+    def post(self, request):\n+        \"\"\"\n+        Enable or disable user by user id.\n+        \"\"\"\n+        data = request.data\n+        try:\n+            user = User.objects.get(id=data['user_id'])\n+            user.is_active = string_to_boolean(data['is_active'])\n+            user.save()\n+        except  User.DoesNotExist:\n+            return Response(data={\"user_message\": \"Wrong id User does not exist\"}, status=400)","path":"lms/djangoapps/etc_api/views.py","position":101,"original_position":101,"commit_id":"ee9ef20c2e9d944ec8fe2cb3d2fb5f4ac3108a2e","original_commit_id":"ee9ef20c2e9d944ec8fe2cb3d2fb5f4ac3108a2e","user":{"login":"idegtiarov","id":7392821,"node_id":"MDQ6VXNlcjczOTI4MjE=","avatar_url":"https://avatars1.githubusercontent.com/u/7392821?v=4","gravatar_id":"","url":"https://api.github.com/users/idegtiarov","html_url":"https://github.com/idegtiarov","followers_url":"https://api.github.com/users/idegtiarov/followers","following_url":"https://api.github.com/users/idegtiarov/following{/other_user}","gists_url":"https://api.github.com/users/idegtiarov/gists{/gist_id}","starred_url":"https://api.github.com/users/idegtiarov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/idegtiarov/subscriptions","organizations_url":"https://api.github.com/users/idegtiarov/orgs","repos_url":"https://api.github.com/users/idegtiarov/repos","events_url":"https://api.github.com/users/idegtiarov/events{/privacy}","received_events_url":"https://api.github.com/users/idegtiarov/received_events","type":"User","site_admin":false},"body":"s/Wrong id/Wrong user_id./","created_at":"2018-09-11T09:13:00Z","updated_at":"2018-09-11T09:14:08Z","html_url":"https://github.com/raccoongang/edx-platform/pull/571#discussion_r216598483","pull_request_url":"https://api.github.com/repos/raccoongang/edx-platform/pulls/571","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/raccoongang/edx-platform/pulls/comments/216598483"},"html":{"href":"https://github.com/raccoongang/edx-platform/pull/571#discussion_r216598483"},"pull_request":{"href":"https://api.github.com/repos/raccoongang/edx-platform/pulls/571"}}},"pull_request":{"url":"https://api.github.com/repos/raccoongang/edx-platform/pulls/571","id":214540040,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE0NTQwMDQw","html_url":"https://github.com/raccoongang/edx-platform/pull/571","diff_url":"https://github.com/raccoongang/edx-platform/pull/571.diff","patch_url":"https://github.com/raccoongang/edx-platform/pull/571.patch","issue_url":"https://api.github.com/repos/raccoongang/edx-platform/issues/571","number":571,"state":"open","locked":false,"title":"[ETC] Endpoints fo create a user and enroll  a user","user":{"login":"AndreyLykhoman","id":9655643,"node_id":"MDQ6VXNlcjk2NTU2NDM=","avatar_url":"https://avatars2.githubusercontent.com/u/9655643?v=4","gravatar_id":"","url":"https://api.github.com/users/AndreyLykhoman","html_url":"https://github.com/AndreyLykhoman","followers_url":"https://api.github.com/users/AndreyLykhoman/followers","following_url":"https://api.github.com/users/AndreyLykhoman/following{/other_user}","gists_url":"https://api.github.com/users/AndreyLykhoman/gists{/gist_id}","starred_url":"https://api.github.com/users/AndreyLykhoman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndreyLykhoman/subscriptions","organizations_url":"https://api.github.com/users/AndreyLykhoman/orgs","repos_url":"https://api.github.com/users/AndreyLykhoman/repos","events_url":"https://api.github.com/users/AndreyLykhoman/events{/privacy}","received_events_url":"https://api.github.com/users/AndreyLykhoman/received_events","type":"User","site_admin":false},"body":"**Description:** Realise endpoints fo create a user and enroll a user\r\n\r\n**Youtrack:** https://youtrack.raccoongang.com/issue/ETC-11\r\n","created_at":"2018-09-11T07:40:41Z","updated_at":"2018-09-11T09:14:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2bdd5f07de7066d8e6fa547ea7495fd417f94fe6","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/raccoongang/edx-platform/pulls/571/commits","review_comments_url":"https://api.github.com/repos/raccoongang/edx-platform/pulls/571/comments","review_comment_url":"https://api.github.com/repos/raccoongang/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/raccoongang/edx-platform/issues/571/comments","statuses_url":"https://api.github.com/repos/raccoongang/edx-platform/statuses/ee9ef20c2e9d944ec8fe2cb3d2fb5f4ac3108a2e","head":{"label":"raccoongang:etc-ficus-stage","ref":"etc-ficus-stage","sha":"ee9ef20c2e9d944ec8fe2cb3d2fb5f4ac3108a2e","user":{"login":"raccoongang","id":11388447,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMzg4NDQ3","avatar_url":"https://avatars0.githubusercontent.com/u/11388447?v=4","gravatar_id":"","url":"https://api.github.com/users/raccoongang","html_url":"https://github.com/raccoongang","followers_url":"https://api.github.com/users/raccoongang/followers","following_url":"https://api.github.com/users/raccoongang/following{/other_user}","gists_url":"https://api.github.com/users/raccoongang/gists{/gist_id}","starred_url":"https://api.github.com/users/raccoongang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raccoongang/subscriptions","organizations_url":"https://api.github.com/users/raccoongang/orgs","repos_url":"https://api.github.com/users/raccoongang/repos","events_url":"https://api.github.com/users/raccoongang/events{/privacy}","received_events_url":"https://api.github.com/users/raccoongang/received_events","type":"Organization","site_admin":false},"repo":{"id":26811891,"node_id":"MDEwOlJlcG9zaXRvcnkyNjgxMTg5MQ==","name":"edx-platform","full_name":"raccoongang/edx-platform","owner":{"login":"raccoongang","id":11388447,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMzg4NDQ3","avatar_url":"https://avatars0.githubusercontent.com/u/11388447?v=4","gravatar_id":"","url":"https://api.github.com/users/raccoongang","html_url":"https://github.com/raccoongang","followers_url":"https://api.github.com/users/raccoongang/followers","following_url":"https://api.github.com/users/raccoongang/following{/other_user}","gists_url":"https://api.github.com/users/raccoongang/gists{/gist_id}","starred_url":"https://api.github.com/users/raccoongang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raccoongang/subscriptions","organizations_url":"https://api.github.com/users/raccoongang/orgs","repos_url":"https://api.github.com/users/raccoongang/repos","events_url":"https://api.github.com/users/raccoongang/events{/privacy}","received_events_url":"https://api.github.com/users/raccoongang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/raccoongang/edx-platform","description":"Open edX, the edX platform that powers http://edx.org","fork":true,"url":"https://api.github.com/repos/raccoongang/edx-platform","forks_url":"https://api.github.com/repos/raccoongang/edx-platform/forks","keys_url":"https://api.github.com/repos/raccoongang/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/raccoongang/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/raccoongang/edx-platform/teams","hooks_url":"https://api.github.com/repos/raccoongang/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/raccoongang/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/raccoongang/edx-platform/events","assignees_url":"https://api.github.com/repos/raccoongang/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/raccoongang/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/raccoongang/edx-platform/tags","blobs_url":"https://api.github.com/repos/raccoongang/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/raccoongang/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/raccoongang/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/raccoongang/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/raccoongang/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/raccoongang/edx-platform/languages","stargazers_url":"https://api.github.com/repos/raccoongang/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/raccoongang/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/raccoongang/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/raccoongang/edx-platform/subscription","commits_url":"https://api.github.com/repos/raccoongang/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/raccoongang/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/raccoongang/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/raccoongang/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/raccoongang/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/raccoongang/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/raccoongang/edx-platform/merges","archive_url":"https://api.github.com/repos/raccoongang/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/raccoongang/edx-platform/downloads","issues_url":"https://api.github.com/repos/raccoongang/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/raccoongang/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/raccoongang/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/raccoongang/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/raccoongang/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/raccoongang/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/raccoongang/edx-platform/deployments","created_at":"2014-11-18T14:05:58Z","updated_at":"2018-09-03T14:05:20Z","pushed_at":"2018-09-11T07:41:33Z","git_url":"git://github.com/raccoongang/edx-platform.git","ssh_url":"git@github.com:raccoongang/edx-platform.git","clone_url":"https://github.com/raccoongang/edx-platform.git","svn_url":"https://github.com/raccoongang/edx-platform","homepage":"http://openedx.org/","size":1067696,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"archived":false,"open_issues_count":12,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":12,"open_issues":12,"watchers":9,"default_branch":"ginkgo-rg"}},"base":{"label":"raccoongang:etc-ficus","ref":"etc-ficus","sha":"6996afb66026dc5de4ec1808aba0faee4f2132cc","user":{"login":"raccoongang","id":11388447,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMzg4NDQ3","avatar_url":"https://avatars0.githubusercontent.com/u/11388447?v=4","gravatar_id":"","url":"https://api.github.com/users/raccoongang","html_url":"https://github.com/raccoongang","followers_url":"https://api.github.com/users/raccoongang/followers","following_url":"https://api.github.com/users/raccoongang/following{/other_user}","gists_url":"https://api.github.com/users/raccoongang/gists{/gist_id}","starred_url":"https://api.github.com/users/raccoongang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raccoongang/subscriptions","organizations_url":"https://api.github.com/users/raccoongang/orgs","repos_url":"https://api.github.com/users/raccoongang/repos","events_url":"https://api.github.com/users/raccoongang/events{/privacy}","received_events_url":"https://api.github.com/users/raccoongang/received_events","type":"Organization","site_admin":false},"repo":{"id":26811891,"node_id":"MDEwOlJlcG9zaXRvcnkyNjgxMTg5MQ==","name":"edx-platform","full_name":"raccoongang/edx-platform","owner":{"login":"raccoongang","id":11388447,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMzg4NDQ3","avatar_url":"https://avatars0.githubusercontent.com/u/11388447?v=4","gravatar_id":"","url":"https://api.github.com/users/raccoongang","html_url":"https://github.com/raccoongang","followers_url":"https://api.github.com/users/raccoongang/followers","following_url":"https://api.github.com/users/raccoongang/following{/other_user}","gists_url":"https://api.github.com/users/raccoongang/gists{/gist_id}","starred_url":"https://api.github.com/users/raccoongang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raccoongang/subscriptions","organizations_url":"https://api.github.com/users/raccoongang/orgs","repos_url":"https://api.github.com/users/raccoongang/repos","events_url":"https://api.github.com/users/raccoongang/events{/privacy}","received_events_url":"https://api.github.com/users/raccoongang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/raccoongang/edx-platform","description":"Open edX, the edX platform that powers http://edx.org","fork":true,"url":"https://api.github.com/repos/raccoongang/edx-platform","forks_url":"https://api.github.com/repos/raccoongang/edx-platform/forks","keys_url":"https://api.github.com/repos/raccoongang/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/raccoongang/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/raccoongang/edx-platform/teams","hooks_url":"https://api.github.com/repos/raccoongang/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/raccoongang/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/raccoongang/edx-platform/events","assignees_url":"https://api.github.com/repos/raccoongang/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/raccoongang/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/raccoongang/edx-platform/tags","blobs_url":"https://api.github.com/repos/raccoongang/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/raccoongang/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/raccoongang/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/raccoongang/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/raccoongang/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/raccoongang/edx-platform/languages","stargazers_url":"https://api.github.com/repos/raccoongang/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/raccoongang/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/raccoongang/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/raccoongang/edx-platform/subscription","commits_url":"https://api.github.com/repos/raccoongang/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/raccoongang/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/raccoongang/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/raccoongang/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/raccoongang/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/raccoongang/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/raccoongang/edx-platform/merges","archive_url":"https://api.github.com/repos/raccoongang/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/raccoongang/edx-platform/downloads","issues_url":"https://api.github.com/repos/raccoongang/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/raccoongang/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/raccoongang/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/raccoongang/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/raccoongang/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/raccoongang/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/raccoongang/edx-platform/deployments","created_at":"2014-11-18T14:05:58Z","updated_at":"2018-09-03T14:05:20Z","pushed_at":"2018-09-11T07:41:33Z","git_url":"git://github.com/raccoongang/edx-platform.git","ssh_url":"git@github.com:raccoongang/edx-platform.git","clone_url":"https://github.com/raccoongang/edx-platform.git","svn_url":"https://github.com/raccoongang/edx-platform","homepage":"http://openedx.org/","size":1067696,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"archived":false,"open_issues_count":12,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":12,"open_issues":12,"watchers":9,"default_branch":"ginkgo-rg"}},"_links":{"self":{"href":"https://api.github.com/repos/raccoongang/edx-platform/pulls/571"},"html":{"href":"https://github.com/raccoongang/edx-platform/pull/571"},"issue":{"href":"https://api.github.com/repos/raccoongang/edx-platform/issues/571"},"comments":{"href":"https://api.github.com/repos/raccoongang/edx-platform/issues/571/comments"},"review_comments":{"href":"https://api.github.com/repos/raccoongang/edx-platform/pulls/571/comments"},"review_comment":{"href":"https://api.github.com/repos/raccoongang/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/raccoongang/edx-platform/pulls/571/commits"},"statuses":{"href":"https://api.github.com/repos/raccoongang/edx-platform/statuses/ee9ef20c2e9d944ec8fe2cb3d2fb5f4ac3108a2e"}},"author_association":"NONE"}}
{"actor":{"display_login":"idegtiarov"}}