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