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

Frontend/231/submit-form #383

wants to merge 63 commits into from

Conversation

hilvitzs
Copy link

@hilvitzs hilvitzs commented Nov 2, 2020

This pull request changes...

  • This PR allows the user to submit their profile information in order to be assigned a role by an admin user.

  • This adds a requestAccess action and reducer in order to store the information from the user endpoint.

  • requestAccess action will trigger the SET_AUTH action to set user information

  • It also adds associated tests for the action and reducers.

  • This changes the fetchStts action and reducer names to fetchSttLists.

  • This PR also ensures that the Federal Government is always the first option in the STT combo box.

  • This also adds the word required to the labels for all form elements in Edit Profile based on the feedback from Robert's accessibility review.

  • Adds a fix for space bar not triggering skip links anchor

  • Updates App.test.js

[AC] This pull request is ready to merge when...

  • Tests have been updated (and all tests are passing)
  • Vulnerability Scan Test (Zap) has no high/critcial CVEs
  • Linting Tests (ESLint for UI and Flake8 for Python)
  • Unit Tests ( including a code coverage test report)
  • Accessibility Tests (Pa11y UI Only)
  • This code has been reviewed by someone other than the original author
  • The experience passes a basic manual accessibility audit (keyboard nav, screenreader, text scaling) OR an exemption is documented
  • The change has been documented
  • Associated OpenAPI documentation has been updated
  • Changelog is updated as appropriate

[DoD] This feature is done when...

  • Design has approved the experience
  • Product has approved the experience

carltonsmith and others added 30 commits October 1, 2020 13:40
…le, update mockstore in routes.test with requestAccess module, add requestAccess reducer and action
@@ -0,0 +1,38 @@
import {
Copy link
Author

Choose a reason for hiding this comment

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

This is the reducer for requestAccess which will set loading and requestAccess.

Copy link

@carltonsmith carltonsmith left a comment

Choose a reason for hiding this comment

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

Backend changes are looking good

@@ -1,15 +1,15 @@
import reducer from './stts'
import reducer from './sttList'
Copy link
Author

Choose a reason for hiding this comment

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

Just updating the name from stt to sttList

@carltonsmith carltonsmith added the raft review This issue is ready for raft review label Nov 5, 2020
@@ -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

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.

describe('actions/requestAccess.js', () => {
const mockStore = configureStore([thunk])

it('sends a PATCH request when requestAccess is called', async () => {

Choose a reason for hiding this comment

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

Update the frontend to reflect the different REST method for the set_profile end point



----
**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.

Comment on lines +74 to +79
if (requestAccessError) {
dispatch(
setAlert({ heading: requestAccessError.message, type: ALERT_ERROR })
)
}
dispatch(fetchSttList())
Copy link
Author

Choose a reason for hiding this comment

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

Realized that the user would not know if the request itself failed so adding in that logic and added the corresponding test below.

Copy link

@carltonsmith carltonsmith left a comment

Choose a reason for hiding this comment

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

I just had one question. After that this is ready to go.

@@ -38,6 +38,12 @@ export const fetchStts = () => async (dispatch) => {
})

if (data) {
data.forEach((item, i) => {
if (item.id === 57) {

Choose a reason for hiding this comment

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

@hilvitzs Are we sure this ID will remain constant in all environments?

@hilvitzs
Copy link
Author

hilvitzs commented Nov 9, 2020 via email

withCredentials: true,
})

instance.defaults.headers['X-CSRFToken'] = csrf

Choose a reason for hiding this comment

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

Due to an issue in production that was not present in our development environments, the csrf token was not available in the cookies like we were expecting them to be. We decided to deal with this by passing csrf with the auth request, since we expected it to be exposed to the client via a cookie any way, we believe this solution to be as secure as using a cookie.

if (user) {
dispatch({ type: SET_AUTH, payload: { user } })
} else {
dispatch({ type: CLEAR_AUTH })
}
// cookieJar.getCookies(URL, (err, cookies) => {

Choose a reason for hiding this comment

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

Should remove this commented code, we thought we could access the cookies via another route to fix the csrf issue, this turned out to not be true.

try {
const URL = `${process.env.REACT_APP_BACKEND_URL}/users/set_profile/`
const user = { first_name: firstName, last_name: lastName, stt: { id } }
const { data } = await (await utils.axiosInstance).patch(URL, user, {

Choose a reason for hiding this comment

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

We are using a custom axios client for these authenticated patch requests, we set the csrf token as a default value here, but not for the global axios client.

Comment on lines +15 to +17
axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.xsrfHeaderName = 'X-CSRFToken'
axios.defaults.withCredentials = true

Choose a reason for hiding this comment

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

I'm not sure we need these lines any more, now that we are getting csrf from auth_check

get axiosInstance() {
if (memo) return memo
memo = axios.create({
withCredentials: true,

Choose a reason for hiding this comment

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

We had some difficulty testing this, it could possibly be refactored, but we are delaying that to a future ticket since this works. We think it is possible the csrf issue is a configuration issue on the frontend ticket. The goal of adding this was to unblock the project while we pursued this

Copy link

@carltonsmith carltonsmith left a comment

Choose a reason for hiding this comment

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

This is ready to go

@carltonsmith carltonsmith linked an issue Nov 10, 2020 that may be closed by this pull request
18 tasks
@carltonsmith
Copy link

Closing and re-opening to re-run Snyk

riatzukiza pushed a commit that referenced this pull request Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
raft review This issue is ready for raft review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As a user, I can fill out and submit a form to create my profile.
3 participants