Skip to content

Commit

Permalink
Merge branch 'elastic-bulk-doc-creation' of https://github.com/raft-t…
Browse files Browse the repository at this point in the history
…ech/TANF-app into 1858-kibana-ofa-access
  • Loading branch information
elipe17 committed Dec 19, 2023
2 parents 30ee5ed + e32cb0d commit e9e0d78
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 97 deletions.
2 changes: 0 additions & 2 deletions tdrs-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Copy this file to `.env` and replace variables as needed
#

#REACT_APP_DEVAUTH=dev@test.com

# ##
# Required environment variables
# These must be defined or the application will encounter fatal errors
Expand Down
1 change: 0 additions & 1 deletion tdrs-backend/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ services:
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- cluster.routing.allocation.disk.threshold_enabled=false
- logger.discovery.level=debug
ports:
- 9200:9200
Expand Down
3 changes: 0 additions & 3 deletions tdrs-backend/tdpservice/data_files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ class DataFileViewSet(ModelViewSet):

def create(self, request, *args, **kwargs):
"""Override create to upload in case of successful scan."""
logger.debug(f"{self.__class__.__name__}: {request}")
response = super().create(request, *args, **kwargs)

# only if file is passed the virus scan and created successfully will we perform side-effects:
# * Send to parsing
# * Upload to ACF-TITAN
# * Send email to user

logger.debug(f"{self.__class__.__name__}: status: {response.status_code}")
if response.status_code == status.HTTP_201_CREATED or response.status_code == status.HTTP_200_OK:
user = request.user
data_file_id = response.data.get('id')
Expand Down Expand Up @@ -111,7 +109,6 @@ def create(self, request, *args, **kwargs):
if len(recipients) > 0:
send_data_submitted_email(list(recipients), data_file, email_context, subject)

logger.debug(f"{self.__class__.__name__}: return val: {response}")
return response

def get_s3_versioning_id(self, file_name, prefix):
Expand Down
3 changes: 1 addition & 2 deletions tdrs-backend/tdpservice/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,5 +475,4 @@ class Common(Configuration):
KIBANA_BASE_URL = os.getenv('KIBANA_BASE_URL', 'http://localhost:5601')
BYPASS_KIBANA_AUTH = strtobool(os.getenv("BYPASS_KIBANA_AUTH", "no"))

REACT_APP_DEVAUTH = os.getenv('REACT_APP_DEVAUTH', None)
CYPRESS_TOKEN = 'local-cypress-token' if REACT_APP_DEVAUTH else os.getenv('CYPRESS_TOKEN', None)
CYPRESS_TOKEN = os.getenv('CYPRESS_TOKEN', None)
2 changes: 0 additions & 2 deletions tdrs-backend/tdpservice/users/api/authorization_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class AuthorizationCheck(APIView):

def get(self, request, *args, **kwargs):
"""Handle get request and verify user is authorized."""
logger.debug(f"{self.__class__.__name__}: {request} {args} {kwargs}")

user = request.user
serializer = UserProfileSerializer(user)

Expand Down
1 change: 0 additions & 1 deletion tdrs-backend/tdpservice/users/api/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ class CypressLoginDotGovAuthenticationOverride(TokenAuthorizationOIDC):

def post(self, request):
"""Create a session for the specified user, if they exist."""
logging.debug(f"{self.__class__.__name__}: {request} ; {request.data}")
username = request.data.get('username', None)
token = request.data.get('token', None)

Expand Down
31 changes: 9 additions & 22 deletions tdrs-backend/tdpservice/users/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,36 @@
from django.contrib.auth import get_user_model

from rest_framework.authentication import BaseAuthentication
from rest_framework.request import Request
import logging
logger = logging.getLogger(__name__)

class CustomAuthentication(BaseAuthentication):
"""Define authentication and get user functions for custom authentication."""

