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
93dd9b1f
Commit
93dd9b1f
authored
Feb 01, 2018
by
Jeff LaJoie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds in permissions script to discovery to grant admin and group permissions
parent
6d608269
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
+81
-0
course_discovery/apps/publisher/management/commands/create_dev_publisher_user_with_org.py
+81
-0
No files found.
course_discovery/apps/publisher/management/commands/create_dev_publisher_user_with_org.py
0 → 100644
View file @
93dd9b1f
import
logging
from
django.core.management
import
BaseCommand
from
django.contrib.auth.models
import
Group
from
course_discovery.apps.course_metadata.models
import
Organization
from
course_discovery.apps.publisher.choices
import
PublisherUserRole
from
course_discovery.apps.publisher.models
import
OrganizationExtension
,
OrganizationUserRole
from
course_discovery.apps.publisher.constants
import
ADMIN_GROUP_NAME
,
INTERNAL_USER_GROUP_NAME
from
course_discovery.apps.core.models
import
User
logger
=
logging
.
getLogger
(
__name__
)
class
Command
(
BaseCommand
):
help
=
'Adds a dev publisher user to an example org with permissions'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--username'
,
action
=
'store'
,
dest
=
'username'
,
default
=
'edx'
,
required
=
False
,
help
=
'Username to add permissions to.'
)
parser
.
add_argument
(
'--organization_name'
,
action
=
'store'
,
dest
=
'organization_name'
,
default
=
'edX'
,
required
=
False
,
help
=
'Username to add permissions to.'
)
def
handle
(
self
,
*
args
,
**
options
):
"""Adds a dev publisher user to an example org with permissions"""
# Find the user your want to modify (edx) and set their permissions (active, staff, superuser)
user
=
User
.
objects
.
get
(
username
=
options
.
get
(
'username'
))
print
(
'Retrieved user {}'
.
format
(
user
.
username
))
user
.
is_active
=
True
user
.
is_staff
=
True
user
.
is_superuser
=
True
# Add the groups you want to the user
groups
=
Group
.
objects
.
filter
(
name__in
=
[
ADMIN_GROUP_NAME
,
INTERNAL_USER_GROUP_NAME
])
for
group
in
groups
:
if
group
not
in
user
.
groups
.
all
():
print
(
'Added {} group to {} user'
.
format
(
group
.
name
,
user
.
username
))
user
.
groups
.
add
(
group
)
# Find the Organization that the user should be a part of
organization
=
Organization
.
objects
.
get
(
key
=
options
.
get
(
'organization_name'
))
print
(
'Retrieved {} organization'
.
format
(
organization
.
name
))
# Add Organization Course Admin via PublisherOrganizationExtension
organization_extension
,
created
=
OrganizationExtension
.
objects
.
get_or_create
(
organization
=
organization
)
if
created
:
print
(
'Created new Organization Extension for {}'
.
format
(
organization
.
name
))
else
:
print
(
'Retrieved Organization Extension for {}'
.
format
(
organization
.
name
))
organization_extension
.
group
=
Group
.
objects
.
get
(
name
=
ADMIN_GROUP_NAME
)
organization_extension
.
auto_create_in_studio
=
False
organization_extension
.
save
()
print
(
'Updated Organization Extension with {} group'
.
format
(
ADMIN_GROUP_NAME
))
# Create an OrganizationUserRole if it doesn't exist, setting the role to publisher, organization and user
organization_user_role
,
created
=
OrganizationUserRole
.
objects
.
get_or_create
(
user
=
user
,
organization
=
organization
)
if
created
:
print
(
'Created new Organization Role for user {} and organization {}'
.
format
(
user
.
username
,
organization
.
name
))
organization_user_role
.
role
=
PublisherUserRole
.
Publisher
organization_user_role
.
save
()
user
.
save
()
print
(
'Successfully granted permissions to {}'
.
format
(
user
.
username
))
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