When populating the $user->roles array in user_load(), line 174 and line 177 in version 6.9, the predefined roles are inserted 'as is', they don't get translated.
When modules try to discover permissions or load settings based on roles, they use the function user_roles(), which does role translating using t().
I discovered this bug when trying to blog to a German Drupal installation using Microsofts Windows Live Writer and accessing the xmlrpc interface using the WLW_BlogAPI module. Posting attachments was not possible due to not being able to figure out the permitted upload sizes for my role.
The lines in user.module should be:
172 $user->roles = array();
173 if ($user->uid) {
174 $user->roles[DRUPAL_AUTHENTICATED_RID] = t('authenticated user');
175 }
176 else {
177 $user->roles[DRUPAL_ANONYMOUS_RID] = t('anonymous user');
178 }
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | user-roles-translated-blogapi.patch | 1.18 KB | gábor hojtsy |
Comments
Comment #1
gábor hojtsyModules use user_access() not user_roles() to look up permissions, since given roles cannot be assumed on the site. Looking into user_access() it does not care about the textual name of the role, but only about the key (internal role id).
Which modules do you see using user_roles()?
Comment #2
bkraegelin commentedThanks for the reply.
I found the bug when trying to set up wlw_blogapi module for use with M$ Windows Live Writer. It rejected uploading images or other files.
The core module blogapi (wlw_blogapi is a textual daughter of it) does permission checking for allowed uploads in function blogapi_metaweblog_new_media_object() using array_intersect() of
- user_roles(FALSE, 'administer content with blog api')
// all roles, which have permission to use blogapi
- $user->roles
// roles, the logged in user belongs to
user_roles() gives 'Authentifizierter Benutzer' in the German Drupal installation, $user->roles gives 'authenticated user'.
As blogapi belongs to core, I consider this a serious bug.
Comment #3
gábor hojtsyOk, seeing this at http://api.drupal.org/api/function/blogapi_metaweblog_new_media_object/6. Since the role numbers are only what is ever used in the function later, that function should just intersect the array keys, not the array values.
Something like:
Can you try this change out? (Marking as patch needs review, although I've only described the required changes).
Once this is validated to work, it should be ported to both the core blogapi module and whatever descendants it has.
Comment #4
bkraegelin commentedWorks, no question.
Remember Larry Wall's book on Perl: "There's More Than One Way To Do It".
My suggestion was, to get a consistent behaviour to user_roles(). So the user module would be consistent within itself.
Are there specific reasons, not to fix it in user_load()?
Comment #5
gábor hojtsyIt probably would be best to fix in user_load() as well, but that would require validation of all core and at least critical contributed module code where $user->roles or a derivative/copy/excerpt of $user->roles is used, so that it also assumes a translated role name.
Comment #6
bkraegelin commentedI can live with either... waiting for your decision.
I give the fix to the developers of wlw_blogapi. Core blogapi should be your responsibility.
Comment #7
gábor hojtsyHere is all direct use of ->roles in Drupal 6 core:
Here is a patch version of the above suggestion for review.
Comment #8
bkraegelin commentedSorry being late... waited for wlw_blogapi activity, closed on no activity
Fix tested, works.
Comment #9
damien tournoud commentedThis needs to be fixed in D7, then backported.
By the way, we should really use array_diff_keys() here.
Comment #10
turbotad commentedDo you know if this has been integrated into the WLW module as yet? I am running into the same file upload bugs now as was described earlier, and have used what I thought was the most recent WLW blog api plugin.
Comment #11
bkraegelin commentedThe corresponding Issue #346159: images permission problem had no activity, there seems to be no activity at all on wlw_blogapi.
Can be fixed like this in wlw_blogapi.module, Line 389 of Version 6.x-1.4 (Line 401 of Revision 1.16 of Head):
Comment #12
gábor hojtsyDamien was right this needs to be fixed in D7 first.
Comment #13
cem kaan commentedD7 i18n makes me worry about update.
Comment #14
catchDamien was right in July 2009, but in April 2010 blogapi module is no longer in core.
Comment #15
dpearcefl commentedIs there any interest in this issue?
Comment #16
dpearcefl commented