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

RN-423: Add 'Sync Groups' to the Admin Panel (kobo sync link part 1) #4088

Merged
merged 15 commits into from
Aug 23, 2022

Conversation

rohan-bes
Copy link
Collaborator

Issue RN-423:

In this PR, we've added 'Sync Groups' to the Admin Panel. This is where the user can configure the mapping between Tupaia<->Kobo in the Config section.

The mapping is just a JSON configuration which we accept for now is good enough for the user.

Subsequent PRs will add the functionality to view the Sync Group logs, and perform manual syncs via the Admin Panel, which should help the end user test out configuring a new Sync Group.

All credit to @IgorNadj on this one, I'm just ferrying it over.

const syncGroupChecker = accessPolicy =>
assertSyncGroupEditPermissions(accessPolicy, this.models, this.recordId);

await this.assertPermissions(assertAnyPermissions([assertBESAdminAccess, syncGroupChecker]));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We may need to consider how to change this permission check... I suspect there will be some lesmis users who want to configure the sync group but don't have BES Admin...

Copy link
Contributor

@IgorNadj IgorNadj left a comment

Choose a reason for hiding this comment

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

Reviewed by Rohan in #4015, I had a look as well still looks good

`DROP TRIGGER IF EXISTS data_service_sync_group_trigger ON data_service_sync_group`,
);

await db.runSql(`ALTER TABLE data_service_sync_group RENAME COLUMN code TO data_group_code`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I don't understand how this works. We can't change code here without updating DataBroker.

https://github.com/beyondessential/tupaia/blob/dev/packages/data-broker/src/DataBroker.js#L82

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah honestly I found this rename a bit confusing as well.
It seems like a dssg has a data_group_code which corresponds to a survey code in Tupaia. But should the syncGroupCode in the config actually just be the code of this dssg? I made that mistake a couple times when writing logic around this, as it seems really weird to me that dssg's don't have a code of their own atm...

I'd suggest changing so that:

current:
id  |  data_group_code | service_type |         config             | sync_cursor
-----------------------------------------------------------------------------------
123 |    LEMIS_FQS1    |      kobo    | { syncGroupCode: FQS1, ...} | 10-10-2020

becomes:
id  | code |  data_group_code | service_type | config | sync_cursor
------------------------------------------------------------------------
123 | FQS1 |     LEMIS_FQS1   |      kobo    | { ...} | 10-10-2020

Then when pulling from data-broker, you do:

const koboData = await dataBroker.pull(
  {
    code: 'FQS1',
    type: 'SYNC_GROUP',
  }
);

Thoughts?

You could possibly argue that the koboSurveyCode (which exists in the config) should also have its own column, but I think given that this table is meant to be agnostic in regards to the service_type its appropriate for it to be in the config.

Copy link
Collaborator Author

@rohan-bes rohan-bes Aug 18, 2022

Choose a reason for hiding this comment

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

Also, just wanted to flag a slight concern I have around how often we rely on pseudo foriegn key relationships. Here the data_group_code must correspond to a data_group code. But we don't enforce that in any way via foreign key constraints. It's quiet common for us to do this in Tupaia, but it always feels a bit risky to me... Do you think I ought to add a constraint here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed, like the code column, FK not necessary but worth a chat in the future.

data_group_code = trim(both '"' from config->>'internalSurveyCode'),
code = trim(both '"' from config->>'internalSurveyCode'),
config = (config || jsonb_build_object('syncGroupCode', code)) - 'internalSurveyCode'
`);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@IgorNadj reworked this as discussed.

Note: the kobo sync logic won't actually work right now (due to a mismatch between the code in the sync_group table's config column and the current values) however that will be fixed up in the pt2 PR

Copy link
Contributor

@IgorNadj IgorNadj left a comment

Choose a reason for hiding this comment

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

LGTM!

@rohan-bes rohan-bes force-pushed the rn-423-kobo-sync-link-p1 branch from 81215d5 to dca2df8 Compare August 21, 2022 23:37
@rohan-bes rohan-bes enabled auto-merge (squash) August 23, 2022 06:36
@rohan-bes rohan-bes merged commit af994f7 into dev Aug 23, 2022
@rohan-bes rohan-bes deleted the rn-423-kobo-sync-link-p1 branch August 23, 2022 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants