示例#1
0
 def _cache_owner_voip_service_attrs(self, ou2sko):
     # First cache the constants
     const2str = dict()
     for cnst in self.const.fetch_constants(self.const.VoipServiceTypeCode):
         assert int(cnst) not in const2str
         const2str[int(cnst)] = str(cnst)
     # Second the voipServices...
     vp = VoipService(self._db)
     owner_data = dict()
     for row in vp.search():
         uid = str(row["entity_id"])
         ou = row["ou_id"]
         owner_data[row["entity_id"]] = {"uid": uid,
                                         "mail": uid + "@usit.uio.no",
                                         "cn": row["description"],
                                         "voipOwnerType": "service",
                                         "voipServiceType": const2str[row["service_type"]],
                                         "voipSKO": (ou2sko[ou],)}
     return owner_data
示例#2
0
 def _cache_owner_voip_service_attrs(self, ou2sko):
     # First cache the constants
     const2str = dict()
     for cnst in self.const.fetch_constants(self.const.VoipServiceTypeCode):
         assert int(cnst) not in const2str
         const2str[int(cnst)] = str(cnst)
     # Second the voipServices...
     vp = VoipService(self._db)
     owner_data = dict()
     for row in vp.search():
         uid = str(row["entity_id"])
         ou = row["ou_id"]
         owner_data[row["entity_id"]] = {
             "uid": uid,
             "mail": uid + "@usit.uio.no",
             "cn": row["description"],
             "voipOwnerType": "service",
             "voipServiceType": const2str[row["service_type"]],
             "voipSKO": (ou2sko[ou], )
         }
     return owner_data
示例#3
0
    def voip_service_find(self, operator, designation):
        """List all voip_services matched in some way by designation.

        This has been requested to ease up looking up voip_services for users.

        designation is used to look up voip_services in the following fashion:

          - if all digits -> by entity_id
          - by description (exactly)
          - by description (substring search)
          - if all digits -> by ou_id
          - if all digits -> by stedkode

        All the matching voip_services are collected and returned as a sequence
        so people can pluck out the entities they want and use them in
        subsequent commands.
        """

        def fold_description(s):
            cutoff = 15
            suffix = "(...)"
            if len(s) > cutoff:
                return s[:(cutoff - len(suffix))] + suffix
            return s

        self.ba.can_view_voip_service(operator.get_entity_id())
        ident = designation.strip()
        collect = dict()
        vs = VoipService(self.db)

        # let's try by-id lookup first
        if ident.isdigit():
            try:
                vs.find(int(ident))
                collect[vs.entity_id] = (vs.description,
                                         vs.service_type,
                                         vs.ou_id)
            except Errors.NotFoundError:
                pass

        # then by-description...
        for exact_match in (False, True):
            results = vs.search_voip_service_by_description(
                             designation, exact_match=exact_match)
            for row in results:
                collect[row["entity_id"]] = (row["description"],
                                             row["service_type"],
                                             row["ou_id"])

        # then by OU (stedkode and ou_id)
        try:
            ou = self._get_ou(designation)
            for row in vs.search(ou_id=ou.entity_id):
                collect[row["entity_id"]] = (row["description"],
                                             row["service_type"],
                                             row["ou_id"])
        except CerebrumError:
            pass

        # Finally, the presentation layer
        if len(collect) > cereconf.BOFHD_MAX_MATCHES:
            raise CerebrumError("More than %d (%d) matches, please narrow "
                                "search criteria" %
                                (cereconf.BOFHD_MAX_MATCHES, len(collect)))

        answer = list()
        for entity_id in collect:
            description, service_type, ou_id = collect[entity_id]
            service_type = self.const.VoipServiceTypeCode(service_type)
            answer.append({
                "entity_id": entity_id,
                "description": fold_description(description),
                "service_type": text_type(service_type),
                "ou": self._typeset_ou(ou_id),
            })
        return answer
示例#4
0
    def voip_service_find(self, operator, designation):
        """List all voip_services matched in some way by designation.

        This has been requested to ease up looking up voip_services for users.

        designation is used to look up voip_services in the following fashion:
        
          - if all digits -> by entity_id
          - by description (exactly)
          - by description (substring search)
          - if all digits -> by ou_id
          - if all digits -> by stedkode

        All the matching voip_services are collected and returned as a sequence
        so people can pluck out the entities they want and use them in
        subsequent commands. 
        """
        def fold_description(s):
            cutoff = 15
            suffix = "(...)"
            if len(s) > cutoff:
                return s[:(cutoff - len(suffix))] + suffix
            return s

        # end fold_description

        self.ba.can_view_voip_service(operator.get_entity_id())
        ident = designation.strip()
        collect = dict()
        vs = VoipService(self.db)

        # let's try by-id lookup first
        if ident.isdigit():
            try:
                vs.find(int(ident))
                collect[vs.entity_id] = (vs.description, vs.service_type,
                                         vs.ou_id)
            except Errors.NotFoundError:
                pass

        # then by-description...
        for exact_match in (False, True):
            results = vs.search_voip_service_by_description(
                designation, exact_match=exact_match)
            for row in results:
                collect[row["entity_id"]] = (row["description"],
                                             row["service_type"], row["ou_id"])

        # then by OU (stedkode and ou_id)
        try:
            ou = self._get_ou(designation)
            for row in vs.search(ou_id=ou.entity_id):
                collect[row["entity_id"]] = (row["description"],
                                             row["service_type"], row["ou_id"])
        except CerebrumError:
            pass

        # Finally, the presentation layer
        if len(collect) > cereconf.BOFHD_MAX_MATCHES:
            raise CerebrumError("More than %d (%d) matches, please narrow "
                                "search criteria" %
                                (cereconf.BOFHD_MAX_MATCHES, len(collect)))

        answer = list()
        for entity_id in collect:
            description, service_type, ou_id = collect[entity_id]
            answer.append({
                "entity_id":
                entity_id,
                "description":
                fold_description(description),
                "service_type":
                str(self.const.VoipServiceTypeCode(service_type)),
                "ou":
                self._typeset_ou(ou_id),
            })
        return answer