Skip to content

Commit

Permalink
added fra feature flag and filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
raftmsohani committed Jan 15, 2025
1 parent 486b19a commit 6f18151
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 42 deletions.
84 changes: 42 additions & 42 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ tasks:
dir: tdrs-backend
cmds:
- task: create-network
- docker compose -f docker-compose.yml up -d --build
- docker compose -f docker-compose.yml exec web sh -c "python ./manage.py makemigrations"
- docker compose -f docker-compose.yml exec web sh -c "python ./manage.py migrate"
- docker compose -f docker-compose.yml down
- docker-compose -f docker-compose.yml up -d --build
- docker-compose -f docker-compose.yml exec web sh -c "python ./manage.py makemigrations"
- docker-compose -f docker-compose.yml exec web sh -c "python ./manage.py migrate"
- docker-compose -f docker-compose.yml down
- task: sentry-down

clone-sentry-repo:
Expand Down Expand Up @@ -48,88 +48,88 @@ tasks:
- docker cp .env sentry:/self-hosted/.env
- docker exec sentry bash -c "cd self-hosted && ./install.sh --skip-user-creation --no-report-self-hosted-issues"
# create a new user
- docker exec sentry bash -c "cd self-hosted && docker compose run --rm web createuser --email admin@tanf.com --password admin --superuser"
- docker exec sentry bash -c "cd self-hosted && docker-compose run --rm web createuser --email admin@tanf.com --password admin --superuser"
# copy backup.json file to sentry
- docker cp backup.json sentry:/self-hosted/sentry/backup.json
# restore backup
- docker exec sentry bash -c "cd self-hosted && docker compose up -d"
- docker exec sentry bash -c "cd self-hosted && docker-compose up -d"
- docker exec sentry bash -c "docker cp /self-hosted/sentry/backup.json sentry-self-hosted-web-1:/home/sentry/backup.json"
- docker exec sentry bash -c "docker exec sentry-self-hosted-web-1 bash -c 'sentry import /home/sentry/backup.json'"
- docker exec sentry bash -c "cd self-hosted && docker compose down"
- docker exec sentry bash -c "cd self-hosted && docker compose up -d"
- docker exec sentry bash -c "cd self-hosted && docker-compose down"
- docker exec sentry bash -c "cd self-hosted && docker-compose up -d"


sentry-up:
desc: Start sentry service
dir: sentry
cmds:
- docker exec sentry bash -c "cd self-hosted && docker compose up -d"
- docker exec sentry bash -c "cd self-hosted && docker-compose up -d"

sentry-down:
desc: Stop sentry service
dir: sentry
cmds:
- docker exec sentry bash -c "cd self-hosted && docker compose down"
- docker exec sentry bash -c "cd self-hosted && docker-compose down"

drop-db:
desc: Drop the backend database
dir: tdrs-backend
cmds:
- docker compose -f docker-compose.yml down
- docker-compose -f docker-compose.yml down
- docker volume rm tdrs-backend_postgres_data

backend-up:
desc: Start backend web server
dir: tdrs-backend
cmds:
- docker compose -f docker-compose.yml up -d
- docker-compose -f docker-compose.yml up -d

backend-down:
desc: Stop backend web server
dir: tdrs-backend
cmds:
- docker compose -f docker-compose.yml down
- docker-compose -f docker-compose.yml down

backend-logs:
desc: Show and follow backend web server logs
dir: tdrs-backend
cmds:
- docker compose -f docker-compose.yml logs -f
- docker-compose -f docker-compose.yml logs -f

backend-restart:
desc: Restart backend web server
dir: tdrs-backend
cmds:
- docker compose -f docker-compose.yml restart
- docker-compose -f docker-compose.yml restart

backend-bash:
desc: Open a shell in the backend container
dir: tdrs-backend
cmds:
- docker compose -f docker-compose.yml exec web sh
- docker-compose -f docker-compose.yml exec web sh

backend-shell:
desc: Open a Django shell in the backend container
dir: tdrs-backend
cmds:
- docker compose -f docker-compose.yml exec web sh -c "python ./manage.py shell"
- docker-compose -f docker-compose.yml exec web sh -c "python ./manage.py shell"

backend-exec:
desc: Execute a command in the backend container
dir: tdrs-backend
vars:
CMD: '{{.CMD}}'
cmds:
- docker compose -f docker-compose.yml exec web sh -c "python manage.py {{.CMD}}"
- docker-compose -f docker-compose.yml exec web sh -c "python manage.py {{.CMD}}"

