c90c4a2fe8adf71b924c1ba02879619221887c2e
[plcapi.git] / PLC / Methods / AddRole.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Roles import Role, Roles
5 from PLC.Auth import Auth
6
7 class AddRole(Method):
8     """
9     Adds a new role.
10
11     Returns 1 if successful, faults otherwise.
12     """
13
14     roles = ['admin']
15
16     accepts = [
17         Auth(),
18         Role.fields['role_id'],
19         Role.fields['name']
20         ]
21
22     returns = Parameter(int, '1 if successful')
23
24     event_type = 'Add'
25     object_type = 'Role'
26
27     def call(self, auth, role_id, name):
28         role = Role(self.api)
29         role['role_id'] = role_id
30         role['name'] = name
31         role.sync(insert = True)
32         self.object_ids = [role['role_id']]
33
34         return 1