Ejemplo n.º 1
0
    def GET(self, request, **kwargs):
        try:
            if 'gmail_id' in request.GET:
                gmail_id = request.GET.get('gmail_id', '').strip()
                person = get_person_by_gmail_id(gmail_id)
                return self.response_for_google_person(person)
            elif 'net_id' in request.GET:
                net_id = netid_from_request(request.GET)
                person = get_person_by_netid(net_id)
                return self.response_for_person(person)
            elif 'reg_id' in request.GET:
                reg_id = regid_from_request(request.GET)
                person = get_person_by_regid(reg_id)
                return self.response_for_person(person)
            else:
                return self.json_response('{"error":"Unrecognized user ID"}',
                                          status=400)

        except DataFailureException as err:
            data = json.loads(err.msg)
            return self.json_response('{"error":"%s %s"}' % (
                err.status, data["StatusDescription"]), status=400)

        except Exception as err:
            return self.json_response('{"error":"%s"}' % err, status=400)
Ejemplo n.º 2
0
    def _process(self, admin):
        if admin.queue_id is not None:
            self.queue_id = admin.queue_id

        account_id = admin.account.sis_id
        role = settings.ASTRA_ROLE_MAPPING[admin.role]
        status = 'deleted' if admin.is_deleted else 'active'
        action = 'REMOVE' if admin.is_deleted else 'ADD'

        try:
            person = get_person_by_regid(admin.reg_id)
            if not self.add_user_data_for_person(person):
                raise UserPolicyException('Invalid UWNetID')

        except UserPolicyException as err:
            logger.info(
                'SKIP ADMIN "{}", account: "{}", role: "{}", {}'.format(
                    admin.net_id, account_id, role, err))
            return

        if str(admin.canvas_id) == settings.RESTCLIENTS_CANVAS_ACCOUNT_ID:
            account_id = ''

        self.data.add(AdminCSV(admin.reg_id, account_id, role, status=status))

        logger.info('{} ADMIN "{}", account: "{}", role: "{}"'.format(
            action, admin.net_id, account_id, role))

        if admin.role in settings.ANCILLARY_CANVAS_ROLES:
            ancillary_role = settings.ANCILLARY_CANVAS_ROLES.get(
                admin.role).get('canvas_role')
            if ('root' == settings.ANCILLARY_CANVAS_ROLES.get(
                    admin.role).get('account')):
                ancillary_account_id = ''
            else:
                ancillary_account_id = account_id

            self.data.add(
                AdminCSV(admin.reg_id,
                         ancillary_account_id,
                         ancillary_role,
                         status=status))

            logger.info('{} ADMIN "{}", account: "{}", role "{}"'.format(
                action, admin.net_id, ancillary_account_id, ancillary_role))
    def _process(self, enrollment):
        if enrollment.queue_id is not None:
            self.queue_id = enrollment.queue_id

        try:
            enrollment.person = get_person_by_regid(enrollment.reg_id)

            section = self.get_section_resource_by_id(enrollment.course_id)
            section.independent_study_instructor_regid = (
                enrollment.instructor_reg_id)

            if not is_active_section(section):
                return

            enrollment.section = section

        except MissingLoginIdException as err:
            if enrollment.last_modified > self.retry_missing_id:
                self._requeue_enrollment_event(enrollment, err)
            else:
                self._skip_enrollment_event(enrollment, err)
            return
        except (UserPolicyException,
                InvalidCanvasIndependentStudyCourse) as err:
            self._skip_enrollment_event(enrollment, err)
            return
        except DataFailureException as err:
            if err.status == 404:
                self._skip_enrollment_event(enrollment, err)
            else:
                self._requeue_enrollment_event(enrollment, err)
            return

        if enrollment.is_instructor():
            self._process_instructor_enrollment(enrollment)
        else:  # student/auditor
            if len(section.linked_section_urls):
                # Don't enroll students into primary sections
                self._skip_enrollment_event(
                    enrollment, 'Section has linked sections')
            else:
                self._process_student_enrollment(enrollment)
    def _process(self, enrollment):
        try:
            enrollment.person = get_person_by_regid(enrollment.reg_id)

            section = self.get_section_resource_by_id(enrollment.course_id)
            section.independent_study_instructor_regid = (
                enrollment.instructor_reg_id)

            if not is_active_section(section):
                return

            enrollment.section = section

        except MissingLoginIdException as err:
            if enrollment.last_modified > self.retry_missing_id:
                self._requeue_enrollment_event(enrollment, err)
            else:
                self._skip_enrollment_event(enrollment, err)
            return
        except (UserPolicyException,
                InvalidCanvasIndependentStudyCourse) as err:
            self._skip_enrollment_event(enrollment, err)
            return
        except DataFailureException as err:
            if err.status == 404:
                self._skip_enrollment_event(enrollment, err)
            else:
                self._requeue_enrollment_event(enrollment, err)
            return

        if enrollment.is_instructor():
            self._process_instructor_enrollment(enrollment)
        else:  # student/auditor
            if len(section.linked_section_urls):
                # Don't enroll students into primary sections
                self._skip_enrollment_event(
                    enrollment, 'Section has linked sections')
            else:
                self._process_student_enrollment(enrollment)
    def _process(self, inv_enrollment):
        now = datetime.utcnow().replace(tzinfo=utc)
        status = None

        try:
            # Verify that the check conditions still exist
            if (inv_enrollment.user.is_affiliate_user() or
                    inv_enrollment.user.is_sponsored_user()):
                status = ENROLLMENT_ACTIVE
                if inv_enrollment.deleted_date is not None:
                    inv_enrollment.restored_date = now
                    inv_enrollment.save()

            elif user.is_student_user():
                grace_dt = now - timedelta(days=getattr(
                    settings, 'INVALID_ENROLLMENT_GRACE_DAYS', 90))

                if inv_enrollment.found_date < grace_dt:
                    status = ENROLLMENT_DELETED
                    inv_enrollment.deleted_date = now
                    inv_enrollment.restored_date = None
                    inv_enrollment.save()

            if status is not None:
                person = get_person_by_regid(inv_enrollment.user.reg_id)
                if self.add_user_data_for_person(person):
                    self.data.add(EnrollmentCSV(
                        section_id=inv_enrollment.section_id,
                        person=person,
                        role=inv_enrollment.role,
                        status=status))

        except DataFailureException as err:
            inv_enrollment.queue_id = None
            inv_enrollment.save()
            self.logger.info('Requeue invalid enrollment {} in {}: {}'.format(
                inv_enrollment.reg_id, inv_enrollment.section_id, err))
Ejemplo n.º 6
0
    def GET(self, request, **kwargs):
        json_rep = {
            'courses': []
        }

        filt_kwargs = None

        if 'queue_id' in request.GET:
            queue_id = request.GET.get('queue_id', '').strip()
            if re.match(r'^[0-9]+$', str(queue_id)):
                filt_kwargs = {'queue_id': queue_id}
            else:
                err = 'invalid queue_id: %s' % queue_id
                self._log.error(err)
                return self.json_response('{"error":"%s"}' % err, status=400)
        else:
            provisioned_error = request.GET.get('provisioned_error')
            if provisioned_error:
                filt_kwargs = {
                    'provisioned_error': self._is_true(provisioned_error),
                    'queue_id__isnull': True
                }

        if filt_kwargs:
            try:
                filt_kwargs['priority__gt'] = PRIORITY_NONE
                course_list = list(Course.objects.filter(
                    **filt_kwargs).order_by('course_id'))

                include_sws_url = can_view_source_data()
                for course in course_list:
                    json_data = course.json_data(include_sws_url)
                    json_rep['courses'].append(json_data)

                return self.json_response(json.dumps(json_rep))
            except Exception as err:
                self._log.error('course kwargs search fail: %s' + err)
                return self.json_response('{"error":"%s"}' % err, status=400)

        net_id = None
        reg_id = None
        try:
            if 'net_id' in request.GET:
                net_id = netid_from_request(request.GET)
            elif 'reg_id' in request.GET:
                reg_id = regid_from_request(request.GET)
            else:
                self._criteria[2]['required'] = True

            filter_terms = self._validCourseFilter(request)
            filter_prefix = '-'.join(filter_terms)
            course_list = list(Course.objects.filter(
                course_id__startswith=filter_prefix).order_by('course_id'))
        except CourseInvalidException as err:
            return self.json_response('{"error":"%s"}' % err, status=400)
        except Exception as err:
            self._log.error('course filter fail: %s' % err)
            return self.json_response('{"error":"%s"}' % err, status=400)

        if (net_id is not None or reg_id is not None) and len(course_list):
            try:
                if net_id is not None:
                    instructor = get_person_by_netid(net_id)
                else:
                    instructor = get_person_by_regid(reg_id)

                year = request.GET.get('year')
                quarter = request.GET.get('quarter')
                term = get_term_by_year_and_quarter(year, quarter)

                white_list = []
                for section in get_sections_by_instructor_and_term(
                        instructor, term):
                    white_list.append('-'.join([
                        section.term.canvas_sis_id(),
                        section.curriculum_abbr.upper(),
                        section.course_number,
                        section.section_id.upper()]))

            except Exception as err:
                self._log.error('section search fail: %s' % err)
                return self.json_response('{"error":"%s"}' % err, status=400)

        include_sws_url = can_view_source_data()
        for course in course_list:
            if 'white_list' in locals() and course.course_id not in white_list:
                continue

            json_data = course.json_data(include_sws_url)
            json_rep['courses'].append(json_data)

        return self.json_response(json.dumps(json_rep))
