Beispiel #1
0
def create(request):
    acc = acc_for_user(request.user)
    my_meetings_sco = get_sco(acc, _user_meeting_folder(request, acc))
    template_sco_id = acc.default_template_sco_id
    if not template_sco_id:
        template_sco_id = settings.DEFAULT_TEMPLATE_SCO
    room = Room(creator=request.user, folder_sco=my_meetings_sco, source_sco=get_sco(acc, template_sco_id))
    what = "Create"
    title = "Create a new room"

    if request.method == 'POST':
        form = CreateRoomForm(request.POST, instance=room)
        _init_update_form(request, form, acc, my_meetings_sco)
        if form.is_valid():
            _update_room(request, room, form.cleaned_data)
            room = form.save()
            return redirect_to("/rooms#%d" % room.id)
    else:
        form = CreateRoomForm(instance=room)
        _init_update_form(request, form, acc, my_meetings_sco)

    return respond_to(request, {'text/html': 'apps/room/create.html'},
                      {'form': form,
                       'formtitle': title,
                       'cancelurl': '/rooms',
                       'cancelname': 'Cancel',
                       'submitname': '%s Room' % what})
Beispiel #2
0
    def create(acc, api, row):
        sco_id = row.get('sco-id')
        byte_count = api.get_byte_count(sco_id)
        if byte_count or byte_count == 0:
            sco_element = api.get_sco_info(sco_id)
            if sco_element is not None and not sco_element.get('source-sco-id'):  # Object is not a reference
                views = api.get_sco_views(sco_id)
                owner = api.get_owner(sco_element.findtext('url-path'))
                if not owner:
                    owner = get_owner_by_folder(api, acc, sco_element)
                try:
                    domain = owner['login'].split('@')[1].split(';')[0]
                    user, created = User.objects.get_or_create(username=owner['login'])
                    if created:
                        user.set_unusable_password()
                except IndexError:
                    user = None
                    domain = None

                datecreated = row.findtext('date-created')
                if not datecreated:
                    datecreated = row.findtext('date-modified')
                try:
                    content, created = Content.objects.get_or_create(
                        sco=get_sco(acc, sco_id),
                        creator=user,
                        name=row.findtext('name'),
                        folder_sco=get_sco(acc, sco_element.get('folder-id')),
                        type=row.get('icon'),
                        urlpath=row.findtext('url'),
                        bytecount=byte_count,
                        created=datecreated,
                        modified=row.findtext('date-modified'),
                        views=views['views'],
                        lastviewed=views['last-viewed-date']
                    )
                except IntegrityError:
                    content = Content.objects.get(sco=get_sco(acc, sco_id))
                    created = False
                if not created:
                    Content.objects.filter(sco=content.sco).update(
                        creator=user,
                        name=row.findtext('name'),
                        folder_sco=get_sco(acc, sco_element.get('folder-id')),
                        type=row.get('icon'),
                        urlpath=row.findtext('url'),
                        bytecount=byte_count,
                        modified=row.findtext('date-modified'),
                        views=views['views'],
                        lastviewed=views['last-viewed-date']
                    )

                if user and domain:
                    tags = []
                    for group in user.groups.all():
                        tags.append("group:%s" % group.name)
                    tags.append("domain:%s" % domain)
                    Tag.objects.update_tags(content, ' '.join(tags))
Beispiel #3
0
def _user_templates(request, acc, folder_sco):
    templates = []
    with ac_api_client(acc) as api:
        if folder_sco:
            my_templates = api.request('sco-contents', {'sco-id': folder_sco.sco_id, 'filter-type': 'folder'}).et.xpath(
                './/sco[folder-name="My Templates"][0]')
            if my_templates and len(my_templates) > 0:
                my_templates_sco_id = my_templates[0].get('sco_id')
                meetings = api.request('sco-contents', {'sco-id': my_templates_sco_id, 'filter-type': 'meeting'})
                if meetings:
                    templates += [(get_sco(acc, r.get('sco-id')), r.findtext('name')) for r in
                                  meetings.et.findall('.//sco')]

        shared_templates_sco = get_sco_shortcuts(acc, 'shared-meeting-templates')
        shared_templates = api.request('sco-contents',
                                       {'sco-id': shared_templates_sco.sco_id, 'filter-type': 'meeting'})
        if shared_templates:
            templates += [(get_sco(acc, r.get('sco-id')).id, r.findtext('name')) for r in
                          shared_templates.et.findall('.//sco')]

    return templates
