Skip to content

Removing purge.js file from project config root does not remove the purge settings #642

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

Closed
sugat009 opened this issue Nov 12, 2024 · 14 comments · Fixed by #676
Closed

Removing purge.js file from project config root does not remove the purge settings #642

sugat009 opened this issue Nov 12, 2024 · 14 comments · Fixed by #676
Assignees
Labels
released Type: Bug Fix something that isn't working as intended

Comments

@sugat009
Copy link
Member

Describe the bug
The way to add purging to a project is to add a purge.js file to the project config root as per the docs. So, naturally, to remove purging from a project, a user would think that removing purge.js would be the way to do so, but it doesn't work. If you empty the purge.js file, it creates an empty object in the purge key of the settings JSON file but it's not ideal to have an empty object even in the database.

To Reproduce
Steps to reproduce the behavior:

  1. Create a purge.js file and add your purge logic
  2. Run the command cht compile-app-settings
  3. Check the app_settings.json file. A new key purge should have been minified created with the content from the purge.js.
  4. Delete or move or rename the purge.js file.
  5. Run the command cht-compile-app-settings
  6. Check the app_settings.json file. The purge key still exists.

Expected behavior
When I delete or move or rename the purge.js file from the root of the project config, the settings should also remove the purge key from the JSON file.

Logs
If applicable, include the cht-conf output, server logs, and/or browser logs.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment

  • Instance: Local
  • Client platform: Linux
  • cht-conf version: 4.1.1
  • cht-core version: N/A

Additional context
Add any other context about the problem here. What have you tried? Is there a workaround?

@sugat009 sugat009 added the Type: Bug Fix something that isn't working as intended label Nov 12, 2024
@sugat009 sugat009 changed the title Removing purge.js from project config root does not remove the purge settings Removing purge.js file from project config root does not remove the purge settings Nov 12, 2024
@rishabhr4
Copy link
Contributor

hi @sugat009 i have solved the issue locally but i have a question regarding raising a pr specifically for this issue
is there any slack/discord channel where we can discuss ?

@sugat009
Copy link
Member Author

That's incredible @rishabhr4 . We keep everything as open and public as possible. We can discuss this here if needed and we also have a forum: https://forum.communityhealthtoolkit.org/

@rishabhr4
Copy link
Contributor

ok so purging logic is present in /test/data/compile-app-settings/base-settings
i have rewritten the logic there only with some modifications and fixed the error so it works as expected as described in the issue
so i should keep it there or move the purgin logic to root directory

@sugat009
Copy link
Member Author

I believe there might be some confusion. The logic for data purging is defined in the purge.js file, which is situated in the base_settings directory. The cht-conf tool then compiles this file, resulting in its minified version within the app_settings.json file. This compilation is handled by the compile-app-settings action, here. The resulting app_settings.json file then, is uploaded to the CHT Core server using cht-conf tool with upload-app-settings action. Then, the server knows which documents to purge based on the logic in purge key in the app_settings.json.

Please note that the files you referenced are test files. To achieve the existing behavior, you will need to edit the logic within this file:

const purgeConfig = parsePurge(projectDir);
.

@rishabhr4
Copy link
Contributor

rishabhr4 commented Mar 28, 2025

ok on investigating i found out this issue arises when there is no base_settings.json file present in app_settings folder in the root directory
if it exists it works as expected

@rishabhr4
Copy link
Contributor

hi @sugat009
i tried adding errors then baseSettingsPath doesn't exist
but even then errors are not being thrown
am i missing something ?
sorry for asking too much doubts

@sugat009
Copy link
Member Author

sugat009 commented Mar 30, 2025

@rishabhr4 I think you are deviating from this task. I'll give you some more details.

A project in this context is a collection of configurations. For eg:

project
├── forms.json
└── schedules.json

Here, project is the folder that contains files app_settings.json, forms.json, and schedules.json. This is a minimal example, for a more detailed sample check this.

If you run this tool(cht-conf) from within the project folder, it will generate a file called app_settings.json which will contain the minified version of the settings data that is to be uploaded to the CHT server. For more info on app_settings.json.

Now, after all, this is set up. Try doing the recreation steps from the details of this ticket. The purge.js file needs to be created inside the project folder.

NOTE: project folder does not necessarily have to be inside the folder where this repo is cloned in your machine but it is easier to have it there.

@rishabhr4
Copy link
Contributor

thank you for the help

@sugat009
Copy link
Member Author

sugat009 commented Apr 8, 2025

hello @rishabhr4 , any updates on this?

@rishabhr4
Copy link
Contributor

sorry @sugat009 i have my exams going on which will be finishing this week
i have understood the issue and will try to make a pr this weekend

@rishabhr4
Copy link
Contributor

rishabhr4 commented Apr 9, 2025

Image Image

hello @sugat009 i created the new folder and tried to worked on the issue
but it was working perfectly fine for me when i renamed the purge.js to xx.js the app_setting.json removed the purge key
i have attached the screenshots for your reference

@sugat009
Copy link
Member Author

sugat009 commented Apr 9, 2025

Thanks for investigating this @rishabhr4 and awesome finding. We now know that this does not happen when the project config structure has the base_settings.json within the app_settings directory. Given that the base_settings.json file does not have a purge setting.

However, there is another way of configuring a project as well, (and my bad for now mentioning this above anywhere). A app_settings.json file can directly be created in the project root folder without the app_settings folder. The issue exists in that particular case. I've added a video to make it clearer.

In the video, I'm running the cht-conf commands in the cht-core repo's default config folder.

2025-04-09.22-05-24.mp4

@rishabhr4
Copy link
Contributor

hi @sugat009 please review the pr thanks for the support , help and patience.

@medic-ci
Copy link
Collaborator

🎉 This issue has been resolved in version 4.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Type: Bug Fix something that isn't working as intended
Projects
Status: 🚀 Done
3 participants