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
fbac0672
Commit
fbac0672
authored
Dec 14, 2016
by
Awais Qureshi
Committed by
GitHub
Dec 14, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #479 from edx/awais786/ECOM-6293-list-as-pc
Awais786/ecom 6293 list as pc
parents
39303c11
056b58c7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
5 deletions
+83
-5
course_discovery/apps/publisher/constants.py
+3
-0
course_discovery/apps/publisher/migrations/0019_create_user_groups.py
+35
-0
course_discovery/apps/publisher/tests/test_utils.py
+15
-2
course_discovery/apps/publisher/tests/test_views.py
+0
-0
course_discovery/apps/publisher/utils.py
+15
-1
course_discovery/apps/publisher/views.py
+15
-2
No files found.
course_discovery/apps/publisher/constants.py
View file @
fbac0672
# Name of the administrative group for the Publisher app
ADMIN_GROUP_NAME
=
'Publisher Admins'
INTERNAL_USER_GROUP_NAME
=
'Internal Users'
PARTNER_COORDINATOR_GROUP_NAME
=
'Partner Coordinators'
REVIEWER_GROUP_NAME
=
'Marketing Reviewers'
PUBLISHER_GROUP_NAME
=
'Publishers'
course_discovery/apps/publisher/migrations/0019_create_user_groups.py
0 → 100644
View file @
fbac0672
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
from
course_discovery.apps.publisher.constants
import
(
PARTNER_COORDINATOR_GROUP_NAME
,
PUBLISHER_GROUP_NAME
,
REVIEWER_GROUP_NAME
)
GROUPS
=
[
PARTNER_COORDINATOR_GROUP_NAME
,
REVIEWER_GROUP_NAME
,
PUBLISHER_GROUP_NAME
]
def
create_groups
(
apps
,
schema_editor
):
Group
=
apps
.
get_model
(
'auth'
,
'Group'
)
for
group
in
GROUPS
:
Group
.
objects
.
get_or_create
(
name
=
group
)
def
remove_groups
(
apps
,
schema_editor
):
Group
=
apps
.
get_model
(
'auth'
,
'Group'
)
for
group
in
GROUPS
:
Group
.
objects
.
filter
(
name
=
group
)
.
delete
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'publisher'
,
'0018_create_internal_user_group'
),
(
'auth'
,
'0006_require_contenttypes_0002'
),
]
operations
=
[
migrations
.
RunPython
(
create_groups
,
remove_groups
)
]
course_discovery/apps/publisher/tests/test_utils.py
View file @
fbac0672
...
...
@@ -3,10 +3,13 @@ from django.contrib.auth.models import Group
from
django.test
import
TestCase
from
course_discovery.apps.core.tests.factories
import
UserFactory
from
course_discovery.apps.publisher.constants
import
ADMIN_GROUP_NAME
,
INTERNAL_USER_GROUP_NAME
from
course_discovery.apps.publisher.constants
import
(
ADMIN_GROUP_NAME
,
INTERNAL_USER_GROUP_NAME
,
PARTNER_COORDINATOR_GROUP_NAME
)
from
course_discovery.apps.publisher.tests
import
factories
from
course_discovery.apps.publisher.utils
import
(
is_email_notification_enabled
,
is_publisher_admin
,
is_internal_user
,
get_internal_users
is_email_notification_enabled
,
is_publisher_admin
,
is_internal_user
,
get_internal_users
,
is_partner_coordinator_user
)
...
...
@@ -69,3 +72,13 @@ class PublisherUtilsTests(TestCase):
self
.
user
.
groups
.
add
(
internal_user_group
)
self
.
assertEqual
(
get_internal_users
(),
[
self
.
user
])
def
test_is_partner_coordinator_user
(
self
):
""" Verify the function returns a boolean indicating if the user
is a member of the partner coordinator group.
"""
self
.
assertFalse
(
is_partner_coordinator_user
(
self
.
user
))
partner_coordinator_group
=
Group
.
objects
.
get
(
name
=
PARTNER_COORDINATOR_GROUP_NAME
)
self
.
user
.
groups
.
add
(
partner_coordinator_group
)
self
.
assertTrue
(
is_partner_coordinator_user
(
self
.
user
))
course_discovery/apps/publisher/tests/test_views.py
View file @
fbac0672
This diff is collapsed.
Click to expand it.
course_discovery/apps/publisher/utils.py
View file @
fbac0672
""" Publisher Utils."""
from
course_discovery.apps.core.models
import
User
from
course_discovery.apps.publisher.constants
import
ADMIN_GROUP_NAME
,
INTERNAL_USER_GROUP_NAME
from
course_discovery.apps.publisher.constants
import
(
ADMIN_GROUP_NAME
,
INTERNAL_USER_GROUP_NAME
,
PARTNER_COORDINATOR_GROUP_NAME
)
def
is_email_notification_enabled
(
user
):
...
...
@@ -50,3 +52,15 @@ def get_internal_users():
list
"""
return
list
(
User
.
objects
.
filter
(
groups__name
=
INTERNAL_USER_GROUP_NAME
))
def
is_partner_coordinator_user
(
user
):
""" Returns True if the user is an partner coordinator user.
Arguments:
user (:obj:`User`): User whose permissions should be checked.
Returns:
bool: True, if user is an PC user; otherwise, False.
"""
return
user
.
groups
.
filter
(
name
=
PARTNER_COORDINATOR_GROUP_NAME
)
.
exists
()
course_discovery/apps/publisher/views.py
View file @
fbac0672
...
...
@@ -27,7 +27,10 @@ from course_discovery.apps.publisher.models import (
Course
,
CourseRun
,
Seat
,
State
,
UserAttributes
)
from
course_discovery.apps.publisher.serializers
import
UpdateCourseKeySerializer
from
course_discovery.apps.publisher.utils
import
is_internal_user
,
get_internal_users
,
is_publisher_admin
from
course_discovery.apps.publisher.utils
import
(
is_internal_user
,
get_internal_users
,
is_publisher_admin
,
is_partner_coordinator_user
)
from
course_discovery.apps.publisher.wrappers
import
CourseRunWrapper
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -56,6 +59,7 @@ class Dashboard(mixins.LoginRequiredMixin, ListView):
internal_user_courses
=
Course
.
objects
.
filter
(
course_user_roles__user
=
user
)
course_runs
=
CourseRun
.
objects
.
filter
(
course__in
=
internal_user_courses
)
.
select_related
(
'course'
)
.
all
()
else
:
# in future we will change permission from course to OrganizationExtension model
courses
=
get_objects_for_user
(
user
,
Course
.
VIEW_PERMISSION
,
Course
)
course_runs
=
CourseRun
.
objects
.
filter
(
course__in
=
courses
)
.
select_related
(
'course'
)
.
all
()
...
...
@@ -72,7 +76,16 @@ class Dashboard(mixins.LoginRequiredMixin, ListView):
unpublished_course_runs
=
course_runs
.
exclude
(
state__name
=
State
.
PUBLISHED
)
studio_request_courses
=
unpublished_course_runs
.
filter
(
lms_course_id__isnull
=
True
)
# Studio requests needs to check depending upon the user role with course
# Also user should be part of partner coordinator group.
if
is_publisher_admin
(
self
.
request
.
user
):
studio_request_courses
=
unpublished_course_runs
.
filter
(
lms_course_id__isnull
=
True
)
elif
is_partner_coordinator_user
(
self
.
request
.
user
):
studio_request_courses
=
unpublished_course_runs
.
filter
(
lms_course_id__isnull
=
True
)
.
filter
(
course__course_user_roles__role
=
PublisherUserRole
.
PartnerCoordinator
)
else
:
studio_request_courses
=
[]
context
[
'studio_request_courses'
]
=
[
CourseRunWrapper
(
course_run
)
for
course_run
in
studio_request_courses
]
context
[
'unpublished_course_runs'
]
=
[
CourseRunWrapper
(
course_run
)
for
course_run
in
unpublished_course_runs
]
...
...
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