3da92aabd5cd6eacf02e07e314d3941fe49db1da
[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     event_type = 'Add'
25     object_type = 'Role'
26     object_ids = []
27
28     def call(self, auth, role_id, name):
29         role = Role(self.api)
30         role['role_id'] = role_id
31         role['name'] = name
32         role.sync(insert = True)
33         self.object_ids = [role['role_id']]
34
35         return 1