示例#1
0
    def _get_filters_from_slugs(self, mobile_user_and_group_slugs, can_access_all_locations):
        """
        for full organization access:
            for selected groups return group ids and groups user ids otherwise fetches case sharing groups and
            locations ids
        for restricted access:
            fetches case sharing location ids
        :return: set of filters using OwnerFilter and LastModifiedByFilter along with group independent filters
        """
        group_ids = None

        if can_access_all_locations:
            group_ids = self._get_group_ids(mobile_user_and_group_slugs)

        owner_filter_ids = []
        last_modified_filter_ids = []
        if group_ids:
            groups_static_user_ids = Group.get_static_user_ids_for_groups(group_ids)
            groups_static_user_ids = flatten_non_iterable_list(groups_static_user_ids)
            owner_filter_ids = group_ids + groups_static_user_ids
            last_modified_filter_ids = groups_static_user_ids

        return [OR(
            OwnerFilter(owner_filter_ids),
            LastModifiedByFilter(last_modified_filter_ids),
            *self._get_group_independent_filters(mobile_user_and_group_slugs, can_access_all_locations)
        )]
示例#2
0
    def get_form_filter(self, mobile_user_and_group_slugs, can_access_all_locations):
        """
        :param mobile_user_and_group_slugs: slug from request like
        ['g__e80c5e54ab552245457d2546d0cdbb03', 'g__e80c5e54ab552245457d2546d0cdbb04',
        'u__e80c5e54ab552245457d2546d0cdbb05', 't__1']
        :param can_access_all_locations: if request user has full organization access permission
        :return: set of form filters for export
        :filters:
        OR
            for full access:
                group's user ids via GroupFormSubmittedByFilter,
                users under user types,
                users by user_ids,
                users at locations and their descendants
            for restrict access:
                users by user_ids
                users at locations and their descendants
        AND
            datespan filter
        """
        form_filters = []
        if can_access_all_locations:
            form_filters += filter(None, [
                self._get_group_filter(mobile_user_and_group_slugs),
                self._get_user_type_filter(mobile_user_and_group_slugs),
            ])

        form_filters += filter(None, [
            self._get_users_filter(mobile_user_and_group_slugs),
            self._get_locations_filter(mobile_user_and_group_slugs)
        ])

        form_filters = flatten_non_iterable_list(form_filters)
        if form_filters:
            form_filters = [OR(*form_filters)]
        form_filters.append(self._get_datespan_filter())
        return form_filters