PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '14-868-menu' for key 'PRIMARY': INSERT INTO {workbench_access_user} (uid, access_id, access_scheme) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 14 [:db_insert_placeholder_1] => 868 [:db_insert_placeholder_2] => menu ) in drupal_write_record() (line 6852 of /kiva/cms/main/includes/common.inc).

Probably should do a select first to ensure the user doesn't already exist in workbench_access_user and if so then do the insert, otherwise drupal_set_message(t('User is already assigned to this section'));

As probably a separate bug, after adding a user, they didn't show up, so I tried again, and got the above.

Comments

agentrickard’s picture

Did you ignore the autocomplete and type in a user name?

agentrickard’s picture

Status: Active » Postponed (maintainer needs more info)

Also need the path to the form you used.

agentrickard’s picture

Cannot replicate at admin/config/workbench/access/editors/taxonomy/workbench_access nor at admin/config/workbench/access/editors/menu/menu-primary-links.

Nor at the 'section' tab for a user.

agentrickard’s picture

Note that in workbench_access_editor_form_submit we already check if the user is assigned. Line 525.

    $account = user_load_by_name($values['add_user']);
    $sections = $account->workbench_access;
    if (!empty($account->workbench_access_by_role)) {
      foreach ($account->workbench_access_by_role as $key) {
        unset($sections[$key]);
      }
    }
    if (!empty($account->status) && !in_array($values['workbench_access']['access_id'], array_keys($sections))) {
      workbench_access_user_section_save($account->uid, $values['workbench_access']['access_id'], $values['workbench_access']['access_scheme']);
    }

May be it's the role-based exclusion that causes the issue, but even if I add the user by role, I can't replicate this error.

I suspect you are having a different issue.

coderintherye’s picture

Status: Postponed (maintainer needs more info) » Active

The problem seemed to be if the user didn't have a role with permissions allowing them to be assigned? e.g.,
"Allow all members of this role to be assigned to Workbench Access sections"

There's definitely a bug here, but you are right that it could be different than as described, in that you might need to just do better confirmation on the initial user add.

I was able to get it to work, but only by adding adding a role to that user which had the permission defined above. I managed to figure out what was needed by looking at the sql statement in workbench_access.admin.inc Here is some output from the

It was only once I got the query to return a count of 1 (by doing the above) that the user actually appeared:
(Note the user in question is uid 14)

mysql> SELECT COUNT(wau.uid) FROM workbench_access_user wau INNER JOIN users_roles ur ON wau.uid = ur.uid INNER JOIN role_permission rp ON ur.rid = rp.rid;
+----------------+
| COUNT(wau.uid) |
+----------------+
| 0 |
+----------------+
1 row in set (0.00 sec)

mysql> desc workbench_access_user;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| uid | int(11) | NO | PRI | NULL | |
| access_id | varchar(80) | NO | PRI | | |
| access_scheme | varchar(40) | NO | PRI | | |
+---------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> select * from workbench_access user;
+-----------+---------------+-------------+----------------+
| access_id | access_scheme | access_type | access_type_id |
+-----------+---------------+-------------+----------------+
| 868 | menu | menu | main-menu |
| 869 | menu | menu | main-menu |
| 870 | menu | menu | main-menu |
+-----------+---------------+-------------+----------------+
3 rows in set (0.00 sec)

mysql> select * from workbench_access_user;
+-----+-----------+---------------+
| uid | access_id | access_scheme |
+-----+-----------+---------------+
| 14 | 868 | menu |
+-----+-----------+---------------+
1 row in set (0.00 sec)

mysql> select count(uid) from workbench_access_user;
+------------+
| count(uid) |
+------------+
| 1 |
+------------+
1 row in set (0.00 sec)

mysql> SELECT COUNT(wau.uid) FROM workbench_access_user wau
-> INNER JOIN users_roles ur ON wau.uid = ur.uid
-> INNER JOIN role_permission rp ON ur.rid = rp.rid
-> WHERE wau.access_scheme = 'menu' AND wau.access_id = '868'
-> AND rp.permission = 'access workbench access by role';
+----------------+
| COUNT(wau.uid) |
+----------------+
| 0 |
+----------------+
1 row in set (0.00 sec)

