Announcement

Collapse
No announcement yet.

Portal user creation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Portal user creation

    In current system there are no possibility to delegare creation of Users to customers portal for some users, like "Sales manager". Now only "Admins" can do that, but it's not good to give admins right for "Salas manager" only to Portal users creation. Is it possible to create a separate feature or access rights to have a possibility to delegate this task to any user.

  • #2
    I would love to have this feature as well. Is there a way to vote for a feature like this?

    Comment


    • #3
      Hi partomas,

      Unfortunately there is no such possibility. As workaround you can try to create a Portal via API:

      Comment


      • #4
        Hi partomas,

        As a workaround, you can create a new entity, for example, called Potential Portal User, create fields in this entity, like fields from User entity (userName, name, email address, portal (you can try to use the enum field)) that managers can fill in. After that, you will need to insert something like this into the Potential Portal User entity formula:
        Code:
        ifThen(
        portal == 'Portal 1',
        $portalId = 'your-portal-id-1';
        $portalURL = 'your-portal-URL-1'
        );
        
        ifThen(
        portal == 'Portal 2',
        $portalId = 'your-portal-id-2';
        $portalURL = 'your-portal-URL-2'
        );​
        
        $password = password\generate();
        $hash = password\hash($password);
        
        ifThen(
        entity\isNew(),
        $userId = record\create('User',
        'userName', userName,
        'name', name,
        'password', $hash,
        'emailAddress', emailAddress,
        'type', 'Portal',
        'portal', $portalId)
        );
        
        $emailBody = string\concatenate(
        'Portal URL', $portalURL, '\n',
        'Username: ', userName, '\n',
        'Password: ', $password, '\n'
        );
        
        ifThen(
        entity\isNew(),
        $emailId = record\create(
        'Email',
        'to', emailAddress,
        'status', 'Sending',
        'subject', 'Access info to portal',
        'body', $emailBody,
        'isHtml', false)
        );
        
        ifThen(
        entity\isNew(),
        ext\email\send($emailId)
        );​
        That is, after saving the Potential Portal User record, a new portal user will be immediately created in your instance of EspoCRM.​

        If you have any problems with this solution, please write about it and I will help you refine it.
        Last edited by lazovic; 06-02-2023, 09:01 AM.

        Comment


        • #5
          Hi @lazovic​, while this is a nice workaround for the use case of creating a new user this is not sufficient for the further lifecycle of such an entity. If something needs to be adjusted it needs to be reflected from the dummy entity to the actual (portal)user entity and so on. So a complete feature to let users be created/edited by lower priviliged other users would be great Nonetheless thank you!

          Comment


          • #6
            helix101,

            In fact, this formula script can be modified in such a way that it will change certain fields in an existing Portal User, this is not a problem.

            Comment


            • #7
              @lazovic​ of course this can be done this way but from an maintenance point of view this is not a "nice" solution. I could also implement this feature by means of SQL procedures/triggers. Even not that nice

              Comment


              • #8
                helix101 ,

                Please have a look at this extension https://osomcrm.com/product/create-portal-user/

                Admin Users can create Portal Users, add Portal, add Portal Role, and send access info straight from the Contact record. There is an option to bulk-create Portal Users.

                Regular Users can create Portal Users, but you have to set up a workflow that adds Portal, Portal Role and sends access info to Portal User, since Regular Users have no direct access to Portals and Portal Roles.

                Comment


                • #9
                  Originally posted by Laimonas View Post
                  helix101 ,

                  Please have a look at this extension https://osomcrm.com/product/create-portal-user/

                  Admin Users can create Portal Users, add Portal, add Portal Role, and send access info straight from the Contact record. There is an option to bulk-create Portal Users.

                  Regular Users can create Portal Users, but you have to set up a workflow that adds Portal, Portal Role and sends access info to Portal User, since Regular Users have no direct access to Portals and Portal Roles.
                  Hi Laimonas, thanks for sharing. I will investigate it.

                  Comment


                  • #10
                    Originally posted by lazovic View Post
                    Hi partomas,

                    As a workaround, you can create a new entity, for example, called Potential Portal User, create fields in this entity, like fields from User entity (userName, name, email address, portal (you can try to use the enum field)) that managers can fill in. After that, you will need to insert something like this into the Potential Portal User entity formula:
                    Code:
                    ifThen(
                    portal == 'Portal 1',
                    $portalId = 'your-portal-id-1';
                    $portalURL = 'your-portal-URL-1'
                    );
                    
                    ifThen(
                    portal == 'Portal 2',
                    $portalId = 'your-portal-id-2';
                    $portalURL = 'your-portal-URL-2'
                    );​
                    
                    $password = password\generate();
                    $hash = password\hash($password);
                    
                    ifThen(
                    entity\isNew(),
                    $userId = record\create('User',
                    'userName', userName,
                    'name', name,
                    'password', $hash,
                    'emailAddress', emailAddress,
                    'type', 'Portal',
                    'portal', $portalId)
                    );
                    
                    $emailBody = string\concatenate(
                    'Portal URL', $portalURL, '\n',
                    'Username: ', userName, '\n',
                    'Password: ', $password, '\n'
                    );
                    
                    ifThen(
                    entity\isNew(),
                    $emailId = record\create(
                    'Email',
                    'to', emailAddress,
                    'status', 'Sending',
                    'subject', 'Access info to portal',
                    'body', $emailBody,
                    'isHtml', false)
                    );
                    
                    ifThen(
                    entity\isNew(),
                    ext\email\send($emailId)
                    );​
                    That is, after saving the Potential Portal User record, a new portal user will be immediately created in your instance of EspoCRM.​

                    If you have any problems with this solution, please write about it and I will help you refine it.
                    Hi @lazovic​,

                    I am going to setup a little PoC to check how good this solution might fit when a few users work with it. Therefore I would like to know the following:
                    The 'User' entity has a field called 'accounts' of type 'Url-Multiple'. My dummy entity that will be mapped to a 'User' via the script above will either have the same kind of field or a field of type 'Url', I just don't know yet for sure. But nevermind - what would be the correct syntax to map the 'Dummy'->'account(s)' to 'User'->'accounts'?

                    Something like this?
                    Code:
                    record\create(
                      'User',
                      'userName', $userName,
                      'name', $name,
                      'emailAddress', $emailAddress,
                      'type', 'portal',
                      'accounts', list($account),
                      'portalsIds', list($portalId)
                    )
                    Thanks in advance!
                    Last edited by helix101; 06-03-2023, 07:50 AM.

                    Comment


                    • #11
                      Wow, ok, got it... Tricky and not covered by the docs I would say. I recognized the 'portalIds' field name which is no actual field in the UI. But looking into the source I found other usages like this. Seems to belong to some kind of behind the scene logic to manage entity referenciation.

                      First things first:
                      Correct syntax:
                      Code:
                      record\create(
                      'User',
                      'id', $userId,
                      'isActive', isActive,
                      'userName', userName,
                      'firstName', firstName,
                      'lastName', lastName,
                      'name', name,
                      'emailAddress', emailAddress,
                      'type', 'portal',
                      'portalsIds', list($portalId),
                      'accountsIds', list(organisationId) // <-
                      );
                      And here is my complete script to keep the dummy entity in sync with the actual user entity:
                      Code:
                      $portalId = 'xyz';
                      $userId = entity\attribute('id'); // <- I use the same Id for Dummy and for User as it makes some querying more convenient
                      // output\printLine($userId);
                      // output\printLine(userName);
                      // output\printLine(sendNewPassword);
                      // output\printLine(organisationId);
                      if (entity\isNew())
                      {
                      record\create(
                      'User',
                      'id', $userId,
                      'isActive', isActive,
                      'userName', userName,
                      'firstName', firstName,
                      'lastName', lastName,
                      'name', name,
                      'emailAddress', emailAddress,
                      'type', 'portal',
                      'portalsIds', list($portalId),
                      'accountsIds', list(organisationId)
                      );
                      }
                      else
                      {
                      if (record\exists('User', 'id=', $userId))
                      {
                      record\update(
                      'User',
                      $userId,
                      'isActive', isActive,
                      'userName', userName,
                      'firstName', firstName,
                      'lastName', lastName,
                      'name', name,
                      'emailAddress', emailAddress,
                      'accountsIds', list(organisationId)
                      );
                      }
                      else
                      {
                      record\create(
                      'User',
                      'id', $userId,
                      'isActive', isActive,
                      'userName', userName,
                      'firstName', firstName,
                      'lastName', lastName,
                      'name', name,
                      'emailAddress', emailAddress,
                      'type', 'portal',
                      'portalsIds', list($portalId),
                      'accountsIds', list(organisationId)
                      );
                      }
                      }
                      if (entity\isNew() || sendNewPassword)
                      {
                      // output\printLine('Setting new password');
                      ext\user\sendAccessInfo($userId); // <- I use the pre configured function to send password instructions.
                      sendNewPassword = 0;
                      }
                      
                      ​
                      ​
                      Last edited by helix101; 06-04-2023, 01:21 PM.

                      Comment


                      • yuri
                        yuri commented
                        Editing a comment
                        > Tricky and not covered by the docs

                        It would not say it's that tricky.

                        > 'portalIds' field name which is no actual field in the UI

                        A field list for an entity type can be obtained at Administration > Entity Manager > {Entity Type} > Field. Here useful information about attributes: https://docs.espocrm.com/administrat...ing/#attribute. Here about link-multiple: https://docs.espocrm.com/administrat...#link-multiple. It's pretty much covered in docs, just needs some time to learn as with anything in programming.

                        You could also use record\relate function instead of using link-multiple portalsIds.
                        Last edited by yuri; 06-04-2023, 02:57 PM.
                    Working...
                    X