Beispiel #4
0
def myroom(request):
    acc = acc_for_user(request.user)
    my_meetings_sco = get_sco(acc, _user_meeting_folder(request, acc))
    template_sco_id = acc.default_template_sco_id
    if not template_sco_id:
        template_sco_id = settings.DEFAULT_TEMPLATE_SCO
    template_sco = get_sco(acc, template_sco_id)
    room = None
    try:
        room = Room.by_name(acc, name=request.user.username)
    except MultipleObjectsReturned:
        raise ValueError("Oops - there seem to be multiple rooms with name '%s'" % request.user.username)
    except ObjectDoesNotExist:
        room = Room(creator=request.user,
                    folder_sco=my_meetings_sco,
                    name=request.user.username,
                    source_sco=template_sco)
        _update_room(request, room, dict(access='public'))

    if not room:
        raise ValueError("Opps - can't find your room")

    return _goto(request, room)
Beispiel #5
0
def publish_archive(room,sco_id,tags=None):
    acc = room.sco.acc
    sco = get_sco(acc,sco_id)

    info = sco.info(True)
    dt = info['timecreated']
    folder_sco = sco_mkdir(acc,"content/%d/%s/%s" % (dt.year,dt.month,dt.day))
    with ac_api_client(acc) as api:
        ar,create = Archive.objects.get_or_create(sco=sco,folder_sco=folder_sco,room=room)
        ar.timecreated=info['timecreated']
        if 'description' in info:
            ar.description = info['description']
        if 'name' in info:
            ar.name = info['name']
        ar.save()
        try:
            r = api.request('sco-move',{'sco-id':sco_id,'folder-id':folder_sco.sco_id},True)
            r = api.request('permissions-update',{'acl-id':sco_id,'permission-id': 'view','principal-id':'public-access'})
        except Exception,ex:
            ar.delete()
            raise ex
Beispiel #6
0
def room_recordings(request, room):
    acc = room.sco.acc
    with ac_api_client(acc) as api:
        r = api.request('sco-expanded-contents', {'sco-id': room.sco.sco_id, 'filter-icon': 'archive'}, True)
        return [{'published': False,
                 'name': sco_elt.findtext('name'),
                 'sco': get_sco(acc, sco_elt.get('sco-id')),
                 'url': room.sco.acc.make_url(sco_elt.findtext('url-path')),
                 'dl': room.sco.acc.make_dl_url(sco_elt.findtext('url-path')),
                 'description': sco_elt.findtext('description'),
                 'date_created': iso8601.parse_date(sco_elt.findtext('date-created')),
                 'date_modified': iso8601.parse_date(sco_elt.findtext('date-modified'))} for sco_elt in
                r.et.findall(".//sco")] + [
                   {'published': True,
                    'ar': ar,
                    'name': ar.name,
                    'description': ar.description,
                    'sco': ar.sco,
                    'url': room.sco.acc.make_url(ar.urlpath),
                    'dl': room.sco.acc.make_url(ar.urlpath),
                    'date_created': ar.timecreated,
                    'date_modified': ar.lastupdated} for ar in
                   room.archives.all().prefetch_related("creator", "sco", "folder_sco", "source_sco", "deleted_sco")
               ]
