def __init__(self, **kwargs):
        course_id = None  # course_id is not used for SIS enrollments
        if kwargs.get("registration"):  # Student registration object
            registration = kwargs.get("registration")
            person = registration.person
            section_id = registration.section.canvas_section_sis_id()
            role = Enrollment.STUDENT_ROLE
            status = self._status_from_registration(registration)

        elif kwargs.get("instructor"):
            section = kwargs.get("section")
            person = kwargs.get("instructor")
            section_id = section.canvas_section_sis_id()
            role = Enrollment.INSTRUCTOR_ROLE
            status = kwargs.get("status")

        else:
            course_id = kwargs.get("course_id", None)
            section_id = kwargs.get("section_id", None)
            person = kwargs.get("person")
            role = kwargs.get("role")
            status = kwargs.get("status")

        user_id = user_sis_id(person)
        if not any(status == val for (val, name) in Enrollment.STATUS_CHOICES):
            raise EnrollmentPolicyException("Invalid enrollment status for %s: %s" % (user_id, status))

        if course_id is None and section_id is None:
            raise EnrollmentPolicyException("Missing course and section for %s: %s" % (user_id, status))

        self.data = [course_id, None, user_id, role, None, section_id, status, None]
示例#2
0
    def _get_user_from_login(self, login):
        user = AddUser(login=login)
        try:
            try:
                person = get_person_by_gmail_id(login)
                user.login = person.login_id
            except UserPolicyException:
                person = get_person_by_netid(login)
                user.login = person.uwnetid

            user.email = user_email(person)
            user.name = user_fullname(person)
            user.regid = user_sis_id(person)

            if user.regid in self._course_users:
                user.name = self._course_users[user.regid].name
                user.status = 'present'
                user.comment = 'Already in course'

        except DataFailureException as ex:
            if ex.status != 401:
                raise
        except UserPolicyException as ex:
            user.status = 'invalid'
            user.comment = "%s" % self._prettify(str(ex))

        return user
 def __init__(self, user, status="active"):
     self.key = user_sis_id(user)
     self.data = [
         self.key,
         user.uwnetid if hasattr(user, "uwnetid") else user.login_id,
         None,
         None,
         None,
         user_fullname(user),
         None,
         None,
         user_email(user),
         status,
     ]
示例#4
0
    def post(self, request, *args, **kwargs):
        try:
            login_data = request.data['logins']
        except KeyError as ex:
            return RESTDispatch.error_response(400, 'Missing list of logins')

        users = []
        for login in login_data:
            login = login.strip().lower()
            if not any(u.get('login') == login for u in users):
                try:
                    user = {}
                    try:
                        person = get_person_by_gmail_id(login)
                        user['login'] = person.login_id
                        user['full_name'] = person.login_id
                        user['is_person'] = True
                    except UserPolicyException:
                        login = self.strip_domain(login)
                        person = get_person_by_netid(login)
                        user['login'] = person.uwnetid
                        try:
                            user['full_name'] = person.get_formatted_name(
                                '{first} {last}')
                            user['is_person'] = True
                        except AttributeError as ex:
                            user['full_name'] = person.display_name
                            user['is_person'] = False  # UW entity

                    sis_id = user_sis_id(person)
                    if not any(u.get('sis_id') == sis_id for u in users):
                        try:
                            can_access_canvas(user['login'])
                        except UserPolicyException as ex:
                            user['error'] = '{}'.format(ex)

                        user['sis_id'] = sis_id
                        user['email'] = user_email(person)
                        users.append(user)

                except DataFailureException as ex:
                    users.append({'login': login, 'error': ex.msg})

                except UserPolicyException as ex:
                    users.append({'login': login, 'error': '{}'.format(ex)})

        return RESTDispatch.json_response({'users': users})
    def __init__(self, user, status='active'):
        self.key = user_sis_id(user)
        name = user_fullname(user)
        if len(name) == 2:
            first_name = name[0]
            last_name = name[1]
            full_name = None
        else:
            first_name = None
            last_name = None
            full_name = name[0]

        self.data = [
            self.key,
            user.uwnetid if hasattr(user, 'uwnetid') else user.login_id,
            None, first_name, last_name, full_name, None, None,
            user_email(user),
            status]
    def __init__(self, **kwargs):
        course_id = None  # course_id is not used for SIS enrollments
        if kwargs.get('registration'):  # Student registration object
            registration = kwargs.get('registration')
            person = registration.person
            section_id = registration.section.canvas_section_sis_id()
            role = get_student_sis_import_role()
            status = enrollment_status_from_registration(registration)

        elif kwargs.get('instructor'):
            section = kwargs.get('section')
            person = kwargs.get('instructor')
            section_id = section.canvas_section_sis_id()
            role = get_instructor_sis_import_role()
            status = kwargs.get('status')

        else:
            course_id = kwargs.get('course_id', None)
            section_id = kwargs.get('section_id', None)
            person = kwargs.get('person')
            role = get_sis_import_role(kwargs['role']) or kwargs['role']
            status = kwargs.get('status')

        user_id = user_sis_id(person)
        if not valid_enrollment_status(status):
            raise EnrollmentPolicyException(
                'Invalid enrollment status for {}: {}'.format(user_id, status))

        if course_id is None and section_id is None:
            raise EnrollmentPolicyException(
                'Missing course and section for {}: {}'.format(
                    user_id, status))

        if not role:
            raise EnrollmentPolicyException(
                'Missing role for {}: {}'.format(user_id, role))

        self.key = '{}:{}:{}:{}:{}'.format(
            course_id, section_id, user_id, role, status)
        self.data = [course_id, None, user_id, role, None, section_id, status,
                     None]