Skip to content

Commit

Permalink
Merge pull request #415 from sinamics/add-routes-to-database
Browse files Browse the repository at this point in the history
Added notification if a subnet already exist
  • Loading branch information
sinamics authored May 17, 2024
2 parents 44b6bc2 + ad5465b commit 90a003c
Show file tree
Hide file tree
Showing 27 changed files with 428 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Warnings:
- You are about to drop the column `email` on the `OrganizationInvitation` table. All the data in the column will be lost.
- You are about to drop the column `expiresAt` on the `OrganizationInvitation` table. All the data in the column will be lost.
- You are about to drop the column `invitedById` on the `OrganizationInvitation` table. All the data in the column will be lost.
- You are about to drop the column `mailSentAt` on the `OrganizationInvitation` table. All the data in the column will be lost.
- You are about to drop the column `role` on the `OrganizationInvitation` table. All the data in the column will be lost.
- You are about to drop the column `token` on the `OrganizationInvitation` table. All the data in the column will be lost.
- You are about to drop the column `updatedAt` on the `OrganizationInvitation` table. All the data in the column will be lost.
- You are about to drop the `UserInvitation` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `invitationId` to the `OrganizationInvitation` table without a default value. This is not possible if the table is not empty.
*/
-- DropIndex
DROP INDEX "OrganizationInvitation_token_key";

-- AlterTable
ALTER TABLE "OrganizationInvitation" DROP COLUMN "email",
DROP COLUMN "expiresAt",
DROP COLUMN "invitedById",
DROP COLUMN "mailSentAt",
DROP COLUMN "role",
DROP COLUMN "token",
DROP COLUMN "updatedAt",
ADD COLUMN "invitationId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "network" ADD COLUMN "routes" JSONB;

-- DropTable
DROP TABLE "UserInvitation";

