Hide menu items for anonymous users in Drupal 8 - drupal-8

How to hide the menu items for anonymous users in drupal 8?
Since the hook_translated_link_alter has been deprecated , which hooks can be used to perform the task?

You need to override/extends the DefaultMenuLinkTreeManipulators class to provide the role as access on menu items.
Namespace is Drupal\Core\Menu\DefaultMenuLinkTreeManipulators;
OR
You can use menu per role module to set the role based access on menu items

Your menu items will have a certain route bound to them. In your .routing.yml file you can set permissions on your route which will be carried on to the link.
Quick example: Lets say we create a link to the following route:
profile.page:
path: 'profile'
defaults:
_controller: '\Drupal\profile\Controller\ProfileController::profile'
_title: 'Profile'
requirements:
_permission: 'access profile content'
Here, 'access profile content' is a custom permission but it doesn't really matter what permission it is. Your link will also get this permission and Drupal will hide your link when the user doesn't have permission to access the content behind it.
Hope this helps

Related

Sitecore Custom role permissions for experience editor

We need to add a custom role which should have edit permissions on the page but should be able to add components\create new content. The user shouldn't be able to publish content or add new pages. He can edit page and add\create relevant components\content on the page. Currently, we've added below roles to the custom role and denied 'create' permission to the role on the entire content tree except for relevant page templates and placeholder settings.
Sitecore Designer
Sitecore client authoring
But while adding content in experience editor user is getting 'you don't have access to add content' error. What should be the exact set of permissions to be able to add content to pages but not create pages.
By default items are denied access and you need grant the specific access on the items in question. To be able to edit an item a user will need the Write permission.
Resources:
The different Access Rights explained
Assigning Access Rights

System folder not visible

I have role named "GCP US Alias and Redirect" and I have given full access permission for "/sitecore/system/Aliases" and its descendants as in screen shot below.
Now I have assigned "GCP US Alias and Redirect" role to a user, When I login to sitecore as "GCP US Alias and Redirect" user I don't see "/sitecore/system" folder. I can just see "/sitecore/content" folder as in below screen shot.
I can see System folder when searched it by GUID as shown in below screen shot.
What do I do to make it visible at initial place when I open content editor?
Switch to the View tab and select Hidden items and Entire tree checkboxes. They are unchecked by default for non-admin users.
If you don't see the View tab, make sure that either your role has Read access to it (/sitecore/content/Applications/Content Editor/Ribbons/Ribbons/Default/View and /sitecore/content/Applications/Content Editor/Ribbons/Chunks/View in core database) or that your role inherits from e.g. sitecore\Sitecore Client Designing role (check if that role doesn't have too much access rights for your custom role first).

Django/guardian default permission

What I would like to do is to set view permissions of certain parts of the site depending on the user (that is easy using permissions and guardian).
I have a set of buttons across the top of the page. For one or two buttons I want to set permissions for only a few users or groups to be able to see that button. That part is fine (using guardian).
Each button is related to a model instance. The model has a view_button permission. Is there a way to have the view_button permission be default to True if the permissions is empty? Or, is there a way of saying has_perm be True for all users?
Maybe I could just create a static method within the model that does that check for me. Is there a better way to do it?

How do I enable editing features in Sitecore page editor?

I'm using Sitecore 7.2 and trying to allow a user to set things like datasources and some custom parameters on sublayouts in page editor mode. The user is a member of sitecore\Designer and sitecore\Author, but when that user tries to edit the component properties, the fields appear grayed out/disabled.
I am able to enable these options by setting a user as an admin, but don't want to grant quite that much power to this particular user.
Here is how tried it and it works on Sitecore 7.2
Create a new user called cbarnes (and in your case if there are other content editors)
Create a new Role - call it say SP Content Editor Authoring
Make that role a member of sitecore\Author and sitecore\Designer. This way it inherits everything from those two roles.
Make the user cbarnes one of the members of that role.
Lastly go to the security editor and give Write permission on the item after selecting the SP Content Editor Authoring Role under Roles and Users section.
Login as cbarnes user and check if it work!
Let us know if this works for you. Happy Sitecoring!
I actually ran into this same issue today on a 7.2 project. While my user had both the sitecore\Designer and sitecore\Author roles as a part of a client-specific author role I created, they were not able to edit rendering parameters.
By default, users in these roles have read-only access the Sitecore\Templates folder. Within this folder I had an additional folder named "Rendering Parameters" where I stored all my rendering parameters templates. I added Write access to the client-specific role for my "Rendering Parameters" template folder and users in that role can now edit and save rendering parameters without elevated permissions.
Use "Access Viewer" tool from Sitecore start menu to define why your user does not have required rights.
By default both roles sitecore\Designer and sitecore\Author have field read and field write access to Layout template section fields. But, it seems that roles have only read access to item that you are trying to edit. You can add write access to that item.
For more details look at Security Administrator´s Cookbook

Allow admin role to view certain pages in Parse

So as of right now I just have a page that I use locally to change objects. How can I go about creating a page that is only visible to the admin user. Using roles you can restrict access to certain objects but Im not sure the best way to include a page in your application that is only visible to certain users. Thanks for any help
Create an AccessRole (or similar) class that you can use for this, then show or hide the link/button (from menu or whatever) to open that page. Users who are not members of the Admin role does not see the button/link/menu option.
In the AccessRole class, you have a "users" column where you store an array of users that are members of the role, and a "name" column for the role name (Admin, Editor, Reader etc).
When your application starts, you check if the user is a member of the Admin role (which should be temporarily stored locally).