Rename Organization to Project

We'll probably need a concept of organizations at some point in the future, but in practice the way we're using these in the codebase right now is as a project, so this renames it to that to avoid confusion.
This commit is contained in:
Kyle Corbitt
2023-08-09 15:49:19 -07:00
parent ac99c8e0f7
commit 16aa6672fc
30 changed files with 292 additions and 248 deletions

View File

@@ -1,4 +1,4 @@
import { OrganizationUserRole } from "@prisma/client";
import { ProjectUserRole } from "@prisma/client";
import { TRPCError } from "@trpc/server";
import { type TRPCContext } from "~/server/api/trpc";
import { prisma } from "~/server/db";
@@ -16,16 +16,16 @@ export const requireNothing = (ctx: TRPCContext) => {
ctx.markAccessControlRun();
};
export const requireIsOrgAdmin = async (organizationId: string, ctx: TRPCContext) => {
export const requireIsProjectAdmin = async (projectId: string, ctx: TRPCContext) => {
const userId = ctx.session?.user.id;
if (!userId) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
const isAdmin = await prisma.organizationUser.findFirst({
const isAdmin = await prisma.projectUser.findFirst({
where: {
userId,
organizationId,
projectId,
role: "ADMIN",
},
});
@@ -37,16 +37,16 @@ export const requireIsOrgAdmin = async (organizationId: string, ctx: TRPCContext
ctx.markAccessControlRun();
};
export const requireCanViewOrganization = async (organizationId: string, ctx: TRPCContext) => {
export const requireCanViewProject = async (projectId: string, ctx: TRPCContext) => {
const userId = ctx.session?.user.id;
if (!userId) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
const canView = await prisma.organizationUser.findFirst({
const canView = await prisma.projectUser.findFirst({
where: {
userId,
organizationId,
projectId,
},
});
@@ -57,17 +57,17 @@ export const requireCanViewOrganization = async (organizationId: string, ctx: TR
ctx.markAccessControlRun();
};
export const requireCanModifyOrganization = async (organizationId: string, ctx: TRPCContext) => {
export const requireCanModifyProject = async (projectId: string, ctx: TRPCContext) => {
const userId = ctx.session?.user.id;
if (!userId) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
const canModify = await prisma.organizationUser.findFirst({
const canModify = await prisma.projectUser.findFirst({
where: {
userId,
organizationId,
role: { in: [OrganizationUserRole.ADMIN, OrganizationUserRole.MEMBER] },
projectId,
role: { in: [ProjectUserRole.ADMIN, ProjectUserRole.MEMBER] },
},
});
@@ -82,10 +82,10 @@ export const requireCanViewDataset = async (datasetId: string, ctx: TRPCContext)
const dataset = await prisma.dataset.findFirst({
where: {
id: datasetId,
organization: {
organizationUsers: {
project: {
projectUsers: {
some: {
role: { in: [OrganizationUserRole.ADMIN, OrganizationUserRole.MEMBER] },
role: { in: [ProjectUserRole.ADMIN, ProjectUserRole.MEMBER] },
userId: ctx.session?.user.id,
},
},
@@ -120,10 +120,10 @@ export const canModifyExperiment = async (experimentId: string, userId: string)
prisma.experiment.findFirst({
where: {
id: experimentId,
organization: {
organizationUsers: {
project: {
projectUsers: {
some: {
role: { in: [OrganizationUserRole.ADMIN, OrganizationUserRole.MEMBER] },
role: { in: [ProjectUserRole.ADMIN, ProjectUserRole.MEMBER] },
userId,
},
},

View File

@@ -5,10 +5,10 @@ import { NumberParam, useQueryParam, withDefault } from "use-query-params";
import { useAppStore } from "~/state/store";
export const useExperiments = () => {
const selectedOrgId = useAppStore((state) => state.selectedOrgId);
const selectedProjectId = useAppStore((state) => state.selectedProjectId);
return api.experiments.list.useQuery(
{ organizationId: selectedOrgId ?? "" },
{ enabled: !!selectedOrgId },
{ projectId: selectedProjectId ?? "" },
{ enabled: !!selectedProjectId },
);
};
@@ -27,10 +27,10 @@ export const useExperimentAccess = () => {
};
export const useDatasets = () => {
const selectedOrgId = useAppStore((state) => state.selectedOrgId);
const selectedProjectId = useAppStore((state) => state.selectedProjectId);
return api.datasets.list.useQuery(
{ organizationId: selectedOrgId ?? "" },
{ enabled: !!selectedOrgId },
{ projectId: selectedProjectId ?? "" },
{ enabled: !!selectedProjectId },
);
};
@@ -150,7 +150,10 @@ export const useScenario = (scenarioId: string) => {
export const useVisibleScenarioIds = () => useScenarios().data?.scenarios.map((s) => s.id) ?? [];
export const useSelectedOrg = () => {
const selectedOrgId = useAppStore((state) => state.selectedOrgId);
return api.organizations.get.useQuery({ id: selectedOrgId ?? "" }, { enabled: !!selectedOrgId });
export const useSelectedProject = () => {
const selectedProjectId = useAppStore((state) => state.selectedProjectId);
return api.projects.get.useQuery(
{ id: selectedProjectId ?? "" },
{ enabled: !!selectedProjectId },
);
};