mysql> SELECT COUNT(wau.uid) FROM workbench_access_user wau INNER JOIN users_roles ur ON wau.uid = ur.uid INNER JOIN role_permission rp ON ur.rid = rp.rid WHERE wau.access_scheme = 'menu' AND wau.access_id = '868' AND rp.permission = 'access workbench access by role';
+----------------+
| COUNT(wau.uid) |
+----------------+
| 0 |
+----------------+
1 row in set (0.00 sec)

mysql> select * from users_roles;
+-----+-----+
| uid | rid |
+-----+-----+
| 1 | 3 |
| 3 | 3 |
| 10 | 3 |
| 11 | 3 |
| 13 | 3 |
| 23 | 3 |
| 39 | 3 |
| 50 | 3 |
| 108 | 3 |
| 12 | 4 |
| 131 | 4 |
+-----+-----+
11 rows in set (0.07 sec)

mysql> select * from users_roles;
+-----+-----+
| uid | rid |
+-----+-----+
| 1 | 3 |
| 3 | 3 |
| 10 | 3 |
| 11 | 3 |
| 13 | 3 |
| 23 | 3 |
| 39 | 3 |
| 50 | 3 |
| 108 | 3 |
| 12 | 4 |
| 14 | 4 |
| 131 | 4 |
+-----+-----+
12 rows in set (0.00 sec)

mysql> SELECT COUNT(wau.uid) FROM workbench_access_user wau INNER JOIN users_roles ur ON wau.uid = ur.uid INNER JOIN role_permission rp ON ur.rid = rp.rid WHERE wau.access_scheme = 'menu' AND wau.access_id = '868' AND rp.permission = 'access workbench access by role';
+----------------+
| COUNT(wau.uid) |
+----------------+
| 0 |
+----------------+
1 row in set (0.00 sec)

mysql> SELECT COUNT(wau.uid) FROM workbench_access_user wau INNER JOIN users_roles ur ON wau.uid = ur.uid INNER JOIN role_permission rp ON ur.rid = rp.rid WHERE wau.access_scheme = 'menu' AND wau.access_id = '868' AND rp.permission = 'access workbench access by role';
+----------------+
| COUNT(wau.uid) |
+----------------+
| 1 |
+----------------+
1 row in set (0.00 sec)

coderintherye’s picture

Path is: example.com/admin/config/workbench/access/editors/menu/868

agentrickard’s picture

I was able to get it to work, but only by adding adding a role to that user which had the permission defined above.

This is by design. See the release notes and README.

We still need some _validate magic, I agree.

coderintherye’s picture

Yeah, I don't disagree that's the way it should work, but it definitely should have validation. If I can figure out the right magic I'll upload a patch.

agentrickard’s picture

Thanks.

coderintherye’s picture

Status: Active » Needs review
StatusFileSize
new747 bytes

Here is a simple patch. Tested to work for me on a fresh workbench checkout from git.
May want to change the wording or formatting.

agentrickard’s picture

To be sure: you triggered the error by typing in a user name that was not auto-completed and did not have this permission, right?

coderintherye’s picture

Yes. So in the original code it went like

1) Type in name
2) Click "Add editors"
3) The form submits, no error is displayed, the user doesn't show up but it appears in the db that they were still added.

New code:

1) Type in name
2) Click "Add editors"
3) Validation function checks to see if they are in the proper role to be allowed to be a moderator.
4a) If validation fails, the error message is displayed
4b) If the user does have the role and validates, user is added as normal. User shows up now.

agentrickard’s picture

StatusFileSize
new566 bytes

String concatenation like that inside t() will drive translators crazy, I believe. PHP ignores white space.

Revised patch. Not sure we want to tell the user which permission to change.

coderintherye’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies cleanly and works, looks good to me, look forward to seeing it make it into your next release.

agentrickard’s picture

Status: Reviewed & tested by the community » Fixed

Committed!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.