def approve_account(account_name: str): """ Approve user manually :param account_name: account name for approval """ WhitelistModel.add_account( account_name=account_name, status=WhitelistStatus.approved_manually.value) logger.info(f"Account {account_name!r} approved successfully.")
def multiple_whitelist_entries(): yield [ WhitelistModel.add_account(account_name="Rayquaza", status="approved_manually"), WhitelistModel.add_account(account_name="Deoxys", status="approved_manually"), # Not a typo, account_name repeated intentionally to check behaviour WhitelistModel.add_account(account_name="Deoxys", status="waiting"), WhitelistModel.add_account(account_name="Solgaleo", status="waiting"), WhitelistModel.add_account(account_name="Zacian", status="approved_manually"), ]
def approve_account(account_name: str) -> bool: """ Approve user manually :param account_name: account name for approval :return: """ WhitelistModel.add_account( account_name=account_name, status=WhitelistStatus.approved_manually.value ) logger.info(f"Account {account_name} approved successfully") return True
def multiple_whitelist_entries(): with get_sa_session() as session: session.query(WhitelistModel).delete() yield [ WhitelistModel.add_account(account_name="Rayquaza", status="approved_manually"), WhitelistModel.add_account(account_name="Deoxys", status="approved_manually"), # Not a typo, account_name repeated intentionally to check behaviour WhitelistModel.add_account(account_name="Deoxys", status="waiting"), WhitelistModel.add_account(account_name="Solgaleo", status="waiting"), WhitelistModel.add_account(account_name="Zacian", status="approved_manually"), ]
def remove_account(account_name: str) -> bool: """ Remove account from whitelist. :param account_name: account name for removing :return: has the account existed before? """ account_existed = False if WhitelistModel.get_account(account_name): WhitelistModel.remove_account(account_name) logger.info(f"Account {account_name!r} removed from postgres whitelist!") account_existed = True if not account_existed: logger.info(f"Account {account_name!r} does not exists!") return account_existed
def remove_account(account_name: str) -> bool: """ Remove account from whitelist. :param account_name: github login :return: """ account_existed = False if WhitelistModel.get_account(account_name): WhitelistModel.remove_account(account_name) logger.info(f"Account: {account_name} removed from postgres whitelist!") account_existed = True if not account_existed: logger.info(f"Account: {account_name} does not exists!") return account_existed
def accounts_waiting() -> List[str]: """ Get accounts waiting for approval :return: list of accounts waiting for approval """ return [ account.account_name for account in WhitelistModel.get_accounts_by_status( WhitelistStatus.waiting.value) ]
def add_account(self, event: InstallationEvent) -> bool: """ Add account to whitelist. Status is set to 'waiting' or to 'approved_automatically' if the account is a packager in Fedora. :param event: Github app installation info :return: was the account (auto/already)-whitelisted? """ if self.is_approved(event.account_login): return True WhitelistModel.add_account(event.account_login, WhitelistStatus.waiting.value) if self._signed_fpca(event.sender_login): event.status = WhitelistStatus.approved_automatically WhitelistModel.add_account(event.account_login, event.status.value) return True return False
def multiple_whitelist_entries(): yield [ WhitelistModel.add_account( account_name=SampleValues.account_name, status="approved_manually" ), WhitelistModel.add_account( account_name=SampleValues.different_account_name, status="approved_manually" ), # Not a typo, account_name repeated intentionally to check behaviour WhitelistModel.add_account( account_name=SampleValues.different_account_name, status="waiting" ), WhitelistModel.add_account( account_name=SampleValues.another_different_acount_name, status="waiting" ), WhitelistModel.add_account( account_name=SampleValues.yet_another_different_acount_name, status="approved_manually", ), ]
def add_account(self, account_login: str, sender_login: str) -> bool: """ Add account to whitelist. Status is set to 'waiting' or to 'approved_automatically' if the account is a packager in Fedora. :param sender_login: login of the user who installed the app into 'account' :param account_login: login of the account into which the app was installed :return: was the account (auto/already)-whitelisted? """ if WhitelistModel.get_account(account_login): return True WhitelistModel.add_account(account_login, WhitelistStatus.waiting.value) if self._signed_fpca(sender_login): WhitelistModel.add_account( account_login, WhitelistStatus.approved_automatically.value) return True return False
def test_get_account(clean_before_and_after, multiple_whitelist_entries): assert WhitelistModel.get_account("Rayquaza").status == "approved_manually" assert WhitelistModel.get_account("Rayquaza").account_name == "Rayquaza" assert WhitelistModel.get_account("Deoxys").status == "waiting" assert WhitelistModel.get_account("Deoxys").account_name == "Deoxys" assert WhitelistModel.get_account("Solgaleo").status == "waiting" assert WhitelistModel.get_account("Solgaleo").account_name == "Solgaleo"
def is_approved(account_name: str) -> bool: """ Check if user is approved in the whitelist :param account_name: account name to check :return: """ account = WhitelistModel.get_account(account_name) if account: db_status = account.status s = WhitelistStatus(db_status) return (s == WhitelistStatus.approved_automatically or s == WhitelistStatus.approved_manually) return False
def test_remove_account(clean_before_and_after, multiple_whitelist_entries): assert WhitelistModel.get_account("Rayquaza").account_name == "Rayquaza" WhitelistModel.remove_account("Rayquaza") assert WhitelistModel.get_account("Rayquaza") is None
def test_get_accounts_by_status(clean_before_and_after, multiple_whitelist_entries): a = WhitelistModel.get_accounts_by_status("waiting") assert len(list(a)) == 2 b = WhitelistModel.get_accounts_by_status("approved_manually") assert len(list(b)) == 2
def new_whitelist_entry(): with get_sa_session() as session: session.query(WhitelistModel).delete() yield WhitelistModel.add_account(account_name="Rayquaza", status="approved_manually")
def get(self, login): """A specific whitelist item details""" account = WhitelistModel.get_account(login) return account.to_dict() if account else ("", HTTPStatus.NO_CONTENT)
def get(self): """List all Whitelisted FAS accounts""" return [account.to_dict() for account in WhitelistModel.get_all()]
def new_whitelist_entry(clean_before_and_after): yield WhitelistModel.add_account( account_name=SampleValues.account_name, status="approved_manually" )
def get_account(account_name) -> Optional[WhitelistModel]: """ Get selected account from DB, return None if it's not there :param account_name: account name for approval """ return WhitelistModel.get_account(account_name=account_name)
def new_whitelist_entry(clean_before_and_after): yield WhitelistModel.add_account(account_name="Rayquaza", status="approved_manually")