Ejemplo n.º 1
0
    def get_queryset(self, request, **kwargs):
        group_id = kwargs.get('group_id', 0)

        # Check access before doing anything else.
        handle_access(request, 'machine', group_id)

        return get_object_or_404(self.model, pk=group_id)
Ejemplo n.º 2
0
    def get_queryset(self, request, **kwargs):
        group_id = kwargs.get('group_id', 0)

        # Check access before doing anything else.
        handle_access(request, 'machine', group_id)

        return get_object_or_404(self.model, pk=group_id)
Ejemplo n.º 3
0
    def get_queryset(self, request, **kwargs):
        """Get a filtered queryset for this plugin's Machine model.

        Filters machines to only members of the passed group.
        Filters undeployed machines if deployed is True.
        Filters out machines that don't match this plugin's
        supported_os_families.

        Args:
            request (Request): The request passed from the View.
            **kwargs: Expected kwargs follow
                group_type (str): One of 'all' (the default),
                    'business_unit', or 'machine_group'.
                group_id (int, str): ID of the group_type's object to
                    filter by. Default to 0.
                deployed (bool): Filter by Machine.deployed. Defaults
                    to True.

        Returns:
            Filtered queryset.
        """
        group_type = kwargs.get('group_type', 'all')
        group_id = kwargs.get('group_id', 0)

        # Check access before doing anything else.
        handle_access(request, group_type, group_id)

        queryset = self.model.objects.filter(
            os_family__in=self.get_supported_os_families())

        # By default, plugins filter out undeployed machines.
        if self.only_use_deployed_machines:
            queryset = self.model.objects.filter(deployed=True)

        if group_type == "business_unit":
            queryset = queryset.filter(
                machine_group__business_unit__pk=group_id)
        elif group_type == "machine_group":
            queryset = queryset.filter(machine_group__pk=group_id)
        elif is_global_admin(request.user):
            # GA users won't have business units, so just do nothing.
            pass
        else:
            # The 'all' / 'front' type is being requested.
            queryset = queryset.filter(machine_group__business_unit__in=request
                                       .user.businessunit_set.all())

        return queryset
Ejemplo n.º 4
0
    def get_queryset(self, request, **kwargs):
        """Get a filtered queryset for this plugin's Machine model.

        Filters machines to only members of the passed group.
        Filters undeployed machines if deployed is True.
        Filters out machines that don't match this plugin's
        supported_os_families.

        Args:
            request (Request): The request passed from the View.
            **kwargs: Expected kwargs follow
                group_type (str): One of 'all' (the default),
                    'business_unit', or 'machine_group'.
                group_id (int, str): ID of the group_type's object to
                    filter by. Default to 0.
                deployed (bool): Filter by Machine.deployed. Defaults
                    to True.

        Returns:
            Filtered queryset.
        """
        group_type = kwargs.get('group_type', 'all')
        group_id = kwargs.get('group_id', 0)

        # Check access before doing anything else.
        handle_access(request, group_type, group_id)

        queryset = self.model.objects.filter(os_family__in=self.get_supported_os_families())

        # By default, plugins filter out undeployed machines.
        if self.only_use_deployed_machines:
            queryset = self.model.objects.filter(deployed=True)

        if group_type == "business_unit":
            queryset = queryset.filter(machine_group__business_unit__pk=group_id)
        elif group_type == "machine_group":
            queryset = queryset.filter(machine_group__pk=group_id)
        elif is_global_admin(request.user):
            # GA users won't have business units, so just do nothing.
            pass
        else:
            # The 'all' / 'front' type is being requested.
            queryset = queryset.filter(
                machine_group__business_unit__in=request.user.businessunit_set.all())

        return queryset