Skip to content

Commit

Permalink
remove old temporary Login views, utilize built in dj-rest-auth views
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham4401 committed Dec 19, 2023
1 parent 487ad7b commit b13f059
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 62 deletions.
26 changes: 8 additions & 18 deletions client/src/features/Profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
import { UserOrg } from 'components/Org';
import { RcraProfile } from 'components/RcraProfile';
import { HtCard } from 'components/UI';
import { HtCard, HtSpinner } from 'components/UI';
import { UserInfoForm } from 'components/User';
import { useTitle } from 'hooks';
import React, { ReactElement, useEffect } from 'react';
import React, { ReactElement } from 'react';
import { Col, Container, Row } from 'react-bootstrap';
import {
getRcraProfile,
HaztrakUser,
selectHaztrakProfile,
selectUser,
useAppDispatch,
useAppSelector,
} from 'store';
import { selectHaztrakProfile, useAppSelector, useGetUserQuery } from 'store';

/**
* Display user profile, including their Haztrak information, their organization,
* and their RCRAInfo profile.
* @constructor
*/
export function Profile(): ReactElement {
const dispatch = useAppDispatch();
const profile = useAppSelector(selectHaztrakProfile);
const user: HaztrakUser | undefined = useAppSelector(selectUser);
const { data: user, isLoading } = useGetUserQuery();
useTitle('Profile');

if (!user) {
return <div>loading...</div>;
if (isLoading) {
return <HtSpinner center />;
} else if (!user) {
return <div>Unable to load user profile.</div>;
}

useEffect(() => {
dispatch(getRcraProfile());
}, [profile.user]);

return (
<>
<Container fluid className="py-2">
Expand Down
4 changes: 2 additions & 2 deletions client/src/store/authSlice/auth.slice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { RootState } from 'store/rootStore';
import { haztrakApi } from 'store/haztrakApiSlice';
import { RootState } from 'store/rootStore';

export interface HaztrakUser {
username: string;
Expand Down Expand Up @@ -82,7 +82,7 @@ export const authApi = haztrakApi.injectEndpoints({
// Note: build.query<ReturnType, ArgType>
login: build.mutation<LoginResponse, LoginRequest>({
query: (data) => ({
url: 'auth/login',
url: 'user/login',
method: 'POST',
data: data,
}),
Expand Down
2 changes: 2 additions & 0 deletions server/apps/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class HaztrakUserSerializer(ModelSerializer):
Model serializer for marshalling/unmarshalling a user's HaztrakUser
"""

id = serializers.CharField(source="pk")
username = serializers.CharField(
required=False,
)
Expand All @@ -29,6 +30,7 @@ class HaztrakUserSerializer(ModelSerializer):
class Meta:
model = HaztrakUser
fields = [
"id",
"username",
"firstName",
"lastName",
Expand Down
17 changes: 12 additions & 5 deletions server/apps/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from dj_rest_auth.views import LoginView, LogoutView, UserDetailsView
from django.urls import include, path

from .views import ( # type: ignore
HaztrakProfileView,
HaztrakUserView,
LaunchExampleTaskView,
Login,
RcraProfileView,
SyncRcraProfileView,
TaskStatusView,
Expand All @@ -21,9 +20,17 @@
]
),
),
path("profile", HaztrakProfileView.as_view()),
path("user", HaztrakUserView.as_view()),
path("user/login", Login.as_view()),
path("task/example", LaunchExampleTaskView.as_view()),
path("task/<str:task_id>", TaskStatusView.as_view()),
path("profile", HaztrakProfileView.as_view()),
path(
"user",
include(
[
path("", UserDetailsView.as_view(), name="rest_user_details"),
path("/login", LoginView.as_view(), name="rest_login"),
path("/logout", LogoutView.as_view(), name="rest_logout"),
]
),
),
]
2 changes: 0 additions & 2 deletions server/apps/core/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from .auth_view import Login
from .profile_views import (
HaztrakProfileView,
HaztrakUserView,
RcraProfileView,
SyncRcraProfileView,
)
Expand Down
12 changes: 0 additions & 12 deletions server/apps/core/views/auth_view.py

This file was deleted.

13 changes: 1 addition & 12 deletions server/apps/core/views/profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@
from rest_framework.request import Request
from rest_framework.response import Response

from apps.core.models import HaztrakProfile, HaztrakUser, RcraProfile
from apps.core.models import HaztrakProfile, RcraProfile
from apps.core.serializers import (
HaztrakProfileSerializer,
HaztrakUserSerializer,
RcraProfileSerializer,
)
from apps.site.tasks import sync_user_rcrainfo_sites


class HaztrakUserView(RetrieveUpdateAPIView):
"""Retrieve the current user's base information"""

queryset = HaztrakUser.objects.all()
serializer_class = HaztrakUserSerializer

def get_object(self):
return self.request.user


class HaztrakProfileView(RetrieveAPIView):
"""Displays a user's HaztrakProfile"""

Expand Down
2 changes: 2 additions & 0 deletions server/haztrak/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,5 @@
},
},
}

REST_AUTH = {"USER_DETAILS_SERIALIZER": "apps.core.serializers.HaztrakUserSerializer"}
11 changes: 0 additions & 11 deletions server/haztrak/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
1. Import the 'include()' function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from dj_rest_auth.views import LoginView, LogoutView, UserDetailsView
from django.contrib import admin
from django.urls import include, path
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
Expand All @@ -38,16 +37,6 @@
name="swagger-ui",
),
path(r"health/", include("health_check.urls")),
path(
"auth/",
include(
[
path("login", LoginView.as_view(), name="rest_login"),
path("logout", LogoutView.as_view(), name="rest_logout"),
path("user", UserDetailsView.as_view(), name="rest_user_details"),
]
),
),
]
),
),
Expand Down

0 comments on commit b13f059

Please sign in to comment.