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
0f5fa3fc
Commit
0f5fa3fc
authored
Jul 03, 2018
by
attiyaishaque
Committed by
Attiya Ishaque
Jul 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add publisher user permission on publisher Organization API.
parent
cf1dad56
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
5 deletions
+22
-5
course_discovery/apps/publisher/api/permissions.py
+3
-0
course_discovery/apps/publisher/api/tests/test_views.py
+18
-4
course_discovery/apps/publisher/api/views.py
+1
-1
No files found.
course_discovery/apps/publisher/api/permissions.py
View file @
0f5fa3fc
...
@@ -30,3 +30,6 @@ class PublisherUserPermission(BasePermission):
...
@@ -30,3 +30,6 @@ class PublisherUserPermission(BasePermission):
def
has_object_permission
(
self
,
request
,
view
,
obj
):
def
has_object_permission
(
self
,
request
,
view
,
obj
):
return
is_publisher_user
(
request
.
user
)
return
is_publisher_user
(
request
.
user
)
def
has_permission
(
self
,
request
,
view
):
return
is_publisher_user
(
request
.
user
)
course_discovery/apps/publisher/api/tests/test_views.py
View file @
0f5fa3fc
...
@@ -145,18 +145,21 @@ class OrganizationGroupUserViewTests(SiteMixin, TestCase):
...
@@ -145,18 +145,21 @@ class OrganizationGroupUserViewTests(SiteMixin, TestCase):
def
setUp
(
self
):
def
setUp
(
self
):
super
(
OrganizationGroupUserViewTests
,
self
)
.
setUp
()
super
(
OrganizationGroupUserViewTests
,
self
)
.
setUp
()
user
=
UserFactory
.
create
(
username
=
"test_user"
,
password
=
USER_PASSWORD
)
self
.
user
=
UserFactory
.
create
(
username
=
"test_user"
,
password
=
USER_PASSWORD
)
self
.
client
.
login
(
username
=
user
.
username
,
password
=
USER_PASSWORD
)
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
USER_PASSWORD
)
self
.
internal_user_group
=
Group
.
objects
.
get
(
name
=
INTERNAL_USER_GROUP_NAME
)
self
.
user
.
groups
.
add
(
self
.
internal_user_group
)
organization_extension
=
factories
.
OrganizationExtensionFactory
()
organization_extension
=
factories
.
OrganizationExtensionFactory
()
self
.
org_user1
=
UserFactory
.
create
(
full_name
=
"org user1"
)
self
.
org_user1
=
UserFactory
.
create
(
full_name
=
"org user1"
)
self
.
org_user2
=
UserFactory
.
create
(
first_name
=
''
,
last_name
=
''
,
full_name
=
''
)
self
.
org_user2
=
UserFactory
.
create
(
first_name
=
''
,
last_name
=
''
,
full_name
=
''
)
organization_extension
.
group
.
user_set
.
add
(
*
[
self
.
org_user1
,
self
.
org_user2
])
organization_extension
.
group
.
user_set
.
add
(
*
[
self
.
org_user1
,
self
.
org_user2
])
self
.
organization
=
organization_extension
.
organization
self
.
organization
=
organization_extension
.
organization
def
test_get_organization_user_group
(
self
):
def
test_get_organization_user_group
_with_publisher_user_permissions
(
self
):
"""
"""
Verify that view returns list of users associated with the group related to given organization id.
Verify that view returns list of users associated with the group related to given organization id with
login users is associated with any publisher group.
"""
"""
response
=
self
.
client
.
get
(
response
=
self
.
client
.
get
(
path
=
self
.
_get_organization_group_user_url
(
self
.
organization
.
id
),
content_type
=
JSON_CONTENT_TYPE
path
=
self
.
_get_organization_group_user_url
(
self
.
organization
.
id
),
content_type
=
JSON_CONTENT_TYPE
...
@@ -184,6 +187,17 @@ class OrganizationGroupUserViewTests(SiteMixin, TestCase):
...
@@ -184,6 +187,17 @@ class OrganizationGroupUserViewTests(SiteMixin, TestCase):
content_type
=
JSON_CONTENT_TYPE
)
content_type
=
JSON_CONTENT_TYPE
)
self
.
assertEqual
(
response
.
status_code
,
404
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_get_organization_user_group_without_publisher_user_permissions
(
self
):
"""
Verify that endpoint returns a permission error with login users not associated
with any publisher group.
"""
self
.
user
.
groups
.
remove
(
self
.
internal_user_group
)
response
=
self
.
client
.
get
(
path
=
self
.
_get_organization_group_user_url
(
self
.
organization
.
id
),
content_type
=
JSON_CONTENT_TYPE
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
_get_organization_group_user_url
(
self
,
org_id
):
def
_get_organization_group_user_url
(
self
,
org_id
):
return
reverse
(
return
reverse
(
'publisher:api:organization_group_users'
,
kwargs
=
{
'pk'
:
org_id
}
'publisher:api:organization_group_users'
,
kwargs
=
{
'pk'
:
org_id
}
...
...
course_discovery/apps/publisher/api/views.py
View file @
0f5fa3fc
...
@@ -38,7 +38,7 @@ class CourseRoleAssignmentView(UpdateAPIView):
...
@@ -38,7 +38,7 @@ class CourseRoleAssignmentView(UpdateAPIView):
class
OrganizationGroupUserView
(
ListAPIView
):
class
OrganizationGroupUserView
(
ListAPIView
):
""" List view for Users filtered by group """
""" List view for Users filtered by group """
serializer_class
=
GroupUserSerializer
serializer_class
=
GroupUserSerializer
permission_classes
=
(
IsAuthenticated
,)
permission_classes
=
(
IsAuthenticated
,
PublisherUserPermission
)
pagination_class
=
LargeResultsSetPagination
pagination_class
=
LargeResultsSetPagination
def
get_queryset
(
self
):
def
get_queryset
(
self
):
...
...
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