Exemplo n.º 1
0
    def remove_account(self, account_name: str) -> bool:
        """
        Remove account from whitelist.
        :param account_name: github login
        :return:
        """

        account_existed = False

        # Delete from Postgres
        if DBWhitelist.get_account(account_name) is not None:
            DBWhitelist.remove_account(account_name)
            logger.info(
                f"Account: {account_name} removed from postgres whitelist!")
            account_existed = True
        # Delete from redis
        if account_name in self.db:
            del self.db[account_name]
            # TODO: delete all artifacts from copr
            logger.info(
                f"Account: {account_name} removed from redis whitelist!")
            account_existed = True

        if account_existed:
            return True
        else:
            logger.info(f"Account: {account_name} does not exists!")
            return False
Exemplo n.º 2
0
def test_get_account(multiple_whitelist_entries):
    assert Whitelist.get_account("Rayquaza").status == "approved_manually"
    assert Whitelist.get_account("Rayquaza").account_name == "Rayquaza"
    assert Whitelist.get_account("Deoxys").status == "waiting"
    assert Whitelist.get_account("Deoxys").account_name == "Deoxys"
    assert Whitelist.get_account("Solgaleo").status == "waiting"
    assert Whitelist.get_account("Solgaleo").account_name == "Solgaleo"
Exemplo n.º 3
0
    def is_approved(self, account_name: str) -> bool:
        """
        Check if user is approved in the whitelist
        :param account_name:
        :return:
        """

        # Postgres
        if DBWhitelist.get_account(account_name) is not None:
            db_status = DBWhitelist.get_account(account_name).status
            s = WhitelistStatus(db_status)
            return (s == WhitelistStatus.approved_automatically
                    or s == WhitelistStatus.approved_manually)

        # Redis
        if account_name in self.db:
            account = self.get_account(account_name)
            db_status = account["status"]
            s = WhitelistStatus(db_status)
            return (s == WhitelistStatus.approved_automatically
                    or s == WhitelistStatus.approved_manually)
        return False
Exemplo n.º 4
0
def test_remove_account(multiple_whitelist_entries):
    assert Whitelist.get_account("Rayquaza").account_name == "Rayquaza"
    Whitelist.remove_account("Rayquaza")
    assert Whitelist.get_account("Rayquaza") is None