-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add temporary API to replace enabled/disabled lists #1789
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
Open
tathagat2241
wants to merge
1
commit into
main
Choose a base branch
from
temporary-replace-enabled-disabled-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,6 +251,92 @@ function ConfigurationController(ctx) { | |
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Replaces enabled/disabled lists for a handler. | ||
| * This is a temporary API that replaces (not merges) the provided arrays. | ||
| * | ||
| * TEMPORARY API: This endpoint was created to clean up enabled and disabled lists | ||
| * by removing unnecessary site IDs. Unlike the existing updateHandler endpoint | ||
| * which merges arrays, this endpoint completely replaces the specified arrays. | ||
| * This API will be removed once the cleanup task is completed. | ||
| * | ||
| * @param {UniversalContext} context - Context of the request. | ||
| * @return {Promise<Response>} Updated configuration response. | ||
| */ | ||
| /* c8 ignore start - temporary API, no unit tests needed */ | ||
| const replaceHandlerEnabledDisabled = async (context) => { | ||
| if (!accessControlUtil.hasAdminAccess()) { | ||
| return forbidden('Only admins can update handler configuration'); | ||
| } | ||
|
|
||
| const { handlerType } = context.params; | ||
| const { data } = context; | ||
|
|
||
| if (!hasText(handlerType)) { | ||
| return badRequest('Handler type is required'); | ||
| } | ||
|
|
||
| if (!isNonEmptyObject(data)) { | ||
| return badRequest('Request body is required and cannot be empty'); | ||
| } | ||
|
|
||
| // Validate that at least one of enabled or disabled is provided | ||
| const hasEnabled = data.enabled !== undefined; | ||
| const hasDisabled = data.disabled !== undefined; | ||
|
|
||
| if (!hasEnabled && !hasDisabled) { | ||
| return badRequest('At least one of enabled or disabled must be provided'); | ||
| } | ||
|
|
||
| // Validate that at least one array is provided within enabled/disabled | ||
| // (empty arrays are allowed) | ||
| if (hasEnabled) { | ||
| const hasEnabledSites = data.enabled.sites !== undefined; | ||
| const hasEnabledOrgs = data.enabled.orgs !== undefined; | ||
| if (!hasEnabledSites && !hasEnabledOrgs) { | ||
| return badRequest('At least one of enabled.sites or enabled.orgs must be provided'); | ||
| } | ||
| // Validate that if provided, they must be arrays | ||
| if (hasEnabledSites && !Array.isArray(data.enabled.sites)) { | ||
| return badRequest('enabled.sites must be an array'); | ||
| } | ||
| if (hasEnabledOrgs && !Array.isArray(data.enabled.orgs)) { | ||
| return badRequest('enabled.orgs must be an array'); | ||
| } | ||
| } | ||
|
|
||
| if (hasDisabled) { | ||
| const hasDisabledSites = data.disabled.sites !== undefined; | ||
| const hasDisabledOrgs = data.disabled.orgs !== undefined; | ||
| if (!hasDisabledSites && !hasDisabledOrgs) { | ||
| return badRequest('At least one of disabled.sites or disabled.orgs must be provided'); | ||
| } | ||
| // Validate that if provided, they must be arrays | ||
| if (hasDisabledSites && !Array.isArray(data.disabled.sites)) { | ||
| return badRequest('disabled.sites must be an array'); | ||
| } | ||
| if (hasDisabledOrgs && !Array.isArray(data.disabled.orgs)) { | ||
| return badRequest('disabled.orgs must be an array'); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be we can simplify the checks like |
||
|
|
||
| try { | ||
| const configuration = await Configuration.findLatest(); | ||
| if (!configuration) { | ||
| return notFound('Configuration not found'); | ||
| } | ||
|
|
||
| configuration.replaceHandlerEnabledDisabled(handlerType, data); | ||
| setUpdatedBy(configuration, context); | ||
| await configuration.save(); | ||
|
|
||
| return ok(ConfigurationDto.toJSON(configuration)); | ||
| } catch (error) { | ||
| return badRequest(error.message); | ||
| } | ||
| }; | ||
| /* c8 ignore stop */ | ||
|
|
||
| /** | ||
| * Updates the entire configuration or specific sections. | ||
| * Allows updating handlers, jobs, and/or queues in a single request. | ||
|
|
@@ -362,6 +448,7 @@ function ConfigurationController(ctx) { | |
| updateQueues, | ||
| updateJob, | ||
| updateHandler, | ||
| replaceHandlerEnabledDisabled, | ||
| updateConfiguration, | ||
| restoreVersion, | ||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if its temporary better to have unit tests to check the contract and avoid unexpected destructions.