As far as I know, you cannot change Moduleroles dynamically.
For userroles, you can set those for users in a running application. Just retrieve the desired role from the Database and add it to the the User (or remove it). But I think, the changes will only take effect, after the user has logged out and logged in again.
If I understand you correctly, it looks like you want to build something similar to a Multitenant App.
Maybe this helps: https://docs.mendix.com/howto/security/set-up-your-first-multi-tenant-app