Search code examples
sitecoresitecore7.2sitecore-intranet-portal

Sitecore Intranet Portal: How to change the default structuring of User profiles


I am using Sitecore Intranet Portal. The user profiles are saved in folders which are created by default. E.g. For a user "Jonny Bravo" two folders J and Jo are created automatically and then the user profile is saved in it.

 `J -> Jo -> Jonny Bravo`

I would like to disable this default behavior instead I want to structure the user profiles according to departments. E.g. Finance, Purchase, Administration etc. So a folder Purchase would contains all the users working in this department.

Please let me know if:

1. Its possible or not ?

2. Does it has any consequences ?


Solution

  • In Sitecore Intranet Portal 4.1.0, in Intranet.Profiles.config config, you can define your own UserProfileProvider instead of the default one, which uses Sitecore.Intranet.Profiles.Providers.UserProfileProvider class.

    Just inherit from that class and override public virtual Item GetProfileFolder(string userName, bool createIfNotExist) method.

    Default implementation of this method is:

    public virtual Item GetProfileFolder(string userName, bool createIfNotExist)
    {
        userName = StringUtil.GetLastPart(userName, '\\', userName);
        Item item = this.settings.Database.GetItem(this.settings.UserProfilesFolder);
        int num = Math.Min(this.settings.UserProfilesTreeDepth, userName.Length);
        for (int i = 0; i < num; i++)
        {
            string firstLetters = this.GetFirstLetters(userName, i + 1);
            Item item2 = this.GetItem(item, firstLetters, TemplateIDs.Folder);
            if (item2 == null)
            {
                if (!createIfNotExist)
                {
                    return item;
                }
                item = this.CreateFolder(item, firstLetters);
            }
            else
            {
                item = item2;
            }
        }
        return item;
    }
    

    I don't know about any disadvantages of changing default folder structure.


    EDIT

    You need to change the type of the provider to you custom provider here:

    <UserProfileProvider>
      <x:attribute name="type">Sitecore.Intranet.Profiles.Providers.UserProfileProvider, Sitecore.Intranet.Profiles</x:attribute>
      <param ref="profilesSettings"/>
    </UserProfileProvider>