How to export user permissions?

Hi there,

I would like to add some permissions to the anonymous role and export them in some way for better deployment.

Looks like SQL create/update scripts may solve the issue, but anonymous role is already presented in the database and I’m not sure how I can determine it’s ID for the reference.

So, what is the recommended way to achieve the result?

Hi,

You can just refer it by name instead of id. It is probably unique?

The role name is unique.
Also, the Anonymous role is created by the CUBA init scripts and its ID is predefined. So if you don’t change it in your app, you can safely refer by its standard ID: cd541dd4-eeb7-cd5b-847e-d32236552fa9

2 Likes

Thanks! Role ID is really the same, so I just added update scripts to set needed permissions.

Regarding role name,

SEC_PERMISSION table uses ROLE_ID for reference, so how can I use a role name there?

It is probably already not relevant but here some of possible implementations:

update SEC_PERMISSION
SET /* ... */
where SEC_PERMISSION.ROLE_ID = (
    select r.id 
    from sec_role r
    where r.name = 'NAME'
)
insert into SEC_PERMISSION(/* ... */, role_id)
values(
    /*...*/, 
    (
        select r.id 
        from sec_role r
        where r.name = 'NAME'
    ));
1 Like