From 82f3951f0f0909a7043d7c24304b23fe50553c56 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Fri, 20 Oct 2006 00:37:58 +0000 Subject: [PATCH] more compatibility functions --- PLC/Methods/AdmDeleteAllPersonKeys.py | 55 +++++++++++++++++++++++++++ PLC/Methods/AdmDeletePersonKeys.py | 54 ++++++++++++++++++++++++++ PLC/Methods/AdmGetAllKeyTypes.py | 8 ++++ PLC/Methods/AdmGetPersonKeys.py | 34 +++++++++++++++++ PLC/Methods/AdmGetSitePIs.py | 44 +++++++++++++++++++++ 5 files changed, 195 insertions(+) create mode 100644 PLC/Methods/AdmDeleteAllPersonKeys.py create mode 100644 PLC/Methods/AdmDeletePersonKeys.py create mode 100644 PLC/Methods/AdmGetAllKeyTypes.py create mode 100644 PLC/Methods/AdmGetPersonKeys.py create mode 100644 PLC/Methods/AdmGetSitePIs.py diff --git a/PLC/Methods/AdmDeleteAllPersonKeys.py b/PLC/Methods/AdmDeleteAllPersonKeys.py new file mode 100644 index 00000000..374bbb96 --- /dev/null +++ b/PLC/Methods/AdmDeleteAllPersonKeys.py @@ -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 index 00000000..7a72e6c8 --- /dev/null +++ b/PLC/Methods/AdmDeletePersonKeys.py @@ -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 index 00000000..4383f847 --- /dev/null +++ b/PLC/Methods/AdmGetAllKeyTypes.py @@ -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 index 00000000..965ee55d --- /dev/null +++ b/PLC/Methods/AdmGetPersonKeys.py @@ -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 index 00000000..7bf8fd80 --- /dev/null +++ b/PLC/Methods/AdmGetSitePIs.py @@ -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] -- 2.47.0