Ejemplo n.º 1
0
 def get_all_users(self, includes=None, role_id=None):
     """
     :param includes: specify the additioanl data you want in the response.
     :param role_id: filter users by role_id
      Valid value is one of 'account_admin', 'admin', 'author', etc
     Return a list of BridgeUser objects of the active user records.
     """
     resp = get_resource(get_all_users_url(includes, role_id))
     return self._process_json_resp_data(resp)
Ejemplo n.º 2
0
 def get_custom_fields(self):
     resp = get_resource(URL)
     resp_data = json.loads(resp)
     for field in resp_data["custom_fields"]:
         if field.get("id") is not None and field.get("name") is not None:
             cf = BridgeCustomField(field_id=field["id"],
                                    name=field["name"].lower())
             self.fields.append(cf)
             self.name_id_map[cf.name] = cf.field_id
             self.id_name_map[cf.field_id] = cf.name
Ejemplo n.º 3
0
 def get_user(self, uwnetid):
     """
     Return a BridgeUser object
     """
     url = "{0}?{1}".format(author_uid_url(uwnetid),
                            includes_to_query_params(GET_USER_INCLUDES))
     resp = get_resource(url)
     return self._get_obj_from_list(
         "get_user by netid('{0}')".format(uwnetid),
         self._process_json_resp_data(resp))
Ejemplo n.º 4
0
 def get_user_roles(self):
     resp = get_resource(URL)
     resp_data = json.loads(resp)
     if resp_data.get("roles") is not None:
         for role in resp_data["roles"]:
             if (role.get("is_deprecated") is False or
                     role.get("is_deprecated") is None):
                 cf = BridgeUserRole(role_id=role.get("id"),
                                     name=role.get("name"))
                 self.roles.append(cf)
                 self.id_name_map[cf.role_id] = cf.name
                 self.name_ip_map[cf.name] = cf.role_id
Ejemplo n.º 5
0
    def get_user_by_id(self, bridge_id, include_deleted=False):
        """
        :param bridge_id: integer
        :param include_deleted: specify if you want to include
                                terminated user record in the response.
        Return a BridgeUser object
        """
        url = "{0}?{1}".format(author_id_url(bridge_id),
                               includes_to_query_params(GET_USER_INCLUDES))
        if include_deleted:
            url = "{0}&{1}".format(url, "with_deleted=true")

        resp = get_resource(url)
        return self._get_obj_from_list(
            "get_user by bridge_id('{0}')".format(bridge_id),
            self._process_json_resp_data(resp))
Ejemplo n.º 6
0
    def _process_json_resp_data(self, resp):
        """
        process the response and return a list of BridgeUser
        """
        bridge_users = []
        while True:
            resp_data = json.loads(resp)
            link_url = None
            if (resp_data.get("meta") is not None
                    and resp_data["meta"].get("next") is not None):
                link_url = resp_data["meta"]["next"]

            try:
                bridge_users = self._process_apage(resp_data, bridge_users)
            except Exception as err:
                logger.error("{0} in {1}".format(str(err), resp_data))

            if link_url is None:
                break
            resp = get_resource(link_url)
        return bridge_users