3

I want this check box checked for each user

Hi, is there is a way to enforce this checkbox value = true each user login ? If enforce not possible, can we globally set check = true for each users?

I found similar question here: Set Default Value of Ribbon Checkbox and make some adjustment since it have different settings and sitecore version as follow

using Sitecore.Diagnostics;
using Sitecore.Pipelines.LoggedIn;
using Sitecore.Security.Accounts;

namespace CustomLogin
{
    public class EnforceEntireTree
    {
        public void Process(LoggedInArgs args)
        {
            User user = User.FromName(args.Username, true);
            Assert.IsNotNull(user, "user");
            user.Profile.SetPropertyValue("/Content Editor/Ribbons/Chunks/View/Entire Tree", "on");
        }
    }
}

When it's executed it's throw error: "The settings property '/Content Editor/Ribbons/Chunks/View/Entire Tree' was not found."

UPDATE:

I found proper name for that setting but these code isn't working

namespace CustomLogin
{
    public class EnforceEntireTree
    {
        public void Process(LoggedInArgs args)
        {
            User user = User.FromName(args.Username, true);
            Assert.IsNotNull(user, "user");

            string key = "/" + user.Name + "/UserOptions.View.ShowEntireTree";
            user.Profile.Initialize(user.Name, true);
            user.Profile[key] = "true";
            user.Profile.Save();
        }
    }
}

UPDATE #2: After Andrey Bobrov said, i try to clear cache by using this way:

namespace CustomLogin
{
    public class EnforceEntireTree
    {
        public void Process(LoggedInArgs args)
        {
            User user = User.FromName(args.Username, true);
            Assert.IsNotNull(user, "user");

            string key = "/" + user.Name + "/UserOptions.View.ShowEntireTree";
            user.Profile.Initialize(user.Name, true);
            user.Profile[key] = "true";
            user.Profile.Save();

            RegistryCache registryCache = CacheManager.GetRegistryCache(Context.Site);
            registryCache.Clear();
        }
    }
}

Still not working, Do I doing it wrong? If I clear all the cache from sitecore/admin/cache.aspx then the checkbox is checked just by using refresh (F5)

Thank You

  • have you cleared the registry cache after executing your code? – Andrey Bobrov Mar 16 '17 at 7:29
  • Hi @AndreyBobrov, could you tell me how to clear cache? I trying using above code but not working. Now i'm sure it's about cache since clearing them, then checkbox is checked. Thank You – Hadi Susanto Mar 16 '17 at 11:09
  • @HadiSusanto, I think the cache that is being cleared is not the one which is responsible for the ribbon to take the new values. Check what is the Context.Site returning. – Hishaam Namooya Mar 16 '17 at 19:55
2

As you have specified in your comment, clearing the cache from the cache.aspx page, fixed the issue. The reason why even clearing the cache from the code is not working is because the Context.Site is not the correct one.

The Context.Site at this point is equal to login. You should clear the cache for the shell.

namespace CustomLogin
{
    public class EnforceEntireTree
    {
        public void Process(LoggedInArgs args)
        {
            User user = User.FromName(args.Username, true);
            Assert.IsNotNull(user, "user");

            string key = "/" + user.Name + "/UserOptions.View.ShowEntireTree";
            user.Profile.Initialize(user.Name, true);
            user.Profile[key] = "true";
            user.Profile.Save();

            // Get the shell site here
            var site = Sitecore.Sites.SiteContext.GetSite("shell");
            RegistryCache registryCache = CacheManager.GetRegistryCache(site );
            registryCache.Clear();
        }
    }
}
  • Thanks a lot, this do the trick. As you said Context.Site at that point is login – Hadi Susanto Mar 17 '17 at 2:52
0

You could achieve this by setting registry as shown.

PS script to change the registry

PS script:

    --Get the default value
    [Sitecore.Web.UI.HtmlControls.Registry]::GetBool("/Current_User/UserOptions.View.ShowEntireTree")
    --Set 'true' to the context user        
[Sitecore.Web.UI.HtmlControls.Registry]::SetBool("/Current_User/UserOptions.View.ShowEntireTree",$true)

You can write respective C# code to do the similar stuff after post login or something like that.

  • Hi Balaji Kuppuswamy, I use Registry.SetBool(key, true); but it give me these error: This property cannot be set for anonymous users. FYI: Those code is running at LoggedIn pipeline – Hadi Susanto Mar 16 '17 at 11:12
  • as mentioned, this should be applicable for CMS users and users should be logged-in or post login event. May i know where are you trying this code,which pipeline ? – Balaji Kuppuswamy Mar 16 '17 at 11:18
  • I hook those code by using web.config <sitecore> <processors> <loggedin argsType="Sitecore.Pipelines.LoggedIn.LoggedInArgs"> <processor mode="on" type="CustomLogin.EnforceEntireTree, CustomLogin" /> </loggedin> </processors> </sitecore> – Hadi Susanto Mar 16 '17 at 11:29
  • could you make your processor as a last processor i.e. below CleanupUserProfile ? – Balaji Kuppuswamy Mar 16 '17 at 11:34
  • It's already bellow CleanupUserProfile, 1. Sitecore.Pipelines.LoggedIn.Ticket, Sitecore.Kernel 2. Sitecore.Pipelines.LoggedIn.CleanupUserProfile, Sitecore.Kernel 3. CustomLogin.EnforceEntireTree, CustomLogin – Hadi Susanto Mar 16 '17 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.