Skip to content

Conversation

@ghalse
Copy link
Collaborator

@ghalse ghalse commented Jul 16, 2020

By default, discopower sorts the display alphabetically by English name. This is good where there are lots of identity providers, but where there are smaller numbers (eg social providers) it may be desirable to override the sort order to influence user behaviour.

This introduces a discopower.weight to all entries to be weighted so that they appear higher or lower than they normally would.

If discopower.weight is not set, the value of defaultweight from the configuration is used. This allows us to push up or down a single entry with ease, as all others remain sorted alphabetically (and equal weights are always alphabetical).

If no weights are set, the previous behaviour remains unchanged.

By default discopower sorts the display alphabetically by English
name. This is good where there are lots of identity providers, but where
there are smaller numbers (eg social providers) it may be desirable to
override the sort order to influence user behaviour.

This introduces a 'discopower.weight' to all entries to be
weighted so that they appear higher or lower than they normally would.
@codecov
Copy link

codecov bot commented Jul 16, 2020

Codecov Report

Merging #8 into master will increase coverage by 20.81%.
The diff coverage is 90.90%.

@@              Coverage Diff              @@
##             master       #8       +/-   ##
=============================================
+ Coverage      0.00%   20.81%   +20.81%     
- Complexity       78       82        +4     
=============================================
  Files             1        1               
  Lines           188      197        +9     
=============================================
+ Hits              0       41       +41     
+ Misses          188      156       -32     

The uasort function is static, and needs a static config variable :(
@ghalse
Copy link
Collaborator Author

ghalse commented Jul 16, 2020

The 07d1608 commit fixes a stupid mistake, and should be squashed into 19cd533.

@tvdijen
Copy link
Member

tvdijen commented Jul 16, 2020

Thanks again Guy!

Two thoughts..

  1. I've never seen any algorithm use a default weight of 50.. It's usually 0 or 100..
  2. Would it be an idea to add support for a sorting callback-method instead, so people can have their own sorting algorithm?

Regardless of the above, this needs a unit test..

@ghalse
Copy link
Collaborator Author

ghalse commented Jul 17, 2020

  1. I've never seen any algorithm use a default weight of 50.. It's usually 0 or 100..

I chose 50 to try and match what users of SSP might expect. The authproc filters set an implicit scale of 0-100, with 50 being used as the "default" in the documentation. Nevertheless, am not wedded to it, and am happy to change it to 100.

  1. Would it be an idea to add support for a sorting callback-method instead, so people can have their own sorting algorithm?

Hmm. A hook. I'll have a look at this.

Even so, I think that weights are still useful as a simple mechanism. If I have four social providers I want to order (as I do), I don't want to have to write a hook to fix the order; weights in the metadata config are much easier.

Regardless of the above, this needs a unit test..

I knew you'd say that, and I'd have done so if there were already unit tests for PowerIdPDisco.php. I think this is a bigger problem than just this change. IMHO some documentation is just as important, perhaps more so.

@tvdijen
Copy link
Member

tvdijen commented Jul 17, 2020

Yeah, unit testing is a bigger problem.. But you gotta start somewhere, so that's why I asked :)
We're putting a lot of work in it lately and managed to get the saml2-lib to ~90% 🎉

@tvdijen
Copy link
Member

tvdijen commented Jul 17, 2020

Woah, that's great work Guy! 🚀

ghalse added a commit to ghalse/simplesamlphp-module-discopower that referenced this pull request Jul 17, 2020
ghalse added a commit to ghalse/simplesamlphp-module-discopower that referenced this pull request Aug 7, 2020
@ghalse
Copy link
Collaborator Author

ghalse commented Aug 7, 2020

After giving @tvdijen's callback idea some thought, it seems the easiest and most flexible way to do this is simply to call a hook if it exists. If we use the existing hook functionality, that requires passing the entire metadata array to the hook. However, that in turn gives the user/admin complete control of the sorting including using functions other than uasort.

I think I'm all done here now :)

@tvdijen tvdijen merged commit 1cc6277 into simplesamlphp:master Aug 7, 2020
@tvdijen
Copy link
Member

tvdijen commented Aug 7, 2020

Thanks Guy!!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants