remove simplejson dependency
[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
25     def call(self, auth, role_id, name):
26         role = Role(self.api)
27         role['role_id'] = role_id
28         role['name'] = name
29         role.sync(insert = True)
30         self.event_objects = {'Role': [role['role_id']]}
31
32         return 1