diff options
author | Leif Johansson <leifj@sunet.se> | 2011-05-02 14:43:23 +0200 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2011-05-02 14:43:23 +0200 |
commit | 1c3423d452d0ca1e20dff36ce05c2e35d2894f29 (patch) | |
tree | dd52ff1e96b185f62bceef6e57f96d7e9bf6c9fe /src/meetingtools/apps/room | |
parent | f936e1317c3ba08ab94a39ea99126c9d61337718 (diff) |
new acl - first version
Diffstat (limited to 'src/meetingtools/apps/room')
-rw-r--r-- | src/meetingtools/apps/room/forms.py | 43 | ||||
-rw-r--r-- | src/meetingtools/apps/room/models.py | 8 | ||||
-rw-r--r-- | src/meetingtools/apps/room/views.py | 58 |
3 files changed, 80 insertions, 29 deletions
diff --git a/src/meetingtools/apps/room/forms.py b/src/meetingtools/apps/room/forms.py index aef7d8d..a211b2d 100644 --- a/src/meetingtools/apps/room/forms.py +++ b/src/meetingtools/apps/room/forms.py @@ -3,21 +3,42 @@ Created on Feb 1, 2011 @author: leifj ''' -from django.forms.models import ModelForm +from django.forms.models import ModelChoiceField from meetingtools.apps.room.models import Room from django.forms.widgets import Select, TextInput -from django.forms.fields import ChoiceField, BooleanField +from django.forms.fields import BooleanField from django.forms.forms import Form from form_utils.forms import BetterModelForm +from django.contrib.auth.models import Group PUBLIC = 0 PROTECTED = 1 PRIVATE = 2 -class UpdateRoomForm(BetterModelForm): - #protection = ChoiceField(choices=((PUBLIC,'Anyone can enter the room.'), - # (PROTECTED,'Only group members and accepted guests can enter the room.'), - # (PRIVATE,'Only group members can enter.'))) +class ModifyRoomForm(BetterModelForm): + class Meta: + model = Room + fields = ['name','source_sco_id','self_cleaning'] + fieldsets = [('name',{'fields': ['name'], + 'classes': ['step'], + 'legend': 'Step 1: Room name', + 'description': 'The room name should be short and descriptive.' + }), + ('properties',{'fields': ['self_cleaning','urlpath','source_sco_id'], + 'classes': ['step'], + 'legend': 'Step 2: Room properties', + 'description': 'These are basic properties for your room. If you set your room to be self-cleaning it will be reset every time the last participant leaves the room.'}), + ] + widgets = {'source_sco_id': Select(), + 'urlpath': TextInput(attrs={'size': '40'}), + 'name': TextInput(attrs={'size': '40'})} + + +class CreateRoomForm(BetterModelForm): + + participants = ModelChoiceField(Group,required=False) + presenters = ModelChoiceField(Group,required=False) + hosts = ModelChoiceField(Group,required=False) class Meta: model = Room @@ -34,15 +55,11 @@ class UpdateRoomForm(BetterModelForm): ('rights',{'fields': ['participants','presenters','hosts'], 'classes': ['step','submit_step'], 'legend': 'Step 3: Room rights (optional)', - 'description': 'Define the groups that are to have access to your room.'}) + 'description': 'Define the groups that are to have access to your room. If you leave the <em>Participants</em> field empty that implies that anyone who knows the URL may enter the room.'}) ] - widgets = {'participants': Select(), - 'presenters': Select(), - 'hosts': Select(), - 'source_sco_id': Select(), + widgets = {'source_sco_id': Select(), 'urlpath': TextInput(attrs={'size': '40'}), - 'name': TextInput(attrs={'size': '40'}), - } + 'name': TextInput(attrs={'size': '40'})} class DeleteRoomForm(Form): confirm = BooleanField(label="Confirm remove room")
\ No newline at end of file diff --git a/src/meetingtools/apps/room/models.py b/src/meetingtools/apps/room/models.py index f0adb99..1c7f2cd 100644 --- a/src/meetingtools/apps/room/models.py +++ b/src/meetingtools/apps/room/models.py @@ -10,15 +10,17 @@ from django.db.models.fields.related import ForeignKey from django.contrib.auth.models import User from meetingtools.apps.cluster.models import ACCluster import time +from django_co_acls.models import AccessControlEntry class Room(models.Model): creator = ForeignKey(User,editable=False) name = CharField(max_length=128,unique=True) urlpath = CharField(max_length=128,unique=True) acc = ForeignKey(ACCluster,verbose_name="Adobe Connect Cluster",editable=False) - participants = CharField(max_length=255,blank=True,verbose_name="Participants") # populate from entitlement held by creator session - presenters = CharField(max_length=255,blank=True,verbose_name="Presenters") # populate from entitlement held by creator session - hosts = CharField(max_length=255,blank=True,verbose_name="Hosts") # populate from entitlement held by creator session + acl = ForeignKey(AccessControlEntry,blank=True,null=True) + #participants = CharField(max_length=255,blank=True,verbose_name="Participants") # populate from entitlement held by creator session + #presenters = CharField(max_length=255,blank=True,verbose_name="Presenters") # populate from entitlement held by creator session + #hosts = CharField(max_length=255,blank=True,verbose_name="Hosts") # populate from entitlement held by creator session self_cleaning = BooleanField(verbose_name="Clean-up when empty?") sco_id = IntegerField(verbose_name="Adobe Connect Room") source_sco_id = IntegerField(verbose_name="Template",blank=True,null=True) diff --git a/src/meetingtools/apps/room/views.py b/src/meetingtools/apps/room/views.py index 65e085b..0489d63 100644 --- a/src/meetingtools/apps/room/views.py +++ b/src/meetingtools/apps/room/views.py @@ -5,7 +5,8 @@ Created on Jan 31, 2011 ''' from meetingtools.apps.room.models import Room, ACCluster from meetingtools.multiresponse import respond_to, redirect_to -from meetingtools.apps.room.forms import UpdateRoomForm, DeleteRoomForm +from meetingtools.apps.room.forms import DeleteRoomForm,\ + CreateRoomForm, ModifyRoomForm from django.shortcuts import get_object_or_404 from meetingtools.ac import ac_api_client, api import re @@ -20,6 +21,7 @@ from meetingtools.settings import GRACE from django.utils.datetime_safe import datetime from django.http import HttpResponseRedirect from django.core.exceptions import ObjectDoesNotExist +from django_co_acls.models import allow, deny, acl def _acc_for_user(user): (local,domain) = user.username.split('@') @@ -115,13 +117,17 @@ def view(request,id): }) def _init_update_form(request,form,acc,my_meetings_sco_id): - form.fields['participants'].widget.choices = [('','-- anyone --')]+[(g,g) for g in groups(request)] - form.fields['presenters'].widget.choices = [('','-- nobody --')]+[(g,g) for g in groups(request)] - form.fields['hosts'].widget.choices = [('','-- nobody --')]+[(g,g) for g in groups(request)] - form.fields['source_sco_id'].widget.choices = [('','-- select template --')]+[r for r in _user_templates(request,acc,my_meetings_sco_id)] + if form.fields.has_key('participants'): + form.fields['participants'].queryset = request.user.groups + if form.fields.has_key('presenters'): + form.fields['presenters'].queryset = request.user.groups + if form.fields.has_key('hosts'): + form.fields['hosts'].queryset = request.user.groups + if form.fields.has_key('source_sco_id'): + form.fields['source_sco_id'].widget.choices = [('','-- select template --')]+[r for r in _user_templates(request,acc,my_meetings_sco_id)] @login_required -def _update_room(request, room): +def _update_room(request, room, form=None): api = ac_api_client(request, room.acc) params = {'type':'meeting', 'name':room.name, @@ -136,7 +142,29 @@ def _update_room(request, room): room.sco_id = r.et.find(".//sco").get('sco-id') room.source_sco_id = r.et.find(".//sco").get('sco-source-id') room.save() - #room = _import_room(params['sco-id'], params['name'], params['source-sco-id'], params['url-path'], request.user, acc) + logging.debug(pformat(room)) + + for (key,perm) in [('participants','view'),('presenters','mini-host'),('hosts','host')]: + if form.cleaned_data.has_key(key): + group = form.cleaned_data[key] + if not group and key == 'participants': + group = "anyone" + permission = "view-hidden" + + if group: + allow(room, group, permission) + else: + deny(room,group,permission) + + r = api.request('permissions-reset',{'acl-id': room.sco_id},True) + user_principal = api.find_user(request.user.username) + r = api.request('permissions-update',{'acl-id': room.sco_id,'principal-id': user_principal.get('principal-id'),'permission-id':'host'}) # owner is always host + for ace in acl(room): + principal_id = "public-access" + if ace.group: + principal_id = ace.group.name + r = api.request('permissions-update',{'acl-id': room.sco_id, 'principal-id': principal_id, 'permission-id': ace.permission},True) + return room @login_required @@ -158,17 +186,21 @@ def update(request,id=None): update = False if request.method == 'POST': - form = UpdateRoomForm(request.POST,instance=room) + if update: + form = ModifyRoomForm(request.POST,instance=room) + else: + form = CreateRoomForm(request.POST,instance=room) _init_update_form(request, form, acc, room.folder_sco_id) if form.is_valid(): - room = _update_room(request, room) + room = _update_room(request, room, form) room = form.save() return redirect_to("/rooms#%d" % room.id) else: - form = UpdateRoomForm(instance=room) - _init_update_form(request, form, acc, room.folder_sco_id) if update: - form.fields['urlpath'].widget.attrs['readonly'] = True + form = ModifyRoomForm(instance=room) + else: + form = CreateRoomForm(instance=room) + _init_update_form(request, form, acc, room.folder_sco_id) return respond_to(request,{'text/html':'apps/room/%s.html' % formname},{'form':form,'formtitle': title,'submitname':'%s Room' % what}) @@ -225,7 +257,7 @@ def list(request): ar.append(int(sco_id)) #logging.debug(pformat(ar)) - + for r in Room.objects.filter(creator=request.user).all(): #logging.debug(pformat(r)) if (not r.sco_id in ar) and (not r.self_cleaning): |