Skip to content

Commit

Permalink
3074 TDP Datafile page for DIGIT and Sys Admin groups (#3158)
Browse files Browse the repository at this point in the history
* added migration and changes

* 3074 corrected test

* revert changes

* 3074 added similar group permissions to DIGITTeam as Admin

* remove logging for frontend

* 3074-added permissions for System Admin
  • Loading branch information
raftmsohani authored Sep 4, 2024
1 parent 1a3e1dc commit abd8609
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ tasks:
desc: Restart backend web server
dir: tdrs-backend
cmds:
- docker-compose -f docker-compose.yml restart -d
- docker-compose -f docker-compose.yml restart

backend-bash:
desc: Open a shell in the backend container
Expand Down Expand Up @@ -178,7 +178,7 @@ tasks:
desc: Restart frontend web server
dir: tdrs-frontend
cmds:
- docker-compose -f docker-compose.yml restart -d
- docker-compose -f docker-compose.yml restart

frontend-av:
desc: Start frontend with optional clamav service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated by Django 3.2.5 on 2021-08-16 14:10
from django.contrib.auth.models import Group
from django.db import migrations

from tdpservice.users.permissions import (
add_permissions_q,
get_permission_ids_for_model,
view_permissions_q
)


def set_digit_team_permissions(apps, schema_editor):
"""Set relevant Group Permissions for DIGIT Team group."""
digit = (
apps.get_model('auth', 'Group').objects.get(name='DIGIT Team')
)

stt_permissions = get_permission_ids_for_model(
'stts',
'stt',
filters=[view_permissions_q]
)


datafile_permissions = get_permission_ids_for_model(
'data_files',
'datafile',
filters=[view_permissions_q, add_permissions_q]
)

# Assign model permissions
digit.permissions.add(*datafile_permissions, *stt_permissions)

def unset_digit_team_permissions(apps, schema_editor):
"""Remove all Group Permissions added to DIGIT Team."""
digit = (
apps.get_model('auth', 'Group').objects.get(name='DIGIT Team')
)
datafile_permissions = get_permission_ids_for_model(
'data_files',
'datafile',
filters=[view_permissions_q, add_permissions_q]
)
digit.permissions.remove(*datafile_permissions)

class Migration(migrations.Migration):

dependencies = [
('auth', '__latest__'),
('users', '0040_users_digit_group_permissions'),
]

operations = [
migrations.RunPython(
set_digit_team_permissions,
reverse_code=unset_digit_team_permissions
)
]
4 changes: 3 additions & 1 deletion tdrs-backend/tdpservice/users/test/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ def test_digit_team_permissions(digit_team):
expected_permissions = {'parsers.view_parsererror',
'parsers.view_datafilesummary',
'data_files.view_datafile',
'data_files.add_datafile',
'stts.view_stt',
'search_indexes.view_ssp_m3',
'search_indexes.view_tribal_tanf_t5',
'search_indexes.view_tribal_tanf_t3',
Expand All @@ -200,7 +202,7 @@ def test_digit_team_permissions(digit_team):
'search_indexes.view_tanf_t4',
'search_indexes.view_ssp_m6',
'search_indexes.view_tribal_tanf_t2',
'search_indexes.view_tanf_t6'
'search_indexes.view_tanf_t6',
}
group_permissions = digit_team.get_group_permissions()
assert group_permissions == expected_permissions
15 changes: 11 additions & 4 deletions tdrs-frontend/src/components/Reports/Reports.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function Reports() {
// The logged in user saved in our redux `auth` state object
const user = useSelector((state) => state.auth.user)
const isOFAAdmin = useSelector(selectPrimaryUserRole)?.name === 'OFA Admin'
const isDIGITTeam = useSelector(selectPrimaryUserRole)?.name === 'DIGIT Team'
const isSystemAdmin =
useSelector(selectPrimaryUserRole)?.name === 'OFA System Admin'
const sttList = useSelector((state) => state?.stts?.sttList)

const [errorModalVisible, setErrorModalVisible] = useState(false)
Expand All @@ -59,7 +62,8 @@ function Reports() {
Q4: 'Quarter 4 (July - September)',
}

const currentStt = isOFAAdmin ? selectedStt : userProfileStt
const currentStt =
isOFAAdmin || isDIGITTeam || isSystemAdmin ? selectedStt : userProfileStt

const stt = sttList?.find((stt) => stt?.name === currentStt)

Expand All @@ -68,7 +72,8 @@ function Reports() {

const errorsCount = formValidation.errors

const missingStt = !isOFAAdmin && !currentStt
const missingStt =
!isOFAAdmin && !isDIGITTeam && !isSystemAdmin && !currentStt

const errorsRef = useRef(null)

Expand Down Expand Up @@ -194,7 +199,7 @@ function Reports() {
)
const touchedFields = Object.keys(touched).length

const expected_fields = isOFAAdmin ? 3 : 2
const expected_fields = isOFAAdmin || isDIGITTeam || isSystemAdmin ? 3 : 2

const errors = touchedFields === 3 ? expected_fields - form.length : 0

Expand All @@ -215,6 +220,8 @@ function Reports() {
setFormValidationState,
touched,
isOFAAdmin,
isDIGITTeam,
isSystemAdmin,
])

return (
Expand All @@ -237,7 +244,7 @@ function Reports() {
</div>
)}
<form>
{isOFAAdmin && (
{(isOFAAdmin || isDIGITTeam || isSystemAdmin) && (
<div
className={classNames('usa-form-group maxw-mobile margin-top-4', {
'usa-form-group--error': formValidation.stt,
Expand Down

0 comments on commit abd8609

Please sign in to comment.