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

fix(server): fixed illegal removal of unowned trigger #965

Merged
merged 1 commit into from
Mar 25, 2023

Conversation

maslow
Copy link
Member

@maslow maslow commented Mar 25, 2023

No description provided.

return ResponseUtil.error('Trigger not found')
}

const res = await this.triggerService.remove(appid, id)
return ResponseUtil.ok(res)
}
}
Copy link

Choose a reason for hiding this comment

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

with a brief code review

This patch seems to be making sure that the trigger exists before it is removed.
First, it checks if the trigger exists by querying the trigger service with the given appid and id.
If the trigger is not found, it returns an error response.
Otherwise, it calls the trigger service remove method with the given appid and id.
It then returns an ok response.

No obvious bugs are visible in this patch, but there are some potential improvements that could be made.
First, it might be a good idea to check that the user has the necessary permissions to delete the trigger before proceeding.
Second, the code should be refactored to make sure that it adheres to the Single Responsibility Principle (SRP) and follows other best practices.
Finally, appropriate logging should be added to track when triggers are deleted.

@maslow maslow merged commit 260b335 into labring:main Mar 25, 2023
where: { id },
async remove(appid: string, id: string) {
const res = await this.prisma.cronTrigger.updateMany({
where: { id, appid },
data: {
state: TriggerState.Deleted,
},
Copy link

Choose a reason for hiding this comment

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

with the code review:

  1. It looks like the findOne and findAll methods have been modified to include additional parameters: appid and state (in the findAll method). This should help to ensure that only valid and active triggers are retrieved.

  2. The remove method has also been modified to include an additional parameter - appid - which should help to ensure that only triggers belonging to the specified appid are removed.

  3. The code is generally well written and adheres to coding standards. However, it could be improved to make it more efficient and readable. For example, the parameters for the various methods could be grouped together in an object, making them easier to read and maintain.

  4. Additionally, some error handling could be added to the methods to ensure that errors are properly handled in case of any unexpected issues.

@maslow maslow deleted the fix-trigger-perm branch March 25, 2023 16:33
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.

1 participant