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
dc3a7ab6
Commit
dc3a7ab6
authored
Oct 25, 2016
by
Clinton Blackburn
Committed by
Awais
Oct 27, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement publisher admin using Django group.
ECOM-5950
parent
74ebfff8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
3 deletions
+57
-3
course_discovery/apps/publisher/constants.py
+2
-0
course_discovery/apps/publisher/migrations/0014_create_admin_group.py
+27
-0
course_discovery/apps/publisher/tests/test_utils.py
+15
-3
course_discovery/apps/publisher/utils.py
+13
-0
No files found.
course_discovery/apps/publisher/constants.py
0 → 100644
View file @
dc3a7ab6
# Name of the administrative group for the Publisher app
ADMIN_GROUP_NAME
=
'Publisher Admins'
course_discovery/apps/publisher/migrations/0014_create_admin_group.py
0 → 100644
View file @
dc3a7ab6
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
from
course_discovery.apps.publisher.constants
import
ADMIN_GROUP_NAME
def
create_admin_group
(
apps
,
schema_editor
):
Group
=
apps
.
get_model
(
'auth'
,
'Group'
)
Group
.
objects
.
get_or_create
(
name
=
ADMIN_GROUP_NAME
)
def
remove_admin_group
(
apps
,
schema_editor
):
Group
=
apps
.
get_model
(
'auth'
,
'Group'
)
Group
.
objects
.
filter
(
name
=
ADMIN_GROUP_NAME
)
.
delete
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'publisher'
,
'0013_create_enable_email_notifications_switch'
),
(
'auth'
,
'0006_require_contenttypes_0002'
),
]
operations
=
[
migrations
.
RunPython
(
create_admin_group
,
remove_admin_group
)
]
course_discovery/apps/publisher/tests/test_utils.py
View file @
dc3a7ab6
""" Tests publisher.utils"""
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
from
course_discovery.apps.publisher.tests
import
factories
from
course_discovery.apps.publisher.utils
import
is_email_notification_enabled
from
course_discovery.apps.publisher.utils
import
is_email_notification_enabled
,
is_publisher_admin
class
PublisherUtilsTests
(
TestCase
):
...
...
@@ -33,7 +34,18 @@ class PublisherUtilsTests(TestCase):
# Disabled email notification
user_attribute
.
enable_email_notification
=
False
user_attribute
.
save
()
# pylint: disable=no-member
user_attribute
.
save
()
# pylint: disable=no-member
# Verify that email notifications are disabled for the user
self
.
assertEqual
(
is_email_notification_enabled
(
self
.
user
),
False
)
def
test_is_publisher_admin
(
self
):
""" Verify the function returns a boolean indicating if the user
is a member of the administrative group.
"""
self
.
assertFalse
(
self
.
user
.
groups
.
filter
(
name
=
ADMIN_GROUP_NAME
)
.
exists
())
self
.
assertFalse
(
is_publisher_admin
(
self
.
user
))
admin_group
=
Group
.
objects
.
get
(
name
=
ADMIN_GROUP_NAME
)
self
.
user
.
groups
.
add
(
admin_group
)
self
.
assertTrue
(
is_publisher_admin
(
self
.
user
))
course_discovery/apps/publisher/utils.py
View file @
dc3a7ab6
""" Publisher Utils."""
from
course_discovery.apps.publisher.constants
import
ADMIN_GROUP_NAME
def
is_email_notification_enabled
(
user
):
...
...
@@ -14,3 +15,15 @@ def is_email_notification_enabled(user):
return
user
.
attributes
.
enable_email_notification
return
True
def
is_publisher_admin
(
user
):
""" Returns True if the user is a Publisher administrator.
Arguments:
user (:obj:`User`): User whose permissions should be checked.
Returns:
bool: True, if user is an administrator; otherwise, False.
"""
return
user
.
groups
.
filter
(
name
=
ADMIN_GROUP_NAME
)
.
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