def _add_admin(self, **kwargs):
        netid = kwargs['net_id']
        regid = kwargs['reg_id']
        self._log.info('ADD: %s is %s in %s' % (netid,
                                                kwargs['role'],
                                                kwargs['account_id']))

        try:
            User.objects.get(reg_id=regid)
        except User.DoesNotExist:
            try:
                person = get_person_by_netid(netid)

                self._log.info('Provisioning admin: %s (%s)' % (
                    person.uwnetid, person.uwregid))

                try:
                    user = get_user_by_sis_id(person.uwregid)
                except DataFailureException as err:
                    if err.status == 404:
                        user = create_user(CanvasUser(
                            name=user_fullname(person),
                            login_id=person.uwnetid,
                            sis_user_id=person.uwregid,
                            email=user_email(person)))

                User.objects.add_user(person)

            except Exception, err:
                self._log.info('Skipped admin: %s (%s)' % (netid, err))
                return
    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,
     ]
Beispiel #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]