Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend/231/submit-form #383

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
826ffbe
add endpoint
carltonsmith Oct 1, 2020
c4a95ae
test authorization
carltonsmith Oct 1, 2020
aed59f5
linting
carltonsmith Oct 1, 2020
719fb28
merge cleanup
carltonsmith Oct 2, 2020
7cc59cd
test users with stts
carltonsmith Oct 5, 2020
cc6aa2d
update to PATCH endpoint
carltonsmith Oct 8, 2020
0a6dea7
update documentation
carltonsmith Oct 8, 2020
a275240
update doc formatting
carltonsmith Oct 8, 2020
a6ffe9e
update permissions
carltonsmith Oct 9, 2020
b9acf63
run frontend
carltonsmith Oct 13, 2020
dd360db
update shape of call and response tests
carltonsmith Oct 13, 2020
93ff1b8
updating serializers
carltonsmith Oct 16, 2020
ff8ae09
accept stts as dict and return as dict
carltonsmith Oct 19, 2020
979ed1a
update docs to show stt changes
carltonsmith Oct 19, 2020
57eda4a
add setUser action and reducer and call it from editprofile
hilvitzs Oct 23, 2020
47a7eb9
Merge branch 'backend/231/profile-update' into 231-submit-form
hilvitzs Oct 23, 2020
30f7a94
pass profileInfo to setUser action
hilvitzs Oct 23, 2020
df647b2
Merge branch '230-form-validation' of github.com:raft-tech/TANF-app i…
hilvitzs Oct 23, 2020
aa76d4d
add axios defaults, add setUser action, update auth reducer to handle…
hilvitzs Oct 23, 2020
4ee034d
rename all stts to sttList
hilvitzs Oct 23, 2020
394c7e3
remove unnecessary useSelector import
hilvitzs Oct 23, 2020
252cf67
add unassigned component, add route and add functionality to editprofile
hilvitzs Oct 27, 2020
c58af7e
Merge branch '230-form-validation' into 231-submit-form
hilvitzs Oct 27, 2020
3e6ed16
middle of working on tests
hilvitzs Oct 28, 2020
a6076a3
add tests to actions/requestAccess, reducers/requestAccess, editprofi…
hilvitzs Oct 29, 2020
4a920b8
Merge branch 'raft-tdp-main' of github.com:raft-tech/TANF-app into 23…
hilvitzs Oct 29, 2020
ef918b1
update Request Access form language
hilvitzs Oct 29, 2020
17b8d94
remove styles and add utility classes
hilvitzs Oct 29, 2020
726a4e2
make ids dynamic
hilvitzs Oct 29, 2020
6fea305
add label prop to formgroup
hilvitzs Oct 29, 2020
d856179
changes from 230
hilvitzs Oct 29, 2020
43e29d3
fix unassigned tests after card removal
hilvitzs Oct 29, 2020
4f2c347
auth_check match set_profile
riatzukiza Oct 30, 2020
5f873c1
Update tests
riatzukiza Oct 30, 2020
da4ae94
Apply black formatting
riatzukiza Oct 30, 2020
455fe5b
add doc string to
riatzukiza Nov 2, 2020
0726c1f
Add period to doc string
riatzukiza Nov 2, 2020
21914f7
Merge branch '231-submit-form' of github.com:raft-tech/TANF-app into …
hilvitzs Nov 2, 2020
8f198d8
fix focus when errors occur on form submission
hilvitzs Nov 2, 2020
c4ef509
Rename SetProfileSerializer
riatzukiza Nov 4, 2020
4fa3eaf
fix skiplinks not working on spacebar press
hilvitzs Nov 4, 2020
1ada22a
Merge pull request #381 from raft-tech/231-auth-check-stt
Nov 5, 2020
e40ff9d
Merge branch '231-submit-form' of github.com:raft-tech/TANF-app into …
hilvitzs Nov 5, 2020
4d0dbf1
rename unassigned with request, update routes and tests
hilvitzs Nov 5, 2020
5e9a559
finish renaming unassigned to request, update app tests
hilvitzs Nov 5, 2020
4625a77
Merge branch 'raft-tdp-main' of github.com:raft-tech/TANF-app into 23…
hilvitzs Nov 5, 2020
55aa54d
change settimeout to 0 in editprofile
hilvitzs Nov 5, 2020
339396d
change test wording
hilvitzs Nov 5, 2020
fa3ad0f
will set alert if api call for requestAccess fails
hilvitzs Nov 5, 2020
2c4b32b
remove unused code in EditProfile.test.js
hilvitzs Nov 6, 2020
b121da6
add sign out function to request and add tests
hilvitzs Nov 6, 2020
59f7259
add request-access-button class to make sign out button correct color
hilvitzs Nov 6, 2020
4931a11
Attempting to fix
riatzukiza Nov 6, 2020
567e570
Allow X-CSRFToken
riatzukiza Nov 6, 2020
e85f72f
update
riatzukiza Nov 6, 2020
cbe3ab6
All tests pass
riatzukiza Nov 9, 2020
4e7c430
Cleaned lint
riatzukiza Nov 9, 2020
64f6068
Change how we get csrf token
riatzukiza Nov 9, 2020
987da47
fix lint
riatzukiza Nov 9, 2020
b80ac89
Merge pull request #401 from raft-tech/csrf-hack
Nov 9, 2020
849d7af
remove unused code lines from Aaron
hilvitzs Nov 9, 2020
fafa313
change federal government check from id to name
hilvitzs Nov 9, 2020
4306d46
remove commented code
riatzukiza Nov 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions tdrs-backend/docs/api/set_profile.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating documentation to reflect the change from a POST endpoint to a PATCH endpoint.

