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

#2796-Added Guest View Tab to Admin Tools #2835

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- AlterTable
ALTER TABLE "Organization" ADD COLUMN "logoImage" TEXT;

-- AlterTable
ALTER TABLE "Project" ADD COLUMN "organizationId" TEXT;

-- AddForeignKey
ALTER TABLE "Project" ADD CONSTRAINT "Project_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("organizationId") ON DELETE SET NULL ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:

- You are about to drop the column `logoImage` on the `Organization` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "Organization" DROP COLUMN "logoImage",
ADD COLUMN "logoImageId" TEXT;
46 changes: 25 additions & 21 deletions src/backend/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,18 @@ model WBS_Element {
}

model Project {
projectId String @id @default(uuid())
wbsElementId String @unique
wbsElement WBS_Element @relation(fields: [wbsElementId], references: [wbsElementId])
budget Int @default(0)
summary String
workPackages Work_Package[]
carId String
car Car @relation(fields: [carId], references: [carId])
teams Team[] @relation(name: "assignedBy")
favoritedBy User[] @relation(name: "favoritedBy")
projectId String @id @default(uuid())
wbsElementId String @unique
wbsElement WBS_Element @relation(fields: [wbsElementId], references: [wbsElementId])
budget Int @default(0)
summary String
workPackages Work_Package[]
carId String
car Car @relation(fields: [carId], references: [carId])
teams Team[] @relation(name: "assignedBy")
favoritedBy User[] @relation(name: "favoritedBy")
organizationId String?
organization Organization? @relation(fields: [organizationId], references: [organizationId])
}

model Work_Package {
Expand Down Expand Up @@ -872,6 +874,7 @@ model Organization {
description String
applyInterestImageId String? @unique
exploreAsGuestImageId String? @unique
logoImageId String?

// Relation references
wbsElements WBS_Element[]
Expand All @@ -893,20 +896,21 @@ model Organization {
usefulLinks Link[]
FrequentlyAskedQuestions FrequentlyAskedQuestion[]
Milestone Milestone[]
featuredProjects Project[]
}

model FrequentlyAskedQuestion {
faqId String @id @default(uuid())
question String
answer String
userCreated User @relation(fields: [userCreatedId], references: [userId], name: "frequentlyAskedQuestionCreator")
userCreatedId String
userDeleted User? @relation(fields: [userDeletedId], references: [userId], name: "frequentlyAskedQuestionDeleter")
userDeletedId String?
dateCreated DateTime @default(now())
dateDeleted DateTime?
organizationId String
organization Organization @relation(fields: [organizationId], references: [organizationId])
faqId String @id @default(uuid())
question String
answer String
userCreated User @relation(fields: [userCreatedId], references: [userId], name: "frequentlyAskedQuestionCreator")
userCreatedId String
userDeleted User? @relation(fields: [userDeletedId], references: [userId], name: "frequentlyAskedQuestionDeleter")
userDeletedId String?
dateCreated DateTime @default(now())
dateDeleted DateTime?
organizationId String
organization Organization @relation(fields: [organizationId], references: [organizationId])
}

model Milestone {
Expand Down
24 changes: 23 additions & 1 deletion src/backend/src/utils/teams.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Prisma, User, Team } from '@prisma/client';
import { Prisma, User, Team, Project } from '@prisma/client';
import prisma from '../prisma/prisma';
import { UserWithSettings } from './auth.utils';
import { NotFoundException } from './errors.utils';

const teamQueryArgsMembersOnly = Prisma.validator<Prisma.TeamArgs>()({
include: {
Expand Down Expand Up @@ -88,3 +90,23 @@ export const removeUsersFromList = (currentUsers: UserWithId[], usersToRemove: U
const userIdsToRemove = usersToRemove.map((user) => user.userId);
return currentUsers.filter((user) => !userIdsToRemove.includes(user.userId));
};

/**
* Given a team id, produces all of the projects assigned to that team
* @param teamId the id of the team
* @returns array of projects currently assigned to the given team (errors if no team is found)
*/
export const getTeamProjects = async (teamId: string): Promise<Project[]> => {
const team = await prisma.team.findUnique({
where: {
teamId
},
include: {
projects: true
}
});
if (!team) {
throw new NotFoundException('Team', teamId);
}
return team.projects;
};
3 changes: 3 additions & 0 deletions src/frontend/src/pages/AdminToolsPage/AdminToolsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const AdminToolsPage: React.FC = () => {
}
if (isUserAdmin) {
tabs.push({ tabUrlValue: 'recruitment', tabName: 'Recruitment' });
tabs.push({ tabUrlValue: 'guest-view', tabName: 'Guest View' });
tabs.push({ tabUrlValue: 'miscellaneous', tabName: 'Miscellaneous' });
}

Expand Down Expand Up @@ -91,6 +92,8 @@ const AdminToolsPage: React.FC = () => {
<AdminToolsFinanceConfig />
) : tabIndex === 3 ? (
<AdminToolsRecruitmentConfig />
) : tabIndex === 4 ? (
<Box></Box>
) : (
<Box>
<Box pb={2}>
Expand Down
Loading