backend-exec-seed-db:
desc: Execute seed_db command in the backend container
dir: tdrs-backend
vars:
CMD: '{{.CMD}}'
cmds:
- docker compose -f docker-compose.yml up -d
- docker compose -f docker-compose.yml exec web sh -c "python manage.py populate_stts; python ./manage.py seed_db"
- docker-compose -f docker-compose.yml up -d
- docker-compose -f docker-compose.yml exec web sh -c "python manage.py populate_stts; python ./manage.py seed_db"

backend-pytest:
desc: 'Run pytest in the backend container E.g: task backend-pytest PYTEST_ARGS="tdpservice/test/ -s -vv"'
Expand All @@ -138,37 +138,37 @@ tasks:
PYTEST_ARGS: '{{.PYTEST_ARGS | default "."}}'
cmds:
- task backend-up
- docker compose -f docker-compose.yml exec web sh -c "pytest {{.PYTEST_ARGS}}"
- docker-compose -f docker-compose.yml exec web sh -c "pytest {{.PYTEST_ARGS}}"

backend-remove-volumes:
desc: Remove the backend volumes
dir: tdrs-backend
cmds:
- docker compose -f docker-compose.yml down -v
- docker-compose -f docker-compose.yml down -v

backend-lint:
desc: Run flake8 in the backend container
dir: tdrs-backend
cmds:
- task backend-up
- docker compose -f docker-compose.yml exec -T web sh -c "flake8 . && if [ $? -eq 0 ]; then echo 'Flake8 linter found no issues'; fi"
- docker-compose -f docker-compose.yml exec -T web sh -c "flake8 . && if [ $? -eq 0 ]; then echo 'Flake8 linter found no issues'; fi"

backend-pip-lock:
#TODO: Add a task to lock the pip dependencies
desc: Lock the pip dependencies
dir: tdrs-backend
cmds:
- task: backend-up
- docker compose -f docker-compose.yml exec web sh -c "pipenv lock"
- docker-compose -f docker-compose.yml exec web sh -c "pipenv lock"

psql:
desc: Open a psql shell in the backend container
dir: tdrs-backend
cmds:
- task create-network || true
- docker compose -f docker-compose.yml up -d postgres
- docker-compose -f docker-compose.yml up -d postgres
- sleep 5
- docker compose -f docker-compose.yml exec postgres sh -c "psql -U tdpuser -d tdrs_test"
- docker-compose -f docker-compose.yml exec postgres sh -c "psql -U tdpuser -d tdrs_test"

clean:
desc: Remove all containers, networks, and volumes
Expand All @@ -182,25 +182,25 @@ tasks:
desc: Start clamav service
dir: tdrs-backend
cmds:
- docker compose -f docker-compose.yml up -d clamav-rest
- docker-compose -f docker-compose.yml up -d clamav-rest

frontend-up:
desc: Start frontend web server
dir: tdrs-frontend
cmds:
- docker compose -f docker-compose.yml up -d
- docker-compose -f docker-compose.yml up -d

frontend-down:
desc: Stop frontend web server
dir: tdrs-frontend
cmds:
- docker compose -f docker-compose.yml down
- docker-compose -f docker-compose.yml down

frontend-restart:
desc: Restart frontend web server
dir: tdrs-frontend
cmds:
- docker compose -f docker-compose.yml restart
- docker-compose -f docker-compose.yml restart

frontend-av:
desc: Start frontend with optional clamav service
Expand All @@ -215,24 +215,24 @@ tasks:
desc: Initialize the frontend project
dir: tdrs-frontend
cmds:
- docker compose -f docker-compose.yml up -d --build
- docker compose -f docker-compose.yml exec tdp-frontend sh -c "apk add nodejs npm"
- docker compose -f docker-compose.yml exec tdp-frontend sh -c "npm install"
- docker compose -f docker-compose.yml down
- docker-compose -f docker-compose.yml up -d --build
- docker-compose -f docker-compose.yml exec tdp-frontend sh -c "apk add nodejs npm"
- docker-compose -f docker-compose.yml exec tdp-frontend sh -c "npm install"
- docker-compose -f docker-compose.yml down

frontend-test:
desc: Run frontend tests
dir: tdrs-frontend
cmds:
- docker compose -f docker-compose.local.yml up tdp-frontend-test -d
- docker compose -f docker-compose.local.yml exec tdp-frontend-test sh -c "npm run test"
- docker-compose -f docker-compose.local.yml up tdp-frontend-test -d
- docker-compose -f docker-compose.local.yml exec tdp-frontend-test sh -c "npm run test"

frontend-test-cov:
desc: Run frontend tests with coverage
dir: tdrs-frontend
cmds:
- docker compose -f docker-compose.local.yml up tdp-frontend-test -d
- docker compose -f docker-compose.local.yml exec tdp-frontend-test sh -c "npm run test:cov"
- docker-compose -f docker-compose.local.yml up tdp-frontend-test -d
- docker-compose -f docker-compose.local.yml exec tdp-frontend-test sh -c "npm run test:cov"

cypress:
desc: Run cypress tests
Expand All @@ -257,20 +257,20 @@ tasks:
desc: Run eslint in the frontend container
dir: tdrs-frontend
cmds:
- docker compose -f docker-compose.local.yml up -d tdp-frontend-test --quiet-pull
- docker compose -f docker-compose.yml exec -T tdp-frontend-test sh -c "npm run lint"
- docker-compose -f docker-compose.local.yml up -d tdp-frontend-test --quiet-pull
- docker-compose -f docker-compose.yml exec -T tdp-frontend-test sh -c "npm run lint"

frontend-logs:
desc: Show and follow frontend web server logs
dir: tdrs-frontend
cmds:
- docker compose -f docker-compose.yml logs -f
- docker-compose -f docker-compose.yml logs -f

frontend-bash:
desc: Open a shell in the frontend container
dir: tdrs-frontend
cmds:
- docker compose -f docker-compose.yml exec tdp-frontend bash
- docker-compose -f docker-compose.yml exec tdp-frontend bash

up:
desc: Start both frontend and backend web servers
Expand Down
15 changes: 15 additions & 0 deletions tdrs-backend/tdpservice/data_files/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ 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
FRA_SECTION_LIST = [
DataFile.Section.FRA_WORK_OUTCOME_TANF_EXITERS,
DataFile.Section.FRA_SECONDRY_SCHOOL_ATTAINMENT,
DataFile.Section.FRA_SUPPLEMENT_WORK_OUTCOMES
]
if not request.user.has_fra_access:
filtered_for_fra = qs.exclude(section__in=FRA_SECTION_LIST)
return filtered_for_fra
else:
return qs.filter(section__in=FRA_SECTION_LIST)

def reparse(self, request, queryset):
"""Reparse the selected data files."""
files = queryset.values_list("id", flat=True)
Expand Down
7 changes: 7 additions & 0 deletions tdrs-backend/tdpservice/data_files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,16 @@ def get_s3_versioning_id(self, file_name, prefix):
def get_queryset(self):
"""Apply custom queryset filters."""
queryset = super().get_queryset().order_by('-created_at')
FRA_SECTION_LIST = [
DataFile.Section.FRA_WORK_OUTCOME_TANF_EXITERS,
DataFile.Section.FRA_SECONDRY_SCHOOL_ATTAINMENT,
DataFile.Section.FRA_SUPPLEMENT_WORK_OUTCOMES
]
if self.action == 'list':
if self.request.query_params.get('file_type') == 'ssp-moe':
queryset = queryset.filter(section__contains='SSP')
elif self.request.query_params.get('file_type') == 'fra':
queryset = queryset.filter(section__in=FRA_SECTION_LIST)
else:
queryset = queryset.exclude(section__contains='SSP')

Expand Down
5 changes: 5 additions & 0 deletions tdrs-backend/tdpservice/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from .models import User

import logging
logger = logging.getLogger()

class UserForm(forms.ModelForm):
"""Customize the user admin form."""
Expand All @@ -19,6 +21,9 @@ class Meta:
exclude = ['password', 'user_permissions']
readonly_fields = ['last_login', 'date_joined', 'login_gov_uuid', 'hhs_id', 'access_request']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def clean(self):
"""Add extra validation for locations based on roles."""
cleaned_data = super().clean()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.15 on 2025-01-15 15:46

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(default={}, help_text='Feature flags for this data file.'),
),
]
10 changes: 10 additions & 0 deletions tdrs-backend/tdpservice/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ class Meta:
_loaded_values = None
_adding = True

# Feature flag for the user to enable or disable FRA access
feature_flags = models.JSONField(
default={},
help_text="Feature flags for this data file."
)

@property
def has_fra_access(self):
return self.feature_flags.get('fra_access', False)

def __str__(self):
"""Return the username as the string representation of the object."""
return self.username
Expand Down

0 comments on commit 6f18151

Please sign in to comment.