8000 added organizations table to account by edewit · Pull Request #32311 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div data-show-on-forbidden-error hidden>

Uh oh!

There was an error while loading. Please reload this page.

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.keycloak.representations.account;

import java.util.Set;

public class OrganizationRepresentation {
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.

We already have a version of OrganizationRepresentation.java in ../idm directory. It would be cleaner to synthesize the two using some form of polymorphism like using a base class and/or interfaces.

I see that ClientRepresentation.java has the same issue. So I'm fine if we want to refactor both in a later PR.


private String id;
private String name;
private String alias;
private boolean enabled = true;
private String description;
private Set<String> domains;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

public String getAlias() {
return alias;
}

public void setAlias(String alias) {
this.alias = alias;
}

public boolean isEnabled() {
return this.enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}

public Set<String> getDomains() {
return domains;
}

public void setDomains(Set<String> domains) {
this.domains = domains;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (!(o instanceof OrganizationRepresentation)) return false;

OrganizationRepresentation that = (OrganizationRepresentation) o;

return id != null && id.equals(that.getId());
}

@Override
public int hashCode() {
if (id == null) {
return super.hashCode();
}
return id.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"isInternationalizationEnabled": ${realm.isInternationalizationEnabled()?c},
"isLinkedAccountsEnabled": ${realm.identityFederationEnabled?c},
"isMyResourcesEnabled": ${(realm.userManagedAccessAllowed && isAuthorizationEnabled)?c},
"isViewOrganizationsEnabled": ${isViewOrganizationsEnabled?c},
"deleteAccountAllowed": ${deleteAccountAllowed?c},
"updateEmailFeatureEnabled": ${updateEmailFeatureEnabled?c},
"updateEmailActionEnabled": ${updateEmailActionEnabled?c},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,12 @@ addressScopeConsentText=Address
phoneScopeConsentText=Phone number
offlineAccessScopeConsentText=Offline Access
samlRoleListScopeConsentText=My Roles
rolesScopeConsentText=User roles
rolesScopeConsentText=User roles
organizations=Organizations
organizationDescription=View organizations that you joined
emptyUserOrganizations=No organizations
emptyUserOrganizationsInstructions=You have not joined any organizations yet.
searchOrganization=Search for organization
organizationList=List of organizations
domains=Domains
refresh=Refresh
5 changes: 5 additions & 0 deletions js/apps/account-ui/public/content.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"path": "groups",
"isVisible": "isViewGroupsEnabled"
},
{
"label": "organizations",
"path": "organizations",
"isVisible": "isViewOrganizationsEnabled"
},
{
"label": "resources",
"path": "resources",
Expand Down
6 changes: 6 additions & 0 deletions js/apps/account-ui/src/api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type KeycloakContext,
} from "@keycloak/keycloak-ui-shared";

import OrganizationRepresentation from "@keycloak/keycloak-admin-client/lib/defs/organizationRepresentation";
import { joinPath } from "../utils/joinPath";
import { parseResponse } from "./parse-response";
import {
Expand Down Expand Up @@ -156,3 +157,8 @@ export async function getGroups({ signal, context }: CallOptions) {
});
return parseResponse<Group[]>(response);
}

export async function getUserOrganizations({ signal, context }: CallOptions) {
const response = await request("/organizations", context, { signal });
return parseResponse<OrganizationRepresentation[]>(response);
}
1 change: 1 addition & 0 deletions js/apps/account-ui/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type Feature = {
updateEmailFeatureEnabled: boolean;
updateEmailActionEnabled: boolean;
isViewGroupsEnabled: boolean;
isViewOrganizationsEnabled: boolean;
isOid4VciEnabled: boolean;
};

10BC8 Expand Down
48 changes: 48 additions & 0 deletions js/apps/account-ui/src/organizations/Organizations.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import OrganizationRepresentation from "@keycloak/keycloak-admin-client/lib/defs/organizationRepresentation";
import {
ErrorBoundaryProvider,
KeycloakSpinner,
ListEmptyState,
OrganizationTable,
useEnvironment,
} from "@keycloak/keycloak-ui-shared";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { getUserOrganizations } from "../api/methods";
import { Page } from "../components/page/Page";
import { Environment } from "../environment";
import { usePromise } from "../utils/usePromise";

