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
ab4b9a7d
Commit
ab4b9a7d
authored
Jan 27, 2017
by
Waheed Ahmed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed organization queryset and team admin issues.
ECOM-6969
parent
e8847a17
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
13 deletions
+62
-13
course_discovery/apps/publisher/forms.py
+11
-4
course_discovery/apps/publisher/tests/test_views.py
+32
-2
course_discovery/static/js/publisher/publisher.js
+16
-4
course_discovery/templates/publisher/add_courserun_form.html
+3
-3
No files found.
course_discovery/apps/publisher/forms.py
View file @
ab4b9a7d
...
...
@@ -12,7 +12,7 @@ from opaque_keys.edx.keys import CourseKey
from
course_discovery.apps.course_metadata.choices
import
CourseRunPacing
from
course_discovery.apps.course_metadata.models
import
Person
,
Organization
,
Subject
from
course_discovery.apps.ietf_language_tags.models
import
LanguageTag
from
course_discovery.apps.publisher.mixins
import
LanguageModelSelect2Multiple
from
course_discovery.apps.publisher.mixins
import
LanguageModelSelect2Multiple
,
check_roles_access
from
course_discovery.apps.publisher.models
import
(
Course
,
CourseRun
,
Seat
,
User
,
OrganizationExtension
,
OrganizationUserRole
,
CourseUserRole
)
...
...
@@ -144,11 +144,18 @@ class CustomCourseForm(CourseForm):
self
.
declared_fields
[
'team_admin'
]
.
queryset
=
User
.
objects
.
filter
(
groups__name
=
org_extension
.
group
)
if
user
:
self
.
declared_fields
[
'organization'
]
.
queryset
=
Organization
.
objects
.
filter
(
organization_extension__organization_id__isnull
=
False
,
organization_extension__group__in
=
user
.
groups
.
all
()
organizations
=
Organization
.
objects
.
filter
(
organization_extension__organization_id__isnull
=
False
)
if
not
check_roles_access
(
user
):
# If not internal user return only those organizations which belongs to user.
organizations
=
organizations
.
filter
(
organization_extension__group__in
=
user
.
groups
.
all
()
)
self
.
declared_fields
[
'organization'
]
.
queryset
=
organizations
super
(
CustomCourseForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
if
edit_mode
:
self
.
fields
[
'title'
]
.
widget
=
forms
.
HiddenInput
()
...
...
course_discovery/apps/publisher/tests/test_views.py
View file @
ab4b9a7d
...
...
@@ -216,11 +216,41 @@ class CreateCourseViewTests(TestCase):
"""Verify that if there are more than one organization then there will be
a drop down of organization choices.
"""
self
.
user
.
groups
.
remove
(
self
.
internal_user_group
)
organization_extension
=
factories
.
OrganizationExtensionFactory
()
self
.
user
.
groups
.
add
(
organization_extension
.
group
)
response
=
self
.
client
.
get
(
reverse
(
'publisher:publisher_courses_new'
))
self
.
assertContains
(
response
,
'<select class="field-input input-select" id="id_organization" name="organization">'
)
self
.
assertContains
(
response
,
'<select class="field-input input-select" id="id_organization" name="organization">'
)
new_organization_extension
=
factories
.
OrganizationExtensionFactory
()
response
=
self
.
client
.
get
(
reverse
(
'publisher:publisher_courses_new'
))
# Verify that course team user cannot see newly created organization in options.
self
.
assertNotContains
(
response
,
'<option value="{value}">{key}: {name}</option>'
.
format
(
value
=
new_organization_extension
.
organization
.
id
,
key
=
new_organization_extension
.
organization
.
key
,
name
=
new_organization_extension
.
organization
.
name
)
)
self
.
user
.
groups
.
add
(
self
.
internal_user_group
)
response
=
self
.
client
.
get
(
reverse
(
'publisher:publisher_courses_new'
))
# Verify that internal user can see newly created organization in options.
self
.
assertContains
(
response
,
'<option value="{value}">{key}: {name}</option>'
.
format
(
value
=
new_organization_extension
.
organization
.
id
,
key
=
new_organization_extension
.
organization
.
key
,
name
=
new_organization_extension
.
organization
.
name
)
)
@ddt.data
(
'contacted_partner_manager'
,
'pacing_type'
)
def
test_create_without_selecting_radio_buttons
(
self
,
button_field
):
...
...
course_discovery/static/js/publisher/publisher.js
View file @
ab4b9a7d
...
...
@@ -101,14 +101,26 @@ function loadAdminUsers(org_id) {
$
.
getJSON
({
url
:
'/publisher/api/admins/organizations/'
+
org_id
+
'/users/'
,
success
:
function
(
data
)
{
var
teamAdminDropDown
=
$
(
'#id_team_admin'
);
var
teamAdminDropDown
=
$
(
'#id_team_admin'
),
selectedTeamAdmin
=
$
(
'#id_team_admin option:selected'
).
val
(),
organizationInputType
=
$
(
'#id_organization'
).
attr
(
'type'
);
teamAdminDropDown
.
empty
();
// it will looks same like other django model choice fields
teamAdminDropDown
.
append
(
'<option selected="selected">---------</option>'
);
if
(
organizationInputType
==
'hidden'
)
{
teamAdminDropDown
.
append
(
'<option>---------</option>'
);
}
else
{
// it will looks same like other django model choice fields
teamAdminDropDown
.
append
(
'<option selected="selected">---------</option>'
);
}
$
.
each
(
data
.
results
,
function
(
i
,
user
)
{
teamAdminDropDown
.
append
(
$
(
'<option> </option>'
).
val
(
user
.
id
).
html
(
user
.
full_name
));
if
(
selectedTeamAdmin
==
user
.
id
&&
organizationInputType
===
'hidden'
)
{
teamAdminDropDown
.
append
(
$
(
'<option selected="selected"> </option>'
).
val
(
user
.
id
).
html
(
user
.
full_name
)
);
}
else
{
teamAdminDropDown
.
append
(
$
(
'<option> </option>'
).
val
(
user
.
id
).
html
(
user
.
full_name
));
}
});
}
});
...
...
course_discovery/templates/publisher/add_courserun_form.html
View file @
ab4b9a7d
...
...
@@ -87,10 +87,10 @@
{{ course_form.team_admin }}
</div>
</div>
{% if parent_course.team_admin %}
{% if parent_course.
course_
team_admin %}
<div
class=
"field-admin-name margin-top20 {% if course_form.team_admin.errors %}hidden{% endif %}"
>
<span
class=
"field-readonly"
>
{{ parent_course.
team_admin.user
name }}
</span>
<input
id=
"team-admin-id"
type=
"hidden"
value=
"{{ parent_course.team_admin.id }}"
>
<span
class=
"field-readonly"
>
{{ parent_course.
course_team_admin.full_
name }}
</span>
<input
id=
"team-admin-id"
type=
"hidden"
value=
"{{ parent_course.
course_
team_admin.id }}"
>
<div>
<a
id=
"change-admin"
href=
"#"
>
{% trans "Change" %}
</a>
</div>
...
...
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