|
35 | 35 | return: QuerySet
|
36 | 36 | """
|
37 | 37 |
|
| 38 | +import d1_gmn.app.auth |
38 | 39 | import d1_gmn.app.did
|
39 | 40 | import d1_gmn.app.models
|
40 | 41 | import d1_gmn.app.revision
|
41 | 42 | import d1_gmn.app.views.assert_db
|
42 | 43 | import d1_gmn.app.views.util
|
43 | 44 |
|
| 45 | +import django.db.models |
44 | 46 |
|
45 | 47 | def add_access_policy_filter(request, query, column_name):
|
| 48 | + """Filter records that do not have ``read`` or better access for one or |
| 49 | + more of the active subjects. |
| 50 | +
|
| 51 | + Since ``read`` is the lowest access level that a subject can have, |
| 52 | + this method only has to filter on the presence of the subject. |
| 53 | + """ |
46 | 54 | q = d1_gmn.app.models.Subject.objects.filter(
|
47 | 55 | subject__in=request.all_subjects_set
|
48 | 56 | ).values('permission__sciobj')
|
49 | 57 | filter_arg = '{}__in'.format(column_name)
|
50 | 58 | return query.filter(**{filter_arg: q})
|
51 | 59 |
|
52 | 60 |
|
| 61 | +def add_redact_annotation(request, query): |
| 62 | + """Flag LogEntry records that require ``ipAddress`` and ``subject`` fields |
| 63 | + to be redacted before being returned to the client. |
| 64 | +
|
| 65 | + Only trusted subjects and subjects with ``write`` or ``changePermission`` on a |
| 66 | + SciObj receive unredacted ``ipAddress`` and ``subject`` in LogEntry records for the |
| 67 | + associated SciObj. |
| 68 | +
|
| 69 | + Subjects with only ``read`` access receive redacted records. |
| 70 | + """ |
| 71 | + return query.annotate( |
| 72 | + redact=django.db.models.Exists( |
| 73 | + d1_gmn.app.models.Permission.objects.filter( |
| 74 | + sciobj=django.db.models.OuterRef('sciobj'), |
| 75 | + subject__subject__in=request.all_subjects_set, |
| 76 | + level__gte=d1_gmn.app.auth.WRITE_LEVEL, |
| 77 | + ), |
| 78 | + negated=True, |
| 79 | + ) |
| 80 | + ) |
| 81 | + |
| 82 | + |
53 | 83 | def add_replica_filter(request, query):
|
54 | 84 | param_name = 'replicaStatus'
|
55 | 85 | bool_val = request.GET.get(param_name, True)
|
|
0 commit comments