view data/plugin/parser/bbb_create.py @ 653:127da830be6c

updated copyright
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 19 Apr 2016 16:29:54 +0200
parents 8f2aa479f8cd
children
line wrap: on
line source
# -*- coding: utf-8 -*-
"""
    MoinMoin - Parser for bigbluebutton meeting controls (http://www.bigbluebutton.org/)

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

import time
from MoinMoin import wikiutil
# pip install bigbluebutton
try:
    from bigbluebutton import Meeting
except ImportError:
    Meeting = None
try:    
    import bbb_settings
except ImportError:
    bbb_settings = None

Dependencies = []
extensions = ['.bbb']

class Parser:
    """
    Lets a user create a meeting page
    It requires a bbb_admin_group defined in wikiconfig.py.
    Only a user of this group is allowed to use this parser. 
    On same directory as wikiconfig.py you need
    a "bbb_settings.py" module with the SALT and the BBB_API_URL.
    
    Example:
    
    #acl YOURNAME:read,write,delete,revert All:
    #format bbb_create
    responsible:: YOURNAME
    meeting_name:: The name of the meeting
    meeting_id:: The ID of the meeting
    attendee_password:: The password for attendee (viewer)
    moderator_password:: The password for moderator
    """

    extensions = ''
    Dependencies = []

    def __init__(self, raw, request, **kw):
        self.raw = raw
        self.request = request
        self.form = request.form
        self._ = request.getText
        self.start_line = kw.get('start_line', 0)

    def format(self, formatter):
        """ Send the text. """
        pagename = formatter.page.page_name
        content = self.request.dicts.get(pagename, {})
        request = self.request
        username = request.user.name
        groups = request.groups
        try:
            bbb_admin_group = groups.get(request.cfg.bbb_admin_group, [])
        except AttributeError:
            wiki_parser = wikiutil.importPlugin(self.request.cfg, "parser", "text_moin_wiki", None)
            wiki_parser = wiki_parser.Parser(self.raw, self.request)
            wiki_parser.format(formatter)
            return


        attendee_password = content["attendee_password"]
        moderator_password = content["moderator_password"]
        meeting_id = content["meeting_id"]
        responsible = content["responsible"]
        if Meeting is not None and bbb_settings is not None:
            meeting = Meeting(bbb_settings.BBB_API_URL, bbb_settings.SALT)
            #XXX meeting.is_running is only True if someone had joined in, so we use meeting_info instead
            meeting_info = meeting.meeting_info(meeting_id, moderator_password)
           
            meeting_data = """\
|| '''Meeting ID''' || '''Participation Count''' || '''Moderator Count'''||
|| %(meeting_id)s || 0 || 0 ||""" % {"meeting_id": meeting_id
                                         }
            if  meeting_info:
                users = meeting_info["users"]
                users_in_meeting = ["%s %s" % (user["name"], user["role"][0]) for user in users]
                meeting_data = """\
|| '''Meeting ID''' || '''Participation Count''' || '''Moderator Count'''|| '''users''' ||
|| %(meeting_id)s || %(participant_count)s || %(moderator_count)s || %(users)s ||""" % {"meeting_id": meeting_id,
                                                                               "participant_count": meeting_info["participant_count"],
                                                                               "moderator_count": meeting_info["moderator_count"],
                                                                               "users": '<<BR>>'.join(users_in_meeting),
                                                                               }
    
            if not attendee_password.strip() or not moderator_password.strip():
                wiki_parser = wikiutil.importPlugin(self.request.cfg, "parser", "text_moin_wiki", None)
                wiki_parser = wiki_parser.Parser(self.raw, self.request)
                wiki_parser.format(formatter)
                return
    
            actions = []
            actions_text = ""
            guest_info_text = ""
            msg = "\n\n/!\ A Moderator has to start the meeting before someone else can join in!"
            if request.user.valid and request.user.may.read(pagename):
                if meeting_info:
                    msg = "\n\n (!) Meeting is running. Please join in!"
                    if username == responsible:
                        actions.append(u' . [[%(moderator_url)s|Join as moderator (%(username)s)]]' % {"moderator_url": meeting.join_url(meeting_id, request.user.name, moderator_password),
                                                                                                       "username": username})
    
                    if meeting.is_running(meeting_id):
                        actions.append(u' . [[%(attendee_url)s|Join as visitor (%(username)s)]]' % {"attendee_url": meeting.join_url(meeting_id, request.user.name, attendee_password),
                                                                                                "username": username})
                    else:
                        msg = "\n\n/!\ Wait until the moderator has joined this meeting!"
                else:
                    if username == responsible:
                        msg = "\n\n/!\ A Moderator has to start the meeting before someone else can join in!"
                        actions.append(u' . <<Action(submit_bbb_start_meeting, text="Click to start this meeting")>>')
    
                if request.user.may.write(pagename) and meeting_info:
                    if username == responsible:
                        actions.append(u' . <<Action(submit_bbb_close_meeting, text="Close this meeting", meeting_id=%(meeting_id)s, password=%(password)s)>>' % {"meeting_id": meeting_id,
                                                                                                                                                      "password": moderator_password
                                                                                                                                                  })
                        
                        if "GUEST_URL" in bbb_settings.__dict__:
                            guest_info_text = "(!) External users can get access by using this URL: %s" % bbb_settings.GUEST_URL
    
    
                if not meeting_info and request.user.may.delete(pagename) and username == responsible:
                    # users with before rights should know to use commands of the menu
                    actions.append(u' . <<Action(edit, text="edit meeting parameter")>>')
                    actions.append(u' . <<Action(DeletePage, text="remove meeting permanently")>>')
    
                if actions:
                    actions_text = """{{{#!wiki dotted
    %(actions)s
    }}}
    """ % {"actions": '\n'.join(actions)}
               
    
            raw = u"""
 %(msg)s
    
Current participants and state of users in this meeting. 
%(meeting_data)s
<<BR>>    
%(actions_text)s
<<BR>>    
%(guest_info_text)s
    """ % {"msg": msg,
           "meeting_data": meeting_data,
           "actions_text": actions_text,
           "guest_info_text": guest_info_text,
          }
    
    
            wiki_parser = wikiutil.importPlugin(self.request.cfg, "parser", "text_moin_wiki", None)
            wiki_parser = wiki_parser.Parser(raw, self.request)
            wiki_parser.format(formatter)