Beispiel #7
0
def _update_room(request, room, data=dict(), acc=None):
    params = {'type': 'meeting'}

    if acc is None:
        acc = acc_for_user(request.user)

    for attr, param in (
        ('sco', 'sco-id'), ('folder_sco', 'folder-id'), ('source_sco', 'source-sco-id'), ('urlpath', 'url-path'),
('name', 'name'), ('description', 'description')):
        v = None
        if hasattr(room, attr):
            v = getattr(room, attr)
        logging.debug("%s,%s = %s" % (attr, param, repr(v)))
        if data.has_key(attr) and data[attr]:
            v = data[attr]

        if v:
            if isinstance(v, (str, unicode)):
                params[param] = v
            elif hasattr(v, 'sco_id'):
                params[param] = v.sco_id # support ACObject instances
            elif hasattr(v, '__getitem__'):
                params[param] = v[0]
            else:
                params[param] = repr(v)

    logging.debug(pformat(params))
    with ac_api_client(acc) as api:
        r = api.request('sco-update', params, True)
        sco_elt = r.et.find(".//sco")
        if sco_elt:
            sco_id = sco_elt.get('sco-id')
            if sco_id:
                data['sco'] = get_sco(acc, sco_id)

            source_sco_id = r.et.find(".//sco").get('sco-source-id')
            if source_sco_id:
                data['source_sco'] = get_sco(acc, source_sco_id)

            room.sco = data['sco']
            room.save()

        sco_id = room.sco.sco_id

        assert (sco_id is not None and sco_id > 0)

        user_principal = api.find_user(room.creator.username)
        #api.request('permissions-reset',{'acl-id': sco_id},True)
        api.request('permissions-update', {'acl-id': sco_id,
                                           'principal-id': user_principal.get('principal-id'),
                                           'permission-id': 'host'}, False)  # owner is always host

        if data.has_key('access'):
            access = data['access']
            if access == 'public':
                allow(room, 'anyone', 'view-hidden')
            elif access == 'private':
                allow(room, 'anyone', 'remove')

        # XXX figure out how to keep the room permissions in sync with the AC permissions
        for ace in acl(room):
            principal_id = None
            if ace.group:
                principal = api.find_group(ace.group.name)
                if principal:
                    principal_id = principal.get('principal-id')
            elif ace.user:
                principal = api.find_user(ace.user.username)
                if principal:
                    principal_id = principal.get('principal-id')
            else:
                principal_id = "public-access"

            if principal_id:
                api.request('permissions-update',
                            {'acl-id': room.sco_id, 'principal-id': principal_id, 'permission-id': ace.permission},
                            False)

        room.deleted_sco = None # if we just cleaned a room we zero out the deleted_sco_id field to indicate the room is now ready for use
        room.save() # a second save here to avoid races
        return room
Beispiel #8
0
 def by_id(acc, sco_id):
     return Content.by_sco(get_sco(acc, sco_id))
Beispiel #9
0
 def by_id(acc,sco_id):
     return Room.by_sco(get_sco(acc,sco_id))
Beispiel #10
0
                return dflt
            else:
                return int(str)

        for elt in r.findall(".//sco[0]"):
            folder_sco_id = _ior0(elt,'folder-id',0)
            source_sco_id = _ior0(elt,'source-sco-id',0)

        logging.debug("urlpath=%s, name=%s, folder_sco_id=%s, source_sco_id=%s" % (urlpath,name,folder_sco_id,source_sco_id))

        if room is None:
            if folder_sco_id:
                user, created = User.objects.get_or_create(username=username)
                if created:
                    user.set_unusable_password()
                room = Room.objects.create(sco=get_sco(acc,sco_id),
                                        creator=user,name=name,
                                        description=description,
                                        folder_sco=get_sco(acc,folder_sco_id),
                                        source_sco=get_sco(acc,source_sco_id),
                                        urlpath=urlpath)
                room.trylock()
        else:
            if folder_sco_id:
                room.folder_sco = get_sco(acc,folder_sco_id)
            room.source_sco = get_sco(acc,source_sco_id)
            room.description = description
            room.urlpath = urlpath
            if date_created is not None:
                room.timecreated = date_created