Hiding Elements for Guests Only

Re: Hiding Elements for Guests Only

by Jason Press -
Number of replies: 13
Hi Алексей,

Thanks so much for your reply. In the Front Page settings, the "Default frontpage role" was set to "None" (since I upgraded from version 1.9). I found the following (from this page):

The default frontpage role enables logged-in users to participate in front page activities. It is recommended that it is set to frontpage role. It should never be set to Guest.

For sites which do not have a default frontpage role (because they upgraded from 1.9), it is recommended that the administrator creates a new role with frontpage archetype, resets it to default and then sets it as the default frontpage role.

So, I tried setting up a new role with the "Authenticated user on frontpage" archetype (called "Front Page User") and I set it as the "Default frontpage role". I then went into the "Navigation" block permissions and prohibited this role (as well as the "Guest" and "Authenticated user" roles, just to be thorough) from the "View block" permission. This seems to have had no effect.

I wonder if there are any specific permissions within my new "Front Page User" role that I should modify in order to activate the block permissions settings?
In reply to Jason Press

Re: Hiding Elements for Guests Only

by Алексей Кадин -

Hmmm. It's interesting. Are you just switching between roles or log in as a user, that is a Guest? Sometimes switching doesn't show any result, so it's better to log in as another user.

And then, try not to "prohibit", but to "prevent" View block for these roles - there is a context conflict and "prevent" will cause lower context's win (as our block is lower in hierarchy, than FrontPage).

In reply to Алексей Кадин

Re: Hiding Elements for Guests Only

by Jason Press -

Hi Алексей,

I can confirm that I'm logging in as a separate user as opposed to using the "Switch role to..." feature. For example, when I first go to my site, I am not logged in as any user (navigation bar just shows the words "Log in"). However, as soon as I click on a page (we have a number of links available to non-logged-in users), I am automatically logged in as "Guest" (at which point the navigation bar shows the word "Guest"). Of course, at any point I can click "Log out" and then use the actual login block to login as an official user.

I went to the Navigation block > Assign roles > Permissions and added "Advanced role overrides" for the three roles I mentioned (Front Page User, Guest, and Authenticated user) so that the "View block" (moodle/block:view) permission is now set to "Prevent" instead of "Prohibit". I also tried purging caches and using different browsers, just in case there was some kind of cache issue, but I'm still seeing no change and the Navigation block is still showing up for all users.

Any other suggestions?

In reply to Jason Press

Re: Hiding Elements for Guests Only

by Алексей Кадин -

Well, I think I got it: the way of restriction was wrong.

When you turn editing on and get to the roles assigning page in your block, you should look at your administration block. Your see a category with 3 lines: "assign roles", "permissions", "check permissions". You are now in "assign roles" (it is bold). You need to go to "permissions". You will see the list of permissions for this block. Near each permission there are roles, which are allowed to have it in this block. You find the permission "view block" and click X near Guest (and other roles your need) - it (they) will disappear. To return them you click ➕ near the permission and choose the role you want to allow to have this permission in this block.

Now I remember, this is the way I did it some time ago, it MUST work. Sorry, I didn't understand that we should go this way from the beginning - we got some waste of time, so expensive in the beginning of the academic year.

And if it works - you can forget about those "prevent" and "prohibit" and reset them to default. And delete those local role assignments in the block that you made - normally you won't need them, normally you won't even remember about them - only managing the list of roles for each permission (function) in the block/activity/resource, which I described now.

In reply to Алексей Кадин

Re: Hiding Elements for Guests Only

by Jason Press -

Well, I hope I'm wrong about this, but I think that was the first thing I tried. Let me share a screenshot of the Navigation block "Permissions" area:

Navigation Block Permissions


As you can see, the "Guest" role is not listed as one of the "Roles with permission" for the block:view permission. I removed it during one of my initial tests.

Also, since it feels like we may be getting closer to the issue, I'll share one more screenshot where I set three roles to "Prohibited":

Navigation Block Permissions 2

Again, this has seemed to make no difference and Guest users can still see the Navigation block on the front page (note- the advanced role overrides are still in place as well). Please let me know if I'm misunderstanding you or if I can provide any other info or screenshots.

In reply to Jason Press

Re: Hiding Elements for Guests Only

by Алексей Кадин -

Sorry, the screenshots are not displayed...

In reply to Алексей Кадин

Re: Hiding Elements for Guests Only

by Jason Press -

Oh ok, thanks for letting me know. I've tried attaching the .png files instead of embedding them directly in the post. Hopefully that will work better. If not, I can upload them to an external location and provide URLs.

Attachment Navigation Block Permissions 1.png
Attachment Navigation Block Permissions 2.png
In reply to Jason Press

Re: Hiding Elements for Guests Only

by Алексей Кадин -

Now it works, thanks.

OK, we have deleted this roles from the allowed ones, set the overrides to prevent, to prohibit - no effect. Than we should make two checks:

1. Make this operations with any other block (blocks) except Navigation and Settings.

2. Unlock the Navigation block: Administration-Plugins-Blocks-Managing Blocks. There will be a list of blocks, normally only two of them are locked - Navigation and Settings (Administration). You can unlock Navigation block and check if the situation changes.

In reply to Алексей Кадин

Re: Hiding Elements for Guests Only

by Jason Press -

Ok, well I think we're getting closer! Thanks for working with me on this smile

Unlocking the Navigation block didn't seem to have any particular effect, but I did try modifying another block, which was interesting. Basically, I just deleted the "Guest" role from the allowed ones for the block:view permission and it took effect immediately. Even after just that one small modification, the block was hidden for all non-authenticated users. Even when initially visiting the front page (before I would technically be logged in as a Guest) the block was hidden.

That's exactly what I would like to do with the Navigation block... however, on this Moodle FAQ page, I was noticing the following text: "...to hide all blocks (including blocks that do not allow you to assign roles - like Navigation), you can go to Administration>Site administration>Users>Permissions>Define roles and edit the Guest role to disallow View block"

It sounds like perhaps the Navigation block is setup in some way that what I'm trying to do is simply not allowed by Moodle? It's funny that the Navigation block as an area where you can assign roles, setup overrides, etc., but they just don't seem to have any effect.

In reply to Jason Press

Re: Hiding Elements for Guests Only

by Алексей Кадин -

Okay. So, we cannot affect the Navigation (and Settings, I guess) block by standard instruments.

So, another decision will be to disallow the guest to view any block ("not set" or "prevent", not "prohibit"), and then allow them to see blocks that we need to be visible (each block, manually).

Not so convenient as the "straight" method, but what else can we do. Is the case only about FrontPage?

In reply to Алексей Кадин

Re: Hiding Elements for Guests Only

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

You can hide the Navigation block from guests in the same way as the Administration block - I just tweaked that documentation page. Click the Assign roles in Navigation block, scroll down past the warning message and click Permissions and then prevent guests from viewing.

In reply to Mary Cooch

Re: Hiding Elements for Guests Only

by Jason Press -

Thanks Mary. I gave this a try but didn't see a warning message in the "Assign roles" area. I've tried preventing Guests from viewing the Navigation block in this area and it hasn't worked for me so far. Алексей's response above was a nice work-around for me in this situation.

In reply to Алексей Кадин

Re: Hiding Elements for Guests Only

by Jason Press -

Yes, of course! That was a great and very simple solution and worked perfectly! (And to answer your question- yes, the Navigation block was only appearing for Guests on the Front Page.)

Thanks so much Алексей!