fix roles interface
[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 PasswordAuth
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         PasswordAuth(),
18         Role.fields['role_id'],
19         Role.fields['name']
20         ]
21
22     returns = Parameter(int, '1 if successful')
23
24     def call(self, auth, role_id, name):
25         role = Role(self.api)
26         role['role_id'] = role_id
27         role['name'] = name
28         role.sync(insert = True)
29
30         return 1