Skip to content

Commit 73e2a23

Browse files
committed
Added error message on saving course-key.
ECOM-6748
1 parent db25b93 commit 73e2a23

File tree

13 files changed

+90
-10
lines changed

13 files changed

+90
-10
lines changed

course_discovery/apps/publisher/api/serializers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Publisher API Serializers"""
22
import waffle
3+
4+
from django.utils.translation import ugettext_lazy as _
35
from opaque_keys import InvalidKeyError
46
from opaque_keys.edx.keys import CourseKey
57
from rest_framework import serializers
@@ -51,7 +53,10 @@ def validate(self, data):
5153
try:
5254
CourseKey.from_string(lms_course_id)
5355
except InvalidKeyError:
54-
raise serializers.ValidationError('Invalid course key [{}]'.format(lms_course_id))
56+
# pylint: disable=no-member
57+
raise serializers.ValidationError(
58+
{'lms_course_id': _('Invalid course key "{lms_course_id}"').format(lms_course_id=lms_course_id)}
59+
)
5560

5661
request = self.context.get('request')
5762
if request:

course_discovery/apps/publisher/api/tests/test_views.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,42 @@ def test_update_course_key_with_errors(self):
243243

244244
self.assertEqual(response.status_code, 400)
245245
self.assertEqual(
246-
response.data.get('non_field_errors'), ['Invalid course key [{}]'.format(invalid_course_id)]
246+
response.data.get('lms_course_id'),
247+
['Invalid course key "{lms_course_id}"'.format(lms_course_id=invalid_course_id)]
248+
)
249+
250+
def test_update_course_key_without_permission(self):
251+
"""
252+
Test that api returns error without permission.
253+
"""
254+
self.user.groups.remove(Group.objects.get(name=INTERNAL_USER_GROUP_NAME))
255+
response = self.client.patch(
256+
self.update_course_key_url,
257+
data=json.dumps({'lms_course_id': 'course-v1:edxTest+TC12+2050Q1'}),
258+
content_type=JSON_CONTENT_TYPE
259+
)
260+
261+
self.assertEqual(response.status_code, 403)
262+
self.assertEqual(
263+
response.data.get('detail'), 'You do not have permission to perform this action.'
264+
)
265+
266+
def test_update_course_key_with_duplicate(self):
267+
"""
268+
Test that api returns error if course key already exist.
269+
"""
270+
lms_course_id = 'course-v1:edxTest+TC12+2050Q1'
271+
factories.CourseRunFactory(lms_course_id=lms_course_id)
272+
273+
response = self.client.patch(
274+
self.update_course_key_url,
275+
data=json.dumps({'lms_course_id': lms_course_id}),
276+
content_type=JSON_CONTENT_TYPE
277+
)
278+
279+
self.assertEqual(response.status_code, 400)
280+
self.assertEqual(
281+
response.data.get('lms_course_id'), ['CourseRun with this lms course id already exists.']
247282
)
248283

249284
def test_update_course_key(self):
Binary file not shown.

course_discovery/conf/locale/en/LC_MESSAGES/django.po

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: PACKAGE VERSION\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2017-01-16 14:06+0500\n"
10+
"POT-Creation-Date: 2017-01-18 12:59+0500\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language-Team: LANGUAGE <[email protected]>\n"
14+
"Language: \n"
1415
"MIME-Version: 1.0\n"
1516
"Content-Type: text/plain; charset=UTF-8\n"
1617
"Content-Transfer-Encoding: 8bit\n"
17-
"Language: \n"
1818

1919
#: apps/api/filters.py
2020
#, python-brace-format
@@ -411,6 +411,11 @@ msgstr ""
411411
msgid "JSON string containing an elasticsearch function score config."
412412
msgstr ""
413413

414+
#: apps/publisher/api/serializers.py
415+
#, python-brace-format
416+
msgid "Invalid course key \"{lms_course_id}\""
417+
msgstr ""
418+
414419
#: apps/publisher/choices.py templates/publisher/courses.html
415420
msgid "Partner Coordinator"
416421
msgstr ""
Binary file not shown.

course_discovery/conf/locale/en/LC_MESSAGES/djangojs.po

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: PACKAGE VERSION\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2017-01-16 14:06+0500\n"
10+
"POT-Creation-Date: 2017-01-18 12:59+0500\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language-Team: LANGUAGE <[email protected]>\n"
14+
"Language: \n"
1415
"MIME-Version: 1.0\n"
1516
"Content-Type: text/plain; charset=UTF-8\n"
1617
"Content-Transfer-Encoding: 8bit\n"
17-
"Language: \n"
1818

1919
#: static/js/catalogs-change-form.js
2020
msgid "Preview"
@@ -26,6 +26,10 @@ msgid ""
2626
"{courseRunDetail} with a start date of {startDate}"
2727
msgstr ""
2828

29+
#: static/js/publisher/views/dashboard.js
30+
msgid "There was an error in saving your data."
31+
msgstr ""
32+
2933
#: static/js/publisher/views/navbar.js
3034
msgid "OFF"
3135
msgstr ""
Binary file not shown.

course_discovery/conf/locale/eo/LC_MESSAGES/django.po

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: PACKAGE VERSION\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2017-01-16 14:06+0500\n"
10+
"POT-Creation-Date: 2017-01-18 12:59+0500\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language-Team: LANGUAGE <[email protected]>\n"
14+
"Language: \n"
1415
"MIME-Version: 1.0\n"
1516
"Content-Type: text/plain; charset=UTF-8\n"
1617
"Content-Transfer-Encoding: 8bit\n"
17-
"Language: \n"
1818
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
1919

2020
#: apps/api/filters.py
@@ -517,6 +517,11 @@ msgstr ""
517517
"JSÖN strïng çöntäïnïng än élästïçséärçh fünçtïön sçöré çönfïg. Ⱡ'σяєм ιρѕυм "
518518
"∂σłσя ѕιт αмєт, ¢σηѕє¢тєтυя α#"
519519

520+
#: apps/publisher/api/serializers.py
521+
#, python-brace-format
522+
msgid "Invalid course key \"{lms_course_id}\""
523+
msgstr "Ìnvälïd çöürsé kéý \"{lms_course_id}\" Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢ση#"
524+
520525
#: apps/publisher/choices.py templates/publisher/courses.html
521526
msgid "Partner Coordinator"
522527
msgstr "Pärtnér Çöördïnätör Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт,#"
Binary file not shown.

course_discovery/conf/locale/eo/LC_MESSAGES/djangojs.po

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: PACKAGE VERSION\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2017-01-16 14:06+0500\n"
10+
"POT-Creation-Date: 2017-01-18 12:59+0500\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language-Team: LANGUAGE <[email protected]>\n"
14+
"Language: \n"
1415
"MIME-Version: 1.0\n"
1516
"Content-Type: text/plain; charset=UTF-8\n"
1617
"Content-Transfer-Encoding: 8bit\n"
17-
"Language: \n"
1818
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
1919

2020
#: static/js/catalogs-change-form.js
@@ -30,6 +30,12 @@ msgstr ""
3030
"{courseRunDetail} wïth ä stärt däté öf {startDate} Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт "
3131
"αмєт, ¢σηѕє¢#"
3232

33+
#: static/js/publisher/views/dashboard.js
34+
msgid "There was an error in saving your data."
35+
msgstr ""
36+
"Théré wäs än érrör ïn sävïng ýöür dätä. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
37+
"¢σηѕє¢тєтυя#"
38+
3339
#: static/js/publisher/views/navbar.js
3440
msgid "OFF"
3541
msgstr "ÖFF Ⱡ'σяєм#"

course_discovery/static/js/publisher/views/dashboard.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ $(document).ready(function() {
1818
courseTitleTag = $courseRunParentTag.find("#course-title").html().trim(),
1919
startDateTag = $courseRunParentTag.find("#course-start").html().trim(),
2020
$studioInstanceSuccess = $(".studio-instance-success"),
21+
$studioInstanceError = $(".studio-instance-error"),
2122
successMessage = interpolateString(
2223
gettext("You have successfully created a studio instance ({studioLinkTag}) for {courseRunDetail} with a start date of {startDate}"),
2324
{
@@ -38,6 +39,16 @@ $(document).ready(function() {
3839
$("#studio-count").html(data_table_studio.rows().count());
3940
$studioInstanceSuccess.find(".copy-meta").html(successMessage);
4041
$studioInstanceSuccess.css("display", "block");
42+
},
43+
error: function (response) {
44+
if(response.responseJSON.lms_course_id) {
45+
$studioInstanceError.find(".copy").html(response.responseJSON.lms_course_id[0]);
46+
} else if(response.responseJSON.detail) {
47+
$studioInstanceError.find(".copy").html(response.responseJSON.detail);
48+
} else {
49+
$studioInstanceError.find(".copy").html(gettext("There was an error in saving your data."));
50+
}
51+
$studioInstanceError.removeClass("hidden");
4152
}
4253
});
4354
});

course_discovery/static/sass/publisher/dashboard.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
}
1111
}
1212

13+
.studio-instance-error {
14+
margin-bottom: 20px;
15+
}
16+
1317
.tabs {
1418
@include padding(0, 0, 0, 0);
1519
@include margin(0, 0, 0, 0);

course_discovery/templates/publisher/dashboard/_studio_requests.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<div class="studio-instance-success depth depth-0">
66
<p class="copy-meta"></p>
77
</div>
8+
<div class="alert alert-error alert-slim studio-instance-error hidden">
9+
<div class="alert-message">
10+
<p class="copy"></p>
11+
</div>
12+
</div>
813
<div class="table-view">
914
<table class="data-table-studio display" cellspacing="0" width="100%">
1015
<thead>

0 commit comments

Comments
 (0)