feat(admin): show group schedule status
This commit is contained in:
@@ -112,7 +112,7 @@ export default async function GroupPage({
|
||||
<PolicyDetail description="Controls whether members can connect to Minecraft. Disabled access always overrides the schedule." label="Minecraft access"><GroupPolicyControl action={setGroupAccess} enabled={group.accessEnabled} groupId={group.id} groupName={group.name} memberCount={memberUsers.length} policy="Minecraft access" returnLocation="detail" /></PolicyDetail>
|
||||
<PolicyDetail description="Allows confirmed VPN, proxy, and Tor connections after access and schedule checks pass." label="VPN / proxy / Tor"><GroupPolicyControl action={setGroupAnonymizedNetworkAccess} enabled={group.anonymizedNetworksAllowed} groupId={group.id} groupName={group.name} memberCount={memberUsers.length} policy="VPN / proxy / Tor" returnLocation="detail" /></PolicyDetail>
|
||||
</div>
|
||||
<div className="mt-7 border-t border-line pt-6">
|
||||
<div className="mt-7 scroll-mt-6 border-t border-line pt-6" id="group-schedule">
|
||||
<div className="flex flex-col gap-5 sm:flex-row sm:items-start sm:justify-between">
|
||||
<div className="max-w-2xl"><h3 className="font-mono text-xs font-bold uppercase">Weekly access schedule</h3><p className="mt-2 text-xs leading-5 text-muted">When Minecraft access is enabled, members may log in only during these recurring UTC windows. Existing sessions are not disconnected when a window ends.</p><div className="mt-4"><GroupScheduleSummary windows={accessWindows} /></div></div>
|
||||
<AdminModalForm action={replaceGroupSchedule} description={`Replace the complete weekly access schedule for ${group.name}. Minecraft access must still be enabled.`} submitLabel="Save schedule" title={`Schedule ${group.name}`} triggerClassName="shrink-0 border border-ink px-4 py-3 font-mono text-[10px] font-bold uppercase tracking-wider" triggerLabel="Edit schedule">
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { groups, userGroupMemberships, users } from "@minecraft-account-manager/database";
|
||||
import { groupAccessWindows, groups, userGroupMemberships, users } from "@minecraft-account-manager/database";
|
||||
import { asc, count, desc } from "drizzle-orm";
|
||||
import Link from "next/link";
|
||||
import { AdminModalForm } from "@/components/admin-modal-form";
|
||||
import { GroupPolicyControl } from "@/components/group-policy-control";
|
||||
import { db } from "@/lib/database";
|
||||
import { effectiveGroupMemberCount } from "@/lib/group-management";
|
||||
import { groupScheduleStatus } from "@/lib/group-schedule";
|
||||
import { createGroup, setGroupAccess, setGroupAnonymizedNetworkAccess } from "./actions";
|
||||
|
||||
const errors: Record<string, string> = {
|
||||
@@ -26,11 +27,15 @@ export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function GroupsPage({ searchParams }: { searchParams: Promise<{ error?: string; saved?: string }> }) {
|
||||
const query = await searchParams;
|
||||
const [allGroups, memberships, [registeredUsers]] = await Promise.all([
|
||||
const [allGroups, memberships, [registeredUsers], scheduleCounts] = await Promise.all([
|
||||
db.select().from(groups).orderBy(desc(groups.isDefault), asc(groups.name)),
|
||||
db.select({ groupId: userGroupMemberships.groupId }).from(userGroupMemberships),
|
||||
db.select({ count: count() }).from(users),
|
||||
db.select({ groupId: groupAccessWindows.groupId, count: count() })
|
||||
.from(groupAccessWindows)
|
||||
.groupBy(groupAccessWindows.groupId),
|
||||
]);
|
||||
const scheduleCountByGroup = new Map(scheduleCounts.map((schedule) => [schedule.groupId, Number(schedule.count)]));
|
||||
return (
|
||||
<main className="mx-auto max-w-6xl px-6 py-14">
|
||||
<header className="flex flex-col gap-6 border-b border-line pb-8 sm:flex-row sm:items-end sm:justify-between">
|
||||
@@ -60,10 +65,10 @@ export default async function GroupsPage({ searchParams }: { searchParams: Promi
|
||||
{query.saved && <p className="mt-7 border-l-2 border-signal bg-panel px-5 py-4 text-sm" role="status">{savedMessages[query.saved] ?? "Group updated."}</p>}
|
||||
|
||||
<div className="mt-9 overflow-x-auto border border-line bg-panel shadow-[8px_8px_0_var(--color-shadow)]">
|
||||
<table className="w-full min-w-[760px] border-collapse text-left">
|
||||
<table className="w-full min-w-[880px] border-collapse text-left">
|
||||
<caption className="sr-only">Access groups and their effective policies</caption>
|
||||
<thead className="border-b border-line font-mono text-[10px] uppercase tracking-widest text-muted">
|
||||
<tr><th className="p-4" scope="col">Name</th><th className="p-4" scope="col">Minecraft access</th><th className="p-4" scope="col">VPN access</th><th className="p-4 text-right" scope="col">Users</th></tr>
|
||||
<tr><th className="p-4" scope="col">Name</th><th className="p-4" scope="col">Minecraft access</th><th className="p-4" scope="col">Schedule</th><th className="p-4" scope="col">VPN access</th><th className="p-4 text-right" scope="col">Users</th></tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-line">
|
||||
{allGroups.map((group) => {
|
||||
@@ -72,6 +77,7 @@ export default async function GroupsPage({ searchParams }: { searchParams: Promi
|
||||
memberships.map((membership) => membership.groupId),
|
||||
group,
|
||||
);
|
||||
const scheduleStatus = groupScheduleStatus(scheduleCountByGroup.get(group.id) ?? 0);
|
||||
return (
|
||||
<tr className="transition-colors hover:bg-canvas/60" key={group.id}>
|
||||
<th className="p-4 text-left" scope="row">
|
||||
@@ -79,6 +85,7 @@ export default async function GroupsPage({ searchParams }: { searchParams: Promi
|
||||
{group.isDefault && <span className="ml-3 bg-ink px-2 py-1 font-mono text-[8px] font-bold uppercase text-canvas">Default</span>}
|
||||
</th>
|
||||
<td className="p-4"><GroupPolicyControl action={setGroupAccess} enabled={group.accessEnabled} groupId={group.id} groupName={group.name} memberCount={memberCount} policy="Minecraft access" returnLocation="list" /></td>
|
||||
<td className="p-4"><Link aria-label={`${scheduleStatus}. Edit schedule for ${group.name}`} className={`font-mono text-[10px] font-bold uppercase underline underline-offset-4 ${scheduleStatus === "Unrestricted" ? "text-muted" : "text-accent"}`} href={`/admin/groups/${group.id}#group-schedule`}>{scheduleStatus}</Link></td>
|
||||
<td className="p-4"><GroupPolicyControl action={setGroupAnonymizedNetworkAccess} enabled={group.anonymizedNetworksAllowed} groupId={group.id} groupName={group.name} memberCount={memberCount} policy="VPN / proxy / Tor" returnLocation="list" /></td>
|
||||
<td className="p-4 text-right font-mono text-sm font-bold">{memberCount}</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
evaluateGroupSchedule,
|
||||
groupScheduleStatus,
|
||||
localWindowToUtc,
|
||||
parseScheduleWindows,
|
||||
utcWindowToLocal,
|
||||
@@ -13,6 +14,12 @@ const fridayEvening: WeeklyAccessWindow = {
|
||||
};
|
||||
|
||||
describe("weekly group access schedules", () => {
|
||||
it("summarizes whether a group has configured windows", () => {
|
||||
expect(groupScheduleStatus(0)).toBe("Unrestricted");
|
||||
expect(groupScheduleStatus(1)).toBe("1 window");
|
||||
expect(groupScheduleStatus(3)).toBe("3 windows");
|
||||
});
|
||||
|
||||
it("allows an enabled group at any time when no schedule is configured", () => {
|
||||
expect(evaluateGroupSchedule([], new Date("2026-08-07T19:00:00Z"))).toEqual({
|
||||
allowed: true,
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
export const MINUTES_PER_WEEK = 7 * 24 * 60;
|
||||
const MAX_WINDOWS = 50;
|
||||
|
||||
export function groupScheduleStatus(windowCount: number) {
|
||||
if (windowCount <= 0) return "Unrestricted";
|
||||
return `${windowCount} ${windowCount === 1 ? "window" : "windows"}`;
|
||||
}
|
||||
|
||||
export interface WeeklyAccessWindow {
|
||||
startMinuteOfWeek: number;
|
||||
endMinuteOfWeek: number;
|
||||
|
||||
Reference in New Issue
Block a user