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
8f7f36ea
Commit
8f7f36ea
authored
Mar 15, 2017
by
Waheed Ahmed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assign user to related role group upon OrganizationUserRole creation.
ECOM-7438
parent
688c7a0a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
3 deletions
+54
-3
course_discovery/apps/publisher/admin.py
+17
-1
course_discovery/apps/publisher/tests/test_admin.py
+37
-2
No files found.
course_discovery/apps/publisher/admin.py
View file @
8f7f36ea
...
...
@@ -4,7 +4,9 @@ from django.contrib.auth.models import Group
from
guardian.admin
import
GuardedModelAdmin
from
guardian.shortcuts
import
assign_perm
from
course_discovery.apps.publisher.constants
import
PROJECT_COORDINATOR_GROUP_NAME
,
REVIEWER_GROUP_NAME
from
course_discovery.apps.publisher.choices
import
PublisherUserRole
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.forms
import
(
CourseRunAdminForm
,
CourseUserRoleForm
,
OrganizationUserRoleForm
,
PublisherUserCreationForm
,
UserAttributesAdminForm
)
from
course_discovery.apps.publisher.models
import
(
Course
,
CourseRun
,
CourseRunState
,
CourseState
,
CourseUserRole
,
...
...
@@ -62,6 +64,20 @@ class UserAttributesAdmin(admin.ModelAdmin):
@admin.register
(
OrganizationUserRole
)
class
OrganizationUserRoleAdmin
(
admin
.
ModelAdmin
):
form
=
OrganizationUserRoleForm
role_groups_dict
=
{
PublisherUserRole
.
MarketingReviewer
:
REVIEWER_GROUP_NAME
,
PublisherUserRole
.
ProjectCoordinator
:
PROJECT_COORDINATOR_GROUP_NAME
,
PublisherUserRole
.
Publisher
:
PUBLISHER_GROUP_NAME
,
PublisherUserRole
.
PartnerManager
:
PARTNER_MANAGER_GROUP_NAME
}
def
save_model
(
self
,
request
,
obj
,
form
,
change
):
obj
.
save
()
# 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
)
@admin.register
(
CourseState
)
...
...
course_discovery/apps/publisher/tests/test_admin.py
View file @
8f7f36ea
...
...
@@ -6,7 +6,9 @@ from guardian.shortcuts import get_group_perms
from
course_discovery.apps.core.tests.factories
import
UserFactory
from
course_discovery.apps.course_metadata.tests.factories
import
OrganizationFactory
from
course_discovery.apps.publisher.constants
import
PROJECT_COORDINATOR_GROUP_NAME
,
REVIEWER_GROUP_NAME
from
course_discovery.apps.publisher.choices
import
PublisherUserRole
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.forms
import
CourseRunAdminForm
from
course_discovery.apps.publisher.models
import
CourseRun
,
OrganizationExtension
from
course_discovery.apps.publisher.tests
import
factories
...
...
@@ -15,7 +17,6 @@ USER_PASSWORD = 'password'
# pylint: disable=no-member
@ddt.ddt
class
AdminTests
(
TestCase
):
""" Tests Admin page."""
...
...
@@ -129,3 +130,37 @@ class OrganizationExtensionAdminTests(TestCase):
def
_assert_permissions
(
self
,
organization_extension
,
group
,
expected_permissions
):
permissions
=
get_group_perms
(
group
,
organization_extension
)
self
.
assertEqual
(
sorted
(
permissions
),
sorted
(
expected_permissions
))
@ddt.ddt
class
OrganizationUserRoleAdminTests
(
TestCase
):
""" Tests for OrganizationUserRoleAdmin."""
def
setUp
(
self
):
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'
)
@ddt.data
(
(
PublisherUserRole
.
MarketingReviewer
,
REVIEWER_GROUP_NAME
),
(
PublisherUserRole
.
ProjectCoordinator
,
PROJECT_COORDINATOR_GROUP_NAME
),
(
PublisherUserRole
.
Publisher
,
PUBLISHER_GROUP_NAME
),
(
PublisherUserRole
.
PartnerManager
,
PARTNER_MANAGER_GROUP_NAME
)
)
@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.
"""
test_organization
=
OrganizationFactory
()
test_user
=
UserFactory
()
post_data
=
{
'organization'
:
test_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.
self
.
assertIn
(
Group
.
objects
.
get
(
name
=
group_name
),
test_user
.
groups
.
all
())
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