Skip to content

Commit

Permalink
feat: enable contact details to be set through configuration
Browse files Browse the repository at this point in the history
Fixes #23 Fixes #49
  • Loading branch information
Tethik committed Nov 2, 2023
1 parent 7c729e4 commit 4516e98
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 11 deletions.
2 changes: 2 additions & 0 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { initSentry } from "./util/sentry.js";
import { retryReviewApproval } from "./resources/gram/v1/admin/retryReviewApproval.js";
import { config } from "@gram/core/dist/config/index.js";
import cookieParser from "cookie-parser";
import { getContact } from "./resources/gram/v1/contact/get.js";

export async function createApp(dal: DataAccessLayer) {
// Start constructing the app.
Expand Down Expand Up @@ -73,6 +74,7 @@ export async function createApp(dal: DataAccessLayer) {
const unauthenticatedRoutes = express.Router();
unauthenticatedRoutes.get("/banners", errorWrap(getBanner(dal)));
unauthenticatedRoutes.get("/menu", errorWrap(getMenu));
unauthenticatedRoutes.get("/contact", errorWrap(getContact));

const tokenRoutes = tokenV1(dal);
unauthenticatedRoutes.get("/auth/token", errorWrap(tokenRoutes.get));
Expand Down
6 changes: 6 additions & 0 deletions api/src/resources/gram/v1/contact/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Request, Response } from "express";
import { config } from "@gram/core/dist/config/index.js";

export const getContact = async (req: Request, res: Response) => {
res.json({ contact: config.contact });
};
12 changes: 12 additions & 0 deletions app/src/api/gram/contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { api } from "./api";

const contactApi = api.injectEndpoints({
endpoints: (build) => ({
getContact: build.query({
query: () => `/contact`,
transformResponse: (response) => response.contact,
}),
}),
});

export const { useGetContactQuery } = contactApi;
42 changes: 42 additions & 0 deletions app/src/components/elements/ContactChip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Chip, IconButton } from "@mui/material";
import EmailIcon from "@mui/icons-material/Email";
import ChatIcon from "@mui/icons-material/Chat";
import { useGetContactQuery } from "../../api/gram/contact";

export function ContactChip(props) {
const { data: contact } = useGetContactQuery();

return (
<Chip
variant="outlined"
label={contact?.name || "Your Gram Admins"}
icon={
<>
{contact?.slackUrl && (
<IconButton
href={contact?.slackUrl}
target="_blank"
rel="noreferrer"
color="inherit"
size="small"
>
<ChatIcon />
</IconButton>
)}
{contact?.mail && (
<IconButton
href={`mailto:${contact?.mail}`}
target="_blank"
rel="noreferrer"
color="inherit"
size="small"
>
<EmailIcon />
</IconButton>
)}
</>
}
{...props}
/>
);
}
17 changes: 6 additions & 11 deletions app/src/components/model/tutorial/Tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ import suggestions from "./img/suggestions.gif";
import indicatorUnknownImg from "./img/unknown.svg";
import indicatorVulnerableImg from "./img/vulnerable.svg";
import actionItemImg from "./img/actionItem.gif";
import { ContactChip } from "../../elements/ContactChip";

const Introduction = () => (
<>
<Typography>
This tutorial will show you how to use the diagramming interface of Gram.
{/* //TODO replace contact blurb */}
If you have any questions or feedback, feel free to reach out to us in{" "}
<Link target="_none" to="">
#team-ea-secure-development
</Link>{" "}
on slack.
</Typography>
<Typography>
If you have any questions or feedback, feel free to reach out to{" "}
<ContactChip />
</Typography>
</>
);
Expand Down Expand Up @@ -468,12 +467,8 @@ const FinalWindow = () => (
<Typography>
This concludes the basic tutorial. We hope it was useful!
</Typography>
{/* //TODO replace contact blurb */}
<Typography>
If you have questions, feel free to reach out us in{" "}
<Link target="_none" to="">
#team-ea-secure-development
</Link>
If you have questions, feel free to reach out to <ContactChip />
</Typography>
</>
);
Expand Down
6 changes: 6 additions & 0 deletions config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ export const defaultConfig: GramConfiguration = {
},
],

contact: {
name: "Security Team",
email: undefined,
slackUrl: undefined,
},

additionalMigrations: [MagicLinkMigrations],

bootstrapProviders: async function (
Expand Down
10 changes: 10 additions & 0 deletions core/src/config/GramConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ export interface GramConfiguration {
};
};

/**
* Optional contact details to the team or person managing this Gram installation.
* See it as the support email for your security team in your org.
*/
contact?: {
name: string;
email?: string;
slackUrl?: string;
};

/**
* Used for CSP policy.
*/
Expand Down

0 comments on commit 4516e98

Please sign in to comment.