more compatibility functions
authorMark Huang <mlhuang@cs.princeton.edu>
Fri, 20 Oct 2006 00:37:58 +0000 (00:37 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Fri, 20 Oct 2006 00:37:58 +0000 (00:37 +0000)
PLC/Methods/AdmDeleteAllPersonKeys.py [new file with mode: 0644]
PLC/Methods/AdmDeletePersonKeys.py [new file with mode: 0644]
PLC/Methods/AdmGetAllKeyTypes.py [new file with mode: 0644]
PLC/Methods/AdmGetPersonKeys.py [new file with mode: 0644]
PLC/Methods/AdmGetSitePIs.py [new file with mode: 0644]

diff --git a/PLC/Methods/AdmDeleteAllPersonKeys.py b/PLC/Methods/AdmDeleteAllPersonKeys.py
new file mode 100644 (file)
index 0000000..374bbb9
--- /dev/null
@@ -0,0 +1,55 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Persons import Person, Persons
+from PLC.Keys import Key, Keys
+from PLC.Auth import PasswordAuth
+
+class AdmDeleteAllPersonKeys(Method):
+    """
+    Deprecated. Functionality can be implemented with GetPersons and
+    DeleteKey.
+
+    Deletes all of the keys associated with an account. Non-admins may
+    only delete their own keys.
+
+    Non-admins may only delete their own keys.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    status = "deprecated"
+
+    roles = ['admin', 'pi', 'tech', 'user']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Person.fields['person_id'],
+              Person.fields['email'])
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    def call(self, auth, person_id_or_email):
+        # Get account information
+        persons = Persons(self.api, [person_id_or_email])
+        if not persons:
+            raise PLCInvalidArgument, "No such account"
+
+        person = persons.values()[0]
+
+        if 'admin' not in self.caller['roles']:
+            if self.caller['person_id'] != person['person_id']:
+                raise PLCPermissionDenied, "Not allowed to update specified account"
+
+        key_ids = person['key_ids']
+        if not key_ids:
+            return 1
+
+        # Get associated key details
+        keys = Keys(self.api, key_ids).values()
+
+        for key in keys:
+            key.delete()
+
+        return 1
diff --git a/PLC/Methods/AdmDeletePersonKeys.py b/PLC/Methods/AdmDeletePersonKeys.py
new file mode 100644 (file)
index 0000000..7a72e6c
--- /dev/null
@@ -0,0 +1,54 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Persons import Person, Persons
+from PLC.Keys import Key, Keys
+from PLC.Auth import PasswordAuth
+
+class AdmDeletePersonKeys(Method):
+    """
+    Deprecated. Functionality can be implemented with GetPersons and
+    DeleteKey.
+
+    Deletes the specified keys. Non-admins may only delete their own
+    keys.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    status = "deprecated"
+
+    roles = ['admin', 'pi', 'tech', 'user']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Person.fields['person_id'],
+              Person.fields['email']),
+        [Key.fields['key_id']]
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    def call(self, auth, person_id_or_email, key_ids):
+        # Get account information
+        persons = Persons(self.api, [person_id_or_email])
+        if not persons:
+            raise PLCInvalidArgument, "No such account"
+
+        person = persons.values()[0]
+
+        if 'admin' not in self.caller['roles']:
+            if self.caller['person_id'] != person['person_id']:
+                raise PLCPermissionDenied, "Not allowed to update specified account"
+
+        key_ids = set(key_ids).intersection(person['key_ids'])
+        if not key_ids:
+            return 1
+
+        # Get associated key details
+        keys = Keys(self.api, key_ids).values()
+
+        for key in keys:
+            key.delete()
+
+        return 1
diff --git a/PLC/Methods/AdmGetAllKeyTypes.py b/PLC/Methods/AdmGetAllKeyTypes.py
new file mode 100644 (file)
index 0000000..4383f84
--- /dev/null
@@ -0,0 +1,8 @@
+from PLC.Methods.GetKeyTypes import GetKeyTypes
+
+class AdmGetAllKeyTypes(GetKeyTypes):
+    """
+    Deprecated. See GetKeyTypes.
+    """
+
+    status = "deprecated"
diff --git a/PLC/Methods/AdmGetPersonKeys.py b/PLC/Methods/AdmGetPersonKeys.py
new file mode 100644 (file)
index 0000000..965ee55
--- /dev/null
@@ -0,0 +1,34 @@
+from PLC.Methods.GetKeys import GetKeys
+
+class AdmGetPersonKeys(GetKeys):
+    """
+    Deprecated. Functionality can be implemented with GetPersons and
+    GetKeys.
+    """
+
+    status = "deprecated"
+
+    roles = ['admin', 'pi', 'user', 'tech']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Person.fields['person_id'],
+              Person.fields['email']),
+        [Key.fields['key_id']]
+        ]
+
+    returns = [Key.fields]
+
+    def call(auth, person_id_or_email):
+        # Get account information
+        persons = Persons(self.api, [person_id_or_email])
+        if not persons:
+            raise PLCInvalidArgument, "No such account"
+
+        person = persons.values()[0]
+
+        if 'admin' not in self.caller['roles']:
+            if self.caller['person_id'] != person['person_id']:
+                raise PLCPermissionDenied, "Not allowed to view keys for specified account"
+
+        return GetKeys.call(self, auth, person['key_ids'])
diff --git a/PLC/Methods/AdmGetSitePIs.py b/PLC/Methods/AdmGetSitePIs.py
new file mode 100644 (file)
index 0000000..7bf8fd8
--- /dev/null
@@ -0,0 +1,44 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Sites import Site, Sites
+from PLC.Persons import Person, Persons
+from PLC.Auth import PasswordAuth
+
+class AdmGetSitePIs(Method):
+    """
+    Deprecated. Functionality can be implemented with GetSites and
+    GetPersons.
+
+    Return a list of person_ids of the PIs for the site specified.
+    """
+
+    status = "deprecated"
+
+    roles = ['admin']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Site.fields['site_id'],
+              Site.fields['login_base'])
+        ]
+
+    returns = Site.fields['person_ids']
+
+    def call(self, auth, site_id_or_login_base):
+        # Authenticated function
+        assert self.caller is not None
+
+        # Get site information
+       sites = Sites(self.api, [site_id_or_login_base]).values()
+       if not sites:
+            raise PLCInvalidArgument, "No such site"
+
+       site = sites[0]
+
+        persons = Persons(self.api, site['person_ids']).values()
+
+        has_pi_role = lambda person: 'pi' in person['roles']
+        pis = filter(has_pi_role, persons)
+
+       return [pi['person_id'] for pi in pis]