[UI Customization] Automatic field composition

This topic has 2 replies, 2 voices, and was last updated 6 years, 3 months ago by F3bio.

  • Author
    Posts
  • #3312
     F3bio
    Participant

    Hi everyone,

    we would like when creating a new user (internal or external), from the UI, the username field is generated automatically and unique.

    For example, if we wanted that the “rule” of creation was “firstname-lastname” (plus an incremental number if it already exists), if firstname is “openidm” and lastname “admin”, the rule should return “openidm-admin2”.

    There is a “best practice” to do it?

    #3314
     Jake Feasel
    Moderator

    The UI creates managed/user records, so to control the behavior for new managed/users you need to adjust the script that is executed as part of the create event. You can do so within conf/managed.json:

    {
        "objects" : [
            {
                "name" : "user",
                "onCreate" : {
                    "type" : "text/javascript",
                    "file" : "ui/onCreate-user-set-default-fields.js"
                },
    ...
    

    I suggest making a copy of the default script (bin/defaults/script/ui/onCreate-user-set-default-fields.js) and placing it in your project-specific script folder, and then update that reference in managed.json to refer to your custom file (“script/onCreate-custom.js”). Within this copy, add the necessary logic to calculate the userName field.

    You will also need to update the policy for managed/user, since it expects the content to be posted with a userName already populated. All you will need to do is remove the policies for userName (they won’t be necessary now that you are implementing your own policies programmatically within that above script).

    Finally you will need to update the UI template so that admin users won’t be prompted to enter the userName themselves. Copy the files

    /ui/default/enduser/public/templates/admin/AdminUserRegistrationTemplate.html
    /ui/default/enduser/public/templates/admin/AdminUserProfileTemplate.html

    to this folder:

    /ui/extension/templates/admin

    Within AdminUserProfileTemplate, I suggest changing the html for the userName field so that it is readonly. Within AdminUserRegistrationTemplate, I would just remove the field entirely. This should prevent people from attempting to define the property.

    Good luck,
    Jake

    #3315
     F3bio
    Participant

    Thanks Jake for your reply.

    This can be a good solution, but when i created the user I don’t know the real username and the administrator must search for the new user.

    So I’m trying something a bit different, but I’m stuck:

    • Editing AdminUserProfileTemplate and AdminUserRegistrationTemplate and make userName readonly
    • Editing ui/default/enduser/public/org/forgerock/openidm/ui/admin/users/AdminUserRegistrationView.js and add two events (change input[name=givenName/sn]) that call a function; this function first check if firstname and lastname are present and after that try to create the userName

    I’m stuck with this strategy because I can’t understand how to check the unique policy of the userName.
    Have you got some suggestion? Unless I rollback and try your solution and add an email that notify the administrator the new username through email.

    Thanks
    F3bio

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

©2021 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?