I just created the CAS Attributes Roles module. This module let's you assign roles that match specified attributes. One thing I noticed while looking through the cas_attributes code is it seems that if an attribute has multiple values then the token gets assigned the first value. Am I wrong in this?
If not can we possibly do something like concatenate it with a "," or something else?
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | cas_attributes-array_tokens-1399304-34.patch | 3.25 KB | olarin |
| #29 | cas_attributes-array_tokens-1399304-29.patch | 3.26 KB | olarin |
| #27 | cas_attributes-array_tokens-1399304-27.patch | 2.53 KB | olarin |
| #26 | cas_attributes-array_tokens-1399304-26.patch | 1.93 KB | olarin |
| #20 | 1399304-20-ick.patch | 5.2 KB | bfroehle |
Comments
Comment #1
bfroehle commentedYes you are correct, and patches are welcome.
Unfortunately we'll need to rig it so that the user can select how they want multiple token values dealt with. For example, an LDAP server might respond with several e-mail addresses and we wouldn't want to assign a ", "-concatenated version to the user's email field.
When I last looked at this almost a year ago the Token module was in the process of adding some array capabilities... I wonder if that has since been finalized.
Comment #2
redndahead commentedUpdating issue. I'll have a quick look tomorrow.
Comment #3
redndahead commentedSo you can use an array token. My suggestion is we make every attribute an array. Then we create a hook_update that converts all the tokens that people have defined from [cas:attribute:xxxx] to [cas:attribute:xxxx:first]
What do you think?
Comment #4
bfroehle commentedI think that sounds reasonable.
Comment #5
redndahead commentedHere is a patch. No need to update the previous values. If someone specifies [cas:attribute:xxxx] it will automatically return the first one.
Comment #7
redndahead commentedNot sure why the tests are failing. Any ideas on where I might have went wrong?
Comment #8
bfroehle commentedI think the
arraytoken is provided by the token module, which isn't set as a requirement for this module.Comment #10
bfroehle commentedThe tests in #8 pass locally on my computer with the token module installed.
Is it worth making token a hard dependency? Alternatively we could fall back on the previous processing style if token is not available, but this might lead to weird errors. We'll need to include a few new tests for this.
Comment #11
redndahead commentedWas there something I screwed up in the first patch? Yours is significantly different.
Comment #12
redndahead commentednvm yours is just better coded. Surprisingly I have never looked at that 3rd parameter in explode. That will change some of my other code that I have written.
I think having a dependency on token isn't that huge of a deal. The d7 version is reported to be used on 50% of the reported sites. But without that requirement multivalue attributes won't be supported correctly.
Comment #13
bfroehle commented#8: 1399304-array-tokens-8.patch queued for re-testing.
So I added a dummy test module to CAS Attributes to force qa.drupal.org to download token module... let's see if this works. I don't know how the list of project dependencies gets refreshed...
Comment #15
redndahead commentedHmm testbot seems to be acting up.
Comment #16
bfroehle commentedFourteenth time is the charm?
Comment #17
redndahead commentedHeyo!!! winner winner chicken dinner
Comment #18
bfroehle commentedEven though I'm sure it works, now I'd like to see a test written to verify the new array functionality. :0
Thanks for doing the leg work on this!
Comment #19
redndahead commentedThis only adds one test to make sure [cas:attribute:memberOf:last] works.
Comment #20
bfroehle commentedI'm attaching a patch which would make #1400466: Combine cas attributes roles module easier to implement, but I'm pretty unhappy with it.
What it does is add a "raw_array" option, which the cas attribute token system checks and then returns an array instead of a flattened array. The problem is that this feature would be unique to the cas attribute tokens, which would greatly limit it's overall applicability.
In fact, it'd probably be easier to just parse the $text with token_scan, and dig the replacements out of cas_phpcas_attributes() yourself!
So consider this patch dead in the water. The patch in the previous comment is much more to my liking.
Comment #21
redndahead commentedI think that we should go back to the normal way of token handling where [cas:attribute:xxxx] returns a comma separated value of all the array values. Then we add an update hook to replace all [cas:attribute:xxxx] to [cas:attribute:xxxx:first]
Then it has array handling so no data is lost.
Comment #22
bfroehle commentedI'm on board with that. The only thing I'm nervous about is introducing the Token dependency, which I'm not sure how well Drupal will handle during a module update.
Comment #23
redndahead commentedI can see that, but at 122 installs now is the time while it's in beta and you can say "Hey it was beta". I think the best we can do is put on the homepage and in the release notes that there is a new requirement. Darn online upgrades get in the way, but not much we can do about that and I think the people actually using this module won't be using that feature anyway.
Comment #24
bfroehle commentedI've split the new token requirement into #1475384: Require Token module, so we can focus on the best technological solution here.
Comment #25
olarin commented#19: 1399304-d7-3.patch queued for re-testing.
Comment #26
olarin commentedThis is a re-roll of the patch in #19. Hasn't yet addressed comment in #21.
Comment #27
olarin commentedAnd here's a version that adds the changes suggested in #21. I think this is good to go but I'd like to have somebody else verify that the update function worked OK for them before I commit it.
Comment #29
olarin commentedWhoops, can't expect that update hook to catch the tokens in the tests. (Well, I suppose I could have written it to do so, but manually amending the tests is probably easier.)
Comment #30
olarin commentedComment #31
bfroehle commentedIf
memberOfis an array, what does the token[cas:attribute:memberOf]return after this patch? If I'm reading it correctly, I think it does[cas:attribute:memberOf:join]which is probably a good idea (but a slight change from the past). We'll just need to highlight this in the release notes.Comment #32
olarin commentedThat is correct, the default assumption is now "join" rather than "first". As suggested in comment #21, the update included in this patch changes all cas attribute tokens in the existing relationships of the form [cas:attribute:memberOf] to [cas:attribute:memberOf:first] so that existing behaviour on old installations is not affected. Yes, we'll definitely want to make a clear indication in the release notes. I've tested the update hook myself but would like somebody else to test it too before I commit this, just for paranoia's sake.
Comment #33
olarin commentedHm, after further testing this patch seems to be causing problems on my test installation, even though the Drupal Tests passed. Need to investigate further.
Comment #34
olarin commentednevermind, the issues were on my end. re-rolling the patch anyway to make sure it applies to latest version of repo and still passes testbot before committing.
Comment #35
olarin commentedwent ahead and pushed to 7.x-1.x.
Comment #37
vinmassaro commentedmemberOf still returns only the first result for me. I am using CAS, LDAP, and CAS Attributes. When I look at the LDAP tokens that are available, it returns [cas:ldap:memberOf] with only the first value, but there are many more. If I test an LDAP Server configuration through the LDAP module, I see many memberOf tokens like [memberof:0], [memberof:1], etc. Am I missing something? Thanks.
Comment #38
vinmassaro commentedOops, it looks like this only applies to [cas:attributes:memberof], not [cas:ldap:memberof].
Comment #39
vinmassaro commentedResetting status as I've opened #2044351 with my question.