Example #1
0
def generic_edit_post(request, post, struct, publish):
    """Generic helper to edit an entry or page."""
    post.parser = select_parser(request.app, struct)
    post.title = struct['title']
    post.text = extract_text(struct)
    generic_update(request, post, struct, publish)
    db.commit()
Example #2
0
def generic_edit_post(request, post, struct, publish):
    """Generic helper to edit an entry or page."""
    post.parser = select_parser(request.app, struct)
    post.title = struct['title']
    post.text = extract_text(struct)
    generic_update(request, post, struct, publish)
    db.commit()
Example #3
0
def pingback_post(response, target_uri, slug):
    """This is the pingback handler for posts."""
    post = Post.query.filter_by(slug=slug).first()
    if post is None:
        return False

    if post is None or not post.pings_enabled:
        raise PingbackError(33, 'no such post')
    elif not post.can_read():
        raise PingbackError(49, 'access denied')
    title, excerpt = get_excerpt(response, target_uri)
    if not title:
        raise PingbackError(17, 'no title provided')
    elif not excerpt:
        raise PingbackError(17, 'no useable link to target')
    old_pingback = Comment.query.filter((Comment.is_pingback == True) &
                                        (Comment.www == response.url)).first()
    if old_pingback:
        raise PingbackError(48, 'pingback has already been registered')
    Comment(post,
            title,
            excerpt,
            '',
            response.url,
            is_pingback=True,
            submitter_ip=get_request().remote_addr,
            parser='text')
    db.commit()
    return True
Example #4
0
def pingback_post(response, target_uri, slug):
    """This is the pingback handler for posts."""
    post = Post.query.filter_by(slug=slug).first()
    if post is None:
        return False

    if post is None or not post.pings_enabled:
        raise PingbackError(33, 'no such post')
    elif not post.can_read():
        raise PingbackError(49, 'access denied')
    title, excerpt = get_excerpt(response, target_uri)
    if not title:
        raise PingbackError(17, 'no title provided')
    elif not excerpt:
        raise PingbackError(17, 'no useable link to target')
    old_pingback = Comment.query.filter(
        (Comment.is_pingback == True) &
        (Comment.www == response.url)
    ).first()
    if old_pingback:
        raise PingbackError(48, 'pingback has already been registered')
    Comment(post, title, excerpt, '', response.url, is_pingback=True,
            submitter_ip=get_request().remote_addr, parser='text')
    db.commit()
    return True
Example #5
0
def wp_new_page(username, password, struct, publish):
    request = login(username, password)
    if not request.user.has_privilege(CREATE_PAGES):
        raise Fault(403, 'you don\'t have the privileges to '
                    'create new pages')
    post = generic_new_post(request, struct, publish, 'post')
    db.commit()
    return dump_post(post)
Example #6
0
def blogger_delete_post(post_id, username, password, publish):
    request = login(username, password)
    entry = Post.query.get(post_id)
    if entry is None or entry.content_type != 'post':
        raise Fault(404, 'No such post')
    db.delete(entry)
    db.commit()
    return True
Example #7
0
def metaweblog_new_post(blog_id, username, password, struct, publish):
    request = login(username, password)
    if not request.user.has_privilege(CREATE_ENTRIES):
        raise Fault(403, 'you don\'t have the privileges to '
                    'create new posts')
    post = generic_new_post(request, struct, publish, 'entry')
    db.commit()
    return dump_post(post)
Example #8
0
def wp_new_category(blog_id, username, password, struct):
    request = login(username, password)
    if not request.user.has_privilege(MANAGE_CATEGORIES):
        raise Fault(403, 'you are not allowed to manage categories')
    category = Category(struct['name'], struct.get('description', u''),
                        slug=struct.get('slug') or None)
    db.commit()
    return category.id
Example #9
0
def wp_new_page(username, password, struct, publish):
    request = login(username, password)
    if not request.user.has_privilege(CREATE_PAGES):
        raise Fault(403, 'you don\'t have the privileges to '
                    'create new pages')
    post = generic_new_post(request, struct, publish, 'post')
    db.commit()
    return dump_post(post)
Example #10
0
def metaweblog_new_post(blog_id, username, password, struct, publish):
    request = login(username, password)
    if not request.user.has_privilege(CREATE_ENTRIES):
        raise Fault(403, 'you don\'t have the privileges to '
                    'create new posts')
    post = generic_new_post(request, struct, publish, 'entry')
    db.commit()
    return dump_post(post)
Example #11
0
def blogger_delete_post(post_id, username, password, publish):
    request = login(username, password)
    entry = Post.query.get(post_id)
    if entry is None or entry.content_type != 'post':
        raise Fault(404, 'No such post')
    db.delete(entry)
    db.commit()
    return True
Example #12
0
def wp_new_category(blog_id, username, password, struct):
    request = login(username, password)
    if not request.user.has_privilege(MANAGE_CATEGORIES):
        raise Fault(403, 'you are not allowed to manage categories')
    category = Category(struct['name'],
                        struct.get('description', u''),
                        slug=struct.get('slug') or None)
    db.commit()
    return category.id
