Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

feat: add ordering to auth providers in login screen#50434

Merged
kopancek merged 5 commits into
mainfrom
milan/order_login_items
Apr 6, 2023
Merged

feat: add ordering to auth providers in login screen#50434
kopancek merged 5 commits into
mainfrom
milan/order_login_items

Conversation

@kopancek

@kopancek kopancek commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

Description

This PR makes several changes to how we handle auth providers in the code, which in the end allows us to change ordering of auth providers on the login screen.

  1. We do not sort auth providers by default (this is an optimization). We call the providers.Providers() method in a bunch of places, but really only need it sorted for the UI
  2. Added default fields to all auth providers (where it made sense), since they are shared amongst all of them
DisplayName   string  `json:"displayName,omitempty"`
DisplayPrefix *string `json:"displayPrefix,omitempty"`
Hidden        bool    `json:"hidden,omitempty"`
Order         int     `json:"order,omitempty"`
  1. Allows to hide each auth provider from the user completely by adding the "hidden" property to the auth provider config
  2. Allows to change the prefix of the auth provider on the screen from "Continue with " to whatever the admin likes
  3. Allows to change the order of auth providers on the login screen by adding optional "order" attribute, which is a positive int (greater than 0). Providers with order will be sorted first, followed by ordering we had up until now.

Related

Possible improvements

Remove the usage of reflect, since I don't like it that much. However our current json schema library for generating Go code does not support struct embedding with $ref attribute, which would fix the problem more elegantly. I was not smart enough to figure out how to change it to support that.

Test plan

Tested locally + unit tests.

@kopancek kopancek requested a review from a team April 6, 2023 10:14
@kopancek kopancek self-assigned this Apr 6, 2023
@cla-bot cla-bot Bot added the cla-signed label Apr 6, 2023

@erzhtor erzhtor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for handling this! Besides left comments, looks good!

Comment thread schema/site.schema.json
"type": "string",
"description": "URL of the Gerrit instance, such as https://gerrit-review.googlesource.com or https://gerrit.example.com.",
"default": "https://gerrit-review.googlesource.com/"
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have displayName and displayPrefix for Gerrit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread schema/site.schema.json
Comment thread schema/site.schema.json
"description": "The name to use when displaying this authentication provider in the UI. Defaults to an auto-generated name with the type of authentication provider and other relevant identifiers (such as a hostname).",
"type": "string"
},
"displayPrefix": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a requested somewhere? I'm not against this but I just thought that 1) it would be better having a single way to present providers on the page 2) avoid unnecessary configuration options, thus keeping it simple

@kopancek kopancek Apr 6, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not requested, but I think the current way is rather inflexible and incompatible, depending on what you put into the DisplayName:
Screenshot 2023-04-06 at 14 14 51

Even having a single option for all of the providers might not work, since depending on the intent, you might need something different. Do you really think it complicates the configuration that much? It's optional in the end...

@kopancek kopancek merged commit 2229942 into main Apr 6, 2023
@kopancek kopancek deleted the milan/order_login_items branch April 6, 2023 16:13
0xnmn pushed a commit that referenced this pull request Apr 7, 2023
jhchabran referenced this pull request Apr 7, 2023
Reverts sourcegraph/sourcegraph#50434

Test Plan: CI tests
almeidapaulooliveira pushed a commit that referenced this pull request Apr 8, 2023
## Description

This PR makes several changes to how we handle auth providers in the
code, which in the end allows us to change ordering of auth providers on
the login screen.

1. We do not sort auth providers by default (this is an optimization).
We call the `providers.Providers()` method in a bunch of places, but
really only need it sorted for the UI
2. Added default fields to all auth providers (where it made sense),
since they are shared amongst all of them
```
DisplayName   string  `json:"displayName,omitempty"`
DisplayPrefix *string `json:"displayPrefix,omitempty"`
Hidden        bool    `json:"hidden,omitempty"`
Order         int     `json:"order,omitempty"`
```
3. Allows to hide each auth provider from the user completely by adding
the `"hidden"` property to the auth provider config
4. Allows to change the prefix of the auth provider on the screen from
`"Continue with "` to whatever the admin likes
5. Allows to change the order of auth providers on the login screen by
adding optional "order" attribute, which is a positive int (greater than
0). Providers with order will be sorted first, followed by ordering we
had up until now.

## Related
- https://github.com/sourcegraph/sourcegraph/issues/49831
- #50284

## Possible improvements

Remove the usage of `reflect`, since I don't like it that much. However
our [current json schema library for generating Go
code](https://github.com/sourcegraph/go-jsonschema) does not support
struct embedding with `$ref` attribute, which would fix the problem more
elegantly. I was not smart enough to figure out how to change it to
support that.

## Test plan

Tested locally + unit tests.
almeidapaulooliveira referenced this pull request Apr 8, 2023
Reverts sourcegraph/sourcegraph#50434

Test Plan: CI tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants