Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
2a87747b
Commit
2a87747b
authored
Jan 11, 2018
by
Asad Azam
Committed by
AsadAzam
Jan 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate course state owner role via admin
parent
777769af
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
69 additions
and
9 deletions
+69
-9
course_discovery/apps/publisher/admin.py
+2
-1
course_discovery/apps/publisher/forms.py
+18
-2
course_discovery/apps/publisher/tests/test_forms.py
+35
-2
course_discovery/conf/locale/en/LC_MESSAGES/django.mo
+0
-0
course_discovery/conf/locale/en/LC_MESSAGES/django.po
+5
-1
course_discovery/conf/locale/en/LC_MESSAGES/djangojs.mo
+0
-0
course_discovery/conf/locale/en/LC_MESSAGES/djangojs.po
+1
-1
course_discovery/conf/locale/eo/LC_MESSAGES/django.mo
+0
-0
course_discovery/conf/locale/eo/LC_MESSAGES/django.po
+7
-1
course_discovery/conf/locale/eo/LC_MESSAGES/djangojs.mo
+0
-0
course_discovery/conf/locale/eo/LC_MESSAGES/djangojs.po
+1
-1
No files found.
course_discovery/apps/publisher/admin.py
View file @
2a87747b
...
...
@@ -10,7 +10,7 @@ from course_discovery.apps.publisher.constants import (INTERNAL_USER_GROUP_NAME,
PROJECT_COORDINATOR_GROUP_NAME
,
PUBLISHER_GROUP_NAME
,
REVIEWER_GROUP_NAME
)
from
course_discovery.apps.publisher.forms
import
(
CourseRunAdminForm
,
CourseRunStateAdminForm
,
OrganizationExtensionForm
,
CourseRunAdminForm
,
CourseRunStateAdminForm
,
CourseStateAdminForm
,
OrganizationExtensionForm
,
PublisherUserCreationForm
,
UserAttributesAdminForm
)
from
course_discovery.apps.publisher.models
import
(
Course
,
CourseRun
,
CourseRunState
,
CourseState
,
CourseUserRole
,
...
...
@@ -73,6 +73,7 @@ class OrganizationUserRoleAdmin(SimpleHistoryAdmin):
@admin.register
(
CourseState
)
class
CourseStateAdmin
(
SimpleHistoryAdmin
):
form
=
CourseStateAdminForm
raw_id_fields
=
(
'changed_by'
,)
list_display
=
[
'id'
,
'name'
,
'approved_by_role'
,
'owner_role'
,
'course'
,
'marketing_reviewed'
]
search_fields
=
[
'id'
,
'course__title'
]
...
...
course_discovery/apps/publisher/forms.py
View file @
2a87747b
...
...
@@ -17,8 +17,8 @@ from course_discovery.apps.ietf_language_tags.models import LanguageTag
from
course_discovery.apps.publisher.choices
import
CourseRunStateChoices
,
PublisherUserRole
from
course_discovery.apps.publisher.mixins
import
LanguageModelSelect2Multiple
,
get_user_organizations
from
course_discovery.apps.publisher.models
import
(
Course
,
CourseRun
,
CourseRunState
,
Course
UserRole
,
OrganizationExtension
,
OrganizationUserRole
,
PublisherUser
,
Seat
,
User
Course
,
CourseRun
,
CourseRunState
,
Course
State
,
CourseUserRole
,
OrganizationExtension
,
OrganizationUserRole
,
PublisherUser
,
Seat
,
User
)
from
course_discovery.apps.publisher.utils
import
VALID_CHARS_IN_COURSE_NUM_AND_ORG_KEY
,
is_internal_user
from
course_discovery.apps.publisher.validators
import
validate_text_count
...
...
@@ -546,6 +546,22 @@ class CourseRunStateAdminForm(forms.ModelForm):
return
cleaned_data
class
CourseStateAdminForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
CourseState
fields
=
'__all__'
def
clean
(
self
):
cleaned_data
=
self
.
cleaned_data
owner_role
=
cleaned_data
.
get
(
'owner_role'
)
course
=
cleaned_data
.
get
(
'course'
)
if
not
CourseUserRole
.
objects
.
filter
(
course
=
course
,
role
=
owner_role
):
raise
forms
.
ValidationError
(
_
(
'Please create {} course user role before assigning it owner role'
.
format
(
owner_role
))
)
return
cleaned_data
class
AdminImportCourseForm
(
forms
.
Form
):
start_id
=
forms
.
IntegerField
(
min_value
=
1
,
label
=
'This course id will import.'
)
create_course_run
=
forms
.
BooleanField
(
...
...
course_discovery/apps/publisher/tests/test_forms.py
View file @
2a87747b
...
...
@@ -12,10 +12,12 @@ from course_discovery.apps.core.tests.factories import UserFactory
from
course_discovery.apps.course_metadata.tests.factories
import
OrganizationFactory
from
course_discovery.apps.publisher.choices
import
CourseRunStateChoices
,
PublisherUserRole
from
course_discovery.apps.publisher.forms
import
(
CourseForm
,
CourseRunForm
,
CourseRunStateAdminForm
,
PublisherUserCreationForm
,
SeatForm
CourseForm
,
CourseRunForm
,
CourseRunStateAdminForm
,
CourseStateAdminForm
,
PublisherUserCreationForm
,
SeatForm
)
from
course_discovery.apps.publisher.models
import
Seat
from
course_discovery.apps.publisher.tests.factories
import
CourseFactory
,
OrganizationExtensionFactory
,
SeatFactory
from
course_discovery.apps.publisher.tests.factories
import
(
CourseFactory
,
CourseUserRoleFactory
,
OrganizationExtensionFactory
,
SeatFactory
)
class
UserModelChoiceFieldTests
(
TestCase
):
...
...
@@ -99,6 +101,37 @@ class CourseRunStateAdminFormTests(TestCase):
self
.
assertEqual
(
run_state_form
.
clean
(),
run_state_form
.
cleaned_data
)
class
CourseStateAdminFormTests
(
TestCase
):
"""
Tests for the publisher "CourseStateAdminForm".
"""
def
test_clean_with_invalid_owner_role
(
self
):
"""
Test that 'clean' raises 'ValidationError' if the user role that has been assigned owner does not exist
"""
course_state_form
=
CourseStateAdminForm
()
course_state_form
.
cleaned_data
=
{
'owner_role'
:
PublisherUserRole
.
CourseTeam
}
with
self
.
assertRaises
(
ValidationError
):
course_state_form
.
clean
()
def
test_clean_with_valid_owner_role
(
self
):
"""
Test that 'clean' does not raise 'ValidationError' if the user role that has been assigned owner does exist
"""
course
=
CourseFactory
()
user
=
UserFactory
()
CourseUserRoleFactory
(
course
=
course
,
user
=
user
,
role
=
PublisherUserRole
.
CourseTeam
)
course_state_form
=
CourseStateAdminForm
()
course_state_form
.
cleaned_data
=
{
'owner_role'
:
PublisherUserRole
.
CourseTeam
,
'course'
:
course
}
self
.
assertEqual
(
course_state_form
.
clean
(),
course_state_form
.
cleaned_data
)
class
PublisherCourseRunEditFormTests
(
TestCase
):
"""
Tests for the publisher 'CourseRunForm'.
...
...
course_discovery/conf/locale/en/LC_MESSAGES/django.mo
View file @
2a87747b
No preview for this file type
course_discovery/conf/locale/en/LC_MESSAGES/django.po
View file @
2a87747b
...
...
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 201
7-12-20 20:2
8+0000\n"
"POT-Creation-Date: 201
8-01-12 11:5
8+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
...
...
@@ -843,6 +843,10 @@ msgid "Owner role can not be publisher if the state is draft or review"
msgstr ""
#: apps/publisher/forms.py
msgid "Please create {} course user role before assigning it owner role"
msgstr ""
#: apps/publisher/forms.py
msgid "Create initial run for the course"
msgstr ""
...
...
course_discovery/conf/locale/en/LC_MESSAGES/djangojs.mo
View file @
2a87747b
No preview for this file type
course_discovery/conf/locale/en/LC_MESSAGES/djangojs.po
View file @
2a87747b
...
...
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 201
7-12-20 20:2
8+0000\n"
"POT-Creation-Date: 201
8-01-12 11:5
8+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
...
...
course_discovery/conf/locale/eo/LC_MESSAGES/django.mo
View file @
2a87747b
No preview for this file type
course_discovery/conf/locale/eo/LC_MESSAGES/django.po
View file @
2a87747b
...
...
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 201
7-12-20 20:2
8+0000\n"
"POT-Creation-Date: 201
8-01-12 11:5
8+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
...
...
@@ -1014,6 +1014,12 @@ msgstr ""
" ∂σłσя ѕιт αмєт, ¢σηѕє¢тєтυя α#"
#: apps/publisher/forms.py
msgid "Please create {} course user role before assigning it owner role"
msgstr ""
"Pléäsé çréäté {} çöürsé üsér rölé ßéföré ässïgnïng ït öwnér rölé Ⱡ'σяєм "
"ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тєтυя α#"
#: apps/publisher/forms.py
msgid "Create initial run for the course"
msgstr ""
"Çréäté ïnïtïäl rün för thé çöürsé Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тє#"
...
...
course_discovery/conf/locale/eo/LC_MESSAGES/djangojs.mo
View file @
2a87747b
No preview for this file type
course_discovery/conf/locale/eo/LC_MESSAGES/djangojs.po
View file @
2a87747b
...
...
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 201
7-12-20 20:2
8+0000\n"
"POT-Creation-Date: 201
8-01-12 11:5
8+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment