Index: WAeUP_SRP/trunk/skins/waeup_custom/logged_in.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_custom/logged_in.py	(revision 1005)
+++ WAeUP_SRP/trunk/skins/waeup_custom/logged_in.py	(revision 1006)
@@ -48,25 +48,44 @@
 member = mtool.getAuthenticatedMember()
 
-if not is_anon:
-    if "Student" in member.getRoles():
-        to_waeup_student_home = True
-        students = context.portal_url.getPortalObject().campus.students
-        student = getattr(students,str(member))
-        student_app = getattr(student,'application')
-        student_pume = getattr(student,'pume',None)
-        s_review_state = wftool.getInfoFor(student,'review_state',None)
-        a_review_state = wftool.getInfoFor(student_app,'review_state',None)
-        logger.info('%s review_state %s' % (member,s_review_state))
-        app_doc = student_app.getContent()
-        #from Products.zdb import set_trace
-        #set_trace()
-        if s_review_state in ("student_created","admitted") and\
-        a_review_state == 'created' :
-            wftool.doActionFor(student_app,'open')
-            if student_pume is not None:
-              wftool.doActionFor(student_pume,'close')
-            da = {}
-            pin = request.get('pin')
-            if not pin:
+if redirect_url.endswith('/logged_out'):
+    redirect_to_portal = True    
+else:
+    if not is_anon:
+        if "Student" in member.getRoles():
+            to_waeup_student_home = True
+            students = context.portal_url.getPortalObject().campus.students
+            student = getattr(students,str(member))
+            student_app = getattr(student,'application')
+            student_pume = getattr(student,'pume',None)
+            s_review_state = wftool.getInfoFor(student,'review_state',None)
+            a_review_state = wftool.getInfoFor(student_app,'review_state',None)
+            logger.info('%s review_state %s' % (member,s_review_state))
+            app_doc = student_app.getContent()
+            #from Products.zdb import set_trace
+            #set_trace()
+            if s_review_state in ("student_created","admitted") and\
+            a_review_state == 'created' :
+                wftool.doActionFor(student_app,'open')
+                if student_pume is not None:
+                  wftool.doActionFor(student_pume,'close')
+                da = {}
+                pin = request.get('pin')
+                if not pin:
+                    jamb_reg_no = app_doc.jamb_reg_no
+                    for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
+                        res = context.portal_pins(student=reg_no)
+                        if len(res) > 0:
+                            break
+                    if len(res) > 0:
+                        p = res[0].pin
+                        if len(p) > 10:
+                            pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
+                        else:
+                            pin = p
+                da['app_ac_pin'] = pin
+                da['app_ac_date'] = current
+                app_doc.edit(mapping = da)
+            elif s_review_state in ("admitted") and a_review_state == 'opened' and\
+            not app_doc.app_ac_pin:
                 jamb_reg_no = app_doc.jamb_reg_no
                 for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
@@ -80,27 +99,11 @@
                     else:
                         pin = p
-            da['app_ac_pin'] = pin
-            da['app_ac_date'] = current
-            app_doc.edit(mapping = da)
-        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
-        not app_doc.app_ac_pin:
-            jamb_reg_no = app_doc.jamb_reg_no
-            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
-                res = context.portal_pins(student=reg_no)
-                if len(res) > 0:
-                    break
-            if len(res) > 0:
-                p = res[0].pin
-                if len(p) > 10:
-                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
-                else:
-                    pin = p
-                da = {}
-                da['app_ac_pin'] = pin
-                app_doc.edit(mapping = da)
-    elif "Manager" in member.getRoles():
-        pass
-    else:
-        to_member_home, to_workspaces = checkRedirect(portal, mtool)
+                    da = {}
+                    da['app_ac_pin'] = pin
+                    app_doc.edit(mapping = da)
+        elif "Manager" in member.getRoles():
+            pass
+        else:
+            to_member_home, to_workspaces = checkRedirect(portal, mtool)
 if (not to_member_home) and (not to_workspaces):
     redirect_to_portal = True
Index: WAeUP_SRP/trunk/skins/waeup_custom/standard_error_message.pt
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_custom/standard_error_message.pt	(revision 1005)
+++ WAeUP_SRP/trunk/skins/waeup_custom/standard_error_message.pt	(revision 1006)
@@ -8,4 +8,9 @@
                         p_props here/portal_properties;
                        ">
+<tal:Anauthorized condition="python:error_type == 'Unauthorized'">
+    <metal:block use-macro="here/error_not_found/macros/not_found" />
+</tal:Anauthorized>
+
+<tal:Anauthorized condition="python:error_type != 'Unauthorized'">
 <metal:body use-macro="here/main_template/macros/master">
 
@@ -53,3 +58,4 @@
 </metal:main>
 </metal:body>
+</tal:Anauthorized>
 </metal:html>
