Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kristoffer Eriksen 169 posts 388 karma points
    Aug 23, 2011 @ 10:06
    Kristoffer Eriksen
    0

    Setting Public Acces Programmaticly ends in loop

    Hey Umbraco

    When trying to set the public access via the APi, my event just ends in a infinite loop.

    After:

    Access.AddMembershipRoleToDocument(doc.Id, memberRole);

    it returns to

    Document doc = sender;

    and starts over...again...

    Below is the full eventcode

    public class SetAccess : ApplicationBase
    {
        public SetAccess()
        {
            Document.BeforePublish += Document_BeforePublish;
        }

        private void Document_BeforePublish(Document sender, PublishEventArgs e)
        {
            Document doc = sender;
            var MemberGroups = new List<string> { "DefaultGroup" };
            if (doc.getProperty("groupOne").Value.ToString() == "1")
            {
                MemberGroups.Add("groupOneDpt1");
                MemberGroups.Add("groupOneDpt2");
                MemberGroups.Add("groupOneDpt3");
            }
            if (doc.getProperty("groupTwo").Value.ToString() == "1")
            {
                MemberGroups.Add("groupTwoDpt1");
                MemberGroups.Add("groupTwoDpt2");
                MemberGroups.Add("groupTwoDpt3");
            }
            int loginDocID = LOGIN_PAGE_ID;
            int errorDocID = ERROR_PAGE_ID;

            Access.ProtectPage(false, doc.Id, loginDocID, errorDocID);
            foreach (string memberRole in MemberGroups)
            {
                Access.AddMembershipRoleToDocument(doc.Id, memberRole);
            }
            doc.Publish(new User(0));
            library.UpdateDocumentCache(doc.Id);
        }
    }

    Been using this as inspiration

    http://our.umbraco.org/forum/developers/api-questions/5669-Setting-Public-Access-on-a-node-programatically

     

  • Kristoffer Eriksen 169 posts 388 karma points
    Aug 23, 2011 @ 10:08
    Kristoffer Eriksen
    0

    To make it easy for the editors, I've created two true/false on the document, so the editor only needs to check this, to set the access-rights on a node before publish

  • Kristoffer Eriksen 169 posts 388 karma points
    Aug 24, 2011 @ 09:18
    Kristoffer Eriksen
    0

    Anyone ?

  • Kristoffer Eriksen 169 posts 388 karma points
    Aug 24, 2011 @ 09:40
    Kristoffer Eriksen
    0

    Oh DAMN! Rookie mistake.....

    Second to last line..... 

    doc.Publish = run Before.Publish method....over and over again... well...

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies