Index: main/waeup.kofa/trunk/src/waeup/kofa/students/dynamicroles.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/dynamicroles.py	(revision 8951)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/dynamicroles.py	(revision 8963)
@@ -46,4 +46,6 @@
     rolename_mapping = {
         'waeup.local.ClearanceOfficer':'waeup.StudentsClearanceOfficer',
+        'waeup.local.UGClearanceOfficer':'waeup.StudentsClearanceOfficer',
+        'waeup.local.PGClearanceOfficer':'waeup.StudentsClearanceOfficer',
         }
 
@@ -51,35 +53,6 @@
         """Get roles for principal with id `principal_id`.
 
-        Different to the default implementation, this method also
-        takes into account local roles set on any department connected
-        to the context student.
-
-        If the given principal has at least one of the
-        `external_rolenames` roles granted for the external object, it
-        additionally gets `additional_rolename` role for the context
-        student.
-
-        For the additional roles the `extra_attrib` and all its parent
-        objects are looked up, because 'role inheritance' does not
-        work on that basic level of permission handling.
-
-        Some advantages of this approach:
-
-        - we don't have to store extra local roles for clearance
-          officers in ZODB for each student
-
-        - when local roles on a department change, we don't have to
-          update thousands of students; the local role is assigned
-          dynamically.
-
-        Disadvantage:
-
-        - More expensive role lookups when a clearance officer wants
-          to see an student form.
-
-        This implementation is designed to be usable also for other
-        contexts than students. You can inherit from it and set
-        different role names to lookup/set easily via the static class
-        attributes.
+        See waeup.kofa.applicants.dynamicroles.ApplicantPrincipalRoleManager
+        for further information.
         """
         apr_manager = AnnotationPrincipalRoleManager(self._context)
@@ -118,4 +91,20 @@
                         result.append(
                             ('waeup.StudentsOfficer', setting))
+                elif 'UGClearanceOfficer' in role_id:
+                    if not self._context.is_postgrad:
+                        result.append(
+                            ('waeup.StudentsClearanceOfficer', setting))
+                    else:
+                        # Otherwise grant at least view permissions.
+                        result.append(
+                            ('waeup.StudentsOfficer', setting))
+                elif 'PGClearanceOfficer' in role_id:
+                    if self._context.is_postgrad:
+                        result.append(
+                            ('waeup.StudentsClearanceOfficer', setting))
+                    else:
+                        # Otherwise grant at least view permissions.
+                        result.append(
+                            ('waeup.StudentsOfficer', setting))
                 elif role_id in self.rolename_mapping.keys():
                     # Grant additional role
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 8951)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 8963)
@@ -1557,5 +1557,5 @@
                            self.browser.contents)
         # Payment session and level are current ones.
-        # Postgrads have to school_fee_1.
+        # Postgrads have to pay school_fee_1.
         self.assertEqual(self.student['payments'][value].amount_auth, 40000.0)
         self.assertEqual(self.student['payments'][value].p_session, 2004)
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_dynamicroles.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_dynamicroles.py	(revision 8951)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_dynamicroles.py	(revision 8963)
@@ -25,4 +25,5 @@
     Test as APRMTest, Manageable)
 from waeup.kofa.testing import FunctionalLayer
+from waeup.kofa.app import University
 from waeup.kofa.students.tests.test_browser import StudentsFullSetup
 from waeup.kofa.students import Student, StudentPrincipalRoleManager
@@ -48,8 +49,9 @@
     def setUp(self):
         super(StudentPrincipalRoleManagerFunctionalTests, self).setUp()
-        self.officer_role = 'waeup.StudentsClearanceOfficer'
         # assign clearance permissions for a virtual officer
         prm = IPrincipalRoleManager(self.app['faculties']['fac1']['dep1'])
         prm.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'alice')
+        prm.assignRoleToPrincipal('waeup.local.PGClearanceOfficer', 'bob')
+        prm.assignRoleToPrincipal('waeup.local.UGClearanceOfficer', 'anne')
         return
 
@@ -74,5 +76,5 @@
         # student
         prm = IPrincipalRoleManager(self.student)
-        result = prm.getRolesForPrincipal('bob')
+        result = prm.getRolesForPrincipal('claus')
         self.assertEqual(result, [])
         return
@@ -83,4 +85,18 @@
         prm = IPrincipalRoleManager(self.student)
         result = prm.getRolesForPrincipal('alice')
-        self.assertEqual(result, [(self.officer_role, Allow)])
+        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
+        # Student is a UG student
+        self.assertFalse(self.student.is_postgrad)
+        result = prm.getRolesForPrincipal('bob')
+        self.assertEqual(result, [('waeup.StudentsOfficer', Allow)])
+        result = prm.getRolesForPrincipal('anne')
+        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
+        # Make student a PG student
+        self.certificate.study_mode = u'pg_ft'
+        self.assertTrue(self.student.is_postgrad)
+        result = prm.getRolesForPrincipal('bob')
+        # The dynamic roles changed
+        self.assertEqual(result, [('waeup.StudentsClearanceOfficer', Allow)])
+        result = prm.getRolesForPrincipal('anne')
+        self.assertEqual(result, [('waeup.StudentsOfficer', Allow)])
         return
