This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Require authentication for facility CSV downloads and log requests #697
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
082bc5a
Add DownloadLog model
jwalgran 5333470
Add API endpoint to log download requests
jwalgran 74a0763
Log facility CSV download request and prompt for auth
jwalgran fd9d226
Remove extraneous parentheses from index reducer
jwalgran 8227563
Update CHANGELOG
jwalgran File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createAction } from 'redux-act'; | ||
|
||
import apiRequest from '../util/apiRequest'; | ||
|
||
import { | ||
makeLogDownloadUrl, | ||
logErrorAndDispatchFailure, | ||
downloadFacilitiesCSV, | ||
} from '../util/util'; | ||
|
||
export const startLogDownload = | ||
createAction('START_LOG_DOWNLOAD'); | ||
export const failLogDownload = | ||
createAction('FAIL_LOG_DOWNLOAD'); | ||
export const completeLogDownload = | ||
createAction('COMPLETE_LOG_DOWNLOAD'); | ||
|
||
export function logDownload() { | ||
return (dispatch, getState) => { | ||
dispatch(startLogDownload()); | ||
|
||
const { | ||
facilities: { | ||
facilities: { | ||
data: { | ||
features: facilities, | ||
}, | ||
}, | ||
}, | ||
} = getState(); | ||
|
||
const path = `${window.location.pathname}${window.location.search}${window.location.hash}`; | ||
const recordCount = facilities ? facilities.length : 0; | ||
return apiRequest | ||
.post(makeLogDownloadUrl(path, recordCount)) | ||
.then(() => downloadFacilitiesCSV(facilities)) | ||
.then(() => dispatch(completeLogDownload())) | ||
.catch(err => dispatch(logErrorAndDispatchFailure( | ||
err, | ||
'An error prevented the download', | ||
failLogDownload, | ||
))); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { createReducer } from 'redux-act'; | ||
import update from 'immutability-helper'; | ||
|
||
import { | ||
startLogDownload, | ||
failLogDownload, | ||
completeLogDownload, | ||
} from '../actions/logDownload'; | ||
|
||
const initialState = Object.freeze({ | ||
fetching: false, | ||
error: null, | ||
}); | ||
|
||
export default createReducer({ | ||
[startLogDownload]: state => update(state, { | ||
fetching: { $set: true }, | ||
error: { $set: initialState.error }, | ||
}), | ||
[failLogDownload]: (state, payload) => update(state, { | ||
fetching: { $set: false }, | ||
error: { $set: payload }, | ||
}), | ||
[completeLogDownload]: state => update(state, { | ||
fetching: { $set: false }, | ||
error: { $set: initialState.error }, | ||
}), | ||
}, initialState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 2.2.3 on 2019-07-19 22:14 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0027_merge_20190716_2207'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='DownloadLog', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('path', models.CharField(help_text='The requested resource path', max_length=2083)), | ||
('record_count', models.IntegerField(help_text='The number of records in the downloaded file')), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('user', models.ForeignKey(help_text='The User account that made the request', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 2083 a maximum value for paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a well researched StackOverflow answer that contributed to this choice of maximum value
https://stackoverflow.com/a/417184
In summary, URLs larger than this bump into some limits in browsers and search crawling infrastructure so it is a reasonable maximum value.