svn keywords
[plcapi.git] / PLC / Methods / AddRole.py
1 # $Id$
2 # $URL$
3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Roles import Role, Roles
7 from PLC.Auth import Auth
8
9 class AddRole(Method):
10     """
11     Adds a new role.
12
13     Returns 1 if successful, faults otherwise.
14     """
15
16     roles = ['admin']
17
18     accepts = [
19         Auth(),
20         Role.fields['role_id'],
21         Role.fields['name']
22         ]
23
24     returns = Parameter(int, '1 if successful')
25
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.event_objects = {'Role': [role['role_id']]}
33
34         return 1