Ejemplo n.º 7
0
    def get(self, request, *args, **kwargs):
        json_rep = {'courses': []}

        filt_kwargs = None

        if 'queue_id' in request.GET:
            queue_id = request.GET.get('queue_id', '').strip()
            if re.match(r'^[0-9]+$', str(queue_id)):
                filt_kwargs = {'queue_id': queue_id}
            else:
                err = 'invalid queue_id: {}'.format(queue_id)
                logger.error(err)
                return self.error_response(400, err)
        else:
            provisioned_error = request.GET.get('provisioned_error')
            if provisioned_error:
                filt_kwargs = {
                    'provisioned_error': self._is_true(provisioned_error),
                    'queue_id__isnull': True
                }

        if filt_kwargs:
            try:
                filt_kwargs['priority__gt'] = Course.PRIORITY_NONE
                course_list = list(
                    Course.objects.filter(**filt_kwargs).order_by('course_id'))

                include_sws_url = self.can_view_source_data(request)
                for course in course_list:
                    json_data = course.json_data(include_sws_url)
                    json_rep['courses'].append(json_data)

                return self.json_response(json_rep)
            except Exception as err:
                logger.error('Course search fail: {}'.format(err))
                return self.error_response(400, err)

        net_id = None
        reg_id = None
        try:
            if 'net_id' in request.GET:
                net_id = self.netid_from_request(request.GET)
            elif 'reg_id' in request.GET:
                reg_id = self.regid_from_request(request.GET)
            else:
                self._criteria[2]['required'] = True

            filter_terms = self._valid_course_filter(request)
            filter_prefix = '-'.join(filter_terms)
            course_list = list(
                Course.objects.filter(
                    course_id__startswith=filter_prefix).order_by('course_id'))
        except CourseInvalidException as err:
            return self.error_response(400, err)
        except Exception as err:
            logger.error('Course filter fail: {}'.format(err))
            return self.error_response(400, err)

        if (net_id is not None or reg_id is not None) and len(course_list):
            try:
                if net_id is not None:
                    instructor = get_person_by_netid(net_id)
                else:
                    instructor = get_person_by_regid(reg_id)

                year = request.GET.get('year')
                quarter = request.GET.get('quarter')
                term = get_term_by_year_and_quarter(year, quarter)

                valid = []
                for section in get_sections_by_instructor_and_term(
                        instructor, term):
                    valid.append('-'.join([
                        section.term.canvas_sis_id(),
                        section.curriculum_abbr.upper(), section.course_number,
                        section.section_id.upper()
                    ]))

            except Exception as err:
                logger.error('Section search fail: {}'.format(err))
                return self.error_response(400, err)

        include_sws_url = self.can_view_source_data(request)
        for course in course_list:
            if 'valid' in locals() and course.course_id not in valid:
                continue

            json_data = course.json_data(include_sws_url)
            json_rep['courses'].append(json_data)

        return self.json_response(json_rep)