Open Closed

Permission initialization #10643


0
ricavir created

Abp 6.4 Angular .Net Core

HI,

I need to add new Permissions to tenant users. The problem is that I need to initialize these new permissions to "True" for all tenant users... if not, a lot of existing users will be blocked for actions that they can do today.

Is it possible to initialize a new Permission to true ? Or do I need to create something that will go throw all existing users to set these new Permissions to true ?


6 Answer(s)
  • 0
    ismcagdas created
    Support Team

    Hi @ricavir,

    You can create a defult role (existing User role for example) and make this role a default role so each newly created user of that tenant will be assigned to this role. After that, you can assign the newly created permission to this role either using Migrations.

    The permissions don't have a defult value.

  • 0
    ricavir created

    Hi @ismcagdas,

    Thank you for your advice. In my case, the roles are already assigned for all existing users. There is no other way to assign a permission for all existing users of all existing tenants ?

  • 0
    ismcagdas created
    Support Team

    Hi @ricavir

    Unfortunately no. You can override PermissionChecker and implement a custom logic but it might not be easy. I couldn't understand why you can't use roles, could you explain it ?

    Thanks,

  • 0
    ricavir created

    Hi @ismcagdas,

    Thanks for your feedback. I can't use roles because all existing users of all tenants have different roles ; some of them have created custom roles and deactivated default "user" static role. This means that if I want to add a new permmission that must be affected to all users, I need to affect a static role to all users before... I don't want to do that.

  • 0
    ismcagdas created
    Support Team

    Hi,

    In that case, you can insert permission record to database for all users using a migration script.

    INSERT INTO AbpPermissions
    SELECT GETDATE() AS CreationTime, NULL AS CreatorUserId, 'UserPermissionSetting' AS Discriminator, 1 AS IsGranted, 'PermisisonName' AS Name, TenantId, NULL AS RoleId, Id AS UserId FROM AbpUsers
    
  • 0
    ricavir created

    Hi @ismcagdas,

    Great solution ! I did'nt thought to act directly on the database. Thank you very much.