Skip to content

Commit

Permalink
Merge pull request #3471 from quantified-uncertainty/upgrade-private-…
Browse files Browse the repository at this point in the history
…models

Allow private model upgrades in admin UI
  • Loading branch information
berekuk authored Jan 6, 2025
2 parents a399d62 + b166169 commit faf18a1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
23 changes: 13 additions & 10 deletions apps/hub/src/app/admin/upgrade-versions/UpgradeVersionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Dropdown,
DropdownMenu,
DropdownMenuActionItem,
LockIcon,
RefreshIcon,
XIcon,
} from "@quri/ui";
Expand Down Expand Up @@ -98,11 +99,16 @@ const ComparedModel: FC<{

return (
<div className="col-span-2 grid grid-cols-subgrid gap-2">
<StyledLink
href={`/admin/upgrade-versions/compare?owner=${model.owner.slug}&slug=${model.slug}`}
>
{model.owner.slug}/{model.slug}
</StyledLink>
<div className="flex items-center gap-1">
<StyledLink
href={`/admin/upgrade-versions/compare?owner=${model.owner.slug}&slug=${model.slug}`}
>
{model.owner.slug}/{model.slug}
</StyledLink>
{model.isPrivate ? (
<LockIcon className="h-4 w-4 text-gray-600" />
) : null}
</div>
<ComparedCode
modelId={model.id}
version={version}
Expand Down Expand Up @@ -149,17 +155,14 @@ export const UpgradeVersionsPage: FC<{

const upgradeableModelsByVersion = modelsByVersion.filter(
(entry) =>
entry.version !== "dev" &&
entry.version !== defaultSquiggleVersion &&
entry.count > 0
entry.version !== "dev" && entry.version !== defaultSquiggleVersion
);

const [selectedVersion, setSelectedVersion] = useState(
upgradeableModelsByVersion.at(0)?.version
);

const getEntryTitle = (entry: Entry) =>
`${entry.version} (${entry.count} models, ${entry.privateCount} private)`;
const getEntryTitle = (entry: Entry) => `${entry.version} (${entry.count})`;

const getEntryByVersion = (version: string): Entry | undefined =>
modelsByVersion.find((entry) => entry.version === version);
Expand Down
5 changes: 5 additions & 0 deletions apps/hub/src/app/admin/upgrade-versions/compare/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { notFound } from "next/navigation";

import { LockIcon } from "@quri/ui";

import { H2 } from "@/components/ui/Headers";
import { StyledLink } from "@/components/ui/StyledLink";
import { modelRoute } from "@/lib/routes";
Expand Down Expand Up @@ -36,6 +38,9 @@ export default async function CompareVersionsPage({ searchParams }: Props) {
>
{model.owner.slug}/{model.slug}
</StyledLink>
{model.isPrivate ? (
<LockIcon className="ml-1 inline-block h-4 w-4 text-gray-600" />
) : null}
</div>
<UpgradeButton model={model} />
</div>
Expand Down
9 changes: 4 additions & 5 deletions apps/hub/src/models/data/byVersion.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { prisma } from "@/lib/server/prisma";
import { checkRootUser } from "@/users/auth";

// Admin-only, for listing models in /admin UI
// Admin-only, for listing models in /admin/upgrade-versions UI
export async function loadModelsByVersion() {
await checkRootUser();

// no DTO but that's fine for admin-only
const models = await prisma.model.findMany({
include: {
currentRevision: {
Expand All @@ -29,13 +30,11 @@ export async function loadModelsByVersion() {

versions.add(version);

groupedModels[version] ??= [];
groupedModels[version].push(model);
if (model.isPrivate) {
privateStats[version] ??= 0;
privateStats[version]++;
} else {
// don't expose private models, they won't be available for loading anyway
groupedModels[version] ??= [];
groupedModels[version].push(model);
}
}
return [...versions.values()].map((version) => ({
Expand Down
3 changes: 3 additions & 0 deletions apps/hub/src/models/data/full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
const select = {
id: true,
slug: true,
isPrivate: true,
owner: {
select: {
id: true,
Expand All @@ -36,6 +37,7 @@ export type ModelFullDTO = {
slug: string;
};
currentRevision: ModelRevisionFullDTO;
isPrivate: boolean;
isEditable: boolean;
lastBuildSeconds: number | null;
};
Expand Down Expand Up @@ -87,6 +89,7 @@ async function toDTO(row: Row): Promise<ModelFullDTO> {
},
currentRevision: await modelRevisionFullToDTO(row.currentRevision),
isEditable: await controlsOwnerId(row.owner.id),
isPrivate: row.isPrivate,
lastBuildSeconds,
};
}
Expand Down

0 comments on commit faf18a1

Please sign in to comment.