Skip to content
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
Expand Up @@ -54,8 +54,8 @@ export default async function RoutePage(
),
with: {
databases: true,
storagePolicies: { with: { storageChannel: true } },
alertPolicies: { with: { notificationChannel: true } },
storagePolicies: true,
alertPolicies: true,
retentionPolicy: true,
},
});
Expand Down
10 changes: 7 additions & 3 deletions app/(customer)/dashboard/(organization)/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ export default async function RoutePage(props: PageParams<{ slug: string }>) {
notFound();
}

const notificationChannels = await getOrganizationChannels(organization.id);
const storageChannels = await getOrganizationStorageChannels(organization.id);
const agents = await getOrganizationAgents(organization.id);
const permissions = computeOrganizationPermissions(activeMember);
const notificationChannels = permissions.canManageNotifications
? await getOrganizationChannels(organization.id)
: [];
const storageChannels = permissions.canManageStorages
? await getOrganizationStorageChannels(organization.id)
: [];
const agents = await getOrganizationAgents(organization.id);

const users = await db.query.user.findMany({
where: (fields) => isNull(fields.deletedAt),
Expand Down
14 changes: 9 additions & 5 deletions src/db/services/notification-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ export async function getOrganizationChannels(
]);

const seen = new Set<string>();
return [...orgChannels, ...systemChannels].filter((c) => {
if (seen.has(c.id)) return false;
seen.add(c.id);
return true;
}) as NotificationChannel[];
return [...orgChannels, ...systemChannels]
.filter((c) => {
if (seen.has(c.id)) return false;
seen.add(c.id);
return true;
})
.map((c) =>
c.organizationId === organizationId ? c : { ...c, config: null },
) as NotificationChannel[];
}
14 changes: 9 additions & 5 deletions src/db/services/storage-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ export async function getOrganizationStorageChannels(
]);

const seen = new Set<string>();
return [...orgChannels, ...systemChannels].filter((c) => {
if (seen.has(c.id)) return false;
seen.add(c.id);
return true;
}) as StorageChannel[];
return [...orgChannels, ...systemChannels]
.filter((c) => {
if (seen.has(c.id)) return false;
seen.add(c.id);
return true;
})
.map((c) =>
c.organizationId === organizationId ? c : { ...c, config: null },
) as StorageChannel[];
}
11 changes: 8 additions & 3 deletions src/features/database/actions/backup-get-data.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {getOrganizationChannels} from "@/db/services/notification-channel";
import {getOrganizationStorageChannels} from "@/db/services/storage-channel";
import {getHealthLast12hLogs} from "@/db/services/healthcheck";
import {assertCanReadDatabase} from "@/features/database/utils/database-acl";
import {maskDatabaseSecretsForClient} from "@/features/database/utils/credential-fields";

type ChannelRow = { id: string; name: string; provider: string; enabled: boolean };

const toClientChannel = ({id, name, provider, enabled}: ChannelRow) => ({id, name, provider, enabled});

export const getDatabaseDataAction = userAction
.inputSchema(
Expand Down Expand Up @@ -88,14 +93,14 @@ export const getDatabaseDataAction = userAction

if (database?.project?.organizationId) {
const organizationChannels = await getOrganizationChannels(database.project.organizationId);
activeOrganizationChannels = organizationChannels.filter(channel => channel.enabled);
activeOrganizationChannels = organizationChannels.filter(channel => channel.enabled).map(toClientChannel);

const organizationStorageChannels = await getOrganizationStorageChannels(database.project.organizationId);
activeOrganizationStorageChannels = organizationStorageChannels.filter(channel => channel.enabled);
activeOrganizationStorageChannels = organizationStorageChannels.filter(channel => channel.enabled).map(toClientChannel);
}

return {
database,
database: database && maskDatabaseSecretsForClient(database),
// @ts-ignore
activeOrganizationChannels,
// @ts-ignore
Expand Down
4 changes: 3 additions & 1 deletion src/features/database/actions/backup-list.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export const fetchBackupsAction = userAction
restorations: true,
storages: {
with: {
storageChannel: true,
storageChannel: {
columns: { id: true, name: true, provider: true },
},
},
},
},
Expand Down
Loading