export const Organizations = () => {
const { t } = useTranslation();
const context = useEnvironment<Environment>();

const [userOrgs, setUserOrgs] = useState<OrganizationRepresentation[]>([]);

usePromise(
(signal) => getUserOrganizations({ signal, context }),
setUserOrgs,
);

if (!userOrgs) {
return <KeycloakSpinner />;
}

return (
<Page title={t("organizations")} description={t("organizationDescription")}>
<ErrorBoundaryProvider>
<OrganizationTable
link={({ children }) => <span>{children}</span>}
loader={userOrgs}
>
<ListEmptyState
message={t("emptyUserOrganizations")}
instructions={t("emptyUserOrganizationsInstructions")}
/>
</OrganizationTable>
</ErrorBoundaryProvider>
</Page>
);
};

export default Organizations;
7 changes: 7 additions & 0 deletions js/apps/account-ui/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { lazy } from "react";
import type { IndexRouteObject, RouteObject } from "react-router-dom";

import { environment } from "./environment";
import { Organizations } from "./organizations/Organizations";
import { ErrorPage } from "./root/ErrorPage";
import { Root } from "./root/Root";

Expand Down Expand Up @@ -59,6 +60,11 @@ export const PersonalInfoRoute: IndexRouteObject = {
element: <PersonalInfo />,
};

export const OrganizationsRoute: RouteObject = {
path: "organizations",
element: <Organizations />,
};

export const Oid4VciRoute: RouteObject = {
path: "oid4vci",
element: <Oid4Vci />,
Expand All @@ -75,6 +81,7 @@ export const RootRoute: RouteObject = {
SigningInRoute,
ApplicationsRoute,
GroupsRoute,
OrganizationsRoute,
PersonalInfoRoute,
ResourcesRoute,
ContentRoute,
Expand Down
21 changes: 18 additions & 3 deletions js/apps/admin-ui/src/organizations/OrganizationsSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import OrganizationRepresentation from "@keycloak/keycloak-admin-client/lib/defs/organizationRepresentation";
import { useAlerts } from "@keycloak/keycloak-ui-shared";
import {
ListEmptyState,
OrganizationTable,
useAlerts,
} from "@keycloak/keycloak-ui-shared";
import {
Button,
ButtonVariant,
Expand All @@ -11,10 +15,9 @@ import { useTranslation } from "react-i18next";
import { Link, useNavigate } from "react-router-dom";
import { useAdminClient } from "../admin-client";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import { ListEmptyState } from "@keycloak/keycloak-ui-shared";
import { ViewHeader } from "../components/view-header/ViewHeader";
import { useRealm } from "../context/realm-context/RealmContext";
import { OrganizationTable } from "./OrganizationTable";
import { toEditOrganization } from "../organizations/routes/EditOrganization";
import { toAddOrganization } from "./routes/AddOrganization";

export default function OrganizationSection() {
Expand Down Expand Up @@ -61,6 +64,18 @@ export default function OrganizationSection() {
<PageSection variant="light" className="pf-v5-u-p-0">
<DeleteConfirm />
<OrganizationTable
link={({ organization, children }) => (
<Link
key={organization.id}
to={toEditOrganization({
realm,
id: organization.id!,
tab: "settings",
})}
>
{children}
</Link>
)}
key={key}
loader={loader}
isPaginated
Expand Down
19 changes: 17 additions & 2 deletions js/apps/admin-ui/src/user/Organizations.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OrganizationRepresentation from "@keycloak/keycloak-admin-client/lib/defs/organizationRepresentation";
import {
ListEmptyState,
OrganizationTable,
useAlerts,
useFetch,
} from "@keycloak/keycloak-ui-shared";
Expand All @@ -15,11 +16,12 @@ import {
} from "@patternfly/react-core";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useParams } from "react-router-dom";
import { Link, useParams } from "react-router-dom";
import { useAdminClient } from "../admin-client";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
import { useRealm } from "../context/realm-context/RealmContext";
import { OrganizationModal } from "../organizations/OrganizationModal";
import { OrganizationTable } from "../organizations/OrganizationTable";
import { toEditOrganization } from "../organizations/routes/EditOrganization";
import useToggle from "../utils/useToggle";
import { UserParams } from "./routes/User";

Expand All @@ -28,6 +30,7 @@ export const Organizations = () => {
const { t } = useTranslation();
const { id } = useParams<UserParams>();
const { addAlert, addError } = useAlerts();
const { realm } = useRealm();

const [key, setKey] = useState(0);
const refresh = () => setKey(key + 1);
Expand Down Expand Up @@ -116,6 +119,18 @@ export const Organizations = () => {
)}
<DeleteConfirm />
<OrganizationTable
link={({ organization, children }) => (
<Link
key={organization.id}
to={toEditOrganization({
realm,
id: organization.id!,
tab: "settings",
})}
>
{children}
</Link>
)}
loader={userOrgs}
=> setSelectedOrgs(orgs)}
deleteLabel="remove"
Expand Down
Loading
0