You can achive this with replacing this function:
function apply_for_role_access($account) {
return $account && $account->uid && (($GLOBALS['user']->uid == $account->uid) && user_access('apply for roles'));
}
with this:
function apply_for_role_access($account) {
global $user;
$roles = variable_get('users_apply_roles', array());
$multiple = variable_get('apply_for_role_multiple', array());
foreach ($roles as $rid => $role) {
// Check if the user has this role or has applied for this role
if (!$user->roles[$rid] && (db_result(db_query("SELECT uid, rid FROM {users_roles_apply} WHERE uid = %d AND rid = %d", $user->uid, $rid)) == 0)) {
$filter_roles[$rid] = $role;
}
}
return $account && $account->uid && (($user->uid == $account->uid) && user_access('apply for roles')) && is_array($filter_roles);
}
Tyrael
Comments
Comment #1
drewish commentedi support this change but i don't think it should be called apply_for_role_access because it conflicts with the naming for hook_access but has a different parameter signature.
Comment #2
Soren Jones commentedI'd actually like to take this a step further and make it an option to disable the tab entirely -- that is three options: 1) always on, 2) off when there are no available roles and 3) always off.
Comment #3
drewish commentedSoren Jones, what would be the use case for always on or always off? It would be easy to achieve either of those states by using hook_menu_alter() to set the callback's #access parameter.
Comment #4
drewish commentedI'd suggest renaming it and moving the bit of code that computes the remaining applications into it's own function:
Comment #5
drewish commentedthough maybe it would make more sense to provide a listing of the pending/denied applications on the tab and show it all the time?
Comment #6
Soren Jones commentedAndrew,
Brilliant idea, it's good real estate and it makes sense to do more with it.
I'm still for the option to hide the tab. However, I don't think it's urgent.
Best,
Soren
Comment #7
Soren Jones commentedAndrew,
RE: #3, one use case I was imagining for always off was a site using nodes as applications rather than the user tab. Given that feature doesn't exist yet, I guess it's not so urgent. Hah. Anyway, I'm more interested in triggers/actions integration, which you're on, greater permissions granularity (role x can only apply for role 1, but role y can apply for roles 2 & 3), and applications as nodes.
Cheers,
Soren
Comment #8
drewish commentedwell for applications as a node i'd think workflow would be a much more flexible solution. you'd have better actions/triggers support since they'd be proper nodes but the downside would be providing access control.
Comment #9
Soren Jones commentedFixed in dev.
Comment #10
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #11
fehin commentedI'm wondering if I could use this code for 5x? Thanks.
Comment #12
fehin commentedI just noticed that this code has been added to the module but my menu item is still visible even when there is no role to apply for. How can I fix this? Thanks.
Comment #13
webcultist commentedAt first: Thankyou for this module, it's very useful!
Could we use the functionality in this ticket for the 7.x version of the module? As I can see, it just shows us an empty form if there are no roles available.
Greetings
Comment #14
jnicola commentedTesting on 7.x-2.x branch.
Logged in user, without permission to apply for a role cannot view tab, gets access denied at page. With permission can see tab and can access page.
Seems to already be integrated!