def test_set_roles(self, course_id, course_key): seed_permissions_roles(course_key) course_roles = dict((r.name, r) for r in Role.objects.filter(course_id=course_key)) self.assertEqual(len(course_roles), 5) # sanity check # Student role is assigned by default on course enrollment. self._auto_auth({'username': '******', 'course_id': course_id}) user = User.objects.get(username='******') user_roles = user.roles.all() self.assertEqual(len(user_roles), 1) self.assertEqual(user_roles[0], course_roles[FORUM_ROLE_STUDENT]) self.client.logout() self._auto_auth({'username': '******', 'course_id': course_id, 'roles': 'Moderator'}) user = User.objects.get(username='******') user_roles = user.roles.all() self.assertEqual( set(user_roles), set([course_roles[FORUM_ROLE_STUDENT], course_roles[FORUM_ROLE_MODERATOR]])) # check multiple roles work. self.client.logout() self._auto_auth({ 'username': '******', 'course_id': course_id, 'roles': '{},{}'.format(FORUM_ROLE_MODERATOR, FORUM_ROLE_ADMINISTRATOR) }) user = User.objects.get(username='******') user_roles = user.roles.all() self.assertEqual( set(user_roles), set([course_roles[FORUM_ROLE_STUDENT], course_roles[FORUM_ROLE_MODERATOR], course_roles[FORUM_ROLE_ADMINISTRATOR]]))
def initialize_permissions(course_key, user_who_created_course): """ Initializes a new course by enrolling the course creator as a student, and initializing Forum by seeding its permissions and assigning default roles. """ # seed the forums seed_permissions_roles(course_key) # auto-enroll the course creator in the course so that "View Live" will work. CourseEnrollment.enroll(user_who_created_course, course_key) # set default forum roles (assign 'Student' role) assign_default_role(course_key, user_who_created_course)
def setUp(self): super(CohortedTestCase, self).setUp() seed_permissions_roles(self.course.id) self.student = UserFactory.create() self.moderator = UserFactory.create() CourseEnrollmentFactory(user=self.student, course_id=self.course.id) CourseEnrollmentFactory(user=self.moderator, course_id=self.course.id) self.moderator.roles.add(Role.objects.get(name="Moderator", course_id=self.course.id)) self.student_cohort = CohortFactory.create( name="student_cohort", course_id=self.course.id, users=[self.student] ) self.moderator_cohort = CohortFactory.create( name="moderator_cohort", course_id=self.course.id, users=[self.moderator] )
def handle(self, *args, **options): data_dir = options['data_directory'] source_dirs = options['course_dirs'] if len(source_dirs) == 0: source_dirs = None do_import_static = not options.get('nostatic', False) # If the static content is not skipped, the python lib should be imported regardless # of the 'nopythonlib' flag. do_import_python_lib = do_import_static or not options.get('nopythonlib', False) python_lib_filename = options.get('python_lib_filename') output = ( u"Importing...\n" u" data_dir={data}, source_dirs={courses}\n" u" Importing static content? {import_static}\n" u" Importing python lib? {import_python_lib}" ).format( data=data_dir, courses=source_dirs, import_static=do_import_static, import_python_lib=do_import_python_lib ) self.stdout.write(output) mstore = modulestore() course_items = import_course_from_xml( mstore, ModuleStoreEnum.UserID.mgmt_command, data_dir, source_dirs, load_error_modules=False, static_content_store=contentstore(), verbose=True, do_import_static=do_import_static, do_import_python_lib=do_import_python_lib, create_if_not_present=True, python_lib_filename=python_lib_filename, ) for course in course_items: course_id = course.id if not are_permissions_roles_seeded(course_id): self.stdout.write(u'Seeding forum roles for course {0}\n'.format(course_id)) seed_permissions_roles(course_id)
def setUp(self): super(ContentGroupTestCase, self).setUp() self.course = CourseFactory.create( org='org', number='number', run='run', # This test needs to use a course that has already started -- # discussion topics only show up if the course has already started, # and the default start date for courses is Jan 1, 2030. start=datetime(2012, 2, 3, tzinfo=UTC), user_partitions=[ UserPartition( 0, 'Content Group Configuration', '', [Group(1, 'Alpha'), Group(2, 'Beta')], scheme_id='cohort') ], grading_policy={ "GRADER": [{ "type": "Homework", "min_count": 1, "drop_count": 0, "short_label": "HW", "weight": 1.0 }] }, cohort_config={'cohorted': True}, discussion_topics={}) seed_permissions_roles(self.course.id) self.staff_user = UserFactory.create(is_staff=True) self.alpha_user = UserFactory.create() self.beta_user = UserFactory.create() self.non_cohorted_user = UserFactory.create() self.community_ta = UserFactory.create(username="******") self.community_ta.roles.add( Role.objects.get(name="Community TA", course_id=self.course.id)) for user in [ self.staff_user, self.alpha_user, self.beta_user, self.non_cohorted_user, self.community_ta ]: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) alpha_cohort = CohortFactory( course_id=self.course.id, name='Cohort Alpha', users=[self.alpha_user, self.community_ta, self.staff_user]) beta_cohort = CohortFactory(course_id=self.course.id, name='Cohort Beta', users=[self.beta_user]) CourseUserGroupPartitionGroup.objects.create( course_user_group=alpha_cohort, partition_id=self.course.user_partitions[0].id, group_id=self.course.user_partitions[0].groups[0].id) CourseUserGroupPartitionGroup.objects.create( course_user_group=beta_cohort, partition_id=self.course.user_partitions[0].id, group_id=self.course.user_partitions[0].groups[1].id) self.alpha_module = ItemFactory.create( parent_location=self.course.location, category='discussion', discussion_id='alpha_group_discussion', discussion_target='Visible to Alpha', group_access={ self.course.user_partitions[0].id: [self.course.user_partitions[0].groups[0].id] }) self.beta_module = ItemFactory.create( parent_location=self.course.location, category='discussion', discussion_id='beta_group_discussion', discussion_target='Visible to Beta', group_access={ self.course.user_partitions[0].id: [self.course.user_partitions[0].groups[1].id] }) self.global_module = ItemFactory.create( parent_location=self.course.location, category='discussion', discussion_id='global_group_discussion', discussion_target='Visible to Everyone') self.course = self.store.get_item(self.course.location)
def create_ccx(request, course, ccx=None): """ Create a new CCX """ name = request.POST.get('name') if hasattr(course, 'ccx_connector') and course.ccx_connector: # if ccx connector url is set in course settings then inform user that he can # only create ccx by using ccx connector url. context = get_ccx_creation_dict(course) messages.error(request, context['use_ccx_con_error_message']) return render_to_response('ccx/coach_dashboard.html', context) # prevent CCX objects from being created for deprecated course ids. if course.id.deprecated: messages.error(request, _( "You cannot create a CCX from a course using a deprecated id. " "Please create a rerun of this course in the studio to allow " "this action.")) url = reverse('ccx_coach_dashboard', kwargs={'course_id': course.id}) return redirect(url) ccx = CustomCourseForEdX( course_id=course.id, coach=request.user, display_name=name) ccx.save() # Make sure start/due are overridden for entire course start = TODAY().replace(tzinfo=pytz.UTC) override_field_for_ccx(ccx, course, 'start', start) override_field_for_ccx(ccx, course, 'due', None) # Enforce a static limit for the maximum amount of students that can be enrolled override_field_for_ccx(ccx, course, 'max_student_enrollments_allowed', settings.CCX_MAX_STUDENTS_ALLOWED) # Save display name explicitly override_field_for_ccx(ccx, course, 'display_name', name) # Hide anything that can show up in the schedule hidden = 'visible_to_staff_only' for chapter in course.get_children(): override_field_for_ccx(ccx, chapter, hidden, True) for sequential in chapter.get_children(): override_field_for_ccx(ccx, sequential, hidden, True) for vertical in sequential.get_children(): override_field_for_ccx(ccx, vertical, hidden, True) ccx_id = CCXLocator.from_course_locator(course.id, unicode(ccx.id)) # Create forum roles seed_permissions_roles(ccx_id) # Assign administrator forum role to CCX coach assign_role(ccx_id, request.user, FORUM_ROLE_ADMINISTRATOR) url = reverse('ccx_coach_dashboard', kwargs={'course_id': ccx_id}) # Enroll the coach in the course email_params = get_email_params(course, auto_enroll=True, course_key=ccx_id, display_name=ccx.display_name) enroll_email( course_id=ccx_id, student_email=request.user.email, auto_enroll=True, email_students=True, email_params=email_params, ) assign_staff_role_to_ccx(ccx_id, request.user, course.id) add_master_course_staff_to_ccx(course, ccx_id, ccx.display_name) # using CCX object as sender here. responses = SignalHandler.course_published.send( sender=ccx, course_key=CCXLocator.from_course_locator(course.id, unicode(ccx.id)) ) for rec, response in responses: log.info(u'Signal fired when course is published. Receiver: %s. Response: %s', rec, response) return redirect(url)
def create_ccx(request, course, ccx=None): """ Create a new CCX """ name = request.POST.get('name') if hasattr(course, 'ccx_connector') and course.ccx_connector: # if ccx connector url is set in course settings then inform user that he can # only create ccx by using ccx connector url. context = get_ccx_creation_dict(course) messages.error(request, context['use_ccx_con_error_message']) return render_to_response('ccx/coach_dashboard.html', context) # prevent CCX objects from being created for deprecated course ids. if course.id.deprecated: messages.error(request, _( "You cannot create a CCX from a course using a deprecated id. " "Please create a rerun of this course in the studio to allow " "this action.")) url = reverse('ccx_coach_dashboard', kwargs={'course_id': course.id}) return redirect(url) ccx = CustomCourseForEdX( course_id=course.id, coach=request.user, display_name=name) ccx.save() # Make sure start/due are overridden for entire course start = TODAY().replace(tzinfo=pytz.UTC) override_field_for_ccx(ccx, course, 'start', start) override_field_for_ccx(ccx, course, 'due', None) # Enforce a static limit for the maximum amount of students that can be enrolled override_field_for_ccx(ccx, course, 'max_student_enrollments_allowed', settings.CCX_MAX_STUDENTS_ALLOWED) # Save display name explicitly override_field_for_ccx(ccx, course, 'display_name', name) # Hide anything that can show up in the schedule hidden = 'visible_to_staff_only' for chapter in course.get_children(): override_field_for_ccx(ccx, chapter, hidden, True) for sequential in chapter.get_children(): override_field_for_ccx(ccx, sequential, hidden, True) for vertical in sequential.get_children(): override_field_for_ccx(ccx, vertical, hidden, True) ccx_id = CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) # Create forum roles seed_permissions_roles(ccx_id) # Assign administrator forum role to CCX coach assign_role(ccx_id, request.user, FORUM_ROLE_ADMINISTRATOR) url = reverse('ccx_coach_dashboard', kwargs={'course_id': ccx_id}) # Enroll the coach in the course email_params = get_email_params(course, auto_enroll=True, course_key=ccx_id, display_name=ccx.display_name) enroll_email( course_id=ccx_id, student_email=request.user.email, auto_enroll=True, email_students=True, email_params=email_params, ) assign_staff_role_to_ccx(ccx_id, request.user, course.id) add_master_course_staff_to_ccx(course, ccx_id, ccx.display_name) # using CCX object as sender here. responses = SignalHandler.course_published.send( sender=ccx, course_key=CCXLocator.from_course_locator(course.id, six.text_type(ccx.id)) ) for rec, response in responses: log.info(u'Signal fired when course is published. Receiver: %s. Response: %s', rec, response) return redirect(url)
def handle(self, *args, **options): course_id = options['course_id'] course_key = CourseKey.from_string(course_id) seed_permissions_roles(course_key)
def handle(self, *args, **options): course_id = options['course_id'] course_key = CourseKey.from_string(course_id) seed_permissions_roles(course_key)
def setUp(self): super(ContentGroupTestCase, self).setUp() self.course = CourseFactory.create( org='org', number='number', run='run', # This test needs to use a course that has already started -- # discussion topics only show up if the course has already started, # and the default start date for courses is Jan 1, 2030. start=datetime(2012, 2, 3, tzinfo=UTC), user_partitions=[ UserPartition( 0, 'Content Group Configuration', '', [Group(1, 'Alpha'), Group(2, 'Beta')], scheme_id='cohort' ) ], grading_policy={ "GRADER": [{ "type": "Homework", "min_count": 1, "drop_count": 0, "short_label": "HW", "weight": 1.0 }] }, cohort_config={'cohorted': True}, discussion_topics={} ) seed_permissions_roles(self.course.id) self.staff_user = UserFactory.create(is_staff=True) self.alpha_user = UserFactory.create() self.beta_user = UserFactory.create() self.non_cohorted_user = UserFactory.create() self.community_ta = UserFactory.create(username="******") self.community_ta.roles.add(Role.objects.get(name="Community TA", course_id=self.course.id)) for user in [ self.staff_user, self.alpha_user, self.beta_user, self.non_cohorted_user, self.community_ta ]: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) alpha_cohort = CohortFactory( course_id=self.course.id, name='Cohort Alpha', users=[self.alpha_user, self.community_ta, self.staff_user] ) beta_cohort = CohortFactory( course_id=self.course.id, name='Cohort Beta', users=[self.beta_user] ) CourseUserGroupPartitionGroup.objects.create( course_user_group=alpha_cohort, partition_id=self.course.user_partitions[0].id, group_id=self.course.user_partitions[0].groups[0].id ) CourseUserGroupPartitionGroup.objects.create( course_user_group=beta_cohort, partition_id=self.course.user_partitions[0].id, group_id=self.course.user_partitions[0].groups[1].id ) self.alpha_module = ItemFactory.create( parent_location=self.course.location, category='discussion', discussion_id='alpha_group_discussion', discussion_target='Visible to Alpha', group_access={self.course.user_partitions[0].id: [self.course.user_partitions[0].groups[0].id]} ) self.beta_module = ItemFactory.create( parent_location=self.course.location, category='discussion', discussion_id='beta_group_discussion', discussion_target='Visible to Beta', group_access={self.course.user_partitions[0].id: [self.course.user_partitions[0].groups[1].id]} ) self.global_module = ItemFactory.create( parent_location=self.course.location, category='discussion', discussion_id='global_group_discussion', discussion_target='Visible to Everyone' ) self.course = self.store.get_item(self.course.location)