I manage an e-commerce website with two types of user roles for customers, retail and dealer. I have dealer setup as the only option in 'apply for role' module. After I approve an application (in 'Manage role applications'), I would like to be able to delete the approved role application without having the role removed (otherwise I will end up with a huge list of old applications). Currently the module deletes the application and the approved role when I hit delete from 'Manage role applications'. I have not found a module setting that controls this. Is there a way to delete only the application?

Comments

Soren Jones’s picture

Title: Deleting approved application deletes approved role from user. » Add an option to delete or archive approved role applications
Version: 6.x-1.8 » 7.x-1.x-dev
Category: support » feature

In case you haven't found it, the function that you want to look at is apply_for_role_remove_apply() in the apply_for_role module.

function apply_for_role_remove_apply($user, $rid) {
  $uid = $user->uid;
  if ($apply = db_fetch_object(db_query("SELECT * FROM {users_roles_apply} WHERE uid = %d AND rid = %d", $uid, $rid))) {
    apply_for_role_delete_role($uid, $rid);
    db_query("DELETE FROM {users_roles_apply} WHERE uid = %d AND rid = %d", $uid, $rid);

    $apply->approval = -1;
    module_invoke_all('apply_for_role', 'remove', $apply);

    return TRUE;
  }
  return FALSE;
}

The line that deletes the roles from the user is:
apply_for_role_delete_role($uid, $rid);

It sees like the best thing to do is to move the call to apply_for_role_delete_role() out of apply_for_role_remove_apply(), but that would be an API change.
So I've changed this to a feature request for an option to delete or archive approved role applications as that would keep the audit trail in place for those who want it.

Soren Jones’s picture

Status: Active » Postponed
Soren Jones’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Postponed » Active
Issue tags: +Needs documentation, +API change

Reactivating this. It at least needs documentation.

Soren Jones’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Postponed
Issue tags: -Needs documentation

Actually this is already documented in line on the delete confirmation page:

The role will be automatically deleted from the user and they will be allowed to re-apply for the role.

And all of the functions need documentation, so I'm deleting that tag and moving this to 7 again.

not_Dries_Buytaert’s picture

Category: bug » feature
Status: Active » Postponed

We at least need an option in '{domain}/admin/settings/apply_for_role' to show either all or only pending role applications in '{domain}/admin/user/apply_for_role'. Select 'only pending' value by default.

As suggested here (http://drupal.org/node/771548) we also need an option in '{domain}/admin/settings/apply_for_role' to automatically archive or delete role applications, after they have been approved or denied.

You rightfully quoted the 'apply_for_role_remove_apply' and 'apply_for_role_delete_role' functions from the 'apply_for_role.module' file of this module.
So, why couldn't you (as the maintainer of this module) alter your code? What does this have to do with (I guess you meant) this (http://api.drupal.org/api/function/user_roles/6) API?

This issue was originally submitted for the D6.x branch. Please, file another one for D7 or to request a port to D7.x, if needed.

not_Dries_Buytaert’s picture

Title: Add an option to delete or archive approved role applications » Add option to automatically and manually archive or delete (denied and approved) role applications without deleting roles
Version: 7.x-1.x-dev » 6.x-1.x-dev
Category: feature » bug
Status: Postponed » Active

Forgot to change category and status too. Records of role applications should by themselves have nothing to do with records of roles.

Soren Jones’s picture

Status: Postponed » Active

Records of role applications should by themselves have nothing to do with records of roles.

That's your use case. Please read the explanation above. This is the expected behavior. It's documented by the designer. And it would be an apply_for_role API change (not a user_roles API change). A change would have very serious consequences for anyone using it as designed.

As a feature request and an API change request, this is unlikely to be changed in 6. This will most likely be addressed with a change to the admin UI in 7 and not to the API.

not_Dries_Buytaert’s picture

Title: Add option to automatically and manually archive or delete (denied and approved) role applications without deleting roles » Add option to automatically and manually archive or delete (denied and approved) role applications with(out) deleting roles

Sry, if my limited technical knowledge causes any confusing or causes me to miss your point. Still, I fail to see why a "automatically delete user-role relationship, when deleting role application" checkbox option in in '{domain}/admin/settings/apply_for_role' could not easily be implemented without implications to existing users of this module (if the default value is set appropriately). A simple if-then around aforementioned apply_for_role_delete_role function of this branch would do just fine, wouldn't it?

not_Dries_Buytaert’s picture

Or following configuration options in '{domain}/admin/settings/apply_for_role' would do the trick:
a) show either only pending (default setting) or all role applications in '{domain}/admin/user/apply_for_role' and
b) not show (default setting) or show the "Delete role application" button in '{domain}/admin/user/apply_for_role'.

NB: Such change would only affects the web UI (not the API/ other modules) and not the current users either.

Soren Jones’s picture

Thank you for clarifying your goals.
It should be possible to address both of these cosmetically in the theming layer.
Try this in a custom module:

/**
  * Implementation of hook_form_alter.
  */
function MYMODULE_form_apply_for_role_admin_form_alter(&$form, $form_state) {
  foreach (element_children($form['apps']) as $uid) {
    foreach (element_children($form['apps'][$uid]) as $rid) {
      unset($form['apps'][$uid][$rid]['delete']);
      if ($form['apps'][$uid][$rid]['status']['#value'] != t('Pending')) {
        unset($form['apps'][$uid][$rid]);
      }
    }
  }
}

Of course, it would still be possible to delete applications via the URL.

Soren Jones’s picture

Title: Add option to automatically and manually archive or delete (denied and approved) role applications with(out) deleting roles » Add an additional privilege to delete or reset applications
Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue tags: -API change

It seems that the solution to most of this issue would best be handled with #364247: Add integration with views, in which case hiding processed applications will be configured in Views.
However, it also seems that an additional permission should be added for deleting or resetting applications.
The permission shouldn't be checked inside apply_for_role_remove_apply(), but in any call to the function in the module.
That way anyone who wants to use the API directly from a custom module can do so without a permission check.

Soren Jones’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

Fixed in 7 -dev. To be ported to 6.

jnicola’s picture

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

Fixedin 7.x, won't be providing 6.x support.

jnicola’s picture

Status: Active » Closed (won't fix)