655ba7036cf3dd41ed1a46f694297c9755c16c8d
[sfa.git] / archive / changes / AddPerson.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Persons import Person, Persons
5 from PLC.Auth import Auth
6 import uuid ##################################soners
7
8 can_update = lambda (field, value): field in \
9              ['first_name', 'last_name', 'title',
10               'email', 'password', 'phone', 'url', 'bio']
11
12 class AddPerson(Method):
13     """
14     Adds a new account. Any fields specified in person_fields are
15     used, otherwise defaults are used.
16
17     Accounts are disabled by default. To enable an account, use
18     UpdatePerson().
19
20     Returns the new person_id (> 0) if successful, faults otherwise.
21     """
22
23     roles = ['admin', 'pi']
24
25     person_fields = dict(filter(can_update, Person.fields.items()))
26
27     accepts = [
28         Auth(),
29         person_fields
30         ]
31
32     returns = Parameter(int, 'New person_id (> 0) if successful')
33
34     def call(self, auth, person_fields):
35         person_fields = dict(filter(can_update, person_fields.items()))
36         person_fields['uuid'] = str(uuid.uuid4().int)###############################soners
37         person_fields['enabled'] = False
38         person = Person(self.api, person_fields)
39         person.sync()
40
41         # Logging variables
42         self.event_objects = {'Person': [person['person_id']]}
43         self.message = 'Person %d added' % person['person_id']  
44
45         return person['person_id']