-- CreateTable
CREATE TABLE "Invitation" (
"id" SERIAL NOT NULL,
"token" TEXT NOT NULL,
"used" BOOLEAN NOT NULL DEFAULT false,
"email" TEXT,
"secret" TEXT,
"groupId" TEXT,
"userGroupId" INTEGER,
"url" TEXT NOT NULL,
"expiresAt" TIMESTAMP(3) NOT NULL,
"mailSentAt" TIMESTAMP(3),
"timesCanUse" INTEGER NOT NULL DEFAULT 1,
"timesUsed" INTEGER NOT NULL DEFAULT 0,
"invitedById" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"role" "Role" NOT NULL DEFAULT 'READ_ONLY',

CONSTRAINT "Invitation_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Invitation_token_key" ON "Invitation"("token");

-- AddForeignKey
ALTER TABLE "Invitation" ADD CONSTRAINT "Invitation_invitedById_fkey" FOREIGN KEY ("invitedById") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Invitation" ADD CONSTRAINT "Invitation_userGroupId_fkey" FOREIGN KEY ("userGroupId") REFERENCES "UserGroup"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "OrganizationInvitation" ADD CONSTRAINT "OrganizationInvitation_invitationId_fkey" FOREIGN KEY ("invitationId") REFERENCES "Invitation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
72 changes: 38 additions & 34 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ model network {
organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
networkMembers network_members[]
notations Notation[]
routes Json?
}

model Notation {
Expand Down Expand Up @@ -190,13 +191,14 @@ enum AccessLevel {
}

model UserGroup {
id Int @id @default(autoincrement())
name String @unique
description String?
maxNetworks Int @default(5)
accessLevel AccessLevel @default(WRITE)
isDefault Boolean @default(false)
users User[]
id Int @id @default(autoincrement())
name String @unique
description String?
maxNetworks Int @default(5)
accessLevel AccessLevel @default(WRITE)
isDefault Boolean @default(false)
users User[]
userInvitation Invitation[]
}

model APIToken {
Expand Down Expand Up @@ -241,6 +243,7 @@ model User {
network network[]
apiTokens APIToken[]
webhooks Webhook[]
invitations Invitation[] @relation("InvitationsSent")
}

model VerificationToken {
Expand All @@ -251,19 +254,33 @@ model VerificationToken {
@@unique([identifier, token])
}

model UserInvitation {
id Int @id @default(autoincrement())
token String @unique
used Boolean @default(false)
email String?
secret String
groupId String?
url String
expires DateTime
timesCanUse Int @default(1)
timesUsed Int @default(0)
createdBy String
createdAt DateTime @default(now())
model Invitation {
id Int @id @default(autoincrement())
token String @unique
used Boolean @default(false)
email String?
secret String?
groupId String?
userGroupId Int?
url String
expiresAt DateTime
mailSentAt DateTime?
timesCanUse Int @default(1)
timesUsed Int @default(0)
invitedById String
createdAt DateTime @default(now())
role Role @default(READ_ONLY)
createdBy User @relation(fields: [invitedById], references: [id], onDelete: Cascade, name: "InvitationsSent")
userGroup UserGroup? @relation(fields: [userGroupId], references: [id], onDelete: Cascade)
organizations OrganizationInvitation[]
}

model OrganizationInvitation {
id String @id @default(cuid())
invitationId Int
organizationId String
invitation Invitation @relation(fields: [invitationId], references: [id], onDelete: Cascade)
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
}

//
Expand All @@ -279,14 +296,14 @@ model Organization {
users User[] @relation("MemberRelation")
networks network[]
settings OrganizationSettings?
invitations OrganizationInvitation[]
membershipRequests MembershipRequest[] @relation("MembershipRequestsForOrganization")
isActive Boolean @default(true)
userRoles UserOrganizationRole[]
messages Messages[]
lastReadByUsers LastReadMessage[]
ActivityLog ActivityLog[]
webhooks Webhook[]
invitations OrganizationInvitation[]
}

model Webhook {
Expand Down Expand Up @@ -348,19 +365,6 @@ model OrganizationSettings {
// Add specific settings fields here
}

model OrganizationInvitation {
id String @id @default(cuid())
token String @unique
email String
role Role @default(READ_ONLY)
expiresAt DateTime @default(now())
invitedById String
organizationId String
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
updatedAt DateTime @default(now())
mailSentAt DateTime?
}

model MembershipRequest {
id Int @id @default(autoincrement())
userId String
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__mocks__/networkById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ jest.mock("../../utils/api", () => ({
network: {
nwid: "1234567890",
name: "Test Network",
duplicateRoutes: [],
private: true,
ipAssignmentPools: [{ ipRangeStart: "10.0.0.1", ipRangeEnd: "10.0.0.254" }],
routes: [{ target: "10.0.0.0/24" }],
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/components/networkIpAssignments.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe("<NetworkIpAssignment />", () => {
it("renders the IP assignment content after loading", async () => {
const mockData = {
network: {
duplicateRoutes: [],
v4AssignMode: {
zt: false,
},
Expand Down Expand Up @@ -84,6 +85,7 @@ describe("<NetworkIpAssignment />", () => {
const mockData = {
// This object is used to mock the data returned by the API
network: {
duplicateRoutes: [],
v4AssignMode: {
zt: false,
},
Expand Down Expand Up @@ -126,6 +128,7 @@ describe("<NetworkIpAssignment />", () => {
it("should handle easy IP assignment", async () => {
const mockData = {
network: {
duplicateRoutes: [],
v4AssignMode: {
zt: true, // Ensure checkbox is checked to show easy IP assignment
},
Expand Down Expand Up @@ -161,6 +164,7 @@ describe("<NetworkIpAssignment />", () => {
it("should handle advanced IP assignment - addition of IP range", async () => {
const mockData = {
network: {
duplicateRoutes: [],
v4AssignMode: {
zt: true, // Ensure checkbox is checked to show advanced IP assignment
},
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/pages/network/[id].test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe("NetworkById component", () => {
network: {
nwid: "1234567890",
name: "Test Network",
duplicateRoutes: [],
private: true,
ipAssignmentPools: [{ ipRangeStart: "10.0.0.1", ipRangeEnd: "10.0.0.254" }],
routes: [{ target: "10.0.0.0/24" }],
Expand Down Expand Up @@ -198,6 +199,7 @@ describe("NetworkById component", () => {
network: {
nwid: "network_id",
name: "Test Network",
duplicateRoutes: [],
private: true,
ipAssignmentPools: [{ ipRangeStart: "10.0.0.1", ipRangeEnd: "10.0.0.254" }],
routes: [{ target: "10.0.0.0/24" }],
Expand Down Expand Up @@ -252,6 +254,7 @@ describe("NetworkById component", () => {
nwid: "network_id",
ipAssignmentPools: [{ ipRangeStart: "10.0.0.1", ipRangeEnd: "10.0.0.254" }],
routes: [{ target: "10.0.0.0/24" }],
duplicateRoutes: [],
multicastLimit: 32,
},
members: [
Expand Down Expand Up @@ -291,6 +294,7 @@ describe("NetworkById component", () => {
nwid: "network_id",
ipAssignmentPools: [{ ipRangeStart: "10.0.0.1", ipRangeEnd: "10.0.0.254" }],
routes: [{ target: "10.0.0.0/24" }],
duplicateRoutes: [],
multicastLimit: 32,
},
members: [
Expand Down Expand Up @@ -330,6 +334,7 @@ describe("NetworkById component", () => {
nwid: "network_id",
ipAssignmentPools: [{ ipRangeStart: "10.0.0.1", ipRangeEnd: "10.0.0.254" }],
routes: [{ target: "10.0.0.0/24" }],
duplicateRoutes: [],
multicastLimit: 32,
},
members: [
Expand Down
8 changes: 4 additions & 4 deletions src/components/adminPage/users/userInvitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const InvitationLink = () => {
});

const showInviationDetails = (invite: InvitationLinkType) => {
const expired = new Date(invite.expires) < new Date() || invite?.used;
const expired = new Date(invite.expiresAt) < new Date() || invite?.used;
callModal({
title: t("admin.users.authentication.generateInvitation.invitationModal.header"),
rootStyle: "text-left",
Expand Down Expand Up @@ -67,7 +67,7 @@ const InvitationLink = () => {
<span className="text-error">Expired</span>
) : (
<span>
Expires in <TimeAgo date={invite.expires} />
Expires in <TimeAgo date={invite.expiresAt} />
</span>
)}
</p>
Expand Down Expand Up @@ -134,7 +134,7 @@ const InvitationLink = () => {
</p>
<div className="flex flex-wrap gap-3">
{invitationData?.map((invite) => {
const expired = new Date(invite.expires) < new Date() || invite?.used;
const expired = new Date(invite.expiresAt) < new Date() || invite?.used;
return (
<div
key={invite.id}
Expand All @@ -154,7 +154,7 @@ const InvitationLink = () => {
{`${expired ? " Expired" : " Expires in"}`}
{!expired && (
<span className="pl-1">
<TimeAgo date={invite.expires} />
<TimeAgo date={invite.expiresAt} />
</span>
)}
</p>
Expand Down
Loading

0 comments on commit 90a003c

Please sign in to comment.