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

Log changes to Web User Invitations #35744

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

minhaminha
Copy link
Contributor

Technical Summary

Jira Ticket
Brief tech spec

With the introduction of editable web user invites, we now have a need to additionally log changes made to these invites. This PR add logs for creating, editing and deleting invitations via the UI (in the Web User page) or through the Invitation creation API (currently there is no way to edit or delete invites using the API).

The new InvitationHistory logging class is a stripped down version of the currently existing UserHistory logging class with 2 big differences: the user_id is an optional field because invites can be made for user that haven't registered yet and the changes field combines the changes and change_message field into one dict/field.

Safety Assurance

Safety story

Tested locally and on staging to verify the logs contain the info I expect it to.

Automated test coverage

QA Plan

Migrations

  • The migrations in this code can be safely applied first independently of the code

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Will have to roll back the migration first!

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@minhaminha minhaminha added the product/invisible Change has no end-user visible impact label Feb 6, 2025
@minhaminha minhaminha requested a review from esoergel as a code owner February 6, 2025 18:16
@dimagimon dimagimon added reindex/migration Reindex or migration will be required during or before deploy Risk: High Change affects files that have been flagged as high risk. labels Feb 6, 2025
@dimagimon dimagimon added the Risk: Medium Change affects files that have been flagged as medium risk. label Feb 7, 2025
:param changed_by: user_id of the invitee or the invitation editor
:param changed_via: INVITATION_CHANGED_VIA_* const (for now just web or api)
:param action: CREATE, UPDATE or DELETE
:param invite: the Invitation object itself. defaults to None for DELETE actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Does that mean we drop the invite from the DB when deleting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep deleted in web.py

@@ -1315,6 +1342,55 @@ def _get_sql_locations(self, primary_location_id, assigned_location_ids):
if assigned_location_id is not None]
return primary_location, assigned_locations

def _get_and_set_changes(self, invite, form_data, profile):
change_values = [None] * 5
Copy link
Contributor

Choose a reason for hiding this comment

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

🤞 nothings breaks in the future because somebody changes the order here but not in _format_changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point! I can change this to a dict

invitation.custom_user_data = data.get("custom_user_data", {})

invitation.role = data.get("role")
invitation.program = data.get("program", None)
invitation.tableau_role = data.get("tableau_role", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason we don't care about tracking changes to the tableau settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For user changes these aren't logged (maybe because they're logged directly in tableau?) but really, in my hastiness (and inability to test it locally) I totally forgot to include those. I'll add those as keys to the final changes dict, if there are any changes from the values stored in the Invitation

domain=domain,
user_id=user.user_id if user else None,
changed_by=request.couch_user.user_id,
changed_via=INVITATION_CHANGE_VIA_WEB,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this not also called via the API?

Copy link
Contributor

Choose a reason for hiding this comment

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

or is there not delete API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None of the documentation/API change PRs I've looked at say we currently support deleting invites through the API but happy to be proven wrong!!

@minhaminha
Copy link
Contributor Author

Sorry yall I'm doing a little more refactoring to contain the logging instances within the Invitation class's create/delete/save methods - might be a bit messy until then

… created via bulk upload + log changes to tableau related fields + minor changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product/invisible Change has no end-user visible impact reindex/migration Reindex or migration will be required during or before deploy Risk: High Change affects files that have been flagged as high risk. Risk: Medium Change affects files that have been flagged as medium risk.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants