From 6548f01efa8f35051568bdd30fa8b53ef2c4a74a Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Sun, 1 Jan 2023 11:19:58 +0000 Subject: [PATCH] Show admin password top banner (#6226) * Invalid-admin fake role * Reset password link + shell --- apps/web/pages/api/auth/[...nextauth].tsx | 2 +- apps/web/public/static/locales/en/common.json | 4 ++- .../users/components/AdminPasswordBanner.tsx | 28 +++++++++++++++++++ packages/types/next-auth.d.ts | 2 +- packages/ui/v2/core/Shell.tsx | 2 ++ 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 packages/features/users/components/AdminPasswordBanner.tsx diff --git a/apps/web/pages/api/auth/[...nextauth].tsx b/apps/web/pages/api/auth/[...nextauth].tsx index 39b9b75c9f..c5f7f9bb9e 100644 --- a/apps/web/pages/api/auth/[...nextauth].tsx +++ b/apps/web/pages/api/auth/[...nextauth].tsx @@ -138,7 +138,7 @@ const providers: Provider[] = [ username: user.username, email: user.email, name: user.name, - role: "USER", + role: "INACTIVE_ADMIN", belongsToActiveTeam: hasActiveTeams, }; } diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index e3d4cae92d..aa7185d81a 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -1481,5 +1481,7 @@ "send_code" : "Send code", "number_verified": "Number Verified", "create_your_first_team_webhook_description": "Create your first webhook for this team event type", - "create_webhook_team_event_type": "Create a webhook for this team event type" + "create_webhook_team_event_type": "Create a webhook for this team event type", + "invalid_admin_password": "You are set as an admin but you do not have a password length of at least 15 characters", + "change_password_admin": "Change Password to gain admin access" } diff --git a/packages/features/users/components/AdminPasswordBanner.tsx b/packages/features/users/components/AdminPasswordBanner.tsx new file mode 100644 index 0000000000..1bf42680d0 --- /dev/null +++ b/packages/features/users/components/AdminPasswordBanner.tsx @@ -0,0 +1,28 @@ +import { useSession } from "next-auth/react"; +import Link from "next/link"; + +import { useLocale } from "@calcom/lib/hooks/useLocale"; +import { TopBanner } from "@calcom/ui"; + +function AdminPasswordBanner() { + const { t } = useLocale(); + const { data } = useSession(); + + if (data?.user.role !== "INACTIVE_ADMIN") return null; + + return ( + <> + + {t("change_password_admin")} + + } + /> + + ); +} + +export default AdminPasswordBanner; diff --git a/packages/types/next-auth.d.ts b/packages/types/next-auth.d.ts index 94c3fba101..8890fe50c3 100644 --- a/packages/types/next-auth.d.ts +++ b/packages/types/next-auth.d.ts @@ -16,6 +16,6 @@ declare module "next-auth" { impersonatedByUID?: number; belongsToActiveTeam?: boolean; username?: PrismaUser["username"]; - role?: PrismaUser["role"]; + role?: PrismaUser["role"] | "INACTIVE_ADMIN"; } } diff --git a/packages/ui/v2/core/Shell.tsx b/packages/ui/v2/core/Shell.tsx index 12f327ebd4..549ac0fedf 100644 --- a/packages/ui/v2/core/Shell.tsx +++ b/packages/ui/v2/core/Shell.tsx @@ -13,6 +13,7 @@ import ImpersonatingBanner from "@calcom/features/ee/impersonation/components/Im import HelpMenuItem from "@calcom/features/ee/support/components/HelpMenuItem"; import { TeamsUpgradeBanner } from "@calcom/features/ee/teams/components"; import { Tips } from "@calcom/features/tips"; +import AdminPasswordBanner from "@calcom/features/users/components/AdminPasswordBanner"; import CustomBranding from "@calcom/lib/CustomBranding"; import classNames from "@calcom/lib/classNames"; import { @@ -157,6 +158,7 @@ const Layout = (props: LayoutProps) => {
+
{props.SidebarContainer || }