-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
+from PLC.Methods.AddPerson import AddPerson
-class AdmAddPerson(Method):
+class AdmAddPerson(AddPerson):
"""
- Adds a new account. Any fields specified in optional_vals are
- used, otherwise defaults are used.
-
- Accounts are disabled by default. To enable an account, use
- AdmSetPersonEnabled() or AdmUpdatePerson().
-
- Returns the new person_id (> 0) if successful, faults otherwise.
+ Deprecated. See AddPerson.
"""
- roles = ['admin', 'pi']
-
- can_update = lambda (field, value): field in \
- ['title', 'email', 'password', 'phone', 'url', 'bio']
- update_fields = dict(filter(can_update, Person.fields.items()))
-
- accepts = [
- PasswordAuth(),
- Person.fields['first_name'],
- Person.fields['last_name'],
- update_fields
- ]
-
- returns = Parameter(int, 'New person_id (> 0) if successful')
-
- def call(self, auth, first_name, last_name, optional_vals = {}):
- if filter(lambda field: field not in self.update_fields, optional_vals):
- raise PLCInvalidArgument, "Invalid fields specified"
-
- person = Person(self.api, optional_vals)
- person['first_name'] = first_name
- person['last_name'] = last_name
- person['enabled'] = False
- person.sync()
-
- return person['person_id']
+ status = "deprecated"
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Keys import Key, Keys
+from PLC.Persons import Person, Persons
+from PLC.Auth import PasswordAuth
+
+class AdmAddPersonKey(AddPersonKey):
+ """
+ Deprecated. See AddPersonKey. Keys can no longer be marked as
+ primary, i.e. the is_primary argument does nothing.
+ """
+
+ status = "deprecated"
+
+ accepts = [
+ PasswordAuth(),
+ Mixed(Person.fields['person_id'],
+ Person.fields['email']),
+ Key.fields['key_type'],
+ Key.fields['key'],
+ Parameter(int, "Make this key the primary key")
+ ]
+
+ def call(self, auth, person_id_or_email, key_type, key_value, is_primary):
+ return AddPersonKey.call(self, auth, person_id_or_email, key_type, key_value)
-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
+from PLC.Methods.AddPersonToSite import AddPersonToSite
-class AdmAddPersonToSite(Method):
+class AdmAddPersonToSite(AddPersonToSite):
"""
- Adds the specified person to the specified site. If the person is
- already a member of the site, no errors are returned. Does not
- change the person's primary site.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See AddPersonToSite.
"""
- 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'] not in person['site_ids']:
- site.add_person(person)
-
- return 1
+ status = "deprecated"
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
+from PLC.Methods.DeletePerson import DeletePerson
-class AdmDeletePerson(Method):
+class AdmDeletePerson(DeletePerson):
"""
- Mark an existing account as deleted.
-
- Users and techs can only delete themselves. PIs can only delete
- themselves and other non-PIs at their sites. Admins can delete
- anyone.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See DeletePerson.
"""
- roles = ['admin', 'pi', 'user', 'tech']
-
- 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]
-
- # Authenticated function
- assert self.caller is not None
-
- # Check if we can update this account
- if not self.caller.can_update(person):
- raise PLCPermissionDenied, "Not allowed to delete specified account"
-
- person.delete()
-
- return 1
+ status = "deprecated"
class AdmGetPersonRoles(Method):
"""
+ Deprecated. See GetPersons.
+
Return the roles that the specified person has as a struct:
{'10': 'admin', '30': 'user', '20': 'pi', '40': 'tech'}
identifiers.
"""
+ status = "deprecated"
+
roles = ['admin', 'pi', 'user', 'tech']
accepts = [
returns = dict
- # Stupid return type, and can get now roles through
- # AdmGetPersons().
- status = "useless"
-
def call(self, auth, person_id_or_email):
# Get account information
persons = Persons(self.api, [person_id_or_email])
class AdmGetPersonSites(Method):
"""
+ Deprecated. See GetPersons.
+
Returns the sites that the specified person is associated with as
an array of site identifiers.
themselves and others at their sites.
"""
- roles = ['admin', 'pi', 'user', 'tech']
-
accepts = [
PasswordAuth(),
Mixed(Person.fields['person_id'],
Person.fields['email'])
]
- returns = [Site.fields['site_id']]
+ returns = Person.fields['site_ids']
def call(self, auth, person_id_or_email):
# Get account information
-import os
+from PLC.Methods.GetPersons import GetPersons
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
-
-class AdmGetPersons(Method):
+class AdmGetPersons(GetPersons):
"""
- Return an array of dictionaries containing details about the
- specified accounts.
-
- Admins may retrieve details about all accounts by not specifying
- person_id_or_email_list or by specifying an empty list. Users and
- techs may only retrieve details about themselves. PIs may retrieve
- details about themselves and others at their sites.
-
- If return_fields is specified, only the specified fields will be
- returned, if set. Otherwise, the default set of fields returned is:
-
+ Deprecated. See GetPersons.
"""
- roles = ['admin', 'pi', 'user', 'tech']
-
- accepts = [
- PasswordAuth(),
- [Mixed(Person.fields['person_id'],
- Person.fields['email'])],
- Parameter([str], 'List of fields to return')
- ]
-
- # Filter out password field
- can_return = lambda (field, value): field not in ['password']
- return_fields = dict(filter(can_return, Person.fields.items()))
- returns = [return_fields]
-
- def __init__(self, *args, **kwds):
- Method.__init__(self, *args, **kwds)
- # Update documentation with list of default fields returned
- self.__doc__ += os.linesep.join(self.return_fields.keys())
-
- def call(self, auth, person_id_or_email_list = None, return_fields = None):
- # Make sure that only valid fields are specified
- if return_fields is None:
- return_fields = self.return_fields
- elif filter(lambda field: field not in self.return_fields, return_fields):
- raise PLCInvalidArgument, "Invalid return field specified"
-
- # Authenticated function
- assert self.caller is not None
-
- # Only admins can not specify person_id_or_email_list or
- # specify an empty list.
- if not person_id_or_email_list and 'admin' not in self.caller['roles']:
- raise PLCInvalidArgument, "List of accounts to retrieve not specified"
-
- # Get account information
- persons = Persons(self.api, person_id_or_email_list)
-
- # Filter out accounts that are not viewable and turn into list
- persons = filter(self.caller.can_view, persons.values())
-
- # Filter out undesired or None fields (XML-RPC cannot marshal
- # None) and turn each person into a real dict.
- valid_return_fields_only = lambda (key, value): \
- key in return_fields and value is not None
- persons = [dict(filter(valid_return_fields_only, person.items())) \
- for person in persons]
-
- return persons
+ status = "deprecated"
from PLC.Parameter import Parameter, Mixed
from PLC.PCUs import PCU, PCUs
from PLC.Auth import PasswordAuth
-from PLC.Methods.GetPCUs import GetPCUs
-class AdmGetPowerControlUnitNodes(GetPCUs):
+class AdmGetPowerControlUnitNodes(Method):
"""
Deprecated. See GetPCUs.
'port_number': Parameter(int, "Port number")}]
def call(self, auth, pcu_id):
- pcus = GetPCUs.call(self, auth, [pcu_id])
+ pcus = PCUs(self.api, [pcu_id]).values()
if not pcus:
raise PLCInvalidArgument, "No such PCU"
pcu = pcus[0]
+ if 'admin' not in self.caller['roles']:
+ if pcu['site_id'] not in self.caller['site_ids']:
+ raise PLCPermissionDenied, "Not allowed to view that PCU"
+
return [{'node_id': node_id, 'port_number': port} \
for (node_id, port) in zip(pcu['node_ids'], pcu['ports'])]
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
-from PLC.Roles import Roles
+from PLC.Methods.AddRoleToPerson import AddRoleToPerson
-class AdmGrantRoleToPerson(Method):
+class AdmGrantRoleToPerson(AddRoleToPerson):
"""
- Grants the specified role to the person.
-
- PIs can only grant the tech and user roles to users and techs at
- their sites. Admins can grant any role to any user.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See AddRoleToPerson.
"""
- roles = ['admin', 'pi']
-
- accepts = [
- PasswordAuth(),
- Mixed(Person.fields['person_id'],
- Person.fields['email']),
- Mixed(Parameter(int, "Role identifier"),
- Parameter(str, "Role name"))
- ]
-
- returns = Parameter(int, '1 if successful')
-
- def call(self, auth, person_id_or_email, role_id_or_name):
- # Get all roles
- roles = {}
- for role_id, role in Roles(self.api).iteritems():
- roles[role_id] = role['name']
- roles[role['name']] = role_id
-
- if role_id_or_name not in roles:
- raise PLCInvalidArgument, "Invalid role identifier or name"
-
- if isinstance(role_id_or_name, int):
- role_id = role_id_or_name
- else:
- role_id = roles[role_id_or_name]
-
- # Get account information
- persons = Persons(self.api, [person_id_or_email])
- if not persons:
- raise PLCInvalidArgument, "No such account"
-
- person = persons.values()[0]
-
- # Authenticated function
- assert self.caller is not None
-
- # Check if we can update this account
- if not self.caller.can_update(person):
- raise PLCPermissionDenied, "Not allowed to update specified account"
-
- # Can only grant lesser (higher) roles to others
- if 'admin' not in self.caller['roles'] and \
- role_id <= min(self.caller['role_ids']):
- raise PLCInvalidArgument, "Not allowed to grant that role"
-
- if role_id not in person['role_ids']:
- person.add_role(role_id)
-
- return 1
+ status = "deprecated"
-from types import StringTypes
-
from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
class AdmIsPersonInRole(Method):
"""
+ Deprecated. Functionality can be implemented with GetPersons.
+
Returns 1 if the specified account has the specified role, 0
otherwise. This function differs from AdmGetPersonRoles() in that
any authorized user can call it. It is currently restricted to
verifying PI roles.
"""
+ status = "deprecated"
+
roles = ['admin', 'pi', 'user', 'tech']
accepts = [
returns = Parameter(int, "1 if account has role, 0 otherwise")
- status = "useless"
-
def call(self, auth, person_id_or_email, role_id_or_name):
# This is a totally fucked up function. I have no idea why it
# exists or who calls it, but here is how it is supposed to
-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
+from PLC.Methods.DeletePersonFromSite import DeletePersonFromSite
-class AdmRemovePersonFromSite(Method):
+class AdmRemovePersonFromSite(DeletePersonFromSite):
"""
- 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.
+ Deprecated. See DeletePersonFromSite.
"""
- 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
+ status = "deprecated"
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
-from PLC.Roles import Roles
+from PLC.Methods.DeleteRoleFromPerson import DeleteRoleFromPerson
-class AdmRevokeRoleFromPerson(Method):
+class AdmRevokeRoleFromPerson(DeleteRoleFromPerson):
"""
- Revokes the specified role from the person.
-
- PIs can only revoke the tech and user roles from users and techs
- at their sites. Admins can revoke any role from any user.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See DeleteRoleFromPerson.
"""
- roles = ['admin', 'pi']
-
- accepts = [
- PasswordAuth(),
- Mixed(Person.fields['person_id'],
- Person.fields['email']),
- Mixed(Parameter(int, "Role identifier"),
- Parameter(str, "Role name"))
- ]
-
- returns = Parameter(int, '1 if successful')
-
- def call(self, auth, person_id_or_email, role_id_or_name):
- # Get all roles
- roles = {}
- for role_id, role in Roles(self.api).iteritems():
- roles[role_id] = role['name']
- roles[role['name']] = role_id
-
- if role_id_or_name not in roles:
- raise PLCInvalidArgument, "Invalid role identifier or name"
-
- if isinstance(role_id_or_name, int):
- role_id = role_id_or_name
- else:
- role_id = roles[role_id_or_name]
-
- # Get account information
- persons = Persons(self.api, [person_id_or_email])
- if not persons:
- raise PLCInvalidArgument, "No such account"
-
- person = persons.values()[0]
-
- # Authenticated function
- assert self.caller is not None
-
- # Check if we can update this account
- if not self.caller.can_update(person):
- raise PLCPermissionDenied, "Not allowed to update specified account"
-
- # Can only revoke lesser (higher) roles from others
- if 'admin' not in self.caller['roles'] and \
- role_id <= min(self.caller['role_ids']):
- raise PLCPermissionDenied, "Not allowed to revoke that role"
-
- if role_id in person['role_ids']:
- person.remove_role(role_id)
-
- return 1
+ status = "deprecated"
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
+from PLC.Methods.UpdatePerson import UpdatePerson
-class AdmSetPersonEnabled(Method):
+class AdmSetPersonEnabled(UpdatePerson):
"""
- Enables or disables a person.
-
- Users and techs can only update themselves. PIs can only update
- themselves and other non-PIs at their sites. Admins can update
- anyone.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See UpdatePerson.
"""
- roles = ['admin', 'pi']
+ status = "deprecated"
accepts = [
PasswordAuth(),
Person.fields['enabled']
]
- returns = Parameter(int, '1 if successful')
-
def call(self, auth, person_id_or_email, enabled):
- # Get account information
- persons = Persons(self.api, [person_id_or_email])
- if not persons:
- raise PLCInvalidArgument, "No such account"
-
- person = persons.values()[0]
-
- # Authenticated function
- assert self.caller is not None
-
- # Check if we can update this account
- if not self.caller.can_update(person):
- raise PLCPermissionDenied, "Not allowed to enable specified account"
-
- person['enabled'] = enabled
- person.sync()
-
- return 1
+ return UpdatePerson.call(self, auth, person_id_or_email, {'enabled': enabled})
-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
+from PLC.Methods.SetPersonPrimarySite import SetPersonPrimarySite
-class AdmSetPersonPrimarySite(Method):
+class AdmSetPersonPrimarySite(SetPersonPrimarySite):
"""
- Makes the specified site the person's primary site. The person
- must already be a member of the site.
-
- Admins may update anyone. All others may only update themselves.
+ Deprecated. See SetPersonPrimarySite.
"""
- roles = ['admin', 'pi', 'user', 'tech']
-
- 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]
-
- # Authenticated function
- assert self.caller is not None
-
- # Non-admins can only update their own primary site
- if 'admin' not in self.caller['roles'] and \
- self.caller['person_id'] != person['person_id']:
- raise PLCPermissionDenied, "Not allowed to update specified account"
-
- # 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'] not in person['site_ids']:
- raise PLCInvalidArgument, "Not a member of the specified site"
-
- person.set_primary_site(site)
-
- return 1
+ status = "deprecated"
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
+from PLC.Methods.UpdatePerson import UpdatePerson
-class AdmUpdatePerson(Method):
+class AdmUpdatePerson(UpdatePerson):
"""
- Updates a person. Only the fields specified in update_fields are
- updated, all other fields are left untouched.
-
- To remove a value without setting a new one in its place (for
- example, to remove an address from the person), specify -1 for int
- and double fields and 'null' for string fields. first_name and
- last_name cannot be unset.
-
- Users and techs can only update themselves. PIs can only update
- themselves and other non-PIs at their sites.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See UpdatePerson.
"""
- roles = ['admin', 'pi', 'user', 'tech']
-
- can_update = lambda (field, value): field in \
- ['first_name', 'last_name', 'title', 'email',
- 'password', 'phone', 'url', 'bio', 'accepted_aup']
- update_fields = dict(filter(can_update, Person.fields.items()))
-
- accepts = [
- PasswordAuth(),
- Mixed(Person.fields['person_id'],
- Person.fields['email']),
- update_fields
- ]
-
- returns = Parameter(int, '1 if successful')
-
- def call(self, auth, person_id_or_email, update_fields):
- if filter(lambda field: field not in self.update_fields, update_fields):
- raise PLCInvalidArgument, "Invalid field specified"
-
- # XML-RPC cannot marshal None, so we need special values to
- # represent "unset".
- for key, value in update_fields.iteritems():
- if value == -1 or value == "null":
- if key in ['first_name', 'last_name']:
- raise PLCInvalidArgument, "first_name and last_name cannot be unset"
- update_fields[key] = None
-
- # Get account information
- persons = Persons(self.api, [person_id_or_email])
- if not persons:
- raise PLCInvalidArgument, "No such account"
-
- person = persons.values()[0]
-
- # Authenticated function
- assert self.caller is not None
-
- # Check if we can update this account
- if not self.caller.can_update(person):
- raise PLCPermissionDenied, "Not allowed to update specified account"
-
- person.update(update_fields)
- person.sync()
-
- return 1
+ status = "deprecated"
def call(self, auth, person_id_or_email, person_fields):
person_fields = dict(filter(can_update, person_fields.items()))
- # Remove admin only fields
- if 'admin' not in self.caller['roles']:
- for key in ['enabled']:
- del person_fields[key]
-
# Get account information
persons = Persons(self.api, [person_id_or_email])
if not persons: