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

feat(projectHistoryLogs): record project history logs for imports TASK-944 #5230

Merged
merged 17 commits into from
Nov 12, 2024

Conversation

rgraber
Copy link
Contributor

@rgraber rgraber commented Nov 6, 2024

📣 Summary

Record every time a user replaces the form on a survey via an import

👀 Preview steps

  1. ℹ️ Create a survey called MyProject
  2. Go to Form -> ... -> Download XLS and save the file as 'MyProject.xls'
  3. Download
    XLSForm_Settings.xlsx
  4. Go to Form and click the 'Replace Form' icon
  5. Select Upload an XLS form and upload MyProject.xls
  6. Go to api/v2/audit-logs/?q=metadata__asset_uid:<asset uid> AND log_type='project-history'
  7. 🟢 There should a log with the action replace-form (order doesn't matter) and the usual metadata plus latest_version_uid.
  8. Click Replace Form again and upload XLSForm_Settings.xlsx. This should change the title of the project.
  9. Reload the endpoint
  10. 🟢 Reload the endpoint. There should be two new logs, one with action=update-name and the other with action=replace-form (order doesn't matter). The log metadata should have all the information as the previous one. The update-name log should additionally have
'name': {
   'old': <oldname>,
   'new': 'Sample Settings Form',
}
  1. Upload MyProject.xls to Google Drive and open in Google Sheets
  2. Go to File -> Share -> Publish to Web and publish as xlsx (entire document). Copy the link.
  3. Back in KoboToolbox, replace the from again and select Import an XLS from via URL
  4. Paste the Google Drive url and import
  5. 🟢 Reload the endpoint. There should be a new replace-form log and a new update-name log.

💭 Notes

Several things in this PR

  1. Pass ip address and source details from ImportTaskView to the task
  2. Update ImportTask._run_task to record details about the asset being updated in the messages field
  3. Update import_in_background to return the uid of the task, which will be sent as result in the task_success signal
  4. Add a signal receiver for task_success that fetches the ImportTask from the uid and calls a new method in ProjectHistoryLog to create a log (or several) from it
  5. Add a new method in ProjectHistoryLog that creates a replace-form log and possibly an update-name log if the name was changed by the import
  6. Extra change: add log_subtype to the fields validated in _check_common_metadata
  7. Extra change: change the questions in the asset_with_settings_and_qa fixture to make it easier to distinguish from other assets

The unit tests are a little redundant, but they are meant to check slightly different things. The ones in test_project_history_logs test the whole flow. The ones in test_models test that we know how to make logs from import tasks after they run. The ones in test_api_imports check that the import tasks are storing the correct information.

Copy link

@rgraber rgraber changed the base branch from main to rsgraber/TASK-944-rest-service-changes November 6, 2024 15:48
Base automatically changed from rsgraber/TASK-944-rest-service-changes to main November 6, 2024 15:49
@rgraber rgraber changed the title feat(projectHistoryLogs): Record imports feat(projectHistoryLogs): record project history logs for imports TASK-944 Nov 6, 2024
@rgraber rgraber force-pushed the rsgraber/TASK-944-log-imports branch from 811a639 to faee2d1 Compare November 7, 2024 13:40
@rgraber rgraber self-assigned this Nov 7, 2024
@rgraber rgraber requested a review from Guitlle November 7, 2024 15:19
@rgraber rgraber marked this pull request as ready for review November 7, 2024 15:19
@rgraber rgraber marked this pull request as draft November 7, 2024 19:14
@rgraber rgraber force-pushed the rsgraber/TASK-944-log-imports branch from b71ddbf to 47cf3c2 Compare November 7, 2024 20:10
@rgraber rgraber changed the base branch from main to rsgraber/TASK-944-include-v1 November 7, 2024 20:11
Base automatically changed from rsgraber/TASK-944-include-v1 to main November 8, 2024 13:26
@rgraber rgraber marked this pull request as ready for review November 8, 2024 17:00
@rgraber rgraber merged commit 7b744e3 into main Nov 12, 2024
7 checks passed
@rgraber rgraber deleted the rsgraber/TASK-944-log-imports branch November 12, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants