Setting tag plcapi-5.4-2
[plcapi.git] / PLC / Methods / GetSliceTags.py
index 579d9c5..c6db287 100644 (file)
@@ -1,4 +1,3 @@
-# $Id$
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
@@ -6,6 +5,7 @@ from PLC.Filter import Filter
 from PLC.SliceTags import SliceTag, SliceTags
 from PLC.Persons import Person, Persons
 from PLC.Sites import Site, Sites
+from PLC.Nodes import Nodes
 from PLC.Slices import Slice, Slices
 from PLC.Auth import Auth
 
@@ -35,11 +35,11 @@ class GetSliceTags(Method):
         ]
 
     returns = [SliceTag.fields]
-    
+
 
     def call(self, auth, slice_tag_filter = None, return_fields = None):
-       # If we are not admin, make sure to only return our own slice
-       # and sliver attributes.
+        # If we are not admin, make sure to only return our own slice
+        # and sliver attributes.
         if isinstance(self.caller, Person) and \
            'admin' not in self.caller['roles']:
             # Get slices that we are able to view
@@ -48,6 +48,11 @@ class GetSliceTags(Method):
                 sites = Sites(self.api, self.caller['site_ids'])
                 for site in sites:
                     valid_slice_ids += site['slice_ids']
+            # techs can view all slices on the nodes at their site
+            if 'tech' in self.caller['roles'] and self.caller['site_ids']:
+                nodes = Nodes(self.api, {'site_id': self.caller['site_ids']}, ['site_id', 'slice_ids'])
+                for node in nodes:
+                    valid_slice_ids.extend(node['slice_ids'])
 
             if not valid_slice_ids:
                 return []
@@ -83,7 +88,7 @@ class GetSliceTags(Method):
         # Remove slice_tag_id if not specified
         if added_fields:
             for slice_tag in slice_tags:
-               if 'slice_tag_id' in slice_tag:
-                   del slice_tag['slice_tag_id']
+                if 'slice_tag_id' in slice_tag:
+                    del slice_tag['slice_tag_id']
 
         return slice_tags