Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[24.2] Show Keycloak provider label in UI #19447

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/src/components/HistoryImport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import { waitOnJob } from "components/JobStates/wait";
import LoadingSpan from "components/LoadingSpan";
import { getAppRoot } from "onload/loadConfig";
import { errorMessageAsString } from "utils/simple-error";
import { capitalizeFirstLetter } from "utils/strings";
import Vue, { ref, watch } from "vue";

import { fetchFileSources } from "@/api/remoteFiles";
Expand Down Expand Up @@ -165,7 +166,7 @@ export default {
return this.invocationImport ? "invocation" : "history";
},
identifierTextCapitalized() {
return this.identifierText.charAt(0).toUpperCase() + this.identifierText.slice(1);
return capitalizeFirstLetter(this.identifierText);
},
identifierTextPlural() {
return this.invocationImport ? "invocations" : "histories";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { computed } from "vue";
import type { SharedItemNotification } from "@/api/notifications";
import { useNotificationsStore } from "@/stores/notificationsStore";
import { absPath } from "@/utils/redirect";
import { capitalizeFirstLetter } from "@/utils/strings";

import NotificationActions from "@/components/Notifications/NotificationActions.vue";

Expand All @@ -21,10 +22,6 @@ const props = defineProps<Props>();

const notificationsStore = useNotificationsStore();

function capitalizeFirstLetter(string: string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

const content = computed(() => props.notification.content);

const sharedItemType = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
title="Disconnect External Identity"
class="d-block mt-3"
@click="onDisconnect(item)">
Disconnect {{ item.provider.charAt(0).toUpperCase() + item.provider.slice(1) }} - {{ item.email }}
Disconnect {{ capitalizeAsTitle(item.provider_label) }} -
{{ item.email }}
</b-button>

<b-modal
Expand Down Expand Up @@ -98,6 +99,8 @@ import { sanitize } from "dompurify";
import { userLogout } from "utils/logout";
import Vue from "vue";

import { capitalizeFirstLetter } from "@/utils/strings";

import svc from "./service";

import ExternalLogin from "components/User/ExternalIdentities/ExternalLogin.vue";
Expand Down Expand Up @@ -156,6 +159,9 @@ export default {
Toast.success(notificationMessage);
},
methods: {
capitalizeAsTitle(str) {
return capitalizeFirstLetter(str);
},
loadIdentities() {
this.loading = true;
svc.getIdentityProviders()
Expand Down
17 changes: 15 additions & 2 deletions client/src/components/User/ExternalIdentities/ExternalLogin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Multiselect from "vue-multiselect";
import { useConfig } from "@/composables/config";
import { withPrefix } from "@/utils/redirect";
import { errorMessageAsString } from "@/utils/simple-error";
import { capitalizeFirstLetter } from "@/utils/strings";

import LoadingSpan from "@/components/LoadingSpan.vue";

Expand All @@ -16,7 +17,14 @@ interface Idp {
OrganizationName: string;
RandS: boolean;
}
type OIDCConfig = Record<string, { icon?: string }>;
type OIDCConfig = Record<
string,
{
icon?: string;
label?: string;
custom_button_text?: string;
}
>;

interface Props {
loginPage?: boolean;
Expand Down Expand Up @@ -271,7 +279,12 @@ function getIdpPreference() {
<BButton class="d-block mt-3" @click="submitOIDCLogin(idp)">
<i :class="oIDCIdps[idp]" />
Sign in with
{{ idp.charAt(0).toUpperCase() + idp.slice(1) }}
<span v-if="iDPInfo['label']">
{{ iDPInfo["label"].charAt(0).toUpperCase() + iDPInfo["label"].slice(1) }}
</span>
<span v-else>
{{ capitalizeFirstLetter(idp) }}
</span>
</BButton>
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { type ComputedRef } from "vue";
import { type components, GalaxyApi } from "@/api";
import { getAppRoot } from "@/onload/loadConfig";
import { errorMessageAsString } from "@/utils/simple-error";
import { capitalizeFirstLetter } from "@/utils/strings";

import LoadingSpan from "../LoadingSpan.vue";
import HelpText from "@/components/Help/HelpText.vue";
Expand Down Expand Up @@ -369,12 +370,8 @@ const metrics = computed(() => {
return Object.fromEntries(items.map((item) => [item.y_title, { spec: itemToSpec(item), item: item }]));
});

function getTimingInTitle(timing: string): string {
return timing.charAt(0).toUpperCase() + timing.slice(1);
}

const timingInTitles = computed(() => {
return getTimingInTitle(timing.value);
return capitalizeFirstLetter(timing.value);
});

const groupByInTitles = computed(() => {
Expand All @@ -391,9 +388,15 @@ const groupByInTitles = computed(() => {
<BRow align-h="end" class="mb-2">
<BButtonGroup>
<b-dropdown right :text="'Timing: ' + timingInTitles">
<b-dropdown-item @click="timing = 'seconds'">{{ getTimingInTitle("seconds") }}</b-dropdown-item>
<b-dropdown-item @click="timing = 'minutes'">{{ getTimingInTitle("minutes") }}</b-dropdown-item>
<b-dropdown-item @click="timing = 'hours'">{{ getTimingInTitle("hours") }}</b-dropdown-item>
<b-dropdown-item @click="timing = 'seconds'">
{{ capitalizeFirstLetter("seconds") }}
</b-dropdown-item>
<b-dropdown-item @click="timing = 'minutes'">
{{ capitalizeFirstLetter("minutes") }}
</b-dropdown-item>
<b-dropdown-item @click="timing = 'hours'">
{{ capitalizeFirstLetter("hours") }}
</b-dropdown-item>
</b-dropdown>
<b-dropdown right :text="'Group By: ' + groupByInTitles">
<b-dropdown-item @click="groupBy = 'tool_id'">Tool</b-dropdown-item>
Expand Down
8 changes: 8 additions & 0 deletions client/src/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ export function snakeCaseToTitleCase(str: string): string {
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(" ");
}

/**
* Capitalize the first letter of a string
*/
export function capitalizeFirstLetter(str: string): string {
str = str.trim();
return str.charAt(0).toUpperCase() + str.slice(1);
}
5 changes: 4 additions & 1 deletion lib/galaxy/authnz/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ def _parse_oidc_backends_config(self, config_file):
elif idp in KEYCLOAK_BACKENDS:
self.oidc_backends_config[idp] = self._parse_custos_config(child)
self.oidc_backends_implementation[idp] = "custos"
self.app.config.oidc[idp] = {"icon": self._get_idp_icon(idp)}
self.app.config.oidc[idp] = {
"icon": self._get_idp_icon(idp),
"label": self.oidc_backends_config[idp].get("label", idp),
}
else:
raise etree.ParseError("Unknown provider specified")
if len(self.oidc_backends_config) == 0:
Expand Down
4 changes: 4 additions & 0 deletions lib/galaxy/webapps/galaxy/controllers/authnz.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ def index(self, trans, **kwargs):
userinfo = jwt.decode(
token.id_token, options={"verify_signature": False, "verify_aud": False, "verify_exp": False}
)
provider_label = trans.app.authnz_manager.oidc_backends_config.get(token.provider, {}).get(
"label", token.provider
)
rtv.append(
{
"id": trans.app.security.encode_id(token.id),
"provider": token.provider,
"provider_label": provider_label,
"email": userinfo["email"],
"expiration": str(datetime.datetime.utcfromtimestamp(userinfo["exp"])),
}
Expand Down
Loading