-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Setting multiple field presets for role not working #10782
Comments
I suppose that this issue #10576 and the related commited might be the reason why now it works in some incorrect way |
Hmm #10576 should just be concerning the App, not the API (when you are creating item with presets), so I believe it's not really related to it. Seems like rather than that commit causing issue, it's more so it didn't resolve this completely, since the directus/api/src/utils/get-permissions.ts Line 197 in 78ba634
Definitely an oversight. I've just tested removing that line and your issue will be resolved 👍 That said, removing the parsing flat out will remove the possibility of using dynamic variables instead as stated here, so we'll probably need to tackle that aspect together when fixing this. Perhaps an offshoot of parseFilter, maybe |
@azrikahar Yeah agreed on that. We should extract the logic that handles the actual replacement of those variables though, so we can re-use it between the two functions 👍🏻 |
I believe Directus need a lot more new unit tests to make sure that we won't see bug regressions. Unit tests will ensure that things that work will stay working, after new code are added and there are accidental oversights. Without unit tests, things will randomly break here and there. |
We agree! We're actively working on tests... but it's slow going with our small team. We'd love an extra set of hands if you're interested in contributing! |
@rijkvanzanten no way around that at the moment? Right now users created don't get the right role added, so they don't get the right privileges which is quite a problem for a user based project 🤓 |
This comment has been minimized.
This comment has been minimized.
We were able to work around that issue, because our use case is rather simple: In our case (when a user registers =public role, then the user should be assigned to the role "Customer") we were able to overcome this issue by creating a custom Hook on Example:
module.exports = function registerHooks({action}, {services, exceptions}) {
const {UsersService} = services;
action('users.create', async ({payload}, {schema}) => {
// public role tries to create user and no payload role is set - set default role
if (!context.accountability.role && !input.payload.role) {
...
console.log('Setting role for ' + payload.email + ' to default role');
const userService = new UsersService({schema: schema});
await userService.updateOne(input.key, {
'role': '<your-role-id-here>'
});
...
}
});
}; In this case we just assign a defaultRole, if no role was specified. |
Preflight Checklist
Describe the Bug
I am trying to make something kind of register. So I gave custom create permissions for the public role on directus_users collection. But when trying to set multiple field presets it's not working. I'm setting the field presets in a such way
But as the result, when I'm using endpoint for users creation, there's only status field set in a new user. Role field is empty. And it doesn't changes if I change the order of presets
To Reproduce
Errors Shown
When I'm trying to login into this users right after I've created it using api, I see the following error from login endpoint. And as i realized this happens because the role is not set from the preset
What version of Directus are you using?
9.4.1
What version of Node.js are you using?
14.18.0
What database are you using?
Postgres 12
What browser are you using?
Chrome
What operating system are you using?
Ubuntu 20.04
How are you deploying Directus?
docker-compose
The text was updated successfully, but these errors were encountered: