- Initial checkin of new API implementation
authorTony Mack <tmack@cs.princeton.edu>
Thu, 10 May 2007 18:02:32 +0000 (18:02 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Thu, 10 May 2007 18:02:32 +0000 (18:02 +0000)
PLC/Methods/AddSession.py [new file with mode: 0644]
PLC/Methods/GetSessions.py [new file with mode: 0644]

diff --git a/PLC/Methods/AddSession.py b/PLC/Methods/AddSession.py
new file mode 100644 (file)
index 0000000..6f5bc88
--- /dev/null
@@ -0,0 +1,37 @@
+import time
+
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Auth import Auth
+from PLC.Sessions import Session, Sessions
+from PLC.Persons import Person, Persons
+
+class AddSession(Method):
+    """
+    Creates and returns a new session key for the specified user. 
+    (Used for website 'user sudo')
+    """
+
+    roles = ['admin']
+    accepts = [
+       Auth(),
+       Mixed(Person.fields['person_id'],
+              Person.fields['email'])
+       ]
+    returns = Session.fields['session_id']
+    
+
+    def call(self, auth, person_id_or_email):
+        
+       persons = Persons(self.api, [person_id_or_email], ['person_id', 'email'])
+       
+       if not persons:
+           raise PLCInvalidArgument, "No such person"
+       
+       person = persons[0]
+       session = Session(self.api)
+        session['expires'] = int(time.time()) + (24 * 60 * 60)
+       session.sync(commit = False)
+       session.add_person(person, commit = True)
+
+        return session['session_id']
diff --git a/PLC/Methods/GetSessions.py b/PLC/Methods/GetSessions.py
new file mode 100644 (file)
index 0000000..a72553c
--- /dev/null
@@ -0,0 +1,35 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Filter import Filter
+from PLC.Sessions import Session, Sessions
+from PLC.Persons import Person, Persons
+from PLC.Auth import Auth
+
+class GetSessions(Method):
+    """
+    Returns an array of structs containing details about users sessions. If
+    session_filter is specified and is an array of user identifiers or
+    session_keys, or a struct of session attributes, only sessions matching the
+    filter will be returned. If return_fields is specified, only the
+    specified details will be returned.
+
+    
+    """
+
+    roles = ['admin']
+
+    accepts = [
+        Auth(),
+        Mixed([Mixed(Session.fields['person_id'],
+                     Session.fields['session_id'])],
+              Filter(Session.fields))
+        ]
+
+    returns = [Session.fields]
+    
+    def call(self, auth, session_filter = None):
+
+        sessions = Sessions(self.api, session_filter)
+       
+       return sessions