From e32cb0d57cc02dff62602b67183f2486189e11b7 Mon Sep 17 00:00:00 2001 From: Eric Lipe Date: Tue, 19 Dec 2023 09:51:11 -0700 Subject: [PATCH] Revert "Changes for fully local development" This reverts commit 556221b310b73bee5e9af32eb4cd603b61a25d02. --- tdrs-backend/.env.example | 2 -- tdrs-backend/tdpservice/data_files/views.py | 3 -- tdrs-backend/tdpservice/settings/common.py | 1 - .../tdpservice/users/authentication.py | 17 ---------- .../management/commands/generate_dev_user.py | 31 ------------------- tdrs-backend/tdpservice/users/permissions.py | 6 ---- tdrs-frontend/.env | 2 -- tdrs-frontend/docker-compose.yml | 6 +++- tdrs-frontend/src/actions/auth.js | 3 -- tdrs-frontend/src/configureStore.js | 23 +------------- 10 files changed, 6 insertions(+), 88 deletions(-) delete mode 100755 tdrs-backend/tdpservice/users/management/commands/generate_dev_user.py diff --git a/tdrs-backend/.env.example b/tdrs-backend/.env.example index 3d325bc9c..5ffe271c1 100644 --- a/tdrs-backend/.env.example +++ b/tdrs-backend/.env.example @@ -2,8 +2,6 @@ # Copy this file to `.env` and replace variables as needed # -DEVELOPMENT=1 - # ## # Required environment variables # These must be defined or the application will encounter fatal errors diff --git a/tdrs-backend/tdpservice/data_files/views.py b/tdrs-backend/tdpservice/data_files/views.py index ebc769172..f01bb5be6 100644 --- a/tdrs-backend/tdpservice/data_files/views.py +++ b/tdrs-backend/tdpservice/data_files/views.py @@ -54,7 +54,6 @@ 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: @@ -62,7 +61,6 @@ def create(self, request, *args, **kwargs): # * 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') @@ -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): diff --git a/tdrs-backend/tdpservice/settings/common.py b/tdrs-backend/tdpservice/settings/common.py index 0c15a9f43..dc4e4c51e 100644 --- a/tdrs-backend/tdpservice/settings/common.py +++ b/tdrs-backend/tdpservice/settings/common.py @@ -293,7 +293,6 @@ class Common(Configuration): "DEFAULT_RENDERER_CLASSES": DEFAULT_RENDERER_CLASSES, "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"], "DEFAULT_AUTHENTICATION_CLASSES": ( - "tdpservice.users.authentication.DevAuthentication", "tdpservice.users.authentication.CustomAuthentication", "rest_framework.authentication.SessionAuthentication", "rest_framework.authentication.TokenAuthentication", diff --git a/tdrs-backend/tdpservice/users/authentication.py b/tdrs-backend/tdpservice/users/authentication.py index 6a5fae2dc..d238771ff 100644 --- a/tdrs-backend/tdpservice/users/authentication.py +++ b/tdrs-backend/tdpservice/users/authentication.py @@ -4,25 +4,8 @@ from rest_framework.authentication import BaseAuthentication import logging -import os logger = logging.getLogger(__name__) -class DevAuthentication(BaseAuthentication): - """Define authentication and get user functions for local/developer authentication.""" - - def authenticate(self, request): - if not os.environ.get('DEVELOPMENT'): - return None - logging.debug(f"{self.__class__.__name__}: {request} ; {request.data}") - requser = request.data.get("user") - reqname = requser if requser and requser != "undefined" else "dev@test.com" - User = get_user_model() - authuser = User.objects.get(username=reqname) - if authuser and requser == "undefined": - request.data["user"] = authuser.id - return (User.objects.get(username=reqname), True) - - class CustomAuthentication(BaseAuthentication): """Define authentication and get user functions for custom authentication.""" diff --git a/tdrs-backend/tdpservice/users/management/commands/generate_dev_user.py b/tdrs-backend/tdpservice/users/management/commands/generate_dev_user.py deleted file mode 100755 index 07a8a3291..000000000 --- a/tdrs-backend/tdpservice/users/management/commands/generate_dev_user.py +++ /dev/null @@ -1,31 +0,0 @@ -"""generate_dev_user command.""" - -from django.contrib.auth import get_user_model -from django.contrib.auth.models import Group -from django.core.management import BaseCommand - -User = get_user_model() - -email = "dev@test.com" -pswd = "pass" -first = "Jon" -last = "Tester" - -class Command(BaseCommand): - """Command class.""" - - def handle(self, *args, **options): - """Generate dev user if they don't exist.""" - try: - user = User.objects.get(username=email) - print(f"Found {vars(user)}") - except User.DoesNotExist: - group = Group.objects.get(name="Developer") - user = User.objects.create(username=email, - email=email, - password=pswd, - first_name=first, - last_name=last, - account_approval_status="Approved") - user.groups.add(group) - print(f"Created {vars(user)}") diff --git a/tdrs-backend/tdpservice/users/permissions.py b/tdrs-backend/tdpservice/users/permissions.py index 31106304c..81e54fe54 100644 --- a/tdrs-backend/tdpservice/users/permissions.py +++ b/tdrs-backend/tdpservice/users/permissions.py @@ -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 @@ -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) @@ -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) diff --git a/tdrs-frontend/.env b/tdrs-frontend/.env index da6c85ddb..087144285 100644 --- a/tdrs-frontend/.env +++ b/tdrs-frontend/.env @@ -4,8 +4,6 @@ # WARNING: This file is checked in to source control, do NOT store any secrets in this file # -DEVELOPMENT=1 - # The hostname behind the tdrs-backend Django app REACT_APP_BACKEND_HOST=http://127.0.0.1:8080 diff --git a/tdrs-frontend/docker-compose.yml b/tdrs-frontend/docker-compose.yml index b8b9c480e..d75772fa5 100644 --- a/tdrs-frontend/docker-compose.yml +++ b/tdrs-frontend/docker-compose.yml @@ -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 @@ -21,6 +21,7 @@ services: - 3000:80 - 8080:8080 networks: + - local - default volumes: - ./:/home/node/app @@ -41,6 +42,9 @@ services: && nginx -g 'daemon off;'" networks: + local: + driver: bridge + default: external: name: external-net diff --git a/tdrs-frontend/src/actions/auth.js b/tdrs-frontend/src/actions/auth.js index 7dad3b0eb..6b0147c6b 100644 --- a/tdrs-frontend/src/actions/auth.js +++ b/tdrs-frontend/src/actions/auth.js @@ -40,9 +40,6 @@ export const SET_MOCK_LOGIN_STATE = 'SET_MOCK_LOGIN_STATE' */ export const fetchAuth = () => async (dispatch) => { - if (process.env.DEVELOPMENT) { - return 0 - } dispatch({ type: FETCH_AUTH }) try { const URL = `${process.env.REACT_APP_BACKEND_URL}/auth_check` diff --git a/tdrs-frontend/src/configureStore.js b/tdrs-frontend/src/configureStore.js index 24d09e21b..a9f340685 100644 --- a/tdrs-frontend/src/configureStore.js +++ b/tdrs-frontend/src/configureStore.js @@ -4,7 +4,6 @@ import { createBrowserHistory } from 'history' import thunkMiddleware from 'redux-thunk' import loggerMiddleware from './middleware/logger' import createRootReducer from './reducers' -import { permissions } from './components/Header/developer_permissions' export const history = createBrowserHistory() @@ -14,29 +13,9 @@ export const history = createBrowserHistory() export default function configureStore(preloadedState) { const middlewares = [thunkMiddleware, loggerMiddleware] const composedEnhancers = composeWithDevTools(applyMiddleware(...middlewares)) - const devState = { - router: { location: { pathname: '/profile' } }, - auth: { - user: { - email: 'dev@test.com', - first_name: 'Jon', - last_name: 'Tester', - roles: [{ id: 1, name: 'Developer', permissions }], - access_request: true, - account_approval_status: 'Approved', - stt: { - id: 31, - type: 'state', - code: 'NJ', - name: 'New Jersey', - }, - }, - authenticated: true, - }, - } const store = createStore( createRootReducer(history), - process.env.DEVELOPMENT ? devState : preloadedState, + preloadedState, composedEnhancers ) return store