示例#1
0
 def set_dashboards(self, request):
     dashboard_id = request.data.get("id", None)
     old_dashboard = request.data
     if (not request.user.is_authenticated()):
         raise XOSPermissionDenied("You must be authenticated in order to use this API")
     elif(not dashboard_id):
         raise XOSPermissionDenied("You should provide the dashboard ID")
     else:
         if(old_dashboard['shown'] is True):
             self.add_dashboard_to_user(request.user.id, dashboard_id, old_dashboard['order'])
         else:
             self.remove_dashboard_from_user(request.user.id, dashboard_id)
         return Response(old_dashboard)
示例#2
0
    def get_dashboards(self, request):
        if (not request.user.is_authenticated()):
            raise XOSPermissionDenied("You must be authenticated in order to use this API")
        else:
            user_id = request.user.id
            available_dashboards = DashboardView.objects.filter(enabled=True).exclude(name="Customize")
            user_dashboards = UserDashboardView.objects.filter(user_id=user_id)

            user_dashboards_ids = []
            user_dashboards_order = {}
            for d in user_dashboards:
                user_dashboards_ids.append(d.dashboardView.id)
                user_dashboards_order[d.dashboardView.id] = d.order

            list = []

            for d in available_dashboards:
                dash = {}
                if(d.id in user_dashboards_ids):
                    dash['shown'] = True
                    dash['order'] = user_dashboards_order[d.id]
                else:
                    dash['shown'] = False
                dash['name'] = d.name
                dash['url'] = d.url
                dash['id'] = d.id
                dash['icon'] = d.icon
                list.append(dash)

            return Response(list)
示例#3
0
    def get_queryset(self):
        current_user_can_see = self.request.query_params.get(
            'current_user_can_see', False)
        site_filter = self.request.query_params.get('site', False)

        if (not self.request.user.is_authenticated()):
            raise XOSPermissionDenied(
                "You must be authenticated in order to use this API")

        slices = SlicePlus.select_by_user(self.request.user)

        if (site_filter and not current_user_can_see):
            slices = SlicePlus.objects.filter(site=site_filter)

        # If current_user_can_see is set, then filter the queryset to return
        # only those slices that the user is either creator or has privilege
        # on.
        if (current_user_can_see):
            slice_ids = []
            for slice in slices:
                if (self.request.user == slice.creator) or (len(
                        slice.getSliceInfo(self.request.user)["roles"]) > 0):
                    slice_ids.append(slice.id)
            if (site_filter):
                slices = SlicePlus.objects.filter(id__in=slice_ids,
                                                  site=site_filter)
            else:
                slices = SlicePlus.objects.filter(id__in=slice_ids)

        return slices
示例#4
0
    def get_queryset(self):
        name = self.request.query_params.get('name', False)

        if (not self.request.user.is_authenticated()):
            raise XOSPermissionDenied(
                "You must be authenticated in order to use this API")
        if (name):
            return Diag.objects.filter(name=name)
        return Diag.objects.all()
示例#5
0
    def get_queryset(self):
        if (not self.request.user.is_authenticated()):
            raise XOSPermissionDenied(
                "You must be authenticated in order to use this API")

        print "kwargs"
        print self.request
        print self.kwargs['pk']

        return Diag.objects.filter(id=self.kwargs['pk'])
示例#6
0
文件: vrouter.py 项目: pan2za/vrouter
 def get_apps(self, request, pk=None):
     if (not request.user.is_authenticated()):
         raise XOSPermissionDenied(
             "You must be authenticated in order to use this API")
     else:
         if (pk is not None):
             apps = VRouterApp.objects.filter(vrouter_service=pk)
         else:
             apps = VRouterApp.objects.all()
         return Response(VRouterAppSerializer(apps, many=True).data)
示例#7
0
 def get_queryset(self):
     if (not self.request.user.is_authenticated()):
         raise XOSPermissionDenied("You must be authenticated in order to use this API")
     return SlicePlus.select_by_user(self.request.user)