# Set Profile
Accepts a POST request from [authenticated](api/authentication.md) users to update the first name and last name on their profile.
Accepts a PATCH request from [authenticated](api/authentication.md) users to update the first name and last name on their profile.


----
**Request**:

`Post` `v1/set_profile/`
`PATCH` `v1/set_profile/`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a patch instead of a post, required changes on both ends of the stack.


Parameters:

Expand All @@ -15,14 +15,24 @@ Parameters:
- JSON request body with the following **required** fields :
```
{
"first_name":"John",
"last_name":"Jones"
"first_name": "John",
"last_name": "Jones",
"stt": {
"id": 1
}
}
```

*Note:*
*Notes:*

- Authorization Protected
### Fields
* first_name: string (first name of user)
* last_name: string (last name of user)
* stt: object
* id: integer (id of the State, Tribe or Terrritory)


Authorization Protected

**Response**:

Expand All @@ -31,12 +41,27 @@ Content-Type application/json
200 Ok

{
"first_name":"John",
"last_name":"Jones"
"first_name": "John",
"last_name": "Jones",
"stt": {
"id": 1,
"type": "state",
"code": "AL",
"name": "Alabama"
}
}
```

This will return a JSON response with the authenticated users first name and last name as defined in their request JSON.
This will return a JSON response with the authenticated user's data as defined in their request JSON.

### Fields
* first_name: string (first name of user)
* last_name: string (last name of user)
* stt: object
* id: integer (id of the State, Tribe or Terrritory)
* type: string (identifies it as a State, Tribe or Territory)
* code: string (abbreviation)
* string (name of State, Tribe or Territory)

----
**Failure to Authenticate Response:**
Expand All @@ -63,4 +88,4 @@ Content-Type application/json
"first_name":["This field is required."],
"last_name":["This field is required."]
}
```
```
13 changes: 13 additions & 0 deletions tdrs-backend/tdpservice/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rest_framework.test import APIClient

from tdpservice.users.test.factories import UserFactory
from tdpservice.stts.test.factories import STTFactory, RegionFactory

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding fixtures for STT and Region



@pytest.fixture(scope="function")
Expand All @@ -15,3 +16,15 @@ def api_client():
def user():
"""Return a basic, non-admin user."""
return UserFactory.create()


@pytest.fixture
def stt():
"""Return an STT."""
return STTFactory.create()


@pytest.fixture
def region():
"""Return a region."""
return RegionFactory.create()
15 changes: 15 additions & 0 deletions tdrs-backend/tdpservice/stts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ def get_code(self, obj):
return obj.code


class STTUpdateSerializer(serializers.ModelSerializer):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serializer for updating STTs

"""STT serializer."""

class Meta:
"""Metadata."""

model = STT
fields = ["id"]
extra_kwargs = {"id": {"read_only": False}}

def to_representation(self, instance):
"""Allow update with only the ID field."""
return STTSerializer(instance).data


class RegionSerializer(serializers.ModelSerializer):
"""Region serializer."""

Expand Down
38 changes: 38 additions & 0 deletions tdrs-backend/tdpservice/stts/test/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Generate test data for stts."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factories for STTs and Regions.


import factory
from ..models import STT, Region


class RegionFactory(factory.django.DjangoModelFactory):
"""Generate test data for regions."""

class Meta:
"""Metadata for regions."""

model = "stts.Region"

id = factory.Sequence(int)

@classmethod
def _create(cls, model_class, *args, **kwargs):
return Region.objects.create(*args, **kwargs)


class STTFactory(factory.django.DjangoModelFactory):
"""Generate test data for stts."""

class Meta:
"""Hardcoded metata data for stts."""

model = "stts.STT"

id = factory.Sequence(int)
name = factory.Sequence(lambda n: "teststt%d" % n)
code = "TT"
type = "STATE"
region = factory.SubFactory(RegionFactory)

@classmethod
def _create(cls, model_class, *args, **kwargs):
return STT.objects.create(*args, **kwargs)
10 changes: 1 addition & 9 deletions tdrs-backend/tdpservice/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@
from django.contrib import admin

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We made some changes to the urls to house the app urls inside the app for easier reference.

from django.urls import include, path, re_path, reverse_lazy
from django.views.generic.base import RedirectView

from rest_framework.routers import DefaultRouter

from .users.api.authorization_check import AuthorizationCheck
from .users.api.login import TokenAuthorizationOIDC
from .users.api.login_redirect_oidc import LoginRedirectOIDC
from .users.api.logout import LogoutUser
from .users.api.logout_redirect_oidc import LogoutRedirectOIDC
from .users import views

router = DefaultRouter()
router.register("users", views.UserViewSet)

urlpatterns = [
path("admin/", admin.site.urls),
Expand All @@ -25,13 +18,12 @@
path("logout", LogoutUser.as_view(), name="logout"),
path("logout/oidc", LogoutRedirectOIDC.as_view(), name="oidc-logout"),
path("auth_check", AuthorizationCheck.as_view(), name="authorization-check"),
path("users/", include("tdpservice.users.urls")),
path("stts/", include("tdpservice.stts.urls")),
# the 'api-root' from django rest-frameworks default router
# http://www.django-rest-framework.org/api-guide/routers/#defaultrouter
re_path(r"^$", RedirectView.as_view(url=reverse_lazy("api-root"), permanent=False)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += router.urls

# Add 'prefix' to all urlpatterns to make it easier to version/group endpoints
urlpatterns = [path("v1/", include(urlpatterns))]
10 changes: 5 additions & 5 deletions tdrs-backend/tdpservice/users/api/authorization_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.permissions import AllowAny
from django.utils import timezone
from ..serializers import UserProfileSerializer

logger = logging.getLogger()
logger.setLevel(logging.INFO)
Expand All @@ -14,18 +16,16 @@ class AuthorizationCheck(APIView):

query_string = False
pattern_name = "authorization-check"
permission_classes = [AllowAny]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add special permission for the authorization check to allow requests from any user. The response indicates the users authorization.


def get(self, request, *args, **kwargs):
"""Handle get request and authenticate user."""
user = request.user
serializer = UserProfileSerializer(user)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the serializer for consistent user output.

if user.is_authenticated:
auth_params = {
"authenticated": True,
"user": {
"email": user.username,
"first_name": user.first_name,
"last_name": user.last_name,
},
"user": serializer.data,
}
logger.info(
"Auth check PASS for user: %s on %s", user.username, timezone.now()
Expand Down
22 changes: 20 additions & 2 deletions tdrs-backend/tdpservice/users/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
"""Serialize user data."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We made updates to the user serializer to give a consistent response with the authorization-check and set-profile endpoints.


import logging
from rest_framework import serializers

from .models import User
from tdpservice.stts.serializers import STTUpdateSerializer

logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())


class UserSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -48,17 +54,29 @@ class Meta:
extra_kwargs = {"password": {"write_only": True}}


class SetUserProfileSerializer(serializers.ModelSerializer):
class UserProfileSerializer(serializers.ModelSerializer):
"""Serializer used for setting a user's profile."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a more general name for this, because it is now used for both authorization-check and set-profile


stt = STTUpdateSerializer(required=True)
email = serializers.SerializerMethodField("get_email")

class Meta:
"""Metadata."""

model = User
fields = ["first_name", "last_name"]
fields = ["first_name", "last_name", "stt", "email"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to add STT to auth-check, and email to set-profile, so they'd have the same payload.


"""Enforce first and last name to be in API call and not empty"""
extra_kwargs = {
"first_name": {"allow_blank": False, "required": True},
"last_name": {"allow_blank": False, "required": True},
}

def update(self, instance, validated_data):
"""Update the user with the STT."""
instance.stt_id = validated_data.pop("stt")["id"]
return super().update(instance, validated_data)

def get_email(self, obj):
"""Return the user's email address."""
return obj.username
1 change: 1 addition & 0 deletions tdrs-backend/tdpservice/users/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ def user_data():
"last_name": "Smith",
"password": "correcthorsebatterystaple",
"auth_token": "xxx",
"stt": "Michigan",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added STT to the user fixture

}
5 changes: 4 additions & 1 deletion tdrs-backend/tdpservice/users/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import factory

from tdpservice.stts.test.factories import STTFactory

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add STT to user factory



class UserFactory(factory.django.DjangoModelFactory):
"""Generate test data for users."""
Expand All @@ -13,13 +15,14 @@ class Meta:
django_get_or_create = ("username",)

id = factory.Faker("uuid4")
username = factory.Sequence(lambda n: f"testuser{n}")
username = factory.Sequence(lambda n: "testuser%d" % n)
password = "test_password" # Static password so we can login.
email = factory.Faker("email")
first_name = factory.Faker("first_name")
last_name = factory.Faker("last_name")
is_active = True
is_staff = False
stt = factory.SubFactory(STTFactory)

@classmethod
def _create(cls, model_class, *args, **kwargs):
Expand Down
Loading