Copied to clipboard

Flag this post as spam?

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


  • Allan Hawkey 232 posts 303 karma points
    Oct 26, 2011 @ 15:24
    Allan Hawkey
    0

    Member only access to a blog post

    I'm using uBlogsy 2.0 beta in Umbraco 4.7.1 for a site I'm developing and I need to get a specific blog post to be restricted to members only when they are signed in, as the post contains confidential info.  The rest of the blog is public.

    I've tried right click / Public Access and resticting this post to members only.  But it is still displayed in the list of posts, and also in the archive list and the RSS feed.

    How can I set this so that it's fully available to signed in members but hidden from anyone else?

    Thanks
    Allan

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Oct 27, 2011 @ 08:50
    Richard Soeteman
    0

    Hi Allan,

    You need to modify the Macro scripts to do this. In Razor you can make use of the HasAccess and IsProtected properties. On the macros that renders the post and archive information you could add the HasAccess property to determine if the current logged in user has access to the post, below an example how I modified the uBlogsyListPosts.cshtml file, You see that I make use of the HasAccess property now the user will only see the protected item if the user has access and is in the correct role

     <div class="uBlogsy_posts_container uBlogsy_bottom_border">
            <h2>
                Latest posts</h2>
            <ul>
                @foreach (DynamicNode n in nodes)
                {
                    if (n.HasAccess)
                    {
                            
                    <li><a href="@n.Url"><span>@n.GetProperty("uBlogsyContentTitle").Value</span> </a>@* - <span>@n.GetProperty("uBlogsyPostDate").Value.FormatDateTimeOrdinal("d MMMM yyyy")</span>*@
                    </li>
                    }
                }
            </ul>
        </div>

     

    For an rss file you only want to make sure the item isn't protected. In the example below I modified the uBlogsyRSS.cshtml file to only show public posts

                @foreach (var p in posts)
                {
                    if (!p.IsProtected)
                    {
                    <item>
                        <title>@p.GetProperty("uBlogsyContentTitle").Value</title>
                        <author>@p.GetProperty("uBlogsyPostAuthor").Value</author>
                        <comments>@blogUrl@p.Url</comments>
                        <description>@p.GetProperty("uBlogsyContentBody").Value.StripHtml().Trim()</description>
                        <link>@blogUrl@p.Url</link>
                        <guid>@blogUrl@p.Url</guid>
                        <pubDate>@p.GetProperty("uBlogsyPostDate").Value.FormatDateTime("ddd, dd MMMM yyyy HH:mm:ss"</pubDate>
                    </item>
                    }
                }
    

    For more info about Razor check out this cheat sheet.

    Hope this helps,

    Richard

     

  • Allan Hawkey 232 posts 303 karma points
    Oct 27, 2011 @ 13:06
    Allan Hawkey
    0

    Hi Richard

    That looks great - many thanks.  I'll give it a try shortly...

    Allan

Please Sign in or register to post replies

Write your reply to:

Draft