Add post callback to request course creator status.
This commit is contained in:
@@ -2,8 +2,10 @@ from django.conf import settings
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.views.decorators.http import require_POST
|
||||
from django_future.csrf import ensure_csrf_cookie
|
||||
from mitxmako.shortcuts import render_to_response
|
||||
from django.core.context_processors import csrf
|
||||
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.modulestore.django import modulestore
|
||||
@@ -11,7 +13,7 @@ from contentstore.utils import get_url_reverse, get_lms_link_for_item
|
||||
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 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 course_creators.views import get_course_creator_status, add_user_with_status_unrequested, user_requested_access
|
||||
|
||||
from .access import has_access
|
||||
|
||||
@@ -45,6 +47,9 @@ def index(request):
|
||||
else:
|
||||
course_creator_status = 'granted'
|
||||
|
||||
request_course_creator_url = reverse('request_course_creator')
|
||||
csrf_token = csrf(request)['csrf_token']
|
||||
|
||||
return render_to_response('index.html', {
|
||||
'new_course_template': Location('i4x', 'edx', 'templates', 'course', 'Empty'),
|
||||
'courses': [(course.display_name,
|
||||
@@ -52,10 +57,21 @@ def index(request):
|
||||
get_lms_link_for_item(course.location, course_id=course.location.course_id))
|
||||
for course in courses],
|
||||
'user': request.user,
|
||||
'course_creator_status': course_creator_status
|
||||
'request_course_creator_url': request_course_creator_url,
|
||||
'course_creator_status': course_creator_status,
|
||||
'csrf': csrf_token
|
||||
})
|
||||
|
||||
|
||||
@require_POST
|
||||
@ensure_csrf_cookie
|
||||
@login_required
|
||||
def request_course_creator(request):
|
||||
user_requested_access(request.user)
|
||||
return JsonResponse({"Status": "OK"})
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
@ensure_csrf_cookie
|
||||
def manage_users(request, location):
|
||||
|
||||
@@ -60,12 +60,14 @@ def post_save_callback(sender, **kwargs):
|
||||
# We only wish to modify the state_changed time if the state has been modified. We don't wish to
|
||||
# modify it for changes to the notes field.
|
||||
if instance.state != instance.orig_state:
|
||||
update_creator_state.send(
|
||||
sender=sender,
|
||||
caller=instance.admin,
|
||||
user=instance.user,
|
||||
add=instance.state == CourseCreator.GRANTED
|
||||
)
|
||||
if hasattr(instance, 'admin'):
|
||||
update_creator_state.send(
|
||||
sender=sender,
|
||||
caller=instance.admin,
|
||||
user=instance.user,
|
||||
add=instance.state == CourseCreator.GRANTED
|
||||
)
|
||||
# TODO: Else must be sure that state change does not switch to or from granted
|
||||
instance.state_changed = timezone.now()
|
||||
instance.orig_state = instance.state
|
||||
instance.save()
|
||||
|
||||
@@ -60,6 +60,17 @@ def get_course_creator_status(user):
|
||||
return user[0].state
|
||||
|
||||
|
||||
def user_requested_access(user):
|
||||
"""
|
||||
User has requested course creator access.
|
||||
|
||||
This changes the user state to CourseCreator.PENDING.
|
||||
"""
|
||||
user = CourseCreator.objects.get(user=user)
|
||||
user.state = CourseCreator.PENDING
|
||||
user.save()
|
||||
|
||||
|
||||
def _add_user(user, state):
|
||||
"""
|
||||
Adds a user to the course creator table with the specified state.
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
<%block name="title">${_("My Courses")}</%block>
|
||||
<%block name="bodyclass">is-signedin index dashboard</%block>
|
||||
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
|
||||
<script src="http://malsup.github.com/jquery.form.js"></script>
|
||||
|
||||
<%block name="header_extras">
|
||||
<script type="text/template" id="new-course-template">
|
||||
<section class="new-course">
|
||||
@@ -44,6 +47,10 @@
|
||||
(e).preventDefault();
|
||||
$(this).closest('.wrapper-creationrights').toggleClass('is-shown').find('.ui-toggle-control').toggleClass('current');
|
||||
});
|
||||
|
||||
$('#request-coursecreator').ajaxForm(function() {
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</%block>
|
||||
@@ -151,10 +158,8 @@
|
||||
<div class="status status-creationrights is-unrequested">
|
||||
<h4 class="title">${_('Your Course Creator Request Status:')}</h4>
|
||||
|
||||
<form id="request-coursecreator" action="request_course_creator_post" method="post">
|
||||
<input type="hidden" id="request-coursecreator-user" name="request-coursecreator-user" value="${ user.username }" />
|
||||
<input type="hidden" id="request-coursecreator-status" name="request-coursecreator-status" value="Requested" />
|
||||
|
||||
<form id="request-coursecreator" action="${request_course_creator_url}" method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrfmiddlewaretoken" value="${csrf}">
|
||||
<div class="form-actions">
|
||||
<button type="submit" id="request-coursecreator-submit" name="request-coursecreator-submit" class="action-primary action-request">${_('Request the Ability to Create Courses')}</button>
|
||||
</div>
|
||||
|
||||
@@ -12,6 +12,7 @@ admin.autodiscover()
|
||||
urlpatterns = ('', # nopep8
|
||||
url(r'^$', 'contentstore.views.howitworks', name='homepage'),
|
||||
url(r'^listing', 'contentstore.views.index', name='index'),
|
||||
url(r'^request_course_creator$', 'contentstore.views.request_course_creator', name='request_course_creator'),
|
||||
url(r'^edit/(?P<location>.*?)$', 'contentstore.views.edit_unit', name='edit_unit'),
|
||||
url(r'^subsection/(?P<location>.*?)$', 'contentstore.views.edit_subsection', name='edit_subsection'),
|
||||
url(r'^preview_component/(?P<location>.*?)$', 'contentstore.views.preview_component', name='preview_component'),
|
||||
|
||||
Reference in New Issue
Block a user