Exemple #1
0
    def search_groups(self, **kwargs):
        """
        Returns a list of restclients.GroupReference objects matching the
        passed parameters. Valid parameters are:
            name: parts_of_name
                name may include the wild-card (*) character.
            stem: group_stem
            member: member netid
            owner: admin netid
            instructor: instructor netid
                stem="course" will be set when this parameter is passed.
            student: student netid
                stem="course" will be set when this parameter is passed.
            affiliate: affiliate_name
            type: search_type
                Values are 'direct' to search for direct membership and
                'effective' to search for effective memberships. Default is
                direct membership.
            scope: search_scope
                Values are 'one' to limit results to one level of stem name
                and 'all' to return all groups.
        """
        kwargs = dict((k.lower(), v.lower()) for k, v in kwargs.iteritems())
        if 'type' in kwargs and (kwargs['type'] != 'direct'
                                 and kwargs['type'] != 'effective'):
            del (kwargs['type'])

        if 'scope' in kwargs and (kwargs['scope'] != 'one'
                                  and kwargs['scope'] != 'all'):
            del (kwargs['scope'])

        if "instructor" in kwargs or "student" in kwargs:
            kwargs["stem"] = "course"

        dao = GWS_DAO()
        url = "/group_sws/v2/search?" + urlencode(kwargs)
        response = dao.getURL(url, self._headers({"Accept": "text/xhtml"}))

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        root = etree.fromstring(response.data)
        group_elements = root.findall('.//*[@class="groupreferences"]' +
                                      '//*[@class="groupreference"]')

        groups = []
        for element in group_elements:
            group = GroupReference()
            group.uwregid = element.find('.//*[@class="regid"]').text
            group.title = element.find('.//*[@class="title"]').text
            group.description = element.find('.//*[@class="description"]').text
            group.name = element.find('.//*[@class="name"]').text
            group.url = element.find('.//*[@class="name"]').get('href')
            groups.append(group)

        return groups
Exemple #2
0
    def search_groups(self, **kwargs):
        """
        Returns a list of restclients.GroupReference objects matching the
        passed parameters. Valid parameters are:
            name: parts_of_name
                name may include the wild-card (*) character.
            stem: group_stem
            member: member netid
            owner: admin netid
            instructor: instructor netid
                stem="course" will be set when this parameter is passed.
            student: student netid
                stem="course" will be set when this parameter is passed.
            affiliate: affiliate_name
            type: search_type
                Values are 'direct' to search for direct membership and
                'effective' to search for effective memberships. Default is
                direct membership.
            scope: search_scope
                Values are 'one' to limit results to one level of stem name
                and 'all' to return all groups.
        """
        kwargs = dict((k.lower(), v.lower()) for k,v in kwargs.iteritems())
        if 'type' in kwargs and (kwargs['type'] != 'direct' and
                                 kwargs['type'] != 'effective'):
            del(kwargs['type'])

        if 'scope' in kwargs and (kwargs['scope'] != 'one' and
                                  kwargs['scope'] != 'all'):
            del(kwargs['scope'])

        if "instructor" in kwargs or "student" in kwargs:
            kwargs["stem"] = "course"

        dao = GWS_DAO()
        url = "/group_sws/v2/search?" + urlencode(kwargs)
        response = dao.getURL(url, self._headers({"Accept": "text/xhtml"}))

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        root = etree.fromstring(response.data)
        group_elements = root.findall('.//*[@class="groupreferences"]' +
                                      '//*[@class="groupreference"]')

        groups = []
        for element in group_elements:
            group = GroupReference()
            group.uwregid = element.find('.//*[@class="regid"]').text
            group.title = element.find('.//*[@class="title"]').text
            group.description = element.find('.//*[@class="description"]').text
            group.name = element.find('.//*[@class="name"]').text
            group.url = element.find('.//*[@class="name"]').get('href')
            groups.append(group)

        return groups
Exemple #3
0
    def get_group_by_id(self, group_id):
        """
        Returns a restclients.Group object for the group identified by the
        passed group ID.
        """
        if not self._is_valid_group_id(group_id):
            raise InvalidGroupID(group_id)

        dao = GWS_DAO()
        url = "/group_sws/v2/group/%s" % group_id
        response = dao.getURL(url, self._headers({"Accept": "text/xhtml"}))

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        return self._group_from_xhtml(response.data)
Exemple #4
0
    def get_group_by_id(self, group_id):
        """
        Returns a restclients.Group object for the group identified by the
        passed group ID.
        """
        if not self._is_valid_group_id(group_id):
            raise InvalidGroupID(group_id)

        dao = GWS_DAO()
        url = "/group_sws/v2/group/%s" % group_id
        response = dao.getURL(url, self._headers({"Accept": "text/xhtml"}))

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        return self._group_from_xhtml(response.data)
Exemple #5
0
    def get_effective_member_count(self, group_id):
        """
        Returns a count of effective members for the group identified by the
        passed group ID.
        """
        if not self._is_valid_group_id(group_id):
            raise InvalidGroupID(group_id)

        dao = GWS_DAO()
        url = "/group_sws/v2/group/%s/effective_member?view=count" % group_id
        response = dao.getURL(url, self._headers({"Accept": "text/xhtml"}))

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        root = etree.fromstring(response.data)
        count = root.find('.//*[@class="member_count"]').get("count")

        return int(count)
Exemple #6
0
    def get_effective_member_count(self, group_id):
        """
        Returns a count of effective members for the group identified by the
        passed group ID.
        """
        if not self._is_valid_group_id(group_id):
            raise InvalidGroupID(group_id)

        dao = GWS_DAO()
        url = "/group_sws/v2/group/%s/effective_member?view=count" % group_id
        response = dao.getURL(url, self._headers({"Accept": "text/xhtml"}))

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        root = etree.fromstring(response.data)
        count = root.find('.//*[@class="member_count"]').get("count")

        return int(count)
Exemple #7
0
    def is_effective_member(self, group_id, netid):
        """
        Returns True if the netid is in the group, False otherwise.
        """
        if not self._is_valid_group_id(group_id):
            raise InvalidGroupID(group_id)

        # GWS doesn't accept EPPNs on effective member checks, for UW users
        netid = re.sub('@washington.edu', '', netid)

        dao = GWS_DAO()
        url = "/group_sws/v2/group/%s/effective_member/%s" % (group_id, netid)
        response = dao.getURL(url, self._headers({"Accept": "text/xhtml"}))

        if response.status == 404:
            return False
        elif response.status == 200:
            return True
        else:
            raise DataFailureException(url, response.status, response.data)
Exemple #8
0
    def is_effective_member(self, group_id, netid):
        """
        Returns True if the netid is in the group, False otherwise.
        """
        if not self._is_valid_group_id(group_id):
            raise InvalidGroupID(group_id)

        # GWS doesn't accept EPPNs on effective member checks, for UW users
        netid = re.sub('@washington.edu', '', netid)

        dao = GWS_DAO()
        url = "/group_sws/v2/group/%s/effective_member/%s" % (group_id, netid)
        response = dao.getURL(url, self._headers({"Accept": "text/xhtml"}))

        if response.status == 404:
            return False
        elif response.status == 200:
            return True
        else:
            raise DataFailureException(url, response.status, response.data)