-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3399 controlled access fra data files page #3430
base: develop
Are you sure you want to change the base?
Changes from 26 commits
5ffa00c
c9d2480
a8dd63d
b9f8331
2027bad
0cc815c
9f93409
e0859a7
486b19a
6f18151
75405a9
cd1a074
e1a9651
8e75ee7
05c20ce
fc8e14a
54d3b7e
dc3cd9d
4ad6999
093c734
0356b72
b353c2f
2bd0f18
a5795c5
1e672fa
2b0e4be
8edc8e0
9c47936
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,16 @@ class Media: | |
|
||
actions = ['reparse'] | ||
|
||
def get_queryset(self, request): | ||
"""Return the queryset.""" | ||
qs = super().get_queryset(request) | ||
# return data files based on user's section | ||
if not (request.user.has_fra_access or request.user.is_an_admin): | ||
filtered_for_fra = qs.exclude(section__in=DataFile.get_fra_section_list()) | ||
return filtered_for_fra | ||
else: | ||
return qs | ||
|
||
def reparse(self, request, queryset): | ||
"""Reparse the selected data files.""" | ||
files = queryset.values_list("id", flat=True) | ||
|
@@ -135,6 +145,28 @@ def queryset(self, request, queryset): | |
else: | ||
return queryset | ||
|
||
class FRA_AccessFilter(admin.SimpleListFilter): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This filter will appear if user has FRA access and is Admin |
||
"""Filter datafile based on user access to FRA files.""" | ||
|
||
title = 'FRA/Non FRA Files' | ||
parameter_name = 'fra_access' | ||
|
||
def lookups(self, request, model_admin): | ||
"""Return a list of tuples.""" | ||
return [ | ||
('1', 'FRA Datafile'), | ||
('0', 'Non FRA Datafile'), | ||
] | ||
|
||
def queryset(self, request, queryset): | ||
"""Return a queryset.""" | ||
if self.value() == '1': | ||
return queryset.filter(section__in=DataFile.get_fra_section_list()) | ||
elif self.value() == '0': | ||
return queryset.exclude(section__in=DataFile.get_fra_section_list()) | ||
else: | ||
return queryset | ||
|
||
inlines = [DataFileInline] | ||
|
||
list_display = [ | ||
|
@@ -162,6 +194,16 @@ def queryset(self, request, queryset): | |
VersionFilter, | ||
] | ||
|
||
def get_list_filter(self, request): | ||
"""Get filter list in DataFile admin page.""" | ||
list_filter = super().get_list_filter(request) | ||
user = request.user | ||
if (user.is_an_admin or user.has_fra_access) and self.FRA_AccessFilter not in list_filter: | ||
list_filter.append(self.FRA_AccessFilter) | ||
elif not user.has_fra_access and self.FRA_AccessFilter in list_filter: | ||
list_filter.remove(self.FRA_AccessFilter) | ||
return list_filter | ||
|
||
@admin.register(LegacyFileTransfer) | ||
class LegacyFileTransferAdmin(ReadOnlyAdminMixin, admin.ModelAdmin): | ||
"""Admin class for LegacyFileTransfer models.""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.15 on 2025-01-08 13:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('data_files', '0016_remove_datafile_reparse_meta_models'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='datafile', | ||
name='section', | ||
field=models.CharField(choices=[('Tribal Closed Case Data', 'Tribal Closed Case Data'), ('Tribal Active Case Data', 'Tribal Active Case Data'), ('Tribal Aggregate Data', 'Tribal Aggregate Data'), ('Tribal Stratum Data', 'Tribal Stratum Data'), ('SSP Aggregate Data', 'Ssp Aggregate Data'), ('SSP Closed Case Data', 'Ssp Closed Case Data'), ('SSP Active Case Data', 'Ssp Active Case Data'), ('SSP Stratum Data', 'Ssp Stratum Data'), ('Active Case Data', 'Active Case Data'), ('Closed Case Data', 'Closed Case Data'), ('Aggregate Data', 'Aggregate Data'), ('Stratum Data', 'Stratum Data'), ('Work Outcomes for TANF Exiters', 'Fra Work Outcome Tanf Exiters'), ('Secondary School Attainment', 'Fra Secondry School Attainment'), ('Supplemental Work Outcomes', 'Fra Supplement Work Outcomes')], max_length=32), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.15 on 2025-01-28 14:53 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('users', '0041_users_digit_group_add_datafile_permission'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='user', | ||
name='feature_flags', | ||
field=models.JSONField(blank=True, default=dict, help_text='Feature flags for this user. This is a JSON field that can be used to store key-value pairs. E.g: {"fra_access": true}'), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,19 @@ class Meta: | |
_loaded_values = None | ||
_adding = True | ||
|
||
# Feature flag for the user to enable or disable FRA access | ||
feature_flags = models.JSONField( | ||
default=dict, | ||
help_text='Feature flags for this user. This is a JSON field that can be used to store key-value pairs. ' + | ||
'E.g: {"fra_access": true}', | ||
blank=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, there is an internal check for {} in JSONField. The only way to bypass is to override JSONField, but I decided to check for null or empty dict during cleaning which is simple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also moved null out |
||
) | ||
|
||
@property | ||
def has_fra_access(self): | ||
"""Return whether or not the user has FRA access.""" | ||
return self.feature_flags.get('fra_access', False) | ||
|
||
def __str__(self): | ||
"""Return the username as the string representation of the object.""" | ||
return self.username | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if user doesn't have FRA access or is Admin, then FRA files will be filtered