Use the new rights code in core
authorSverre Rabbelier <srabbelier@gmail.com>
Fri, 18 Sep 2009 19:56:23 +0200
changeset 2956 50ce8ac13932
parent 2955 b799af27440e
child 2957 f6515daaf000
Use the new rights code in core
app/soc/logic/rights.py
app/soc/modules/soc_core/callback.py
app/soc/views/helper/access.py
--- a/app/soc/logic/rights.py	Fri Sep 18 19:55:03 2009 +0200
+++ b/app/soc/logic/rights.py	Fri Sep 18 19:56:23 2009 +0200
@@ -29,63 +29,12 @@
   """Checker class that maps from prefix and status to membership.
   """
 
-  SITE_MEMBERSHIP = {
-      'admin': [],
-      'restricted': ['host'],
-      'member': ['user'],
-      'list': ['host'],
-      }
-
-  CLUB_MEMBERSHIP = {
-      'admin': ['host', 'club_admin'],
-      'restricted': ['host', 'club_admin'],
-      'member': ['host', 'club_admin', 'club_member'],
-      'list': ['host', 'club_admin', 'club_member'],
-      }
-
-  SPONSOR_MEMBERSHIP = {
-      'admin': ['host'],
-      'restricted': ['host'],
-      'member': ['host'],
-      'list': ['host'],
-      }
-
-  PROGRAM_MEMBERSHIP = {
-      'admin': ['host'],
-      'restricted': ['host', 'org_admin'],
-      'member': ['host', 'org_admin', 'org_mentor', 'org_student'],
-      'list': ['host', 'org_admin', 'org_mentor'],
-      }
-
-  ORGANIZATION_MEMBERSHIP = {
-      'admin': ['host', 'org_admin'],
-      'restricted': ['host', 'org_admin', 'org_mentor'],
-      'member': ['host', 'org_admin', 'org_mentor', 'org_student'],
-      'list': ['host', 'org_admin', 'org_mentor'],
-      }
-
-  USER_MEMBERSHIP = {
-      'admin': ['user_self'],
-      'restricted': ['user_self'], # ,'friends'
-      'member': ['user'],
-      'list': ['user_self'],
-      }
-
-  RIGHTS = {
-      'site': SITE_MEMBERSHIP,
-      'club': CLUB_MEMBERSHIP,
-      'sponsor': SPONSOR_MEMBERSHIP,
-      'program': PROGRAM_MEMBERSHIP,
-      'org': ORGANIZATION_MEMBERSHIP,
-      'user': USER_MEMBERSHIP,
-      }
-
-  def __init__(self, prefix):
+  def __init__(self, rights, prefix):
     """Constructs a Checker for the specified prefix.
     """
 
+    self.rights = rights[prefix]
     self.prefix = prefix
-    self.rights = self.RIGHTS[prefix]
 
   def getMembership(self, status):
     """Retrieves the membership list for the specified status.
--- a/app/soc/modules/soc_core/callback.py	Fri Sep 18 19:55:03 2009 +0200
+++ b/app/soc/modules/soc_core/callback.py	Fri Sep 18 19:56:23 2009 +0200
@@ -143,3 +143,58 @@
     self.core.registerSidebarEntry(mentor.view.getSidebarMenus)
     self.core.registerSidebarEntry(org_app.view.getSidebarMenus)
     self.core.registerSidebarEntry(grading_survey_group.view.getSidebarMenus)
+
+  def registerRights(self):
+    """Called by the server when the documetn rights should be registerd.
+    """
+
+    site_membership = {
+        'admin': [],
+        'restricted': ['host'],
+        'member': ['user'],
+        'list': ['host'],
+        }
+
+    club_membership = {
+        'admin': ['host', 'club_admin'],
+        'restricted': ['host', 'club_admin'],
+        'member': ['host', 'club_admin', 'club_member'],
+        'list': ['host', 'club_admin', 'club_member'],
+        }
+
+    sponsor_membership = {
+        'admin': ['host'],
+        'restricted': ['host'],
+        'member': ['host'],
+        'list': ['host'],
+        }
+
+    program_membership = {
+        'admin': ['host'],
+        'restricted': ['host', 'org_admin'],
+        'member': ['host', 'org_admin', 'org_mentor', 'org_student'],
+        'list': ['host', 'org_admin', 'org_mentor'],
+        }
+
+    organization_membership = {
+        'admin': ['host', 'org_admin'],
+        'restricted': ['host', 'org_admin', 'org_mentor'],
+        'member': ['host', 'org_admin', 'org_mentor', 'org_student'],
+        'list': ['host', 'org_admin', 'org_mentor'],
+        }
+
+    user_membership = {
+        'admin': ['user_self'],
+        'restricted': ['user_self'], # ,'friends'
+        'member': ['user'],
+        'list': ['user_self'],
+        }
+
+    self.core.registerRight('site', site_membership)
+    self.core.registerRight('club': club_membership)
+    self.core.registerRight('sponsor': sponsor_membership)
+    self.core.registerRight('program': program_membership)
+    self.core.registerRight('ghop_program': ghop_program_membership)
+    self.core.registerRight('org': organization_membership)
+    self.core.registerRight('ghop_org': ghop_organization_membership)
+    self.core.registerRight('user': user_membership)
--- a/app/soc/views/helper/access.py	Fri Sep 18 19:55:03 2009 +0200
+++ b/app/soc/views/helper/access.py	Fri Sep 18 19:56:23 2009 +0200
@@ -34,7 +34,6 @@
 from django.utils.translation import ugettext
 
 from soc.logic import dicts
-from soc.logic import rights as rights_logic
 from soc.logic.helper import timeline as timeline_helper
 from soc.logic.models.club_admin import logic as club_admin_logic
 from soc.logic.models.club_member import logic as club_member_logic
@@ -448,7 +447,7 @@
       django_args: the django args to pass on to the checkers
     """
 
-    checker = rights_logic.Checker(prefix)
+    checker = callback.getCore().getRightsChecker(prefix)
     roles = checker.getMembership(status)
 
     message_fmt = DEF_NEED_MEMBERSHIP_MSG_FMT % {
@@ -1946,7 +1945,7 @@
     filter = django_args['filter']
     prefix = filter['prefix']
 
-    checker = rights_logic.Checker(prefix)
+    checker = callback.getCore().getRightsChecker(prefix)
     roles = checker.getMembership('list')
 
     if not self.hasMembership(roles, filter):
@@ -1975,7 +1974,7 @@
     django_args['prefix'] = prefix
     django_args['scope_path'] = get_args['scope_path']
 
-    checker = rights_logic.Checker(prefix)
+    checker = callback.getCore().getRightsChecker(prefix)
     memberships = checker.getMemberships()
 
     roles = []