Commit 6c3b94d2 by Andy Armstrong

Bump User API and Profile Images API to v1

TNL-1669
parent a37166c3
...@@ -317,9 +317,6 @@ FEATURES = { ...@@ -317,9 +317,6 @@ FEATURES = {
# Set to True to change the course sorting behavior by their start dates, latest first. # Set to True to change the course sorting behavior by their start dates, latest first.
'ENABLE_COURSE_SORTING_BY_START_DATE': True, 'ENABLE_COURSE_SORTING_BY_START_DATE': True,
# Flag to enable new user account APIs.
'ENABLE_USER_REST_API': True,
# Expose Mobile REST API. Note that if you use this, you must also set # Expose Mobile REST API. Note that if you use this, you must also set
# ENABLE_OAUTH2_PROVIDER to True # ENABLE_OAUTH2_PROVIDER to True
'ENABLE_MOBILE_REST_API': False, 'ENABLE_MOBILE_REST_API': False,
......
...@@ -268,7 +268,6 @@ FEATURES['ENABLE_OAUTH2_PROVIDER'] = True ...@@ -268,7 +268,6 @@ FEATURES['ENABLE_OAUTH2_PROVIDER'] = True
FEATURES['ENABLE_MOBILE_REST_API'] = True FEATURES['ENABLE_MOBILE_REST_API'] = True
FEATURES['ENABLE_MOBILE_SOCIAL_FACEBOOK_FEATURES'] = True FEATURES['ENABLE_MOBILE_SOCIAL_FACEBOOK_FEATURES'] = True
FEATURES['ENABLE_VIDEO_ABSTRACTION_LAYER_API'] = True FEATURES['ENABLE_VIDEO_ABSTRACTION_LAYER_API'] = True
FEATURES['ENABLE_USER_REST_API'] = True
###################### Payment ##############################3 ###################### Payment ##############################3
# Enable fake payment processing page # Enable fake payment processing page
......
...@@ -86,13 +86,13 @@ urlpatterns = ( ...@@ -86,13 +86,13 @@ urlpatterns = (
# Course content API # Course content API
url(r'^api/course_structure/', include('course_structure_api.urls', namespace='course_structure_api')), url(r'^api/course_structure/', include('course_structure_api.urls', namespace='course_structure_api')),
)
if settings.FEATURES["ENABLE_USER_REST_API"]: # User API endpoints
urlpatterns += ( url(r'^api/user/', include('openedx.core.djangoapps.user_api.urls')),
url(r'^api/user/', include('openedx.core.djangoapps.user_api.urls')),
url(r'^api/profile_images/', include('openedx.core.djangoapps.profile_images.urls')), # Profile Images API endpoints
) url(r'^api/profile_images/', include('openedx.core.djangoapps.profile_images.urls')),
)
if settings.FEATURES["ENABLE_COMBINED_LOGIN_REGISTRATION"]: if settings.FEATURES["ENABLE_COMBINED_LOGIN_REGISTRATION"]:
# Backwards compatibility with old URL structure, but serve the new views # Backwards compatibility with old URL structure, but serve the new views
......
...@@ -10,12 +10,12 @@ USERNAME_PATTERN = r'(?P<username>[\w.+-]+)' ...@@ -10,12 +10,12 @@ USERNAME_PATTERN = r'(?P<username>[\w.+-]+)'
urlpatterns = patterns( urlpatterns = patterns(
'', '',
url( url(
r'^v0/' + USERNAME_PATTERN + '/upload$', r'^v1/' + USERNAME_PATTERN + '/upload$',
ProfileImageUploadView.as_view(), ProfileImageUploadView.as_view(),
name="profile_image_upload" name="profile_image_upload"
), ),
url( url(
r'^v0/' + USERNAME_PATTERN + '/remove$', r'^v1/' + USERNAME_PATTERN + '/remove$',
ProfileImageRemoveView.as_view(), ProfileImageRemoveView.as_view(),
name="profile_image_remove" name="profile_image_remove"
), ),
......
...@@ -42,7 +42,7 @@ class ProfileImageUploadView(APIView): ...@@ -42,7 +42,7 @@ class ProfileImageUploadView(APIView):
**Example Requests**: **Example Requests**:
POST /api/profile_images/v0/{username}/upload POST /api/profile_images/v1/{username}/upload
**Response for POST** **Response for POST**
...@@ -65,7 +65,7 @@ class ProfileImageUploadView(APIView): ...@@ -65,7 +65,7 @@ class ProfileImageUploadView(APIView):
def post(self, request, username): def post(self, request, username):
""" """
POST /api/profile_images/v0/{username}/upload POST /api/profile_images/v1/{username}/upload
""" """
# validate request: # validate request:
# verify that the user's # verify that the user's
...@@ -119,7 +119,7 @@ class ProfileImageRemoveView(APIView): ...@@ -119,7 +119,7 @@ class ProfileImageRemoveView(APIView):
**Example Requests**: **Example Requests**:
POST /api/profile_images/v0/{username}/remove POST /api/profile_images/v1/{username}/remove
**Response for POST** **Response for POST**
...@@ -139,7 +139,7 @@ class ProfileImageRemoveView(APIView): ...@@ -139,7 +139,7 @@ class ProfileImageRemoveView(APIView):
def post(self, request, username): # pylint: disable=unused-argument def post(self, request, username): # pylint: disable=unused-argument
""" """
POST /api/profile_images/v0/{username}/remove POST /api/profile_images/v1/{username}/remove
""" """
try: try:
# update the user account to reflect that the images were removed. # update the user account to reflect that the images were removed.
......
...@@ -28,9 +28,9 @@ class AccountView(APIView): ...@@ -28,9 +28,9 @@ class AccountView(APIView):
**Example Requests**: **Example Requests**:
GET /api/user/v0/accounts/{username}/[?view=shared] GET /api/user/v1/accounts/{username}/[?view=shared]
PATCH /api/user/v0/accounts/{username}/{"key":"value"} "application/merge-patch+json" PATCH /api/user/v1/accounts/{username}/{"key":"value"} "application/merge-patch+json"
**Response Values for GET** **Response Values for GET**
...@@ -154,7 +154,7 @@ class AccountView(APIView): ...@@ -154,7 +154,7 @@ class AccountView(APIView):
def get(self, request, username): def get(self, request, username):
""" """
GET /api/user/v0/accounts/{username}/ GET /api/user/v1/accounts/{username}/
""" """
try: try:
account_settings = get_account_settings(request.user, username, view=request.QUERY_PARAMS.get('view')) account_settings = get_account_settings(request.user, username, view=request.QUERY_PARAMS.get('view'))
...@@ -169,7 +169,7 @@ class AccountView(APIView): ...@@ -169,7 +169,7 @@ class AccountView(APIView):
def patch(self, request, username): def patch(self, request, username):
""" """
PATCH /api/user/v0/accounts/{username}/ PATCH /api/user/v1/accounts/{username}/
Note that this implementation is the "merge patch" implementation proposed in Note that this implementation is the "merge patch" implementation proposed in
https://tools.ietf.org/html/rfc7396. The content_type must be "application/merge-patch+json" or https://tools.ietf.org/html/rfc7396. The content_type must be "application/merge-patch+json" or
......
...@@ -25,7 +25,7 @@ TOO_LONG_PREFERENCE_KEY = u"x" * 256 ...@@ -25,7 +25,7 @@ TOO_LONG_PREFERENCE_KEY = u"x" * 256
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestPreferencesAPI(UserAPITestCase): class TestPreferencesAPI(UserAPITestCase):
""" """
Unit tests /api/user/v0/accounts/{username}/ Unit tests /api/user/v1/accounts/{username}/
""" """
def setUp(self): def setUp(self):
super(TestPreferencesAPI, self).setUp() super(TestPreferencesAPI, self).setUp()
...@@ -342,7 +342,7 @@ class TestPreferencesAPITransactions(TransactionTestCase): ...@@ -342,7 +342,7 @@ class TestPreferencesAPITransactions(TransactionTestCase):
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class TestPreferencesDetailAPI(UserAPITestCase): class TestPreferencesDetailAPI(UserAPITestCase):
""" """
Unit tests /api/user/v0/accounts/{username}/{preference_key} Unit tests /api/user/v1/accounts/{username}/{preference_key}
""" """
def setUp(self): def setUp(self):
super(TestPreferencesDetailAPI, self).setUp() super(TestPreferencesDetailAPI, self).setUp()
......
...@@ -33,9 +33,9 @@ class PreferencesView(APIView): ...@@ -33,9 +33,9 @@ class PreferencesView(APIView):
**Example Requests**: **Example Requests**:
GET /api/user/v0/preferences/{username}/ GET /api/user/v1/preferences/{username}/
PATCH /api/user/v0/preferences/{username}/ with content_type "application/merge-patch+json" PATCH /api/user/v1/preferences/{username}/ with content_type "application/merge-patch+json"
**Response Value for GET** **Response Value for GET**
...@@ -71,7 +71,7 @@ class PreferencesView(APIView): ...@@ -71,7 +71,7 @@ class PreferencesView(APIView):
def get(self, request, username): def get(self, request, username):
""" """
GET /api/user/v0/preferences/{username}/ GET /api/user/v1/preferences/{username}/
""" """
try: try:
user_preferences = get_user_preferences(request.user, username=username) user_preferences = get_user_preferences(request.user, username=username)
...@@ -84,7 +84,7 @@ class PreferencesView(APIView): ...@@ -84,7 +84,7 @@ class PreferencesView(APIView):
def patch(self, request, username): def patch(self, request, username):
""" """
PATCH /api/user/v0/preferences/{username}/ PATCH /api/user/v1/preferences/{username}/
""" """
if not request.DATA or not getattr(request.DATA, "keys", None): if not request.DATA or not getattr(request.DATA, "keys", None):
error_message = _("No data provided for user preference update") error_message = _("No data provided for user preference update")
...@@ -126,11 +126,11 @@ class PreferencesDetailView(APIView): ...@@ -126,11 +126,11 @@ class PreferencesDetailView(APIView):
**Example Requests**: **Example Requests**:
GET /api/user/v0/preferences/{username}/{preference_key} GET /api/user/v1/preferences/{username}/{preference_key}
PUT /api/user/v0/preferences/{username}/{preference_key} PUT /api/user/v1/preferences/{username}/{preference_key}
DELETE /api/user/v0/preferences/{username}/{preference_key} DELETE /api/user/v1/preferences/{username}/{preference_key}
**Response Values for GET** **Response Values for GET**
...@@ -167,7 +167,7 @@ class PreferencesDetailView(APIView): ...@@ -167,7 +167,7 @@ class PreferencesDetailView(APIView):
def get(self, request, username, preference_key): def get(self, request, username, preference_key):
""" """
GET /api/user/v0/preferences/{username}/{preference_key} GET /api/user/v1/preferences/{username}/{preference_key}
""" """
try: try:
value = get_user_preference(request.user, preference_key, username=username) value = get_user_preference(request.user, preference_key, username=username)
...@@ -182,7 +182,7 @@ class PreferencesDetailView(APIView): ...@@ -182,7 +182,7 @@ class PreferencesDetailView(APIView):
def put(self, request, username, preference_key): def put(self, request, username, preference_key):
""" """
PUT /api/user/v0/preferences/{username}/{preference_key} PUT /api/user/v1/preferences/{username}/{preference_key}
""" """
try: try:
set_user_preference(request.user, preference_key, request.DATA, username=username) set_user_preference(request.user, preference_key, request.DATA, username=username)
...@@ -210,7 +210,7 @@ class PreferencesDetailView(APIView): ...@@ -210,7 +210,7 @@ class PreferencesDetailView(APIView):
def delete(self, request, username, preference_key): def delete(self, request, username, preference_key):
""" """
DELETE /api/user/v0/preferences/{username}/{preference_key} DELETE /api/user/v1/preferences/{username}/{preference_key}
""" """
try: try:
preference_existed = delete_user_preference(request.user, preference_key, username=username) preference_existed = delete_user_preference(request.user, preference_key, username=username)
......
...@@ -12,17 +12,17 @@ USERNAME_PATTERN = r'(?P<username>[\w.+-]+)' ...@@ -12,17 +12,17 @@ USERNAME_PATTERN = r'(?P<username>[\w.+-]+)'
urlpatterns = patterns( urlpatterns = patterns(
'', '',
url( url(
r'^v0/accounts/' + USERNAME_PATTERN + '$', r'^v1/accounts/' + USERNAME_PATTERN + '$',
AccountView.as_view(), AccountView.as_view(),
name="accounts_api" name="accounts_api"
), ),
url( url(
r'^v0/preferences/' + USERNAME_PATTERN + '$', r'^v1/preferences/' + USERNAME_PATTERN + '$',
PreferencesView.as_view(), PreferencesView.as_view(),
name="preferences_api" name="preferences_api"
), ),
url( url(
r'^v0/preferences/' + USERNAME_PATTERN + '/(?P<preference_key>[a-zA-Z0-9_]+)$', r'^v1/preferences/' + USERNAME_PATTERN + '/(?P<preference_key>[a-zA-Z0-9_]+)$',
PreferencesDetailView.as_view(), PreferencesDetailView.as_view(),
name="preferences_detail_api" name="preferences_detail_api"
), ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment