Permission-specific styles for people who are logged in

Permalink 1 user found helpful
Hi all

I am starting to play with permissions and have run into a couple of problems with the style of the site when the editing bar is showing. I was using this to apply a specific style (namely adding an extra 50 or so pixels to the floats in the page so they look right when the edit bar is visible):

<?php $cp = new Permissions($c);if($cp->canAdmin()) { ?>


...but now I have created new groups who are not admins, so it therefore doesn't work for them. I tried this:

<?php $cp = new Permissions($c);if($cp->canWrite()) { ?>


...which works, except that there is at least one page where the only permission I've given is to add new pages to it as children, because I don't want them to be able to alter the parent page. Is there a method for that? Or is there a method which simply tests whether the editing bar is displayed, regardless of permissions? That would be the best solution.

Any thoughts much appreciated :)

melat0nin
 
mose replied on at Permalink Reply
mose
How about this?

if ($c->isEditMode()) {
  blah;
  blah;
  blah;
}
melat0nin replied on at Permalink Reply
melat0nin
Thanks for the reply.

That doesn't work - it makes the changes only when the user is in edit mode (i.e. has clicked Edit Page), but not when they are browsing with the c5 bar visible (whether on a page which they can edit or on a page where they can only add subpages).

It would be okay if the c5 bar showed on every page when logged in, because then I could presumably use isLoggedIn or something similar. But since the particular user group I am dealing with has access only to edit/add to a specific part of the site's tree, the c5 bar only shows on those pages and not on the ones where they have no permissions to make changes.

Is it possible, as a workaround, to make the c5 bar show all the time, regardless of permissions? This would also be good from the point of view of letting people know they are logged in.
jgarcia replied on at Permalink Best Answer Reply
jgarcia
Here's what you need:

if ($cp->canWrite() || $cp->canAddSubContent() || $cp->canAdminPage()) {
// Do something
}


This is pulled directly from /concrete/tools/page_controls_menu_js.php, which is the script that actually loads the menu itself.
melat0nin replied on at Permalink Reply
melat0nin
That works great, thankyou!

On a side issue (mentioned above), is it possible to force the banner to always display? Some of my users are less computer-savvy than others, and having the banner display at all times when they are logged in might be a good thing.
jgarcia replied on at Permalink Reply
jgarcia
Not without some fairly significant changes/overrides to the core of the CMS, and it would be a bit tricky. Essentially, what you would need to do is override /concrete/elements/page_controls_header.php and /concrete/tools/page_controls_menu_js.php and find the code that determines if the menu is called (line 8 in page_controls_header and line 75 in page_controls_menu_js). You would need to add "OR if the user is logged in".

SEEMS like this would work, but I'm not really sure. May be more trouble than it's worth...
Sergio replied on at Permalink Reply
Sergio
There is also this:
$u = new User(); 
   $group = $u->getUserGroups();    
   if (in_array("Name of group", $group) || $u->isSuperUser()) {
    //do something
    }
melat0nin replied on at Permalink Reply
melat0nin
Thanks for the suggestion Sergio, but the problem with that is it would require tweaking if the group name changes or a new one is added. That isn't ideal when I want to allow my users to get on with c5 without having to touch code. It's good to know it is possible though, should it come up in another scenario! :)
Sergio replied on at Permalink Reply
Sergio
Indeed. It's a solution for another scenario for sure. :D