Index: WAeUP_SRP/trunk/skins/waeup_pins/search_pins.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_pins/search_pins.py	(revision 1005)
+++ WAeUP_SRP/trunk/skins/waeup_pins/search_pins.py	(revision 1006)
@@ -12,4 +12,5 @@
 list Students for ClearanceOfficers
 """
+
 request = REQUEST
 wftool = context.portal_workflow
@@ -47,6 +48,6 @@
 
 if what == 'student':
-    items_2 = context.portal_pins(student = term)
     items_1 = context.portal_pins(student = term.upper())
+    items_2 = context.portal_pins(student = term.lower())
     items = items_1 + items_2
 elif what == 'pin':
@@ -55,4 +56,6 @@
     items = []
 l = []
+students_url = "%s/%s" % (context.portal_url(),'students')
+pins = []
 for i in items:
     item = {}
@@ -61,17 +64,22 @@
     item['serial'] = i.serial
     item['pin'] = i.pin
+    if i.pin in pins:
+        continue
+    pins.append(i.pins)
     if len(sno)==10:
-    #if bd.prefix == "APP":
         #res = context.portal_catalog(SearchableText=sno,portal_type='StudentApplication')
         res = context.students_catalog(jamb_reg_no=sno.upper())
         if len(res) > 0:
-            item['student_url'] = "%s/%s" % (context.portal_url(),res[0].id)
+            item['student_url'] = "%s/campus/students/%s" % (context.portal_url(),res[0].id)
             item['student_id'] = res[0].id
         else:
             item['student_url'] = None
             item['student_id'] = ''
+    elif sno:
+        item['student_url'] = '%s/campus/students/%s' % (students_url,item['student'])
+        item['student_id'] = student
     else:
-        item['student_url'] = '%s/%s' % (students_url,item['student'])
-        item['student_id'] = student
+        item['student_url'] = ''
+        item['student_id'] = "not used"
     l.append(item)
     
Index: WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py	(revision 1005)
+++ WAeUP_SRP/trunk/skins/waeup_student/getStudentInfo.py	(revision 1006)
@@ -20,22 +20,39 @@
 path_info = request.get('PATH_INFO').split('/')
 
+import logging
+logger = logging.getLogger('getStudentInfo')
+
 info = {}
 member_id = str(member)
+#from Products.zdb import set_trace
+#set_trace()
+student_id = None
 if student is None:
-    if mtool.isAnonymousUser():
-        return None
-    elif not context.isStudent() and 'students' in path_info:
-        student_id = path_info[path_info.index('students')+1]
-    else:
+    while True:
+        if mtool.isAnonymousUser():
+            return None
+        try:
+            requested_id = path_info[path_info.index('students')+1]
+        except ValueError:
+            student_id = member_id
+            break
+        if not context.isStudent() and 'students' in path_info:
+            student_id = requested_id
+            break
+        if member_id != requested_id:
+            logger.info("Student %s tried to access %s" % (member_id,requested_id))
+            student_id = member_id
+            #mtool.assertViewable(context)
+            break
         student_id = member_id
+        break
 else:
     student_id = student.getId()
+
 roles = member.getRoles()
 student_path = "%s/campus/students/%s" % (context.portal_url.getPortalPath(),student_id)
 student = context.restrictedTraverse(student_path,default=None)
-#from Products.zdb import set_trace
-#set_trace()
 
-if student is None or student.portal_type != 'Student':
+if student is None or student.portal_type != "Student":
     return None
 ##res = context.portal_catalog(id = student_id,portal_type='Student')
Index: WAeUP_SRP/trunk/skins/waeup_student/search_students.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_student/search_students.py	(revision 1005)
+++ WAeUP_SRP/trunk/skins/waeup_student/search_students.py	(revision 1006)
@@ -49,6 +49,10 @@
 path_info = request.get('PATH_INFO').split('/')
 validate = request.has_key("cpsdocument_edit_button")
+
+state = "all"
+if "ClearanceOfficers" in member.getGroups():
+    state = "clearance_requested"
 default = {'search_mode': 'name',
-        'review_state': 'all',
+        'review_state': state,
         'search_string': ''
         }
@@ -152,23 +156,24 @@
 if items:
     for item in items:
-        #if context.isClearanceOfficer(info):
+        stcat = context.students_catalog
+        record = stcat(id = item)[0]
         info = {}
+        for field in stcat.schema() + stcat.indexes():
+            info[field] = getattr(record, field)
         if "ClearanceOfficers" in member.getGroups():
             co_view = True
-##            droles = member.getRolesInContext(item)
-##            if "ClearanceOfficer" in droles:
-##                info = context.getStudentInfo(item)
-##                students.append(info)
+            res = context.portal_catalog(portal_type='Student', id = item)
+            if len(res) != 1:
+                continue
+            droles = member.getRolesInContext(res[0].getObject())
+            info['review_state'] = res[0].review_state
+            if "ClearanceOfficer" in droles:
+                students.append(info)
         else:
-            #info = context.getStudentInfo(item)
-            info = context.students_catalog(id = item)
             if len(info) == 1:
-                students.append(info[0])
+                students.append(info)
 
     return context.search_students_form(rendered = rend,
                              psm = "",
-                             #psm = "%d,%d matching Students found QS = %s" %\
-                             #       (len(review_set),len(search_set),query_step),
-                             #psm = "%d found QS = %s items: %s" % (len(items),query_step,items),
                              students = students,
                              allowed = True,
@@ -177,5 +182,4 @@
 return context.search_students_form(rendered = rend,
                              psm = "No student found!",
-                             #psm = """Step: %s found: %s Your search for "%s" in %s with state %s failed.<br\>%s""" % (query_step,len(items),st,what,state,bools),
                              students = students,
                              allowed = True,
Index: WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt	(revision 1005)
+++ WAeUP_SRP/trunk/skins/waeup_student/search_students_form.pt	(revision 1006)
@@ -63,5 +63,5 @@
                 <td tal:condition="options/co_view|nothing">
                        <a href="id" 
-                          tal:attributes="href string:${student/student/clearance/absolute_url}/external_clearance_edit_form"
+                          tal:attributes="href string:${context/portal_url}/campus/students/${student/id}/clearance/external_clearance_edit_form"
                           target="edit"
                           onclick="javascript:window.open('','edit','width=600, height=700, directories=no, toolbar=no, location=no, menubar=no, scrollbars=yes, status=no, resizable=no, dependent=no')"
