Commit Graph

15 Commits

Author SHA1 Message Date
seros1521
e7bd99028e Fixes #8715: eliminates duplicates when used in many-to-many field constraints
When using permissions that use tags, a user may receive multiple permissions
of the same type if multiple tags are assigned to the device. This causes the
RestrictedQuerySet class to generate a query similar to this:

>>> dcim.models.Device.objects.filter(Q(tags__name='tag1')|Q(tags__name='tag2'))
<ConfigContextModelQuerySet [<Device: device1>, <Device: device1>]>

This query returns the same object twice if both tags are assigned to it. This
is due to the use of the django-taggit library. The library's documentation
describes this behavior as expected and suggests using an explicit distinct()
call in queries to avoid duplicates.

However, the use of DISTINCT in queries has a global side effect -
deduplication of responses, which may or may not be acceptable behavior
(depending on further use). Since it is not known how RestrictedQuerySet will
be used in the rest of the code, it was decided to dedupe using a subquery.
2022-03-04 14:37:05 +07:00
Jeremy Stretch
b43c657465 Move ObjectChange creation into signal receivers 2020-08-14 17:03:45 -04:00
Jeremy Stretch
44bb242821 Extend ObjectPermission constraints to OR multiple JSON objects 2020-08-06 15:53:23 -04:00
Jeremy Stretch
05e7af702b Remove restriction enforcement from RestrictedQuerySet 2020-07-23 12:48:03 -04:00
Jeremy Stretch
b135efe81b Set the default action to 'view' for restrict() 2020-06-26 11:57:07 -04:00
Jeremy Stretch
f03969dcec Merge pull request #4770 from netbox-community/3703-limit-tag-creation
Closes #3703: Restrict tag creation
2020-06-17 12:28:04 -04:00
Jeremy Stretch
47a69b0e5b DummyQuerySet should be iterable to allow for serialization 2020-06-17 12:20:56 -04:00
Jeremy Stretch
20a7fd143a Introduce unrestricted() method on RestrictedQuerySet 2020-06-16 12:20:21 -04:00
Jeremy Stretch
515586727c Catch and log evaluation of RestrictedQuerySet without calling restrict() 2020-06-16 10:39:15 -04:00
Jeremy Stretch
59cb0e995a Refine queryset restriction logic 2020-06-01 13:09:34 -04:00
Jeremy Stretch
9a1d62db2b Update views to restrict all querysets 2020-06-01 11:43:49 -04:00
Jeremy Stretch
92ffe54214 Tweak restrict() to accept only an action keyword 2020-06-01 10:45:49 -04:00
Jeremy Stretch
55cc22f41a Implement RestrictedQuerySet as a manager 2020-05-29 16:27:36 -04:00
Jeremy Stretch
10ab884671 Move restrict_queryset() function to RestrictedQuerySet 2020-05-29 15:09:08 -04:00
Jeremy Stretch
b6beb37e36 Rewrote ObjectChangeMiddleware to remove the curried handle_deleted_object() function 2019-10-22 15:10:49 -04:00