Exemple #1
0
def discussion_admin(request):
    user_id = authenticated_userid(request)

    if not user_id:
        return HTTPFound(location='/login?next=/admin/discussions/')

    session = User.default_db

    context = dict(
        get_default_context(request),
        discussions=session.query(Discussion))

    if request.method == 'POST':

        g = lambda x: request.POST.get(x, None)

        (topic, slug, name, host, port,
            ssl, folder, password, username, homepage) = (
            g('topic'),
            g('slug'),
            g('mbox_name'),
            g('host'),
            g('port'),
            True if g('ssl') == 'on' else False,
            g('folder'),
            g('password'),
            g('username'),
            g('homepage')
            )

        discussion = Discussion(
            topic=topic,
            slug=slug
        )

        # Could raise an exception if there is no/incorrect scheme passed
        discussion.homepage = homepage
        session.add(discussion)

        create_default_permissions(session, discussion)
        mailbox_class = (
            MailingList if g('mailing_list_address') else IMAPMailbox)
        mailbox = mailbox_class(
            name=name,
            host=host,
            port=int(port),
            username=username,
            use_ssl=ssl,
            folder=folder,
            password=password,
        )

        if(g('mailing_list_address')):
            mailbox.post_email_address = g('mailing_list_address')
        mailbox.discussion = discussion

    return render_to_response(
        'admin/discussions.jinja2',
        context,
        request=request)
Exemple #2
0
def discussion_with_permissions(request, test_session, discussion):
    """An empty Discussion fixture with default permissions"""
    from assembl.models.auth import create_default_permissions
    create_default_permissions(discussion)
    test_session.flush()

    def fin():
        for ul in discussion.acls:
            ul.delete()
        test_session.flush()
    request.addfinalizer(fin)
    return discussion
Exemple #3
0
def discussion_with_permissions(request, test_session, discussion):
    """An empty Discussion fixture with default permissions"""
    from assembl.models.auth import create_default_permissions
    create_default_permissions(discussion)
    test_session.flush()

    def fin():
        for ul in discussion.acls:
            ul.delete()
        test_session.flush()
    request.addfinalizer(fin)
    return discussion
Exemple #4
0
def discussion_admin(request):
    user_id = authenticated_userid(request)

    if not user_id:
        return HTTPFound(location='/login?next_view=/admin/discussions/')

    session = User.default_db

    context = dict(get_default_context(request),
                   discussions=session.query(Discussion))

    if request.method == 'POST':

        g = lambda x: request.POST.get(x, None)

        (topic, slug, name, host, port, ssl, folder, password, username) = (
            g('topic'),
            g('slug'),
            g('mbox_name'),
            g('host'),
            g('port'),
            True if g('ssl') == 'on' else False,
            g('folder'),
            g('password'),
            g('username'),
        )

        discussion = Discussion(topic=topic, slug=slug)

        session.add(discussion)

        create_default_permissions(session, discussion)
        mailbox_class = (MailingList
                         if g('mailing_list_address') else IMAPMailbox)
        mailbox = mailbox_class(
            name=name,
            host=host,
            port=int(port),
            username=username,
            use_ssl=ssl,
            folder=folder,
            password=password,
        )

        if (g('mailing_list_address')):
            mailbox.post_email_address = g('mailing_list_address')
        mailbox.discussion = discussion

    return render_to_response('admin/discussions.jinja2',
                              context,
                              request=request)
Exemple #5
0
def discussion_admin(request):
    user_id = authenticated_userid(request)

    if not user_id:
        return HTTPFound(location='/login?next=/admin/discussions/')

    session = User.default_db

    context = dict(get_default_context(request),
                   discussions=session.query(Discussion))

    if request.method == 'POST':

        g = lambda x: request.POST.get(x, None)

        (topic, slug, name, host, port, ssl, folder, password, username,
         homepage) = (g('topic'), g('slug'), g('mbox_name'), g('host'),
                      g('port'), True if g('ssl') == 'on' else False,
                      g('folder'), g('password'), g('username'), g('homepage'))

        discussion = Discussion(topic=topic, creator_id=user_id, slug=slug)

        # Could raise an exception if there is no/incorrect scheme passed
        discussion.homepage = homepage
        session.add(discussion)
        discussion.apply_side_effects_without_json(request=request)
        discussion.invoke_callbacks_after_creation()

        create_default_permissions(discussion)
        mailbox_class = (MailingList
                         if g('mailing_list_address') else IMAPMailbox)
        mailbox = mailbox_class(
            name=name,
            host=host,
            port=int(port),
            username=username,
            use_ssl=ssl,
            folder=folder,
            password=password,
        )

        if (g('mailing_list_address')):
            mailbox.post_email_address = g('mailing_list_address')
        mailbox.discussion = discussion

    return render_to_response('admin/discussions.jinja2',
                              context,
                              request=request)
Exemple #6
0
def closed_discussion(request, test_session, discussion):
    """An empty Discussion fixture restricted-to-social login"""
    from assembl.models import Role, DiscussionPermission, Permission
    from assembl.models.auth import create_default_permissions
    create_default_permissions(discussion)
    test_session.flush()
    discussion.preferences['authorization_server_backend'] = 'google-oauth2'
    role = test_session.query(Role).filter_by(name=R_PARTICIPANT).first()
    # Take the read for everyone, put it on participant
    dp = test_session.query(DiscussionPermission).join(Permission).filter(
        DiscussionPermission.discussion == discussion, Permission.name == P_READ).first()
    dp.role = role
    test_session.flush()

    def fin():
        for acl in discussion.acls:
            test_session.delete(acl)
        test_session.flush()
    request.addfinalizer(fin)
    return discussion
Exemple #7
0
def closed_discussion(request, test_session, discussion):
    """An empty Discussion fixture restricted-to-social login"""
    from assembl.models import Role, DiscussionPermission, Permission
    from assembl.models.auth import create_default_permissions
    create_default_permissions(discussion)
    test_session.flush()
    discussion.preferences['authorization_server_backend'] = 'google-oauth2'
    role = test_session.query(Role).filter_by(name=R_PARTICIPANT).first()
    # Take the read for everyone, put it on participant
    dp = test_session.query(DiscussionPermission).join(Permission).filter(
        DiscussionPermission.discussion == discussion, Permission.name == P_READ).first()
    dp.role = role
    test_session.flush()

    def fin():
        for acl in discussion.acls:
            test_session.delete(acl)
        test_session.flush()
    request.addfinalizer(fin)
    return discussion
Exemple #8
0
def discussion(request, test_session, default_preferences,
               test_adminuser_webrequest):
    """An empty Discussion fixture with default preferences"""
    from assembl.models import Discussion
    from assembl.models.auth import create_default_permissions
    d = Discussion(topic=u"Jack Layton",
                   slug="jacklayton2",
                   subscribe_to_notifications_on_signup=False,
                   creator=None)
    test_session.add(d)
    test_session.flush()
    d.apply_side_effects_without_json(
        request=test_adminuser_webrequest._base_pyramid_request)
    d.discussion_locales = ['en', 'fr', 'de']
    create_default_permissions(d)
    test_session.flush()

    def fin():
        print("finalizer discussion")
        discussion = d
        if inspect(discussion).detached:
            # How did this happen?
            discussion = test_session.query(Discussion).get(d.id)
        for acl in discussion.acls:
            test_session.delete(acl)
        test_session.delete(discussion.table_of_contents)
        test_session.delete(discussion.root_idea)
        test_session.delete(discussion.next_synthesis)
        preferences = discussion.preferences
        discussion.preferences = None
        discussion.preferences_id = None
        for ut in discussion.user_templates:
            for ns in ut.notification_subscriptions:
                ns.delete()
            ut.delete()
        test_session.delete(preferences)
        test_session.delete(discussion)
        test_session.flush()

    request.addfinalizer(fin)
    return d
Exemple #9
0
def discussion_admin(request):
    user_id = authenticated_userid(request)

    if not user_id:
        return HTTPFound(location="/login?next_view=/admin/discussions/")

    session = User.default_db

    context = dict(get_default_context(request), discussions=session.query(Discussion))

    if request.method == "POST":

        g = lambda x: request.POST.get(x, None)

        (topic, slug, name, host, port, ssl, folder, password, username) = (
            g("topic"),
            g("slug"),
            g("mbox_name"),
            g("host"),
            g("port"),
            True if g("ssl") == "on" else False,
            g("folder"),
            g("password"),
            g("username"),
        )

        discussion = Discussion(topic=topic, slug=slug)

        session.add(discussion)

        create_default_permissions(session, discussion)
        mailbox_class = MailingList if g("mailing_list_address") else IMAPMailbox
        mailbox = mailbox_class(
            name=name, host=host, port=int(port), username=username, use_ssl=ssl, folder=folder, password=password
        )

        if g("mailing_list_address"):
            mailbox.post_email_address = g("mailing_list_address")
        mailbox.discussion = discussion

    return render_to_response("admin/discussions.jinja2", context, request=request)