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
39299bee
Commit
39299bee
authored
Jun 15, 2017
by
Waheed Ahmed
Committed by
AsadAzam
Jun 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create course user roles upon default role creation for an org.
EDUCATOR-616
parent
7736ba8c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
8 deletions
+52
-8
course_discovery/apps/publisher/admin.py
+9
-3
course_discovery/apps/publisher/tests/test_admin.py
+43
-5
No files found.
course_discovery/apps/publisher/admin.py
View file @
39299bee
...
...
@@ -5,8 +5,9 @@ from guardian.admin import GuardedModelAdmin
from
course_discovery.apps.publisher.assign_permissions
import
assign_permissions
from
course_discovery.apps.publisher.choices
import
InternalUserRole
from
course_discovery.apps.publisher.constants
import
(
PARTNER_MANAGER_GROUP_NAME
,
PROJECT_COORDINATOR_GROUP_NAME
,
PUBLISHER_GROUP_NAME
,
REVIEWER_GROUP_NAME
)
from
course_discovery.apps.publisher.constants
import
(
INTERNAL_USER_GROUP_NAME
,
PARTNER_MANAGER_GROUP_NAME
,
PROJECT_COORDINATOR_GROUP_NAME
,
PUBLISHER_GROUP_NAME
,
REVIEWER_GROUP_NAME
)
from
course_discovery.apps.publisher.forms
import
(
CourseRunAdminForm
,
CourseUserRoleForm
,
OrganizationExtensionForm
,
OrganizationUserRoleForm
,
PublisherUserCreationForm
,
UserAttributesAdminForm
)
...
...
@@ -53,11 +54,16 @@ class OrganizationUserRoleAdmin(admin.ModelAdmin):
def
save_model
(
self
,
request
,
obj
,
form
,
change
):
obj
.
save
()
publisher_courses
=
obj
.
organization
.
publisher_courses
courses_without_role
=
publisher_courses
.
exclude
(
course_user_roles__role
=
obj
.
role
)
CourseUserRole
.
objects
.
bulk_create
(
[
CourseUserRole
(
course
=
course
,
user
=
obj
.
user
,
role
=
obj
.
role
)
for
course
in
courses_without_role
]
)
# Assign user a group according to its role.
group
=
Group
.
objects
.
get
(
name
=
self
.
role_groups_dict
.
get
(
obj
.
role
))
if
group
not
in
obj
.
user
.
groups
.
all
():
obj
.
user
.
groups
.
add
(
group
)
obj
.
user
.
groups
.
add
(
*
(
group
,
Group
.
objects
.
get
(
name
=
INTERNAL_USER_GROUP_NAME
))
)
@admin.register
(
CourseState
)
...
...
course_discovery/apps/publisher/tests/test_admin.py
View file @
39299bee
...
...
@@ -12,6 +12,7 @@ from course_discovery.apps.publisher.constants import (PARTNER_MANAGER_GROUP_NAM
from
course_discovery.apps.publisher.forms
import
CourseRunAdminForm
from
course_discovery.apps.publisher.models
import
CourseRun
,
OrganizationExtension
from
course_discovery.apps.publisher.tests
import
factories
from
course_discovery.apps.publisher.tests.factories
import
CourseFactory
USER_PASSWORD
=
'password'
...
...
@@ -140,9 +141,16 @@ class OrganizationUserRoleAdminTests(TestCase):
super
(
OrganizationUserRoleAdminTests
,
self
)
.
setUp
()
self
.
user
=
UserFactory
(
is_staff
=
True
,
is_superuser
=
True
)
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
USER_PASSWORD
)
self
.
run_state
=
factories
.
CourseRunStateFactory
()
self
.
admin_page_url
=
reverse
(
'admin:publisher_organizationuserrole_add'
)
self
.
organization
=
OrganizationFactory
()
self
.
course1
=
CourseFactory
()
self
.
course2
=
CourseFactory
()
self
.
course1
.
organizations
.
add
(
self
.
organization
)
self
.
course2
.
organizations
.
add
(
self
.
organization
)
@ddt.data
(
(
PublisherUserRole
.
MarketingReviewer
,
REVIEWER_GROUP_NAME
),
(
PublisherUserRole
.
ProjectCoordinator
,
PROJECT_COORDINATOR_GROUP_NAME
),
...
...
@@ -152,15 +160,45 @@ class OrganizationUserRoleAdminTests(TestCase):
@ddt.unpack
def
test_organization_user_role_groups
(
self
,
role
,
group_name
):
"""
Verify that a group is assigned to user according to its role upon OrganizationUserRole creation.
Verify that a group is assigned to user according to its role upon OrganizationUserRole creation
and create course users also.
"""
test_organization
=
OrganizationFactory
()
test_user
=
UserFactory
()
post_data
=
{
'organization'
:
test_
organization
.
id
,
'user'
:
test_user
.
id
,
'role'
:
role
'organization'
:
self
.
organization
.
id
,
'user'
:
test_user
.
id
,
'role'
:
role
}
self
.
client
.
post
(
self
.
admin_page_url
,
data
=
post_data
)
# Verify that user is added to
Marketing Reviewers
group.
# Verify that user is added to
the
group.
self
.
assertIn
(
Group
.
objects
.
get
(
name
=
group_name
),
test_user
.
groups
.
all
())
self
.
assertEqual
(
self
.
course1
.
course_user_roles
.
filter
(
role
=
role
)
.
count
(),
1
)
self
.
assertEqual
(
self
.
course2
.
course_user_roles
.
filter
(
role
=
role
)
.
count
(),
1
)
self
.
assertEqual
(
self
.
course2
.
course_user_roles
.
filter
(
role
=
role
)
.
first
()
.
user
,
test_user
)
def
test_save_method_add_course_user_roles
(
self
):
"""
Verify that save method will not create the duplicate course user roles.
"""
# for course 3 add course roles
user
=
UserFactory
()
course3
=
CourseFactory
()
course3
.
organizations
.
add
(
self
.
organization
)
factories
.
CourseUserRoleFactory
(
course
=
course3
,
role
=
PublisherUserRole
.
MarketingReviewer
,
user
=
user
)
test_user
=
UserFactory
()
post_data
=
{
'organization'
:
self
.
organization
.
id
,
'user'
:
test_user
.
id
,
'role'
:
PublisherUserRole
.
MarketingReviewer
}
self
.
client
.
post
(
self
.
admin_page_url
,
data
=
post_data
)
# for course-3 course-user-role remains there.
self
.
assertTrue
(
course3
.
course_user_roles
.
filter
(
role
=
PublisherUserRole
.
MarketingReviewer
,
user
=
user
)
.
exists
())
self
.
assertTrue
(
self
.
course1
.
course_user_roles
.
filter
(
role
=
PublisherUserRole
.
MarketingReviewer
,
user
=
test_user
)
.
exists
()
)
self
.
assertTrue
(
self
.
course2
.
course_user_roles
.
filter
(
role
=
PublisherUserRole
.
MarketingReviewer
,
user
=
test_user
)
.
exists
()
)
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