Пример #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})
Пример #2
0
def leave_group(group,**kwargs):
    user = kwargs['user']
    acc = acc_for_user(user)
    with ac_api_client(acc) as api:
        principal = api.find_principal("login", user.username, "user")
        if principal:
            gp = api.find_group(group.name)
            if gp:
                api.remove_member(principal.get('principal-id'),gp.get('principal-id'))
Пример #3
0
def ac_api_client(o):
    acc = o
    logging.debug("ac_api_client(%s)" % repr(o))
    if hasattr(o, "user") and isinstance(getattr(o, "user"), User):
        acc = acc_for_user(getattr(o, "user"))
    elif hasattr(o, "acc"):
        acc = getattr(o, "acc")

    tag = "ac_api_client_%d" % acc.id
    pool = _pools.get(tag)
    if pool is None:
        pool = ClientPool(acc, maxsize=30)
        _pools[tag] = pool

    return pool.allocate()
Пример #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)
Пример #5
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
Пример #6
0
def accounts_login_federated(request):
    if request.user.is_authenticated():
        profile, created = UserProfile.objects.get_or_create(user=request.user)
        if created:
            profile.identifier = request.user.username
            profile.user = request.user
            profile.save()        
        
        update = False
        fn = meta1(request,'givenName')
        ln = meta1(request,'sn')
        cn = meta1(request,'cn')
        if not cn:
            cn = meta1(request,'displayName')
        logging.debug("cn=%s" % cn)
        if not cn and fn and ln:
            cn = "%s %s" % (fn,ln)
        if not cn:
            cn = profile.identifier
            
        mail = meta1(request,'mail')
        
        idp = meta1(request,'Shib-Identity-Provider')
        
        for attrib_name, meta_value in (('display_name',cn),('email',mail),('idp',idp)):
            attrib_value = getattr(profile, attrib_name)
            if meta_value and not attrib_value:
                setattr(profile,attrib_name,meta_value)
                update = True
                
        if request.user.password == "":
            request.user.password = "******"
            update = True
            
        if update:
            request.user.save()
        
        # Allow auto_now to kick in for the lastupdated field
        #profile.lastupdated = datetime.datetime.now()    
        profile.save()

        next = request.session.get("after_login_redirect", None)
        if not next and request.GET.has_key('next'):
            next = request.GET['next']
        else:
            next = settings.DEFAULT_URL

        acc = acc_for_user(request.user)
        with ac_api_client(request) as api:
            # make sure the principal is created before shooting off 
            principal = api.find_or_create_principal("login", request.user.username, "user", 
                                                             {'type': "user",
                                                              'has-children': "0",
                                                              'first-name':fn,
                                                              'last-name':ln,
                                                              'email':mail,
                                                              'send-email': 0,
                                                              'login':request.user.username,
                                                              'ext-login':request.user.username})

            #co_import_from_request(request)
            import_user_rooms(acc, api, request.user)
            
            member_or_employee = _is_member_or_employee(request.user)
            for gn in ('live-admins','seminar-admins'):
                group = api.find_builtin(gn)
                if group:
                    api.add_remove_member(principal.get('principal-id'),group.get('principal-id'),member_or_employee)
            
            #(lp,domain) = uid.split('@')
            #for a in ('student','employee','member'):
            #    affiliation = "%s@%s" % (a,domain)
            #    group = connect_api.find_or_create_principal('name',affiliation,'group',{'type': 'group','has-children':'1','name': affiliation})
            #    member = affiliation in affiliations
            #    connect_api.add_remove_member(principal.get('principal-id'),group.get('principal-id'),member)
                
            #for e in epe:
            #    group = connect_api.find_or_create_principal('name',e,'group',{'type': 'group','has-children':'1','name': e})
            #    if group:
            #        connect_api.add_remove_member(principal.get('principal-id'),group.get('principal-id'),True)

            if next is not None:
                return redirect_to(next)
    else:
        pass

    return redirect_to(settings.LOGIN_URL)