#1 May 22, 2013 3:27am

asiral
Member
Registered: May 18, 2013
Posts: 43

Previewer User Role

Hi,

What is the best way to add a user role such as 'Previewer' so changes can be circulated to non-editors before being published?  An alternative would be to remove access control to preview URLs but the former solution is preferred.

Thanks,
Michael

Offline

#2 May 22, 2013 12:10pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Previewer User Role

If you just need to allow people to see the /_preview/ links that are being distributed manually I'd go about it this way:

  1. Create a regular user for them (Normal level) and give them no page/module permissions.

  2. Modify your 404 page (/templates/basic/_404.php) to see if $bigtree["path"][0] == "_preview", if it does then show the user a message saying they need to login to see the page preview (and optionally give them a link to the admin)

They'll be able to see preview pages with no permissions to anything, so essentially a Normal level user would be a Previewer anyway. You could also serve up a custom Dashboard that provides a list of pending pages with their preview links if you want to give those users something when they login.

Offline

#3 May 24, 2013 4:13pm

asiral
Member
Registered: May 18, 2013
Posts: 43

Re: Previewer User Role

Hi, Tim:

Thanks for your guidance with this (and all the discussions).  I took a slightly different approach based on our requirements.

First, we are using Single Sign On which enforces some basic authorization which is all we require and no pending changes will likely be sensitive in nature so simply an obscured URL with the "_preview" path will be enough.  So what I did was edit one line in the custom router, around line 230.  Instead of checking for the path and an administrator session, I just check for the "_preview" path and remove the admin check.

    // See if we're previewing changes.
    $bigtree["preview"] = false;
//    if ($bigtree["path"][0] == "_preview" && $_SESSION["bigtree_admin"]["id"]) {
    // EDIT: remove check for admin
    if ($bigtree["path"][0] == "_preview") {

This is especially nice because it also removes the administrator bar on the page.  I have yet to see any complications, but please let me know if I am missing something.

Thanks,
Michael

Offline

#4 May 27, 2013 9:35am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Previewer User Role

Sounds great! For a long while we didn't do any login checking on preview pages either. The main reason it's in there is to prevent search engines from indexing preview pages but you can also either use robots.txt to block /_preview/ or throw the robots noindex meta tag into your header when $bigtree["path"][0] == "_preview" and that solves that issue.

Offline

#5 June 10, 2013 6:13am

asiral
Member
Registered: May 18, 2013
Posts: 43

Re: Previewer User Role

I've made some further customizations as well I'd thought I'd share.  Since we want to be able to preview sites in a multi-site setup, it helps to enable the previews within the site context, in this case a subdomain.  So in the custom router, before checking for the existing of "_preview" in the path, I've added this code to alter the path variable.

    // right before serving header for HTML, add site 1 or site 2 directory to path based on host
    // the is_sitex() functions are defined in the configuration file, explained here: [url]http://www.bigtreecms.org/discussion/discussion/55/multi-site-setup[/url]
    if(is_site1()) {
        if($bigtree['path'][0] != "" && $bigtree['path'][0] != "_preview") {
            array_unshift($bigtree['path'], "site1");
        } else if($bigtree['path'][0] == "_preview") {
            $bigtree['path'] = array_merge((array)"_preview", (array)"site1", array_slice($bigtree['path'], 1));
        } else {
            $bigtree['path'][0] = "site1";
        }
    } else if(is_site2()) {
        if($bigtree['path'][0] != "" && $bigtree['path'][0] != "_preview") {
            array_unshift($bigtree['path'], "site2");
        } else if($bigtree['path'][0] == "_preview") {
            $bigtree['path'] = array_merge((array)"_preview", (array)"site2", array_slice($bigtree['path'], 1));
        } else {
            $bigtree['path'][0] = "site2";
        }
    }

It's a little hacky, but works very well and allows us to do this:

site1.domain.nyu.edu/_preview/this-is-a-page/
site2.domain.nyu.edu/_preview/this-is-a-different-page/

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.