I need to give certain users edit access to their specific shortcut set and not access to change the set name itself.
I am first posting the feature request here because adding this permission is painfully easy.
Attached is an example module that does this.
I have no problems with starting a new project, but this is so simply it feels like having its own project is overkill.

Example Use Case:

Using the rules module, each individual user can have their own shortcut set.
Doing this means that the rule set name must not conflict on creation.
Using a generated set name of 'user-kevinday' with kevinday being the drupal user name is a way to do this.

This can be done with a single reactionary rule:
Rule Name = Auto-Create Shortcut for New User
Rule Events Name = After saving a new user account
Rule Actions:
- Execute Custom PHP code:

    $set_title = 'user-' . $account->name;
    if (shortcut_set_title_exists($set_title)){
      watchdog('rules', "The shortcut set for the user %username called %shortcut_set already exists and will not be created.", array('%username' => $account->name, '%shortcut_set' => $set_title));

    $shortcut_set = new stdClass();
    $shortcut_set->title = $set_title;

    $shortcut_set = db_select('shortcut_set', 'ss')
    ->condition('title', $set_title)

    if (!is_object($shortcut_set)){
      watchdog('rules', "Cannot assign the shortcut set %shortcut_set to %username due to a database loading error.", array('%username' => $account->name, '%shortcut_set' => $set_title), WATCHDOG_ERROR);

    shortcut_set_assign_user($shortcut_set, $account);

The users themselves will have 'Edit current shortcut set' permission but not the 'Select any shortcut set'.
If the users can change the shortcut set name, then there would be a problem.
This module solves this problem by adding an additional restriction to changing the shortcut set name.

edit_shortcut_name_restriction.tgz1.72 KBthekevinday
Members fund testing for the Drupal project. Drupal Association Learn more


cicero44bc’s picture

This would be a really useful feature. Is it possible already to define a shortcut set for a type of user too, e.g. authenticated user sees a particular shortcut set and the site admin all? Following on from that is it possible create different user groups with different permissions then different shortcut sets, eg, blogger, forum admin, gallery admin, manager (similar permissions to the site admin account but more restricted) etc? Newbie here, sorry if this has been answered elsewhere. I'm just trying to find if this is possible with the core setup or requires an extra module.

cicero44bc’s picture

Sorry for taking up space here with this question. I'm reading the rules module documentation now and it seems contain what I wish to know. If I'm understanding this feature request correctly though, in that it would be useful to give a specific user specific permissions; I completely agree, and from what you have described it appears a quick change/fix, I hope it gets adopted.

David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev

The module looks reasonable, but in terms of adding this as a core feature, it really has to wait until Drupal 8. Adding permissions in a stable branch is too big of a change, unless there is a really really good reason to do so. Please feel free to post it as a contrib module for Drupal 7, though!

Also, I'm not super-familiar with how Rules works, but I'm not sure I understand why you need to force the shortcut set title to be unique? The shortcut module itself doesn't impose this restriction at the API level (only when creating them via the user interface). I guess it would be confusing if you let people edit them and wound up with two shortcut sets that had the same human-readable name, but I don't think anything would actually break?

thekevinday’s picture

I created a sandbox for a drupal 7 version of this here: http://drupal.org/sandbox/thekevinday/1078860

In response to #3, Looking at the code above, I can see that I mixed the 'set_name' with the 'title'.
In this case I believe you are right and it should be safe to rename 'title'.
I guess I mixed up set_name and title.

Wim Leers’s picture

Status: Active » Closed (works as designed)

In Drupal 8, shortcut sets are entities, and like any other entity, it must have a unique name. So the uniqueness constraint is already done.

I think a new issue is in order to clarify why a can change shortcut name permission is useful (that should've been can change shortcutset name, btw).