def assert_user_has_resource_db_permission(user_db, resource_db, permission_type):
    """
    Check that currently logged-in user has specified permission on the provied resource.

    If user doesn't have a required permission, AccessDeniedError is thrown.
    """
    has_permission = user_has_resource_db_permission(user_db=user_db,
                                                     resource_db=resource_db,
                                                     permission_type=permission_type)

    if not has_permission:
        raise ResourceAccessDeniedError(user_db=user_db, resource_db=resource_db,
                                        permission_type=permission_type)
def assert_user_has_resource_api_permission(user_db, resource_api, permission_type):
    """
    Check that currently logged-in user has specified permission for the resource which is to be
    created.
    """
    has_permission = user_has_resource_api_permission(user_db=user_db,
                                                      resource_api=resource_api,
                                                      permission_type=permission_type)

    if not has_permission:
        # TODO: Refactor exception
        raise ResourceAccessDeniedError(user_db=user_db, resource_db=resource_api,
                                        permission_type=permission_type)