Closed (fixed)
Project:
Privatemsg
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
10 Jul 2010 at 00:20 UTC
Updated:
5 Nov 2010 at 08:50 UTC
Jump to comment: Most recent file
Hey Berdir and everyone,
In the latest D7 version of Private Message, the autocomplete feature on the "To" field no longer seems to work. (I tried in both Firefox and Safari.) Basically, as you type a name, the autocomplete "circle" icon spins for a moment, but no names (or roles) are shown in the autocomplete dropdown.
Could an autocomplete bug have been introduced when we ported the "send to role" feature to D7?
--Ben
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | privatemsg_autocomplete_lookup_refactor_6.patch | 23.86 KB | berdir |
| #28 | privatemsg_autocomplete_lookup_refactor_d6.patch | 23.86 KB | berdir |
| #25 | privatemsg_autocomplete_lookup_refactor3.patch | 24.71 KB | berdir |
| #23 | privatemsg_autocomplete_lookup_refactor2.patch | 22.02 KB | berdir |
| #19 | privatemsg_autocomplete_lookup_refactor.patch | 22.81 KB | berdir |
Comments
Comment #1
berdir- Fixed two bugs in the autocomplete
- Added tests for both usernames and roles autocomplete
- I accidently disabled some test functions, re-active these.
Comment #2
BenK commentedThe patch fixes autocomplete for usernames for me, but I can't seem to get autocomplete to work for roles. I've got both an "editor" user and an "editor" role... only the editor user shows up in the autocomplete.
Also, I just noticed that I don't have any permissions related to sending to roles in the D7 port. Didn't we add those in the D6 version? Could that be why the roles autocomplete isn't working?
--Ben
Comment #3
BenK commentedOops! My fault... I didn't have the Private Message Roles module enabled in my latest install. Will test the roles autocomplete now. Sorry about that!
--Ben
Comment #4
berdirThat has happened to me too :) As a hint, the description below the field should indicate what recipient types are enabled.
Comment #5
BenK commentedI've started preliminary testing with roles and I've noticed a few things:
A. Using "[user]" to specify the user (rather than the role with the same name) doesn't seem to work. I'm getting a message that the user isn't valid.
B. I've got a user named "authenticated" and the Drupal default user role "authenticated user." Only "authenticated user" will appear in the autocomplete even though they aren't exactly the same name.
C. I've tested with a user who doesn't have the "Write private message to roles" permission, but does have the "Administer private message" permission. I've also got an "editor" user and an "editor" role. I sent a message to editor (as suggested by the autocomplete) and assumed the message would go to the editor user (since the user can't send to roles according to the permissions). But instead the message went to the editor role. I'm wondering if this a permission issue, autocomplete issue, or both.
D. I'm wondering if the "[role]" or "[user]" suffix could be shown in the autocomplete itself, but only for users with the "Write private message to roles" permission. The issue is a usability one: As a sender with "send to role" permission, it's a bit unclear if you are sending to a role or a user unless you know exactly how the system works.
This could be especially problematic in a production scenario which has many more users and roles than our test environment--plus more users who may be allowed to send to a role. For instance, if a user has a similar name to a role, it's easy to inadvertently send to an entire role when you think you are sending to just one user. Currently, you don't know that you're sending to a role until you see the confirmation message (which has "(role)" appended to it).
Thoughts?
--Ben
Comment #6
BenK commentedAlso, I wasn't exactly sure what you meant by "As a hint, the description below the field should indicate what recipient types are enabled."
Regardless of whether a user has the "Write private message to roles" permission or not (I tried this with different users), I see the same "Enter the recipient, separate recipients with commas" message underneath the "To" field.
--Ben
Comment #7
berdirFurther improvements...
A Please open a new issue. Autocomplete and looking up of names are two separate things and multiple smaller patches are easier to test/handle/backport if necessary.
B Both user and role should now be displayed.
C I am not able to reproduce this. can you try it again with the latest patch applied? And if you can reproduce, please open a new issue (or one together with A, this belongs to name lookup too)
D Remember that there might be multiple recipient types, not just roles. What about simply displaying the type for non-user recipients *for now* and open a new issue where we can discuss on how to improve the autocomplete? There are nice solutions out there which are similiar to facebook's private messages. http://loopj.com/2009/04/25/jquery-plugin-tokenizing-autocomplete-text-e... looks pretty good.
I also fixed the description, that hasn't been correctly ported to D7.
Comment #9
BenK commentedOkay, I'll test the new patch as soon as it passes the tests... I'll open up a new issue for the rest.
--Ben
Comment #10
berdirForgot to remove a debug call, this should pass.
Comment #12
berdirAnother small test fix.
Comment #13
BenK commentedHey Sascha,
I tested the patch in #12 and like the latest version a lot. I really like your simple solution of displaying the type [role] for non-user recipients. Enhances the usability greatly.
I did, however, find one fairly major bug: If you have a user and role of the same name (editor), the message always goes to the role, regardless of whether you select "editor" or "editor [role]".
To see this, try to send a message just to "editor" (the user). When you click "Send message," the confirmation message at the top of the screen says "A message has been sent to editor (role)."
And all users in that role are getting the message instead of just the one user.
Thanks,
Ben
Comment #14
berdir- The thing with displaying [role] is translation stuff. I'm not sure if the current solution works for different languages, for example russian, where text is read from right to left.
- Does the user have permission to write to roles? Then this is imho working as intended, because if there is no [type], the first matching recipient type is used and the default user check comes last.
- I however fully agree that it is confusing to have "editor" and "editor [role]" in the autocomplete and both are sent to the role ;) So I guess the way the autocomplete currently works needs to be improved. Maybe we can display [user] too if the name is not unique, but that requires some internal changes. What do you think?
Comment #15
BenK commentedHmmm.... Good questions. A lot to think about. One thought: It seems a main challenge is the logic that if there is no type specified, then the first matching type is used. The issue with this approach is that we're not really sure who is being sent to... it's just whatever type happens to come first in the list.
How about specifying that if there is no [type], then we assume the type is "user" and just send to the user? This way, any other types we think of later (besides roles) would need to specify a type in the [type] format. This sort of makes sense given the nature of the module: Private Messages are designed to be sent to a user and if you want to send to something else (role, organic group, etc.) then you need to specify the type.
Thoughts?
--Ben
Comment #16
berdirThat's how it originally worked. I went away from it because I think that name conflicts are rather rare and it woud be hard to write to another recipient type when you can't use the autocomplete for whatever reason. But I guess that is hard anyway...
Comment #17
BenK commentedWell, here's a thought: Maybe we should just commit the patch in #12 (which works well).
In thinking about this, it seems the problem is very limited. It would only affect a sender who has the "send to roles" permission and who also has a user and role with the identical name. Furthermore, once the "[user]" suffix works (I'll test http://drupal.org/node/850546), then the sender can be extra sure by attaching "[user]" to the end of the username.
What do you think?
One other option would be to tack on "[user]" at the end of any username only when the user has "send to roles" permission. But maybe this is overkill given that the problem is so limited.
We've got so many other issues to do that we just don't want to lose too much momentum on this... :-)
--Ben
Comment #18
berdirI agree. This improves the current situation already quite a bit. Commited to 7.x-1.x and 6.x-2.x (tests and [role]).
Re-targeting the issue so that we can discuss further improvents...
Comment #19
berdirOk, I have a few ideas....
There are several changes....
1. Autocomplete:
- Autocomplete hook implementations are supposed return an array of full recipient objects keyed by the recipient key instead of just a an array of strings.
- Privatemsg then formats these through the format callback. At this point, recipient type implementations are supposed to return the most simple form of the recipient name. For example, just "editor" for a role called editor.
- Then, Privatemsg checks if there are any overlapping autocomplete suggestions. For example, a user and a role with the same name. In that case, Privatemsg asks for a unique version of the suggestion. That would be "editor [role]" and "editor [user]"
- The advantage of this approach is that the unique-stuff is only necessary if there *are* duplicates. If a user only has permission to send messages to users, he will just see "editor" and it will be sent to the user.
- This also works if there are duplicates within the same type, for example, the reported issue with realname.module, when there are several identical realnames, realname.module can then provide unique suggestions (realname [uid_or_username]).
2. Name Lookup:
- Recipients to which the user doesn't have permission to write to are reported as such, that resolves the problem reported in the permission for roles issue
- As for the autocomplete hook, name lookup are supposed to return an array of full recipient objects keyed by the recipient key. That allows them to return multiple possible matches.
- Privatemsg first collects all possible matches, instead of using the first match. If there *are* multiple possible matches, the recipient string is rejected and the user must clarify which recipient he meant. All possible recipients are displayed.
- Some fancy JS makes these possible recipients clickable and if you click one, it will replace the unclear string in the To: field with the clicked one. I'm not an JS expert and I just hacked the whole thing together but it seems to work fine.
- Some cleanup.
This needs a lot of testing to make sure that everything works fine. Note that you need to clear the (theme) cache and rebuild the menus after applying the patch. I think the JS stuff is pretty cool but it probably needs some work, suggestions are welcome.
Comment #20
BenK commentedAwesome! You've been busy... ;-)
I'm swamped today, but I'll plan on test the patch tomorrow...
--Ben
Comment #21
chuckbar77 commentedsubscribing
Comment #22
BenK commentedHey Berdir,
I tested the patch and it's working very nicely with in cases with one recipient. More specifically, the autocomplete is working great and messages are now being sent to the correct recipient (when there are more than one recipients with the same name). And the JS used with the name lookup is very cool and functioning very well!
Here are the bugs/issues I noticed:
1) If there is more than one recipient in the "To" field and the recipient with more than one name is not listed first, then the system is breaking down. For instance, I sent a message to "person1" and "editor" (in which "editor" is the name of both a user and a role). Upon clicking send, I received both a notice that the message was sent to "person1" as well as the "recipient not unique" error notice (in which the possible recipients were not clickable). And the message was actually sent before I could specify the unique recipient.
The system also breaks down if there are two recipients, one with more than one possible name and a second valid recipient. In this case, the message is being sent to only the valid recipient and the "recipient not unique" message is displayed after the message is already sent.
2) I'd suggest changing the following strings:
a. Change: "The provided recipient editor is not unique, choose one of the following possible recipients:". To this: "Our site has multiple recipients named editor. Please choose your intended recipient:"
b. Change: "Updated recipient field, submit the form again to send the message." To this: "The recipient field has been updated. You may now send your message." Also, this "update successful" message is displaying as an error (red in bartik). It would be better if this one just displayed as a regular notice (green in bartik) since the update action was successful.
3) Once the recipient field has been updated, the "You must include at least one valid recipient" message is also being displayed. I think this is confusing to the end user because it makes it seems as though the updated recipient value is invalid. Is there any way to hide the "You must include at least one valid recipient" in this case?
--Ben
Comment #23
berdir1) Fixed, it should now be a real validation error instead of just a message and generally work better with multiple recipients. Also improved the implementation a bit.
2a) "Our" feels to personal to me for a generic string. I've just used "The site..." instead.
b) Updated. Well, I can try. The problem is that there can be quite a few combinations. For example, when there is only a single error, it is directly inside a div and if there are two or more, there is a list. The patch should be able to handle that (either removes the whole red thing or just the current list element). But what it can't really handle is if there would already by a green thing. It still works but there would be two different green fields. *Way* to complex :) But this shouldn't happen very often because we don't add any status messages on that page.
c) First I thought, OMG, that's going to be hard. Turned out, it's not. That message was assigned to a wrong, non-existing form field. Once changed to use the correct field, it just worked :). Form api automatically only shows the first error for every form field and that is the unique one, if that exists.
Comment #25
berdirFixed the test fail. It wasn't actually broken but it displayed a different error now.
Comment #26
BenK commentedThe patch is working great and all errors are fixed. This is RTBC.
One point I did want to note: If you have two recipients in a message and both of them have multiple possible recipients, then the system only deals with one at a time (meaning you'll get the "choose a recipient" for the first one, fix it, re-send, and then get the "choose a recipient" message for the second one). This wasn't exactly what I expected (I expected to see both "choose a recipient" messages simultaneously), but I actually think this method works fine. And maybe this is better because imagine if you had 10 recipients, each with multiple recipients. That would be a lot of error messages to show at once. So I just wanted to note this (in case it was something other than you intended), but I don't think this approach needs to be changed.
Nice work on this!
--Ben
Comment #27
berdirCommited, this can be backported...
Comment #28
berdirBackported the patch.
Comment #29
berdirComment #30
berdirSame patch without d6 suffix.
Comment #31
berdirCommited!