view data/plugin/action/submit_bbb_create_meeting.py @ 594:ddd078c4ee7a

action.submit_bbb_create_meeting: read rights for bbb_admin_group for new meeting page
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Mon, 11 Jun 2012 16:21:57 +0200
parents ad72bd94694c
children 51287eec8dcf
line wrap: on
line source
# -*- coding: utf-8 -*-
"""
    MoinMoin - Create a Meeting for bigbluebutton (http://www.bigbluebutton.org/)

    @copyright: 2012 MoinMoin:ReimarBauer
    @license: GNU GPL, see COPYING for details.
"""

from MoinMoin.PageEditor import PageEditor
from MoinMoin.Page import Page
# pip install bigbluebutton
from bigbluebutton import Meeting_Setup
import bbb_settings

def execute(pagename, request):
    """
    Creates a bigbluebutton meeting and stores the definitions on a wiki sub page.
    This page is protected by acls for the responsible user. By reloading the Definition
    page the session becomes recreated.
    It requires a bbb_admin_group defined in wikiconfig.py. Only a user of this 
    group is allowed to use this action. On same directory as wikiconfig.py you need
    a "bbb_settings.py" module with the SALT and the BBB_API_URL.

    Example Call by using http://moinmo.in/MacroMarket/FormCreate

    <<FormHeader(submit_bbb_create_meeting)>>
    || Meeting Name: || <<FormText(meeting_name,maxlength=50)>> ||
    || Meeting ID || <<FormText(meeting_id,maxlength=50)>> ||
    || Moderator Passwort: || <<FormText(moderator_password,maxlength=50)>> ||
    || Attendee Passwort: || <<FormText(attendee_password,maxlength=50)>> ||
    ||<-2:> <<FormSubmit(Send)>> ||
    <<FormFooter()>>

    """
    username = request.user.name
    groups = request.groups
    msg = ["Sorry you have not enough previledges", "error"]
    try:
        bbb_admin_group = groups.get(request.cfg.bbb_admin_group, [])
    except AttributeError:
        request.theme.add_msg(msg[0], msg[1])
        Page(request, pagename).send_page()
        return

    if request.user.valid and username in bbb_admin_group:
        _ = request.getText

        attendee_password = request.form["attendee_password"]
        moderator_password = request.form["moderator_password"]

        if not attendee_password.strip() or not moderator_password.strip():
            msg = ["Sorry, we don't support empty passwords!", "error"]
            request.theme.add_msg(msg[0], msg[1])
            Page(request, pagename).send_page()
            return

        session = Meeting_Setup(bbb_api_url=bbb_settings.BBB_API_URL,
                                salt=bbb_settings.SALT,
                                meeting_name=request.form["meeting_name"],
                                meeting_id=request.form["meeting_id"],
                                attendee_password=attendee_password,
                                moderator_password=moderator_password,
                               )
        session.create_meeting()

        sub_pagename = u'%s/%s' % (pagename, request.form["meeting_name"])
        keyval = "\n".join([' %s:: %s' % (key, value) for key, value in request.form.iteritems() if not (key.startswith('labels') or key.startswith('action') or key.startswith('doit'))])
        result = """#acl %(username)s:admin,read,write,delete,revert %(bbb_admin_group)s:read All:
#format bbb_create
 responsible:: %(username)s
%(keyval)s""" % {"username": username,
                 "keyval": keyval,
                 "bbb_admin_group": bbb_admin_group.name}

        try:
            # We write without acl check
            PageEditor(request, sub_pagename)._write_file(result, action='SAVE')
            msg = (_(u"OK!"), "info")
        except PageEditor.SaveError:
            msg = (_(u"A severe error occured:"), "error")
    request.theme.add_msg(msg[0], msg[1])
    Page(request, pagename).send_page()