I will start from the beginning.
Say I have two content types, and two user roles. I want User role A to be able to view content type X only, and user role B to be able to view content type Y only.
By default authenticated drupal users can view all content types, so I used Content Access module. (FYI: I need content type level access control only).
Now I can check if a user have the right to create a content type by using
if( user_access("create my_type content") )
How do I check the view permission which are set by Content Access Module. Obviously I tried "view my_type content", "view all my_type content", and "view own my_type content", but none worked.
I have also tried
if(node_access('view', 'my_type'))
which didn't work.
Any ideas?
Comments
(I don't know the answer ;-)
(I don't know the answer ;-) )
You should create a support request in the issue queue of the content access module (see https://drupal.org/node/644164).
It is more likely, that you will get a good answer there.
It is not clear what the
It is not clear what the context of your code is or why you would need it
Thanks for your interest
Thanks for your interest Nevets,
I want to set the view permission for a content type and use a function to find out if logged in user has the right to view a page (while listing a list of all the pages).
They question is why since
They question is why since drupal core handles that for displaying a single node and views when listing nodes. So once again, the context is unclear.
Hello Nevets,I am not using
Hello Nevets,
I am not using views for the listing. It is some custom code. I wasn't making use of hook_permission() to grant the view permission, but now when I am, it's causing another issue. (Please see https://drupal.org/node/2100697#comment-7919553)
What would be the best way to achieve this?
Why not use views?
Why not use views?
Multiple reasons. Most
Multiple reasons. Most important one is client wants his employees to be able to create views on their own, without any training. This custom code has an easier interface they can work with (when working with multiple tables) and comes with filters as they want them.
Hey ho :DSo you say you
Hey ho :D
So you say you have:
ROLE A | ROLE B | authenticated user | anonymous user
So now you can make it clear and easy by creating your own permissions.
With this you can controll the permissions by View UI and also by code via
Remember authenticated user is a requierd role for each user so dont add your permission to this role.
Hello BlackyWhoElse,Thanks
Hello BlackyWhoElse,
Thanks for your reply. I will try it and let you know how it went.
Regards,
Nick
Hello Blacky,It worked, but
Hello Blacky,
It worked, but there is an issue.
Below is the code I used in .Module file
The following is working
In permissions, when A is checked and B is not I get the output "in No Access", which is desired.
The issue: when I created contents of both types from admin account, user was able to see both (When he shouldn't get access to type B.
Thanks!
One yes/no question to anyone
One yes/no question to anyone who can answer it...
Do I need to place a condition in the template for content to be restricted for a user or drupal does it automatically?
More specifically if I write
does drupal know that I mean view right, and provides/blocks view right, or do I use if(user_access("view contenttype_a")) condition to stop text from loading where needed?
Thanks,
Nick!
Ok lets see.This should help
Ok lets see.
This should help you.
Thanks! I implemented
Thanks!
I implemented something similar in hook_view and it is doing what I wanted.
Regards,
Nick
So if you are using views why
So if you are using views why you downt use the permission system and set it to Roles?
Page settings -> Access
I guess cuz I don't know how
By default drupal shows create, edit, and delete permissions in permissions page, but not the view permission.
So now I am using hook_permission() to create the view permission, which then is visible in permissions page.
After that I am using user_access() in hook_view() in a condition to check the permission.
Is there a better way of achieving this?
Any code implementing that, or keywords to do the search would be a great help.
Thanks,
Nick
Here is an example: Click me
Here is an example:
Click me :D
Thanks for taking the time to
Thanks for taking the time to attach the image BlackyWhoElse,
Actually I am using some custom code for listing, not the drupal's views.
When you said "views" I though you were referring to my "hook_view" message just above it.
I was able to solve the issue with the help of an earlier comment of yours.
Thanks!
Actually I am using some
You need to be clear about this when discussing Drupal. If you use the term 'view', people will think you are referring to the Views module. I mostly ignored this whole thread because I thought you were talking about the Views module, and I don't have much advice to give regarding that module.
Hello Jay, I cleared that in
Hello Jay,
I cleared that in my October 30th comment https://drupal.org/node/2100697#comment-7919563
May be the title of the post could be different to avoid the confusion. Thanks for the suggestion.