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.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 1194530-valdate.patch | 566 bytes | agentrickard |
| #10 | workbenchnoallowadduserifnoroleperm-1194530-10.patch | 747 bytes | coderintherye |
Comments
Comment #1
agentrickardDid you ignore the autocomplete and type in a user name?
Comment #2
agentrickardAlso need the path to the form you used.
Comment #3
agentrickardCannot replicate at
admin/config/workbench/access/editors/taxonomy/workbench_accessnor atadmin/config/workbench/access/editors/menu/menu-primary-links.Nor at the 'section' tab for a user.
Comment #4
agentrickardNote that in
workbench_access_editor_form_submitwe already check if the user is assigned. Line 525.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.
Comment #5
coderintherye commentedThe 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)
Comment #6
coderintherye commentedPath is: example.com/admin/config/workbench/access/editors/menu/868
Comment #7
agentrickardThis is by design. See the release notes and README.
We still need some _validate magic, I agree.
Comment #8
coderintherye commentedYeah, 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.
Comment #9
agentrickardThanks.
Comment #10
coderintherye commentedHere is a simple patch. Tested to work for me on a fresh workbench checkout from git.
May want to change the wording or formatting.
Comment #11
agentrickardTo be sure: you triggered the error by typing in a user name that was not auto-completed and did not have this permission, right?
Comment #12
coderintherye commentedYes. 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.
Comment #13
agentrickardString 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.
Comment #14
coderintherye commentedPatch applies cleanly and works, looks good to me, look forward to seeing it make it into your next release.
Comment #15
agentrickardCommitted!