Skip to content

Commit 13501bd

Browse files
CS-219 Hide devices of platform admin users on People/Devices tab (#2447)
* fix(app): hide platform admin devices on People/Devices tab * fix(app): add platform admin filtering from fleet device source --------- Co-authored-by: chasprowebdev <chasgarciaprowebdev@gmail.com>
1 parent 883caeb commit 13501bd

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

  • apps/app/src/app/(app)/[orgId]/people/devices/data

apps/app/src/app/(app)/[orgId]/people/devices/data/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@ export const getEmployeeDevicesFromDB: () => Promise<DeviceWithChecks[]> = async
2424
}
2525

2626
const devices = await db.device.findMany({
27-
where: { organizationId },
27+
where: {
28+
organizationId,
29+
// Exclude devices for users whose User.role is platform admin (not org Member.role).
30+
NOT: {
31+
member: {
32+
user: {
33+
role: 'admin',
34+
},
35+
},
36+
},
37+
},
2838
include: {
2939
member: {
3040
include: {
@@ -65,7 +75,7 @@ export const getEmployeeDevicesFromDB: () => Promise<DeviceWithChecks[]> = async
6575

6676
/**
6777
* Fetches Fleet (legacy) devices for the current organization.
68-
* Returns Host[] exactly as main branch — untouched Fleet logic.
78+
* Excludes members whose User.role is platform admin (same as getEmployeeDevicesFromDB).
6979
*/
7080
export const getFleetHosts: () => Promise<Host[] | null> = async () => {
7181
const session = await auth.api.getSession({
@@ -80,11 +90,16 @@ export const getFleetHosts: () => Promise<Host[] | null> = async () => {
8090
return null;
8191
}
8292

83-
// Find all members belonging to the organization.
93+
// Members with Fleet labels (exclude platform admins — same filter as device-agent path).
8494
const employees = await db.member.findMany({
8595
where: {
8696
organizationId,
8797
deactivated: false,
98+
NOT: {
99+
user: {
100+
role: 'admin',
101+
},
102+
},
88103
},
89104
include: {
90105
user: true,

0 commit comments

Comments
 (0)