Block Node Access After A Certain Amount of Views I've come across a client requirement in Drupal that is very new to me.

The website is subscriber based, so users pay to subscribe at which point they are granted a subscriber role. They then have access to particular content types that they did not previously have access to. This is all easy enough.

The challenge though is that they require each node to only be accessible 5 times by each user.

The website is running Drupal 7 and presently has both Content Access and NodeAccess modules installed along with Rules and Flag.

So far I've worked out how to block access to an entire content type using Rules and roles. I've also been experimenting with Rules and Flags to block a node. For example:

If a node is flagged 5 times by the same user, it should be blocked.

But it still seems to come back to requiring a role that is not able to access it. It's impractical to have a role for every piece of content that cannot be accessed though. Content Access and NodeAccess also revolve around roles.

It seems like every possibility I come across requires a role in order to prevent access, which just doesn't work for this situation as every user is going to potentially have a number of different nodes they cannot access and they are all going to be different. This severely limits the ability of roles to work as far as I can see.

Does anyone have any ideas that might be able to point me in the right direction to achieve this?

Thanks in advance for your help!
You can control it using hook_node_access($node, $operation, $account) for Drupal 7. For Drupal 6 one can use hook_nodeapi() for similar result.

When $operation is view, first update usage index for that $account (you need a database table with nid and uid as keys, and number of uses field) and then test if he still can see it, or no. Return appropriate NODE_ACCESS_* constant. Done.

Of course you will need to write your own module, but I guess it'll take less time to wrap simple function in a module than to hack 3 or 4 modules to work together in a way they was never designed to.