Skip to content

Commit

Permalink
Create AUP page
Browse files Browse the repository at this point in the history
  • Loading branch information
SteDev2 authored and jacogasp committed Jun 13, 2024
1 parent 195c250 commit 1eac1e4
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/app/(pages)/aup/AupCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Aup } from "@/models/aup";

const calculate = (aup: Aup) => {
const newDate = new Date(aup.lastUpdateTime as string);
return new Date(
newDate.setDate(newDate.getDate() + aup.signatureValidityInDays + 900)
);
};

export const AupCard = (props: { aup: Aup }) => {
const { aup } = props;
const nextSignDate = aup.signatureValidityInDays == 0 ? calculate(aup) : "";
return (
<div>
<h2>
<b>Acceptable Usage Policy URL</b>
</h2>
<a href="{aup?.url}">{aup?.url}</a>
<h3>
The URL above is presented to users at registration time or periodically
if the AUP is configured for periodic reacceptance
</h3>
<h2>
<b>Created</b>
</h2>
<h3>{new Date(aup.creationTime).toISOString()}</h3>
<h2>
<b>Last updated</b>
</h2>
<h3>{new Date(aup?.lastUpdateTime as string)?.toISOString()}</h3>
<h2>
<b>Signature Validity (in days)</b>
</h2>
<h3>{aup?.signatureValidityInDays}</h3>
</div>
);
};
39 changes: 39 additions & 0 deletions src/app/(pages)/aup/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Button } from "@/components/Button";
import { fetchAup } from "@/services/aup";
import { DocumentTextIcon } from "@heroicons/react/16/solid";
import { AupCard } from "./AupCard";

export default async function Aup() {
const aup = await fetchAup();
return (
<div>
<div className="flex items-stretch">
<div
className="me-2 my-auto"
style={{
width: "24px",
height: "24px",
}}
>
<DocumentTextIcon />
</div>
<div>
<h1>Acceptable Usage Policy</h1>
</div>
</div>

<AupCard aup={aup}></AupCard>
<div>
<Button type="button" className="my-auto" color="primary">
Edit AUP
</Button>
<Button type="button" className="my-auto" color="warning">
Request AUP signature
</Button>
<Button type="button" className="my-auto" color="danger">
Delete AUP
</Button>
</div>
</div>
);
}
1 change: 1 addition & 0 deletions src/app/(pages)/components/UserCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const User = (props: { me: Me }) => {
["Status", me.active ? "active" : "disabled"],
["Created", created],
["Last Modified", lastModified],
["AUP expired at", lastModified],
];

return (
Expand Down
2 changes: 2 additions & 0 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UserIcon,
ShieldCheckIcon,
InformationCircleIcon,
DocumentTextIcon,
} from "@heroicons/react/20/solid";

const AccountManagement = () => {
Expand All @@ -30,6 +31,7 @@ const OrganizationManagement = () => {
<DrawerSection title="Organization Management">
<DrawerLink title="Users" href="/users" icon={<UserIcon />} />
<DrawerLink title="Groups" href="/groups" icon={<UserGroupIcon />} />
<DrawerLink title="AUP" href="/aup" icon={<DocumentTextIcon />} />
<DrawerLink title="Clients" href="/clients" icon={<RocketLaunchIcon />} />
<DrawerLink title="Tokens" href="/tokens" icon={<KeyIcon />} />
</DrawerSection>
Expand Down
20 changes: 20 additions & 0 deletions src/models/aup-signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type Aup = {
url: string;
text?: string | null;
description?: string | null;
signatureValidityInDays: number;
creationTime: string;
lastUpdateTime?: string | null;
};

type Account = {
uuid: string;
username: string;
name: string;
};

export interface AupSignature {
aup: Aup;
account: Account;
signatureTime: string;
}
8 changes: 8 additions & 0 deletions src/models/aup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Aup {
url: string;
text?: string | null;
description?: string | null;
signatureValidityInDays: number;
creationTime: string;
lastUpdateTime?: string | null;
}
26 changes: 26 additions & 0 deletions src/services/aup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Aup } from "@/models/aup";
import getConfig from "@/utils/config";
import { getItem } from "@/utils/fetch";

const { BASE_URL } = getConfig();

export const fetchAup = async () => {
let url = `${BASE_URL}/iam/aup`;

return await getItem<Aup>(url);
};

export const fetchAupSignature = async () => {
let url = `${BASE_URL}/iam/aup/signature`;

return await getItem<Aup>(url);
};

// export const editAup = async (_: string | undefined, formData: FormData) => {
// const urlAup = formData.get("url") as string | undefined;
// const validity = formData.get("validity") as string | undefined;

// let url = `${BASE_URL}/iam/aup`;

// // return await putItem<Aup>(url);
// };
3 changes: 3 additions & 0 deletions src/utils/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ export const getItem: GetItem = async (endpoint: string | URL) => {
const response = await authFetch(endpoint);
return response.json();
};

// type PatchItem = <T>(endpoint: string | URL, body: T) => Promise<T>;
// export const patchItem: PatchItem = async (body: T) => {};

0 comments on commit 1eac1e4

Please sign in to comment.