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

Feature/add remove and recursive options #67

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

Conversation

idelcano
Copy link
Contributor

@idelcano idelcano commented Mar 5, 2019

📌 References

🎩 What is the goal?

  • Create a recursive method
  • Make possible to remove objects
  • Make possible to remove ids
  • Fix replace ids using the recursive method
  • Make possible to replace objects using a recursive method

📝 How is it being implemented?

  • I have created a recursive method to apply changes in all the JSON tree.

  • I have fixed a codification problem with json.dumps.

  • I have added remove objects by id option using the recursive method.

  • I have added some new params:
    --remove-objects param to remove provided objects.
    --remove-ids to remove the objects with the provided id.
    -r --recursive to apply actions recursively.

💥 How can it be tested?

Zip with all the example files
usecase.zip

  • Use case 1: - Replace ids

change_user_groups.py -i dashboards.json -o output.json -uga TOREMOVE.json --replace-ids aMwDgrza9xU newuid --apply-to-objects eventCharts charts dashboards reports

All the aMwDgrza9xU id must have been changed by newuid.

  • Use case 2: - Remove objects by ids

change_user_groups.py -i usecase/dashboards.json -o usecase/output.json -uga usecase/TOREMOVE.json --remove-ids aMwDgrza9xU --apply-to-objects eventCharts charts dashboards reports

All the objects with aMwDgrza9xU as id must have been removed from the output file.

  • Use case 3: - Replace objects using a JSON file

change_user_groups.py -i dashboards.json -o output.json -Uga TOREPLACE.json --replace-objects userGroupAccesses --apply-to-objects eventCharts charts dashboards reports

The usergroupaccesses lists inside of the root items must have been replaced by the TOREPLACE.json content.

  • Use case 4: - Replace objects using the recursive method

change_user_groups.py -i dashboards.json -o output.json -uga TOREPLACE.json --replace-objects userGroupAccesses --apply-to-objects eventCharts charts dashboards reports -r

All the usergroupsaccesses lists must have been replaced by the TOREPLACE.json content.

  • Use case 5: - Remove objects using a JSON file

change_user_groups.py -i dashboards.json -o output.json -Uga TOREMOVE.json --remove-objects userGroupAccesses --apply-to-objects eventCharts charts dashboards reports

All the toremove.json usergroups must have been removed from the output.

  • Use case 6: - Remove objects using a JSON file and recursive mode

change_user_groups.py -i dashboards.json -o output.json -uga TOREPLACE.json --remove-objects userGroupAccesses --apply-to-objects eventCharts charts dashboards reports -r

All the usergroupsaccesses lists must have been replaced by the TOREPLACE.json content.

@idelcano idelcano requested a review from ifoche March 5, 2019 09:33
Copy link
Member

@ifoche ifoche left a comment

Choose a reason for hiding this comment

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

@idelcano some comments when testing the different use cases that you suggested, so you can check and let me know if that was the behaviour you were expecting

  • UseCase 1 - It is replacing the userGroupAccesses object by the one in usecase/TOREMOVE.json for the objects provided in the --apply-to-objects changing the id provided in the --replace-ids param
  • UseCase 2 - It is replacing the userGroupAccesses object by the one in usecase/TOREMOVE.json for the objects provided in the --apply-to-objects entirely removing the object whose id's been provided in the --remove-ids param. The problem is that it generates a malformed json, because reference is just removed leaving the entry malformed when there's only one element (e.g. "chart": "a0lFsy4ZXTx" is changed by "chart":
  • UseCase 3 - It is replacing the userGroupAccesses object by the one in usecase/TOREPLACE.json for the objects provided in the --apply-to-objects
  • UseCase 4 - It's doing exactly the same as 3 (but recursively)
  • UseCase 5 - It's doing exactly the same as 2 but for the object elimination
  • UseCase 6 - It's doing exactly the same as 4 (recursively)

So, in a nutshell, I see an error to fix when removing references to objects if the reference is the only element inside its list of references, and I cannot see the difference between remove and replace in the command actions.

@idelcano
Copy link
Contributor Author

@ifoche I rethink some commands to make it easier.

  • UseCase 1 - Yes, but simplest:

-i dashboards.json -o output.json --replace-ids aMwDgrza9xU newuid --apply-to-objects eventCharts charts dashboards reports --replace-objects none

The script will change the aMwDgrza9xU to newuid in the objects eventCharts charts dashboards reports.

Adding replace-objects none the script ignore the default options (publicAccess, userAccesses, userGroupAccesses).

  • UseCase 2 - This works for me removing the entire objects ({charts:"uid"} to {})

Using:
-i usecase/dashboards.json -o usecase/output.json --remove-ids aMwDgrza9xU --apply-to-objects eventCharts charts dashboards reports --replace-objects none

You can check that the report with "aMwDgrza9xU" id is removed

  • UseCase 3 / UseCase 4 / UseCase 5 / Usecase 6- yes to everything.

Some parameters are a bit confusing, I'll explain:

--replace-objects list:
They are the objects that are going to be replaced, publicaccess, useraccess, usergroupaccesses.
--remove-object list:
They are the objects that are going to be replaced, eliminating the objects contained in the files for publicaccess, user-access, user-group-accesses.
For example, if we only put public-access when the public-access do match, it will be erased ignoring the user-access and user-group-access
--apply-to-objects list:
They are the objects that are going to be treated (at first level), dataElements, dataSets, etc.

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.

Add remove and recursive option to change_user_groups script
2 participants