Skip to content

Commit

Permalink
Merge pull request #22 from NatLibFi/feature/simplye-271/given-name
Browse files Browse the repository at this point in the history
Show admin's first name instead of internal authentication ID
  • Loading branch information
attemoi authored Apr 5, 2024
2 parents c1355e3 + f201645 commit 19b51a8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/ContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ContextProviderProps extends React.Props<ContextProvider> {
showCircEventsDownload?: boolean;
settingUp?: boolean;
email?: string;
givenName?: string;
roles?: {
role: string;
library?: string;
Expand All @@ -36,6 +37,7 @@ export default class ContextProvider extends React.Component<
this.admin = new Admin(
props.roles || [],
props.email || null,
props.givenName || null,
props.authType || null
);
this.pathFor = (collectionUrl: string, bookUrl: string, tab?: string) => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class Header extends React.Component<HeaderProps, HeaderState> {
{sitewideLinkItems.map((item) =>
this.renderLinkItem(item, currentPathname)
)}
{this.context.admin.email && (
{(this.context.admin.email || this.context.admin.givenName) && (
<li className="dropdown">
<Button
className="account-dropdown-toggle transparent"
Expand All @@ -235,7 +235,8 @@ export class Header extends React.Component<HeaderProps, HeaderState> {
callback={this.toggleAccountDropdown}
content={
<span>
{this.context.admin.email} <GenericWedgeIcon />
{this.context.admin.givenName || this.context.admin.email}{" "}
<GenericWedgeIcon />
</span>
}
/>
Expand Down
5 changes: 5 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ interface ConfigurationSettings {
/** `email` will be the email address of the currently logged in admin. */
email?: string;

/** `givenName` will be the first name of currently logged in admin.
only available for externally authenticated users (who will have no
email). */
givenName?: string;

/** `roles` contains the logged in admin's roles: system admininstrator,
or library manager or librarian for one or more libraries. */
roles?: {
Expand Down
3 changes: 3 additions & 0 deletions src/models/Admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AdminAuthType, AdminRoleData } from "../interfaces";
export default class Admin {
roles: AdminRoleData[];
email: string | null = null;
givenName: string | null = null;
private authType: AdminAuthType = "password";
private systemAdmin: boolean = false;
private sitewideLibraryManager: boolean = false;
Expand All @@ -13,10 +14,12 @@ export default class Admin {
constructor(
roles: AdminRoleData[],
email?: string,
givenName?: string,
authType?: AdminAuthType
) {
this.roles = roles;
this.email = email;
this.givenName = givenName;
this.authType = authType;
for (const role of roles) {
switch (role.role) {
Expand Down

0 comments on commit 19b51a8

Please sign in to comment.