Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow private model upgrades in admin UI #3471

Merged
merged 2 commits into from
Jan 6, 2025
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
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
Loading