Beispiel #1
0
def process_authorization(author: AccountId, message: str, server: Server,
                          **kwargs):
    """Processes a message requesting an authorization change."""
    author_account = assert_authorized(author, server, Authorization.ADMIN)
    parsed = parse_authorization(message)
    if parsed is None:
        raise CommandException(
            'Authorization formatted incorrectly. The right format is `authorize BENEFICIARY citizen|admin|developer`.'
        )

    beneficiary, auth_level = parsed
    beneficiary_account = assert_is_account(beneficiary, server)
    if beneficiary_account.get_authorization(
    ).value > author_account.get_authorization().value:
        raise CommandException(
            'Cannot change authorization of account with authorization %s because it is higher than yours (%s).'
            % (beneficiary_account.get_authorization(),
               author_account.get_authorization()))

    if auth_level.value > author_account.get_authorization().value:
        raise CommandException(
            'Cannot set authorization of account to %s because it is higher than yours (%s).'
            % (auth_level, author_account.get_authorization()))

    server.authorize(author, beneficiary_account, auth_level)
    return '%s now has authorization level %s.' % (beneficiary,
                                                   auth_level.name)
def process_authorization(author: AccountId, message: str, server: Server, **kwargs):
    """Processes a message requesting an authorization change."""
    author_account = assert_authorized(author, server, Authorization.ADMIN)
    parsed = parse_authorization(message)
    if parsed is None:
        raise CommandException('Authorization formatted incorrectly. The right format is `authorize BENEFICIARY citizen|admin|developer`.')

    beneficiary, auth_level = parsed
    beneficiary_account = assert_is_account(beneficiary, server)
    server.authorize(author_account, beneficiary_account, auth_level)
    return '%s now has authorization level %s.' % (beneficiary, auth_level.name)
def authorize(author_id: Union[AccountId, str], account_id: Union[AccountId,
                                                                  str],
              auth_level: Authorization, server: Server):
    """Changes an account's authorization level to `auth_level`."""
    author = _get_account(author_id, server)
    account = _get_account(account_id, server)
    required = max(Authorization.ADMIN, auth_level,
                   account.get_authorization())
    _assert_authorized(author,
                       account,
                       admin_level=required,
                       min_level=required)
    server.authorize(author_id, account, auth_level)