Example #13
0
def wp_delete_category(blog_id, username, password, category_id):
    request = login(username, password)
    if not request.user.has_privilege(MANAGE_CATEGORIES):
        raise Fault(403, 'you are not allowed to manage categories')
    category = Category.query.get(category_id)
    if category is None:
        raise Fault(404, 'no such category')
    db.delete(category)
    db.commit()
    return category.id
Example #14
0
def wp_delete_page(blog_id, username, password, page_id):
    request = login(username, password)
    page = Post.query.get(page_id)
    if page is None or page.content_type != 'page':
        raise Fault(404, 'no such page')
    if not page.can_edit():
        raise Fault(403, 'you don\'t have privilegs to this post')
    db.delete(page)
    db.commit()
    return True
Example #15
0
def wp_edit_page(blog_id, page_id, username, password, struct, publish):
    request = login(username, password)
    page = Post.query.get(page_id)
    if not page or page.content_type != 'page':
        raise Fault(404, 'no such page')
    if not page.can_edit():
        raise Fault(403, 'you don\'t have access to this page')
    generic_edit_post(request, page, struct, publish)
    db.commit()
    return dump_post(page)
Example #16
0
def metaweblog_edit_post(post_id, username, password, struct, publish):
    request = login(username, password)
    post = Post.query.get(post_id)
    if post is None:
        raise Fault(404, 'No such post')
    if not post.can_edit():
        raise Fault(403, 'missing privileges')
    generic_edit_post(request, post, struct, publish)
    db.commit()
    return dump_post(post)
Example #17
0
def metaweblog_edit_post(post_id, username, password, struct, publish):
    request = login(username, password)
    post = Post.query.get(post_id)
    if post is None:
        raise Fault(404, 'No such post')
    if not post.can_edit():
        raise Fault(403, 'missing privileges')
    generic_edit_post(request, post, struct, publish)
    db.commit()
    return dump_post(post)
Example #18
0
def wp_edit_page(blog_id, page_id, username, password, struct, publish):
    request = login(username, password)
    page = Post.query.get(page_id)
    if not page or page.content_type != 'page':
        raise Fault(404, 'no such page')
    if not page.can_edit():
        raise Fault(403, 'you don\'t have access to this page')
    generic_edit_post(request, page, struct, publish)
    db.commit()
    return dump_post(page)
Example #19
0
def wp_delete_category(blog_id, username, password, category_id):
    request = login(username, password)
    if not request.user.has_privilege(MANAGE_CATEGORIES):
        raise Fault(403, 'you are not allowed to manage categories')
    category = Category.query.get(category_id)
    if category is None:
        raise Fault(404, 'no such category')
    db.delete(category)
    db.commit()
    return category.id
Example #20
0
def wp_delete_page(blog_id, username, password, page_id):
    request = login(username, password)
    page = Post.query.get(page_id)
    if page is None or page.content_type != 'page':
        raise Fault(404, 'no such page')
    if not page.can_edit():
        raise Fault(403, 'you don\'t have privilegs to this post')
    db.delete(page)
    db.commit()
    return True
def fixup_local_user_record(user, request):
    if len(Group.query.all()) == 0: setup_groups()

    if not user.is_somebody:
        return
    username = user.username
    if username is None:
        return

    role = find_role_for_user(username, 
                              request.environ['HTTP_X_OPENPLANS_PROJECT'],
                              request.environ)

    ensure_proper_group(user, role)

    from zine.api import db
    db.commit()
Example #22
0
def mt_set_post_categories(post_id, username, password, categories):
    request = login(username, password)
    post = Post.query.get(post_id)
    if post is None or post.content_type != 'entry':
        raise Fault(404, 'no such post')
    if not post.can_edit():
        raise Fault(403, 'you don\'t have privilegs to this post')
    ids = []
    names = []
    for category in categories:
        if 'categoryId' in category:
            ids.append(category['categoryId'])
        elif 'categoryName' in category:
            names.append(category['categoryName'])
    post.bind_categories(
        Category.query.filter(Category.id.in_(ids)
                              | Category.name.in_(names)).all())
    db.commit()
    return True
Example #23
0
def mt_set_post_categories(post_id, username, password, categories):
    request = login(username, password)
    post = Post.query.get(post_id)
    if post is None or post.content_type != 'entry':
        raise Fault(404, 'no such post')
    if not post.can_edit():
        raise Fault(403, 'you don\'t have privilegs to this post')
    ids = []
    names = []
    for category in categories:
        if 'categoryId' in category:
            ids.append(category['categoryId'])
        elif 'categoryName' in category:
            names.append(category['categoryName'])
    post.bind_categories(Category.query.filter(
        Category.id.in_(ids) |
        Category.name.in_(names)
    ).all())
    db.commit()
    return True