Skip to content

Fix/plat 2584 #610

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

Merged
merged 6 commits into from
Apr 3, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2281,22 +2281,27 @@ function sanitizeData(data, challenge) {
* @returns {Object} the deleted challenge
*/
async function deleteChallenge(currentUser, challengeId) {
const challenge = await challengeDomain.lookup(getLookupCriteria("id", challengeId));
if (challenge.status !== constants.challengeStatuses.New) {
throw new errors.BadRequestError(
`Challenge with status other than "${constants.challengeStatuses.New}" cannot be removed`
);
const { items } = await challengeDomain.scan({
criteria: getScanCriteria({ id: challengeId, status: constants.challengeStatuses.New }),
});
const challenge = _.first(items);
if (!challenge) {
throw new errors.NotFoundError(`Challenge with id: ${challengeId} doesn't exist or is not in New status`);
}
// check groups authorization
await ensureAccessibleByGroupsAccess(currentUser, challenge);
// check if user are allowed to delete the challenge
await ensureAccessibleForChallenge(currentUser, challenge);
// delete DB record
await challengeDomain.delete(getLookupCriteria("id", challengeId));
const { items: deletedItems } = await challengeDomain.delete(getLookupCriteria("id", challengeId));
if (!_.find(deletedItems, { id: challengeId })) {
throw new errors.Internal(`There was an error deleting the challenge with id: ${challengeId} from dynamo`);
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to specifically mention dynamo. Just that there was an error deleting the challenge with id ${challengeId} is fine.

}
// delete ES document
await esClient.delete({
index: config.get("ES.ES_INDEX"),
refresh: config.get("ES.ES_REFRESH"),
type: config.get("ES.OPENSEARCH") == "false" ? config.get("ES.ES_TYPE") : undefined,
id: challengeId,
});
await helper.postBusEvent(constants.Topics.ChallengeDeleted, {
Expand Down