Commit f911c96d by cahrens

Pass course_creator_status to index.html.

parent 41651308
...@@ -11,6 +11,7 @@ from contentstore.utils import get_url_reverse, get_lms_link_for_item ...@@ -11,6 +11,7 @@ from contentstore.utils import get_url_reverse, get_lms_link_for_item
from util.json_request import expect_json, JsonResponse from util.json_request import expect_json, JsonResponse
from auth.authz import STAFF_ROLE_NAME, INSTRUCTOR_ROLE_NAME, get_users_in_course_group_by_role from auth.authz import STAFF_ROLE_NAME, INSTRUCTOR_ROLE_NAME, get_users_in_course_group_by_role
from auth.authz import get_user_by_email, add_user_to_course_group, remove_user_from_course_group from auth.authz import get_user_by_email, add_user_to_course_group, remove_user_from_course_group
from course_creators.views import get_course_creator_status, add_user_with_status_unrequested
from .access import has_access from .access import has_access
...@@ -32,6 +33,18 @@ def index(request): ...@@ -32,6 +33,18 @@ def index(request):
and course.location.name != '') and course.location.name != '')
courses = filter(course_filter, courses) courses = filter(course_filter, courses)
disable_course_creation = settings.MITX_FEATURES.get('DISABLE_COURSE_CREATION', False) and not request.user.is_staff
control_course_creation = settings.MITX_FEATURES.get('ENABLE_CREATOR_GROUP', False)
# course_creator_status should only be used if disable_course_creation is False.
course_creator_status = 'granted'
if not disable_course_creation and control_course_creation:
course_creator_status = get_course_creator_status(request.user)
if course_creator_status is None:
# User not grandfathered in as an existing user, has not previously visited the dashboard page.
# Add the user to the course creator admin table with status 'unrequested'.
add_user_with_status_unrequested(request.user)
course_creator_status = get_course_creator_status(request.user)
return render_to_response('index.html', { return render_to_response('index.html', {
'new_course_template': Location('i4x', 'edx', 'templates', 'course', 'Empty'), 'new_course_template': Location('i4x', 'edx', 'templates', 'course', 'Empty'),
'courses': [(course.display_name, 'courses': [(course.display_name,
...@@ -39,7 +52,8 @@ def index(request): ...@@ -39,7 +52,8 @@ def index(request):
get_lms_link_for_item(course.location, course_id=course.location.course_id)) get_lms_link_for_item(course.location, course_id=course.location.course_id))
for course in courses], for course in courses],
'user': request.user, 'user': request.user,
'disable_course_creation': settings.MITX_FEATURES.get('DISABLE_COURSE_CREATION', False) and not request.user.is_staff 'disable_course_creation': disable_course_creation,
'course_creator_status': course_creator_status
}) })
......
...@@ -2,19 +2,18 @@ ...@@ -2,19 +2,18 @@
Methods for interacting programmatically with the user creator table. Methods for interacting programmatically with the user creator table.
""" """
from course_creators.models import CourseCreator from course_creators.models import CourseCreator
from django.core.exceptions import PermissionDenied
from auth.authz import add_user_to_creator_group, remove_user_from_creator_group from auth.authz import add_user_to_creator_group, remove_user_from_creator_group
def add_user_with_status_unrequested(caller, user): def add_user_with_status_unrequested(user):
""" """
Adds a user to the course creator table with status 'unrequested'. Adds a user to the course creator table with status 'unrequested'.
If the user is already in the table, this method is a no-op If the user is already in the table, this method is a no-op
(state will not be changed). Caller must have staff permissions. (state will not be changed).
""" """
_add_user(caller, user, CourseCreator.UNREQUESTED) _add_user(user, CourseCreator.UNREQUESTED)
def add_user_with_status_granted(caller, user): def add_user_with_status_granted(caller, user):
...@@ -26,7 +25,7 @@ def add_user_with_status_granted(caller, user): ...@@ -26,7 +25,7 @@ def add_user_with_status_granted(caller, user):
This method also adds the user to the course creator group maintained by authz.py. This method also adds the user to the course creator group maintained by authz.py.
""" """
_add_user(caller, user, CourseCreator.GRANTED) _add_user(user, CourseCreator.GRANTED)
update_course_creator_group(caller, user, True) update_course_creator_group(caller, user, True)
...@@ -61,16 +60,13 @@ def get_course_creator_status(user): ...@@ -61,16 +60,13 @@ def get_course_creator_status(user):
return user[0].state return user[0].state
def _add_user(caller, user, state): def _add_user(user, state):
""" """
Adds a user to the course creator table with the specified state. Adds a user to the course creator table with the specified state.
If the user is already in the table, this method is a no-op If the user is already in the table, this method is a no-op
(state will not be changed). (state will not be changed).
""" """
if not caller.is_active or not caller.is_authenticated or not caller.is_staff:
raise PermissionDenied
if CourseCreator.objects.filter(user=user).count() == 0: if CourseCreator.objects.filter(user=user).count() == 0:
entry = CourseCreator(user=user, state=state) entry = CourseCreator(user=user, state=state)
entry.save() entry.save()
...@@ -2,6 +2,22 @@ ...@@ -2,6 +2,22 @@
<%inherit file="base.html" /> <%inherit file="base.html" />
<%block name="jsextra">
<script type="text/javascript">
$(document).ready(function () {
// showing/hiding authorship rights UI
$('.show-authorshiprights').click(function(e){
(e).preventDefault();
$(this).closest('.wrapper-authorshiprights').toggleClass('is-shown').find('.ui-toggle-control').toggleClass('current');
});
});
</script>
</%block>
<%block name="title">${_("My Courses")}</%block> <%block name="title">${_("My Courses")}</%block>
<%block name="bodyclass">is-signedin index dashboard</%block> <%block name="bodyclass">is-signedin index dashboard</%block>
...@@ -45,13 +61,12 @@ ...@@ -45,13 +61,12 @@
<ul> <ul>
<li class="nav-item"> <li class="nav-item">
<!-- if can create courses --> <!-- if can create courses -->
% if not disable_course_creation: % if not disable_course_creation and course_creator_status=='granted':
<a href="#" class="button new-button new-course-button"><i class="icon-plus"></i> ${_("New Course")}</a> <a href="#" class="button new-button new-course-button"><i class="icon-plus icon-inline"></i>
${_("New Course")}</a>
<!-- if cannot create courses --> % elif disable_course_creation and settings.MITX_FEATURES.get('STAFF_EMAIL',''):
% elif settings.MITX_FEATURES.get('STAFF_EMAIL',''): <a href="mailto:${settings.MITX_FEATURES.get('STAFF_EMAIL','')}">${_("Email staff to create course")}</a>
<a href="mailto:${settings.MITX_FEATURES.get('STAFF_EMAIL','')}">${_("Email staff to create course")}</a> % endif
% endif
</li> </li>
</ul> </ul>
</nav> </nav>
...@@ -65,18 +80,18 @@ ...@@ -65,18 +80,18 @@
<section class="content"> <section class="content">
<article class="content-primary" role="main"> <article class="content-primary" role="main">
<!-- if no courses and can create courses -->
<!-- if no courses and cannot create courses -->
<!-- if has courses -->
<div class="introduction"> <div class="introduction">
<h2 class="title">${_("Welcome, %(name)s!") % dict(name= user.username)}</h2> <h2 class="title">${_("Welcome, %(name)s!") % dict(name= user.username)}</h2>
<div class="copy"> <div class="copy">
<p>${_("Here are all of the courses you currently have access to in Studio:")}</p> %if len(courses) > 0:
<p>${_("Here are all of the courses you currently have access to in Studio:")}</p>
%else:
<!-- TODO: update this copy -->
<p>${_("Sorry, you don't have any courses!")}</p>
%endif
</div> </div>
</div> </div>
<div class="my-classes"> <div class="my-classes">
...@@ -103,20 +118,21 @@ ...@@ -103,20 +118,21 @@
<p>${_('edX Studio is a hosted solution for our xConsortium partners and selected guests. Courses for which you are a team member appear above for you to edit, while Course Authorship privileges are granted by edX. Our team will evaluate your request and provide you feedback within 24 hours during the work week.')}</p> <p>${_('edX Studio is a hosted solution for our xConsortium partners and selected guests. Courses for which you are a team member appear above for you to edit, while Course Authorship privileges are granted by edX. Our team will evaluate your request and provide you feedback within 24 hours during the work week.')}</p>
</div> </div>
!-- if request is unrequested --> <!-- if request is unrequested -->
%if course_creator_status = "unrequested": %if course_creator_status == "unrequested":
<div class="status status-authorship is-unrequested"> <div class="status status-authorship is-unrequested">
<h4 class="title">${_('Your Authorship Request Status:')}</h4> <h4 class="title">${_('Your Authorship Request Status:')}</h4>
<ul class="list-actions"> <ul class="list-actions">
<li class="action-item"> <li class="action-item">
<a href="#" class="action-primary action-request">${_('Request the Ability to Author Courses')}</a> <!-- request_course_creator_post -->
<a href="#" class="action-primary action-request">${_('Request the Ability to Create Courses')}</a>
</li> </li>
</ul> </ul>
</div> </div>
!-- if request is pending --> <!-- if request is pending -->
%elif course_creator_status = "pending": %elif course_creator_status == "pending":
<div class="status status-authorship has-status is-pending"> <div class="status status-authorship has-status is-pending">
<h4 class="title">${_('Your Authorship Request Status:')}</h4> <h4 class="title">${_('Your Authorship Request Status:')}</h4>
...@@ -130,8 +146,8 @@ ...@@ -130,8 +146,8 @@
</dl> </dl>
</div> </div>
!-- if request is denied --> <!-- if request is denied -->
%elif course_creator_status = "denied": %elif course_creator_status == "denied":
<div class="status status-authorship has-status is-denied"> <div class="status status-authorship has-status is-denied">
<h4 class="title">${_('Your Authorship Request Status:')}</h4> <h4 class="title">${_('Your Authorship Request Status:')}</h4>
...@@ -174,14 +190,14 @@ ...@@ -174,14 +190,14 @@
% endif % endif
<!-- if request is unrequested --> <!-- if request is unrequested -->
% if not disable_course_creation and course_creator_status = "unrequested": % if not disable_course_creation and course_creator_status == "unrequested":
<div class="bit"> <div class="bit">
<h3 class="title title-3">${_('Can I create courses in Studio?')}</h3> <h3 class="title title-3">${_('Can I create courses in Studio?')}</h3>
<p>${_('In order to create courses in Studio, you must have authorship rights to create your own course.')}</p> <p>${_('In order to create courses in Studio, you must have authorship rights to create your own course.')}</p>
</div> </div>
<!-- if request is denied --> <!-- if request is denied -->
% elif not disable_course_creation and course_creator_status = "denied": % elif not disable_course_creation and course_creator_status == "denied":
<div class="bit"> <div class="bit">
<h3 class="title title-3">${_('Can I create courses in Studio?')}</h3> <h3 class="title title-3">${_('Can I create courses in Studio?')}</h3>
<p>${_('Your request to author courses in studio has been denied. Please')} <a href="http://help.edge.edx.org/discussion/new" class="show-tender">${_('contact edX Staff with further questions')}</a></p> <p>${_('Your request to author courses in studio has been denied. Please')} <a href="http://help.edge.edx.org/discussion/new" class="show-tender">${_('contact edX Staff with further questions')}</a></p>
...@@ -204,7 +220,7 @@ ...@@ -204,7 +220,7 @@
<div class="msg"> <div class="msg">
<h3 class="title">${_('We need to verify your email address')}</h3> <h3 class="title">${_('We need to verify your email address')}</h3>
<div class="copy"> <div class="copy">
<p>${_('Almost there! In order to complete your sign up we need you verify your $emailaddress email address. An activation message and next steps should be waiting for you there.')}</p> <p>${_('Almost there! In order to complete your sign up we need you verify your email address (%(email)s). An activation message and next steps should be waiting for you there.') % dict(email=user.email)}</p>
</div> </div>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment