Hey there,

Was just wondering if it were possible to have user-specific limits have a higher priority than role-specific limits so to say. So if there is a role limit of 1 for role 'myrole' and a specific content type CT, and also a user limit of 2 for user 'A' (role='myrole') for the same content type CT - that then the user A would be able to create two instances of CT and everyone else with the role 'myrole' only 1.

At the moment role limit has full precedence, meaning that specific user limits are ignored.

Thanks,
Martin

Comments

arski’s picture

PS. I see now that it actually takes the smallest of the encountered limits. So if role limit is 1 and user limit is 2, the user will effectively have the limit of 1. And if role limit is 2 and user limit is 1, then the user will have 1 again. This is more consistent that I thought at first, but still it shouldn't be too hard to make the user-specific limit have a positive effect, as opposed to the current restrictive-only implementation.

thisisnotrealpeople’s picture

/**
* Helper function to check limit violations for this node.
* Always returns FALSE for user 1.
*
* @param $node
* The node to check.
*/
function _node_limit_violates_limit(&$node) {
if ($node->uid == 1) {
return FALSE;
}
$limits = node_limit_limits($node);
$my_limits = 0;
$my_counts = 0;
foreach ($limits as $idx => $lid) {
$limit = node_limit_load($lid);
if ($limit['limit'] == NODE_LIMIT_NO_LIMIT) {
continue;
}
$sql = _node_limit_sql($limit['lid']);
$my_counts += db_result(db_query($sql));
$my_limits += $limit['limit'];
//$count = db_result(db_query($sql));
/*if ($count >= $limit['limit']) {
return TRUE;
}*/
}
if($my_counts >= $my_limits) return TRUE;
return FALSE;
}

arski’s picture

Hey, could you tell like where to put this, or actually provide a patch?

DuaelFr’s picture

Category: support » feature
Status: Active » Needs work

The code provided on #2 only adds all limits and all counts to compare them so it is very risky.

Sample : I can create 1 node type "cars" and 1 node type "houses". With this code I could create 2 cars and 0 houses or 1 and 1 or 0 and 2.

The module work as expected and is restrictive. The lowest limit will be the main one.

There are many ways to improve this :
- general configuration to choose priority between the lowest and the highest limit
- general configuration to choose submodules priority by weight
- same as upper but for each limit rule

Lets try to get the module working before improving it

kala4ek’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes