Skip to content

Commit

Permalink
Merge pull request #251 from Peppermint-Lab/next
Browse files Browse the repository at this point in the history
0.4.6
  • Loading branch information
potts99 authored Mar 26, 2024
2 parents cbeac16 + b8c76f0 commit b49011b
Show file tree
Hide file tree
Showing 18 changed files with 2,972 additions and 86 deletions.
76 changes: 74 additions & 2 deletions apps/api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,70 @@ export function authRoutes(fastify: FastifyInstance) {
}
);

// Register a new external user
fastify.post(
"/api/v1/auth/user/register/external",
{
schema: {
body: {
type: "object",
properties: {
email: { type: "string" },
password: { type: "string" },
name: { type: "string" },
language: { type: "string" },
},
required: ["email", "password", "name"],
},
},
},
async (request: FastifyRequest, reply: FastifyReply) => {
// const bearer = request.headers.authorization!.split(" ")[1];

let { email, password, name, language } = request.body as {
email: string;
password: string;
name: string;
language: string;
};

// Checks if email already exists
let record = await prisma.user.findUnique({
where: { email },
});

// if exists, return 400
if (record) {
reply.code(400).send({
message: "Email already exists",
});
}

const user = await prisma.user.create({
data: {
email,
password: await bcrypt.hash(password, 10),
name,
isAdmin: false,
language,
external_user: true,
firstLogin: false,
},
});

const hog = track();

hog.capture({
event: "user_registered",
distinctId: user.id,
});

reply.send({
success: true,
});
}
);

// Forgot password & generate code
fastify.post(
"/api/v1/auth/password-reset",
Expand Down Expand Up @@ -250,6 +314,7 @@ export function authRoutes(fastify: FastifyInstance) {
ticket_comments: user!.notify_ticket_comments,
ticket_assigned: user!.notify_ticket_assigned,
firstLogin: user!.firstLogin,
external_user: user!.external_user,
};

reply.send({
Expand Down Expand Up @@ -278,6 +343,14 @@ export function authRoutes(fastify: FastifyInstance) {
});
}

if (user?.external_user) {
reply.send({
success: true,
message: "External user",
oauth: false,
});
}

const authtype = await prisma.config.findMany({
where: {
sso_active: true,
Expand All @@ -287,8 +360,6 @@ export function authRoutes(fastify: FastifyInstance) {
const provider = await prisma.provider.findMany();
const oauth = provider[0];

console.log(authtype);

if (authtype.length === 0) {
reply.code(200).send({
success: true,
Expand Down Expand Up @@ -456,6 +527,7 @@ export function authRoutes(fastify: FastifyInstance) {
sso_status: config!.sso_active,
version: config!.client_version,
notifcations,
external_user: user!.external_user,
};

reply.send({
Expand Down
102 changes: 102 additions & 0 deletions apps/api/src/controllers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,4 +724,106 @@ export function ticketRoutes(fastify: FastifyInstance) {
}
}
);

// Get all open tickets for an external user
fastify.get(
"/api/v1/tickets/user/open/external",

async (request: FastifyRequest, reply: FastifyReply) => {
const bearer = request.headers.authorization!.split(" ")[1];
const token = checkToken(bearer);

if (token) {
const user = await checkSession(bearer);

const tickets = await prisma.ticket.findMany({
where: { isComplete: false, email: user!.email, hidden: false },
include: {
client: {
select: { id: true, name: true, number: true },
},
assignedTo: {
select: { id: true, name: true },
},
team: {
select: { id: true, name: true },
},
},
});

reply.send({
tickets: tickets,
sucess: true,
});
}
}
);

// Get all closed tickets for an external user
fastify.get(
"/api/v1/tickets/user/closed/external",

async (request: FastifyRequest, reply: FastifyReply) => {
const bearer = request.headers.authorization!.split(" ")[1];
const token = checkToken(bearer);

if (token) {
const user = await checkSession(bearer);

const tickets = await prisma.ticket.findMany({
where: { isComplete: true, email: user!.email, hidden: false },
include: {
client: {
select: { id: true, name: true, number: true },
},
assignedTo: {
select: { id: true, name: true },
},
team: {
select: { id: true, name: true },
},
},
});

reply.send({
tickets: tickets,
sucess: true,
});
}
}
);

// Get all tickets for an external user
fastify.get(
"/api/v1/tickets/user/external",

async (request: FastifyRequest, reply: FastifyReply) => {
const bearer = request.headers.authorization!.split(" ")[1];
const token = checkToken(bearer);

if (token) {
const user = await checkSession(bearer);

const tickets = await prisma.ticket.findMany({
where: { email: user!.email, hidden: false },
include: {
client: {
select: { id: true, name: true, number: true },
},
assignedTo: {
select: { id: true, name: true },
},
team: {
select: { id: true, name: true },
},
},
});

reply.send({
tickets: tickets,
sucess: true,
});
}
}
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "external_user" BOOLEAN NOT NULL DEFAULT false;
1 change: 1 addition & 0 deletions apps/api/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ model User {
notify_ticket_comments Boolean @default(true)
notify_ticket_assigned Boolean @default(true)
firstLogin Boolean @default(true)
external_user Boolean @default(false)
todos Todos[]
tickets Ticket[]
Expand Down
51 changes: 27 additions & 24 deletions apps/client/layouts/newLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ export default function NewLayout({ children }: any) {
alert("You do not have the correct perms for that action.");
}

if (user && user.external_user) {
location.push("/portal");
}

const navigation = [
{
name: t("create_ticket"),
Expand Down Expand Up @@ -437,14 +441,6 @@ export default function NewLayout({ children }: any) {
await fetchUserProfile();
}

// useEffect(() => {
// getQueues();
// }, [user]);

// useEffect(() => {
// getQueues();
// }, [user])

function handleKeyPress(event: any) {
const pathname = location.pathname;
console.log(pathname);
Expand Down Expand Up @@ -493,7 +489,8 @@ export default function NewLayout({ children }: any) {
}, [handleKeyPress, location]);

return (
!loading && (
!loading &&
user && (
<div className="min-h-screen overflow-hidden bg-white dark:bg-[#0A090C]">
<Transition.Root show={sidebarOpen} as={Fragment}>
<Dialog
Expand Down Expand Up @@ -966,11 +963,13 @@ export default function NewLayout({ children }: any) {

<div className="flex flex-1 gap-x-4 self-stretch lg:gap-x-6 items-center">
<div className="flex w-full justify-start items-center space-x-6">
<Link href="https://github.com/Peppermint-Lab/peppermint/releases">
<span className="inline-flex items-center rounded-md bg-green-700/10 px-3 py-2 text-xs font-medium text-green-600 ring-1 ring-inset ring-green-500/20">
Version 0.4.5
</span>
</Link>
{user.isAdmin && (
<Link href="https://github.com/Peppermint-Lab/peppermint/releases">
<span className="inline-flex items-center rounded-md bg-green-700/10 px-3 py-2 text-xs font-medium text-green-600 ring-1 ring-inset ring-green-500/20">
Version 0.4.5
</span>
</Link>
)}

<CommandModal />
</div>
Expand Down Expand Up @@ -1067,15 +1066,17 @@ export default function NewLayout({ children }: any) {
</Popover.Panel>
</Popover>

<Link
href="https://github.com/Peppermint-Lab/peppermint/discussions"
target="_blank"
className="hover:cursor-pointer"
>
<Button variant="outline" className="hover:cursor-pointer">
Send Feedback
</Button>
</Link>
{user.isAdmin && (
<Link
href="https://github.com/Peppermint-Lab/peppermint/discussions"
target="_blank"
className="hover:cursor-pointer"
>
<Button variant="outline" className="hover:cursor-pointer">
Send Feedback
</Button>
</Link>
)}

{/* Profile dropdown */}
<Menu as="div" className="relative">
Expand Down Expand Up @@ -1132,7 +1133,9 @@ export default function NewLayout({ children }: any) {
</div>
</div>

<main className="bg-white dark:bg-[#0A090C]">{children}</main>
{!loading && !user.external_user && (
<main className="bg-white dark:bg-[#0A090C]">{children}</main>
)}
</div>
</div>
)
Expand Down
Loading

0 comments on commit b49011b

Please sign in to comment.