def can_set_new_secret(self, account_id, client_id):
        """Whether account_id can set a new sipSecret on client_id.
        """
        if self.is_superuser(account_id):
            return True

        if self._is_voip_admin(account_id):
            return True

        # We allow resetting a secret to the owner of client_id.
        #
        # The test goes like this: find voip_address to which client_id is
        # bound. Compare it to account_id's owner_id. For non-personal
        # accounts this test is bound to fail.
        acc = Factory.get("Account")(self._db)
        acc.find(account_id)

        client = VoipClient(self._db)
        client.find(client_id)
        address = VoipAddress(self._db)
        address.find(client.voip_address_id)

        if address.owner_entity_id == acc.owner_id:
            return True

        raise PermissionDenied("Account id=%d cannot change sipSecret of "
                               "voip_client id=%d" % (account_id, client_id))
Exemple #2
0
    def can_set_new_secret(self, account_id, client_id):
        """Whether account_id can set a new sipSecret on client_id.
        """
        if self.is_superuser(account_id):
            return True

        if self._is_voip_admin(account_id):
            return True

        # We allow resetting a secret to the owner of client_id.
        #
        # The test goes like this: find voip_address to which client_id is
        # bound. Compare it to account_id's owner_id. For non-personal
        # accounts this test is bound to fail.
        acc = Factory.get("Account")(self._db)
        acc.find(account_id)

        client = VoipClient(self._db)
        client.find(client_id)
        address = VoipAddress(self._db)
        address.find(client.voip_address_id)

        if address.owner_entity_id == acc.owner_id:
            return True

        raise PermissionDenied("Account id=%d cannot change sipSecret of "
                               "voip_client id=%d" % (account_id, client_id))
Exemple #3
0
    def _get_voip_client(self, designation):
        """Locate a voip_client by designation.

        Possible interpretations of designation are:

          + entity_id
          + mac address
        """

        # Don't use _human_repr2id here, since it does not like ':' being part
        # of the identifier (which mac addresses definitely have)
        client = VoipClient(self.db)
        if (isinstance(designation, (int, long))
                or isinstance(designation, text_type)
                and designation.isdigit()):
            try:
                client.find(int(designation))
                return client
            except Errors.NotFoundError:
                pass

        # Try to look up by mac address
        try:
            client.clear()
            client.find_by_mac_address(designation)
            return client
        except (Errors.NotFoundError, AssertionError):
            pass

        raise CerebrumError("Could not uniquely determine voip_client "
                            "from designation %r" % designation)
Exemple #4
0
    def _get_voip_client(self, designation):
        """Locate a voip_client by designation.

        Possible interpretations of designation are:

          + entity_id
          + mac address
        """

        # Don't use _human_repr2id here, since it does not like ':' being part
        # of the identifier (which mac addresses definitely have)
        client = VoipClient(self.db)
        if (isinstance(designation, (int, long))
                or isinstance(designation, str) and designation.isdigit()):
            try:
                client.find(int(designation))
                return client
            except Errors.NotFoundError:
                pass

        # Try to look up by mac address
        try:
            client.clear()
            client.find_by_mac_address(designation)
            return client
        except (Errors.NotFoundError, AssertionError):
            pass

        raise CerebrumError("Could not uniquely determine voip_client "
                            "from designation %s" % str(designation))