Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
First of all, I want to apologize in advance for my english. It's not my native language.

I'm using Couch to create my podcast site. I've made an episode list, blog-style, listing all the entries. Each page have an episode sinopsis, download link, cover, audio player, and comment box.

I want to create some users accounts that will have access to the podcast 24 hours prior the official release. So, the best way I've figured to do this, is to create the episode page for the last release, and set the Acess Level only to "Authenticated User (Special)".

When I visit the website logged as adminstrador, I can see the podcast in the episodes list, and access it, since I have the minimum required privileges.

If i'm not logged to couch, obvisouly I can't access the episode page (It asks for user & pass). However, I can still see it in the episodes list.

Is there a way to not display this "protected" entry?

This question extends to the RSS. Is it possible only to list unprotected entries on the RSS feed generated by couch?

Than you for your time. :D
Hello and welcome, Marcos :)

I can see the problem you mentioned - while listing pages in Couch, the access-level is ignored. It is only when the page itself is accessed that the permissions come into play.

But that is not a problem. We have several different ways of handling your scenario. Allow me to mention some -

1. The simplest would be to compare the user's access-level with the page's access-level while listing and show a page only if the levels match e.g. the following will show a page only if the user's level is greater or equal to a page's level -
Code: Select all
<cms:pages>
    <cms:if k_user_access_level ge k_access_level>
        <!-- show regular content -->
        <h3><cms:show k_page_title /></h3>
    </cms:if>
</cms:pages>

A variation of the above would be to show some message (e.g. 'Members-only content') instead of hiding the page e.g. like this -
Code: Select all
<cms:pages>
    <cms:if k_user_access_level lt k_access_level>
        <h3>Protected Content</h3>
    <cms:else />
        <!-- show regular content -->
        <h3><cms:show k_page_title /></h3>
    </cms:if>
</cms:pages>


2. A slightly more involved way would be to NOT use the 'Advanced setting->Access Level' for setting page access.
Instead we'll use a custom field (i.e. editable region) to set our own security (don't worry it is easy).

a. Create the following editable region in your template
Code: Select all
<cms:editable 
    name="secure_page"
    label="Page visible to"
    opt_values='Everybody=0 | Registered Users Only=1'
    search_type='decimal'
    type='dropdown'
/>

For secure pages, you can select the 'Registered Users Only' option from the above region.

b. Now while listing pages, we make use of our custom-field to skip secure pages
Code: Select all
<cms:pages custom_field="<cms:if k_user_access_level lt '4'>secure_page=0</cms:if>">
    <h3><cms:show k_page_title /></h3>
</cms:pages>

The code above checks if the user is less than a 'Authenticated User (Special)' and if yes, uses the secure_page region for listing.

c. Of course, since we are not setting page-level access, if an unprivileged user happens to get a link to the secure page he'll be able to access it.
To prevent that, put the following somewhere at the top of your template -
Code: Select all
<cms:if k_is_page && secure_page='1'>
    <cms:php>
        global $AUTH;
        $AUTH = new KAuth( K_ACCESS_LEVEL_AUTHENTICATED_SPECIAL );   // allow only 'Authenticated User (Special)'   
    </cms:php>
</cms:if>

We could have used the native 'Advanced setting->Access Level' page setting to do the same but then that would be one more setting to remember for each secure page.

I have some more methods in mind that are specific to your use-case (like setting the publish-date to 24 hours in future and it the meanwhile allow only special users to see the listing and access page - but I think the above mentioned methods would suffice for now).

Hope this helps.
Do let us know.

Thanks.
That's just AMAZING! I followed your second suggestion, and it works! Thanks for the help. I can now implement this resource in page listings and RSS also.
3 posts Page 1 of 1
cron