1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Auth import Auth
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.TagTypes import TagType, TagTypes
6 from PLC.Roles import Role, Roles
8 class AddRoleToTagType(Method):
10 Add the specified role to the tagtype so that
11 users with that role can tweak the tag.
13 Only admins can call this method
15 Returns 1 if successful, faults otherwise.
22 Mixed(Role.fields['role_id'],
24 Mixed(TagType.fields['tag_type_id'],
25 TagType.fields['tagname']),
28 returns = Parameter(int, '1 if successful')
30 def call(self, auth, role_id_or_name, tag_type_id_or_tagname):
32 roles = Roles(self.api, [role_id_or_name])
34 raise PLCInvalidArgument("Invalid role '%s'" % str(role_id_or_name))
37 # Get subject tag type
38 tag_types = TagTypes(self.api, [tag_type_id_or_tagname])
40 raise PLCInvalidArgument("No such tag type")
41 tag_type = tag_types[0]
43 # Authenticated function
44 assert self.caller is not None
47 if 'admin' not in self.caller['roles']:
48 raise PLCInvalidArgument("Not allowed to grant that role")
50 if role['role_id'] not in tag_type['role_ids']:
51 tag_type.add_role(role)
53 self.event_objects = {'TagType': [tag_type['tag_type_id']],
54 'Role': [role['role_id']]}
55 self.message = "Role %d added to tag_type %d" % \
56 (role['role_id'], tag_type['tag_type_id'])