def add_user(request, location): """ This POST-back view will add a user - specified by email - to the list of editors for the specified course """ email = request.POST.get("email") if not email: msg = {"Status": "Failed", "ErrMsg": _("Please specify an email address.")} return JsonResponse(msg, 400) # check that logged in user has admin permissions to this course if not has_access(request.user, location, role=INSTRUCTOR_ROLE_NAME): raise PermissionDenied() user = get_user_by_email(email) # user doesn't exist?!? Return error. if user is None: msg = {"Status": "Failed", "ErrMsg": _("Could not find user by email address '{email}'.").format(email=email)} return JsonResponse(msg, 404) # user exists, but hasn't activated account?!? if not user.is_active: msg = { "Status": "Failed", "ErrMsg": _("User {email} has registered but has not yet activated his/her account.").format(email=email), } return JsonResponse(msg, 400) # ok, we're cool to add to the course group add_user_to_course_group(request.user, user, location, STAFF_ROLE_NAME) return JsonResponse({"Status": "OK"})
def remove_user(request, location): ''' This POST-back view will remove a user - specified by email - from the list of editors for the specified course ''' email = request.POST["email"] # check that logged in user has admin permissions on this course if not has_access(request.user, location, role=INSTRUCTOR_ROLE_NAME): raise PermissionDenied() user = get_user_by_email(email) if user is None: msg = { 'Status': 'Failed', 'ErrMsg': _("Could not find user by email address '{email}'.").format( email=email), } return JsonResponse(msg, 404) # make sure we're not removing ourselves if user.id == request.user.id: raise PermissionDenied() remove_user_from_course_group(request.user, user, location, STAFF_ROLE_NAME) return JsonResponse({"Status": "OK"})
def remove_user(request, location): ''' This POST-back view will remove a user - specified by email - from the list of editors for the specified course ''' email = request.POST["email"] # check that logged in user has admin permissions on this course if not has_access(request.user, location, role=INSTRUCTOR_ROLE_NAME): raise PermissionDenied() user = get_user_by_email(email) if user is None: msg = { 'Status': 'Failed', 'ErrMsg': _("Could not find user by email address '{email}'.").format(email=email), } return JsonResponse(msg, 404) # make sure we're not removing ourselves if user.id == request.user.id: raise PermissionDenied() remove_user_from_course_group(request.user, user, location, STAFF_ROLE_NAME) return JsonResponse({"Status": "OK"})
def add_user(request, location): ''' This POST-back view will add a user - specified by email - to the list of editors for the specified course ''' email = request.POST["email"] if email == '': return create_json_response('Please specify an email address.') # check that logged in user has admin permissions to this course if not has_access(request.user, location, role=INSTRUCTOR_ROLE_NAME): raise PermissionDenied() user = get_user_by_email(email) # user doesn't exist?!? Return error. if user is None: return create_json_response( 'Could not find user by email address \'{0}\'.'.format(email)) # user exists, but hasn't activated account?!? if not user.is_active: return create_json_response( 'User {0} has registered but has not yet activated his/her account.' .format(email)) # ok, we're cool to add to the course group add_user_to_course_group(request.user, user, location, STAFF_ROLE_NAME) return create_json_response()
def remove_user(request, location): ''' This POST-back view will remove a user - specified by email - from the list of editors for the specified course ''' email = request.POST["email"] # check that logged in user has admin permissions on this course if not has_access(request.user, location, role=INSTRUCTOR_ROLE_NAME): raise PermissionDenied() user = get_user_by_email(email) if user is None: return create_json_response( 'Could not find user by email address \'{0}\'.'.format(email)) # make sure we're not removing ourselves if user.id == request.user.id: raise PermissionDenied() remove_user_from_course_group(request.user, user, location, STAFF_ROLE_NAME) return create_json_response()
def add_user(request, location): ''' This POST-back view will add a user - specified by email - to the list of editors for the specified course ''' email = request.POST.get("email") if not email: msg = { 'Status': 'Failed', 'ErrMsg': _('Please specify an email address.'), } return JsonResponse(msg, 400) # remove leading/trailing whitespace if necessary email = email.strip() # check that logged in user has admin permissions to this course if not has_access(request.user, location, role=INSTRUCTOR_ROLE_NAME): raise PermissionDenied() user = get_user_by_email(email) # user doesn't exist?!? Return error. if user is None: msg = { 'Status': 'Failed', 'ErrMsg': _("Could not find user by email address '{email}'.").format( email=email), } return JsonResponse(msg, 404) # user exists, but hasn't activated account?!? if not user.is_active: msg = { 'Status': 'Failed', 'ErrMsg': _('User {email} has registered but has not yet activated his/her account.' ).format(email=email), } return JsonResponse(msg, 400) # ok, we're cool to add to the course group add_user_to_course_group(request.user, user, location, STAFF_ROLE_NAME) return JsonResponse({"Status": "OK"})
def create_a_course(): c = world.CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course') # Add the user to the instructor group of the course # so they will have the permissions to see it in studio g = world.GroupFactory.create(name='instructor_MITx/999/Robot_Super_Course') u = get_user_by_email('*****@*****.**') u.groups.add(g) u.save() world.browser.reload() course_link_css = 'span.class-name' world.css_click(course_link_css) course_title_css = 'span.course-title' assert_true(world.is_css_present(course_title_css))
def create_a_course(): world.CourseFactory.create(org=_COURSE_ORG, course=_COURSE_NUM, display_name=_COURSE_NAME) # Add the user to the instructor group of the course # so they will have the permissions to see it in studio course = world.GroupFactory.create(name='instructor_MITx/{course_num}/{course_name}'.format(course_num=_COURSE_NUM, course_name=_COURSE_NAME.replace(" ", "_"))) user = get_user_by_email('*****@*****.**') user.groups.add(course) user.save() world.browser.reload() course_link_css = 'span.class-name' world.css_click(course_link_css) course_title_css = 'span.course-title' assert_true(world.is_css_present(course_title_css))
def create_a_course(): course = world.CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course') world.scenario_dict['COURSE'] = course user = world.scenario_dict.get("USER") if not user: user = get_user_by_email('*****@*****.**') add_course_author(user, course) # Navigate to the studio dashboard world.visit('/') course_link_css = 'a.course-link' world.css_click(course_link_css) course_title_css = 'span.course-title' assert_true(world.is_css_present(course_title_css))
def other_user_login(_step, name): world.browser.cookies.delete() world.visit('/') signin_css = 'a.action-signin' world.is_css_present(signin_css) world.css_click(signin_css) def fill_login_form(): login_form = world.browser.find_by_css('form#login_form') login_form.find_by_name('email').fill(name + EMAIL_EXTENSION) login_form.find_by_name('password').fill(PASSWORD) login_form.find_by_name('submit').click() world.retry_on_exception(fill_login_form) assert_true(world.is_css_present('.new-course-button')) world.scenario_dict['USER'] = get_user_by_email(name + EMAIL_EXTENSION)
def other_user_login(_step, name): world.visit('logout') world.visit('/') signin_css = 'a.action-signin' world.is_css_present(signin_css) world.css_click(signin_css) def fill_login_form(): login_form = world.browser.find_by_css('form#login_form') login_form.find_by_name('email').fill(name + EMAIL_EXTENSION) login_form.find_by_name('password').fill(PASSWORD) login_form.find_by_name('submit').click() world.retry_on_exception(fill_login_form) assert_true(world.is_css_present('.new-course-button')) world.scenario_dict['USER'] = get_user_by_email(name + EMAIL_EXTENSION)
def other_user_login(step, name): step.given('I log out') world.visit('/') signin_css = 'a.action-signin' world.is_css_present(signin_css) world.css_click(signin_css) def fill_login_form(): login_form = world.browser.find_by_css('form#login_form') login_form.find_by_name('email').fill(name + '@edx.org') login_form.find_by_name('password').fill("test") login_form.find_by_name('submit').click() world.retry_on_exception(fill_login_form) assert_true(world.is_css_present('.new-course-button')) world.scenario_dict['USER'] = get_user_by_email(name + '@edx.org')
def log_into_studio(uname="robot", email="*****@*****.**", password="******"): world.browser.cookies.delete() world.visit("/") signin_css = "a.action-signin" world.is_css_present(signin_css) world.css_click(signin_css) def fill_login_form(): login_form = world.browser.find_by_css("form#login_form") login_form.find_by_name("email").fill(email) login_form.find_by_name("password").fill(password) login_form.find_by_name("submit").click() world.retry_on_exception(fill_login_form) assert_true(world.is_css_present(".new-course-button")) world.scenario_dict["USER"] = get_user_by_email(email)
def create_a_course(): world.CourseFactory.create(org=_COURSE_ORG, course=_COURSE_NUM, display_name=_COURSE_NAME) # Add the user to the instructor group of the course # so they will have the permissions to see it in studio course = world.GroupFactory.create( name='instructor_MITx/{course_num}/{course_name}'.format( course_num=_COURSE_NUM, course_name=_COURSE_NAME.replace(" ", "_"))) user = get_user_by_email('*****@*****.**') user.groups.add(course) user.save() world.browser.reload() course_link_css = 'span.class-name' world.css_click(course_link_css) course_title_css = 'span.course-title' assert_true(world.is_css_present(course_title_css))
def create_a_course(): world.scenario_dict['COURSE'] = world.CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course') # Add the user to the instructor group of the course # so they will have the permissions to see it in studio course = world.GroupFactory.create(name='instructor_MITx/{}/{}'.format(world.scenario_dict['COURSE'].number, world.scenario_dict['COURSE'].display_name.replace(" ", "_"))) if world.scenario_dict.get('USER') is None: user = world.scenario_dict['USER'] else: user = get_user_by_email('*****@*****.**') user.groups.add(course) user.save() world.browser.reload() course_link_css = 'span.class-name' world.css_click(course_link_css) course_title_css = 'span.course-title' assert_true(world.is_css_present(course_title_css))
def log_into_studio( uname='robot', email='*****@*****.**', password='******'): world.browser.cookies.delete() world.visit('/') signin_css = 'a.action-signin' world.is_css_present(signin_css) world.css_click(signin_css) def fill_login_form(): login_form = world.browser.find_by_css('form#login_form') login_form.find_by_name('email').fill(email) login_form.find_by_name('password').fill(password) login_form.find_by_name('submit').click() world.retry_on_exception(fill_login_form) assert_true(world.is_css_present('.new-course-button')) world.scenario_dict['USER'] = get_user_by_email(email)
def log_into_studio(uname='robot', email='*****@*****.**', password='******'): world.browser.cookies.delete() world.visit('/') signin_css = 'a.action-signin' world.is_css_present(signin_css) world.css_click(signin_css) def fill_login_form(): login_form = world.browser.find_by_css('form#login_form') login_form.find_by_name('email').fill(email) login_form.find_by_name('password').fill(password) login_form.find_by_name('submit').click() world.retry_on_exception(fill_login_form) assert_true(world.is_css_present('.new-course-button')) world.scenario_dict['USER'] = get_user_by_email(email)
def create_a_course(): course = world.CourseFactory.create(org="MITx", course="999", display_name="Robot Super Course") world.scenario_dict["COURSE"] = course user = world.scenario_dict.get("USER") if not user: user = get_user_by_email("*****@*****.**") # Add the user to the instructor group of the course # so they will have the permissions to see it in studio for role in ("staff", "instructor"): groupname = get_course_groupname_for_role(course.location, role) group, __ = Group.objects.get_or_create(name=groupname) user.groups.add(group) user.save() world.browser.reload() course_link_css = "span.class-name" world.css_click(course_link_css) course_title_css = "span.course-title" assert_true(world.is_css_present(course_title_css))
def create_a_course(): course = world.CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course') world.scenario_dict['COURSE'] = course user = world.scenario_dict.get("USER") if not user: user = get_user_by_email('*****@*****.**') # Add the user to the instructor group of the course # so they will have the permissions to see it in studio for role in ("staff", "instructor"): groupname = get_course_groupname_for_role(course.location, role) group, __ = Group.objects.get_or_create(name=groupname) user.groups.add(group) user.save() # Navigate to the studio dashboard world.visit('/') course_link_css = 'a.course-link' world.css_click(course_link_css) course_title_css = 'span.course-title' assert_true(world.is_css_present(course_title_css))