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
Add foreign key constraint handler flow in app #9507
Comments
This should be a duplicate of #9365, and was fixed in #9305, however it was then removed in #9425 due to issue with MSSQL as seen in the discussion under that PR. This should be the current remaining effects of that PR: #9365 (comment), which still doesn't address your issue here. Since it wasn't technically solved, I'll keep this open for now. @rijkvanzanten thoughts on this particular scenario? 🤔 |
Good question. This is technically working as expected. There's a foreign key constraint from files to users (in uploaded_by and modified_by) that makes sure you can't have invalid users stored in those columns. We tried setting those to SET NULL on deletion of the user (which would prevent the OP from showing up), however you're not allowed to have > 1 foreign key constraint triggers to the same related collection in certain databases 🤔 The ideal solution here would be to:
|
Does not make any sense at all. You should be able to delete anything you want and leave anything you like, even if it is user's files. This is a valid business scenario to delete user and leave his files. |
@andriusign — Did you read the response by Rijk? That is exactly what he is recommending by saying:
|
Well that only applies if you use the app, but if you use API, then there is no dialog, just a call to back-end. How would this then work? |
@andriusign At that point, it's up to whatever uses the API to resolve the constraint before continuing the original operation, which is exactly what the app would do as well |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Linear: ENG-288 |
Is there a workaround to prevent relating users to files? In terms of GDPR we are not allowed to store user data longer than actually needed. What is a good solution for now? |
Hmm, you might be able to clear out the |
Thanks! |
Oh yeah, that might work as well. There's a |
I have written this extension: // index.js
export default ({ filter }, { services, getSchema }) => {
const { FilesService } = services;
filter("users.delete", async (input, meta, context) => {
const usersToDelete = input;
const {
accountability: { user },
} = context;
const filesService = new FilesService({
...context,
schema: await getSchema(),
});
await filesService.updateByQuery(
{ filter: { uploaded_by: { _in: usersToDelete } } },
{ uploaded_by: user }
);
await filesService.updateByQuery(
{ filter: { modified_by: { _in: usersToDelete } } },
{ modified_by: user }
);
return input;
});
}; Feel free to use it as a workaround, as long as there is no better solution for this ;) What it does, is to replace all user ids in What do you think? |
Looks good! Thanks for reporting back 👍 |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
Hey @rijkvanzanten 👋🏼 Thanks for the quick answer and sorry about some details missing in my message above. I think it is related actually by checking Directus logs.
|
Hi all! Is this still being looked into? I'm having the same issue... I have to manually delete the uploaded files from that particular user before I can delete the user itself... |
Yup! This is an Open Issue, so something we aim to resolve at some point 👍🏻 |
Hello! For anyone wondering how to solve this issue using Flows without needing to do any changes in source code of Directus, here you go: Basically, you create a flow which hooks into the delete user event and handles modified_by and uploaded_by file attributes before deleting the user.
|
Hello, I have an issue when trying to remove user that is no longer part of a company, but can't as it has created some resources. It is a security issue, so was wondering if this is going to be picked up anytime soon? |
Preflight Checklist
Describe the Bug
An error occurs when trying to delete user that have uploaded files to media library.
To Reproduce
Errors Shown
What version of Directus are you using?
v9.0.0
What version of Node.js are you using?
v16.13.0
What database are you using?
Postgres 13
What browser are you using?
Chrome
What operating system are you using?
Linux
How are you deploying Directus?
locally (dev)
The text was updated successfully, but these errors were encountered: