Now invited users can create a new Host profile
authorSverre Rabbelier <srabbelier@gmail.com>
Sat, 29 Nov 2008 21:58:34 +0000
changeset 617 9cc42981d40a
parent 616 580b1c21b808
child 618 b2319f2633bc
Now invited users can create a new Host profile Before the invited user had to be a developer for this to work. Now, instead the default checkIsDeveloper check for the 'edit Host', a custom checkIsInvite check is used. Patch by: Sverre Rabbelier
app/soc/views/helper/access.py
app/soc/views/models/host.py
--- a/app/soc/views/helper/access.py	Sat Nov 29 21:21:04 2008 +0000
+++ b/app/soc/views/helper/access.py	Sat Nov 29 21:58:34 2008 +0000
@@ -215,7 +215,7 @@
   raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
 
 
-def checkIsInvited(request, role):
+def checkIsInvited(request):
   """Returns an alternate HTTP response if Google Account has no Host entity
      for the specified program.
 
@@ -233,13 +233,31 @@
 
   checkIsUser(request)
 
+  login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % {
+      'role': 'a host for this program'}
+
+  splitpath = request.path.split('/')
+
+  if len(splitpath) < 4:
+    # TODO: perhaps this needs a better explanation?
+    deny(request)
+
+  role = splitpath[1]
+  group_id = splitpath[3]
+  user_id = splitpath[4]
+
   user = user_logic.logic.getForFields(
       {'account': users.get_current_user()}, unique=True)
 
+  if user_id != user.link_id:
+    # TODO: perhaps this needs a better explanation?
+    deny(request)
+
   properties = {
-      'requester': user,
+      'link_id': user_id,
       'role': role,
-      'accepted': True,
+      'scope_path': group_id,
+      'group_accepted': True,
       }
 
   request = request_logic.logic.getForFields(properties, unique=True)
@@ -247,7 +265,4 @@
   if request:
     return
 
-  login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % {
-      'role': 'a host for this program'}
-
   raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
--- a/app/soc/views/models/host.py	Sat Nov 29 21:21:04 2008 +0000
+++ b/app/soc/views/models/host.py	Sat Nov 29 21:58:34 2008 +0000
@@ -31,6 +31,7 @@
 from soc.views import helper
 from soc.views.models import base
 from soc.views.models import role
+from soc.views.helper import access
 
 import soc.models.host
 import soc.logic.models.host
@@ -87,7 +88,11 @@
       original_params: a dict with params for this View
     """
 
+    rights = {}
+    rights['edit'] = [access.checkIsInvited]
+
     params = {}
+    params['rights'] = rights
     params['logic'] = soc.logic.models.host.logic
 
     params['logic'] = soc.logic.models.host.logic