Skip to content
Open
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
2 changes: 1 addition & 1 deletion announcements.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"variant": "important",
"isExternal": true,
"closeable": true,
"isCloudOnly": false
"targets": ["selfhosted"]
}
]
8 changes: 4 additions & 4 deletions src/contexts/AnnouncementProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import React, {
useState,
} from "react";
import { usePermissions } from "@/contexts/PermissionsProvider";
import { isLocalDev, isNetBirdHosted } from "@utils/netbird";
import { isLocalDev } from "@utils/netbird";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Restore runtime target detection before filtering.

Line 80 now matches against a hard-coded "selfhosted" target for every deployment, because the isNetBirdHosted() signal was removed at Line 11. That means cloud users will also see self-hosted banners, cloud-targeted banners can never render, and announcements without targets are silently dropped even though the field is optional on Line 34. src/layouts/DashboardLayout.tsx:27-46 still uses isNetBirdHosted() for the same cloud/self-hosted split, so the provider should derive the current target instead of hard-coding one.

Proposed fix
-import { isLocalDev } from "@utils/netbird";
+import { isLocalDev, isNetBirdHosted } from "@utils/netbird";
...
-const TARGET = "selfhosted";
+type AnnouncementTarget = "cloud" | "selfhosted";
...
 export interface Announcement extends AnnouncementVariant {
   tag: string;
   text: string;
   link?: string;
   linkText?: string;
   isExternal?: boolean;
   closeable: boolean;
-  targets?: string[];
+  targets?: AnnouncementTarget[];
 }
...
-    const filtered = raw.filter((a) => a.targets?.includes(TARGET));
+    const currentTarget: AnnouncementTarget = isNetBirdHosted()
+      ? "cloud"
+      : "selfhosted";
+    const filtered = raw.filter(
+      (a) => !a.targets?.length || a.targets.includes(currentTarget),
+    );

Also applies to: 18-18, 34-34, 80-80

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/contexts/AnnouncementProvider.tsx` at line 11, The provider currently
hard-codes the runtime target (e.g. "selfhosted") and no longer imports
isNetBirdHosted(), causing cloud users to see wrong banners and announcements
with no targets to be dropped; restore runtime detection by re-importing
isNetBirdHosted from "@utils/netbird", compute a runtimeTarget (e.g.
runtimeTarget = isNetBirdHosted() ? "selfhosted" : "cloud") inside
AnnouncementProvider (the component that filters announcements), and update the
filter logic in whatever function/method filters announcements (refer to the
announcement filtering code around the existing targets check) so that an
announcement is kept if announcement.targets is undefined/empty OR includes
runtimeTarget (instead of comparing to a hard-coded string). Ensure all
occurrences that previously used the hard-coded "selfhosted" are replaced to use
runtimeTarget so cloud vs self-hosted splits behave the same as
DashboardLayout's isNetBirdHosted() branching.

import announcementFile from "../../announcements.json";

const ANNOUNCEMENTS_URL =
"https://raw.githubusercontent.com/netbirdio/dashboard/main/announcements.json";
const STORAGE_KEY = "netbird-announcements";
const CACHE_DURATION_MS = 30 * 60 * 1000;
const TARGET = "selfhosted";
const BANNER_HEIGHT = 40;

interface AnnouncementStore {
Expand All @@ -30,7 +31,7 @@ export interface Announcement extends AnnouncementVariant {
linkText?: string;
isExternal?: boolean;
closeable: boolean;
isCloudOnly: boolean;
targets?: string[];
}

interface AnnouncementInfo extends Announcement {
Expand Down Expand Up @@ -76,8 +77,7 @@ const getAnnouncements = async (): Promise<AnnouncementInfo[]> => {
raw = await response.json();
}

const isCloud = isNetBirdHosted();
const filtered = raw.filter((a) => !a.isCloudOnly || isCloud);
const filtered = raw.filter((a) => a.targets?.includes(TARGET));
const hashes = new Set(filtered.map((a) => md5(a.text).toString()));
const closed = (stored?.closedAnnouncements ?? []).filter((h) =>
hashes.has(h),
Expand Down