- Renamed (changed Remove to Delete)
authorTony Mack <tmack@cs.princeton.edu>
Fri, 6 Oct 2006 20:02:16 +0000 (20:02 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Fri, 6 Oct 2006 20:02:16 +0000 (20:02 +0000)
PLC/Methods/DeletePersonFromSite.py [new file with mode: 0644]
PLC/Methods/DeleteRoleFromPerson.py [moved from PLC/Methods/RemoveRoleFromPerson.py with 95% similarity]

diff --git a/PLC/Methods/DeletePersonFromSite.py b/PLC/Methods/DeletePersonFromSite.py
new file mode 100644 (file)
index 0000000..b7be3ac
--- /dev/null
@@ -0,0 +1,47 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Persons import Person, Persons
+from PLC.Sites import Site, Sites
+from PLC.Auth import PasswordAuth
+
+class DeletePersonFromSite(Method):
+    """
+    Removes the specified person from the specified site. If the
+    person is not a member of the specified site, no error is
+    returned.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin']
+
+    accepts = [
+        PasswordAuth(),
+        Mixed(Person.fields['person_id'],
+              Person.fields['email']),
+        Mixed(Site.fields['site_id'],
+              Site.fields['login_base'])
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    def call(self, auth, person_id_or_email, site_id_or_login_base):
+        # Get account information
+        persons = Persons(self.api, [person_id_or_email])
+        if not persons:
+            raise PLCInvalidArgument, "No such account"
+
+        person = persons.values()[0]
+
+        # Get site information
+        sites = Sites(self.api, [site_id_or_login_base])
+        if not sites:
+            raise PLCInvalidArgument, "No such site"
+
+        site = sites.values()[0]
+
+        if site['site_id'] in person['site_ids']:
+            site.remove_person(person)
+
+        return 1
similarity index 95%
rename from PLC/Methods/RemoveRoleFromPerson.py
rename to PLC/Methods/DeleteRoleFromPerson.py
index a32f465..132eec4 100644 (file)
@@ -5,9 +5,9 @@ from PLC.Persons import Person, Persons
 from PLC.Auth import PasswordAuth
 from PLC.Roles import Roles
 
-class RemoveRoleFromPerson(Method):
+class DeleteRoleFromPerson(Method):
     """
-    Revokes the specified role from the person.
+    Deletes the specified role from the person.
     
     PIs can only revoke the tech and user roles from users and techs
     at their sites. ins can revoke any role from any user.