- define/modify logging variables
[plcapi.git] / PLC / Methods / DeletePCU.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.PCUs import PCU, PCUs
5 from PLC.Auth import Auth
6
7 class DeletePCU(Method):
8     """
9     Deletes a PCU.
10
11     Non-admins may only delete PCUs at their sites.
12
13     Returns 1 if successful, faults otherwise.
14     """
15
16     roles = ['admin', 'pi', 'tech']
17
18     accepts = [
19         Auth(),
20         PCU.fields['pcu_id'],
21         ]
22
23     returns = Parameter(int, '1 if successful')
24
25     event_type = 'Delete'
26     object_type = 'PCU'
27
28     def call(self, auth, pcu_id):
29         # Get associated PCU details
30         pcus = PCUs(self.api, [pcu_id])
31         if not pcus:
32             raise PLCInvalidArgument, "No such PCU"
33         pcu = pcus[0]
34
35         if 'admin' not in self.caller['roles']:
36             if pcu['site_id'] not in self.caller['site_ids']:
37                 raise PLCPermissionDenied, "Not allowed to update that PCU"
38
39         pcu.delete()
40         self.object_ids = [pcu['pcu_id']]
41
42         return 1