@staticmethod
def authenticate(request=None, username=None, login_gov_uuid=None, hhs_id=None):
def authenticate(username=None, login_gov_uuid=None, hhs_id=None):
"""Authenticate user with the request and username."""
# HACK: This method currently needs to support two unrelated workflows.
# References:
# tdpservice/users/api/login.py:TokenAuthorizationOIDC.handleUser
# https://www.django-rest-framework.org/api-guide/authentication
if type(request) == Request:
username = request.data.get('username')
logging.debug(f"CustomAuthentication::authenticate: {request} {request.data} "
f"login_gov_id={login_gov_uuid} hhs_id={hhs_id}")
else:
logging.debug(f"CustomAuthentication::authenticate: {username} "
f"login_gov_id={login_gov_uuid} hhs_id={hhs_id}")
User = get_user_model()
logging.debug("CustomAuthentication::authenticate:hhs_id {}".format(hhs_id))
logging.debug("CustomAuthentication::authenticate:login_gov_uuid {}".format(login_gov_uuid))
logging.debug("CustomAuthentication::authenticate:username {}".format(username))
try:
if hhs_id:
try:
user_obj = User.objects.get(hhs_id=hhs_id)
return User.objects.get(hhs_id=hhs_id)
except User.DoesNotExist:
# If below line also fails with User.DNE, will bubble up and return None
user = User.objects.filter(username=username)
user.update(hhs_id=hhs_id)
logging.debug("Updated user {} with hhs_id {}.".format(username, hhs_id))
user_obj = User.objects.get(hhs_id=hhs_id)
return User.objects.get(hhs_id=hhs_id)

elif login_gov_uuid:
user_obj = User.objects.get(login_gov_uuid=login_gov_uuid)
return User.objects.get(login_gov_uuid=login_gov_uuid)
else:
user_obj = User.objects.get(username=username)
return User.objects.get(username=username)
except User.DoesNotExist:
user_obj = None
logging.debug(f"CustomAuthentication::authenticate found user: {user_obj}")
if type(request) == Request:
return (user_obj, None) if user_obj else None
return user_obj
return None

@staticmethod
def get_user(user_id):
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions tdrs-backend/tdpservice/users/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
from collections import ChainMap
from copy import deepcopy
from typing import List, Optional, TYPE_CHECKING
import logging

logger = logging.getLogger(__name__)


if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -129,7 +126,6 @@ class IsApprovedPermission(permissions.DjangoModelPermissions):

def has_permission(self, request, view):
"""Return True if the user has been assigned a group and is approved."""
logging.debug(f"{self.__class__.__name__}: {request} ; {view}")
return (request.user.groups.first() is not None and
request.user.account_approval_status == AccountApprovalStatusChoices.APPROVED)

Expand Down Expand Up @@ -164,8 +160,6 @@ def has_permission(self, request, view):
Data Analyst will only have permission to files within their STT and a
Regional Manager will only have permission to files within their region.
"""
logging.debug(f"{self.__class__.__name__}: {request} ; {view}")

# Checks for existence of `data_files.view_datafile` Permission
has_permission = super().has_permission(request, view)

Expand Down
2 changes: 0 additions & 2 deletions tdrs-frontend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# WARNING: This file is checked in to source control, do NOT store any secrets in this file
#

#REACT_APP_DEVAUTH=dev@test.com

# The hostname behind the tdrs-backend Django app
REACT_APP_BACKEND_HOST=http://127.0.0.1:8080

Expand Down
7 changes: 5 additions & 2 deletions tdrs-frontend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
ports:
- 8090:8090
networks:
- default
- local
volumes:
- ./reports:/zap/wrk/:rw
- ../scripts/zap-hook.py:/zap/scripts/zap-hook.py:ro
Expand All @@ -21,14 +21,14 @@ services:
- 3000:80
- 8080:8080
networks:
- local
- default
volumes:
- ./:/home/node/app
environment:
- NGINX_FRONTEND=tdp-frontend
- BACK_END=web
- LOCAL_DEV=true
- REACT_APP_DEVAUTH=${REACT_APP_DEVAUTH}
command: >
/bin/sh -c
"echo 'starting nginx' &&
Expand All @@ -42,6 +42,9 @@ services:
&& nginx -g 'daemon off;'"
networks:
local:
driver: bridge

default:
external:
name: external-net
20 changes: 0 additions & 20 deletions tdrs-frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,8 @@ axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.xsrfHeaderName = 'X-CSRFToken'
axios.defaults.withCredentials = true

function devLogin(devEmail) {
const BACKEND_URL = process.env.REACT_APP_BACKEND_URL
axios
.post(`${BACKEND_URL}/login/cypress`, {
username: devEmail,
token: 'local-cypress-token',
})
.then(function (response) {
console.log(response)
})
.catch(function (error) {
console.log(error)
})
store.dispatch({ type: 'SET_AUTH', payload: { devEmail } })
console.log(`dispatched SET_AUTH(${devEmail})`)
}

// call auth_check
const store = configureStore()
if (process.env.REACT_APP_DEVAUTH) {
devLogin(process.env.REACT_APP_DEVAUTH)
}
store.dispatch(fetchAuth())

// if (window.location.href.match(/https:\/\/.*\.app\.cloud\.gov/)) {
Expand Down

0 comments on commit e9e0d78

Please sign in to comment.