Skip to content

Commit

Permalink
Merge pull request KelvinTegelaar#3427 from JohnDuprey/dev
Browse files Browse the repository at this point in the history
bugfixes and improvements
  • Loading branch information
JohnDuprey authored Jan 22, 2025
2 parents 455f49d + 808ab17 commit 2a8c87f
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 41 deletions.
175 changes: 136 additions & 39 deletions src/components/CippCards/CippDomainCards.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
Typography,
Chip,
Stack,
Divider,
FormControlLabel,
} from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import ClearIcon from "@mui/icons-material/Clear";
Expand All @@ -19,7 +21,7 @@ import ErrorIcon from "@mui/icons-material/Error";
import WarningIcon from "@mui/icons-material/Warning";
import HelpIcon from "@mui/icons-material/Help";
import MoreVertIcon from "@mui/icons-material/MoreVert";
import { Controller, get, useForm } from "react-hook-form";
import { Controller, useForm } from "react-hook-form";
import { ApiGetCall } from "/src/api/ApiCall";
import CippButtonCard from "/src/components/CippCards/CippButtonCard";
import { CippCodeBlock } from "/src/components/CippComponents/CippCodeBlock";
Expand Down Expand Up @@ -268,6 +270,60 @@ function DomainResultCard({ title, data, isFetching, info, type }) {
</>
),
}
: type === "HTTPS"
? {
children: (
<>
{data?.Tests?.map((test, index) => (
<>
<CippPropertyListCard
key={index}
title={`Certificate info for ${test.Hostname}`}
copyItems={true}
showDivider={false}
propertyItems={[
{
label: "Issuer",
value:
test.Certificate.Issuer.match(/O=([^,]+)/)?.[1] ||
test.Certificate.Issuer,
},
{
label: "Subject",
value:
test.Certificate.Subject.match(/CN=([^,]+)/)?.[1] ||
test.Certificate.Subject,
},
{
label: "Created",
value: getCippFormatting(test.Certificate.NotBefore, "NotBefore"),
},
{
label: "Expires",
value: getCippFormatting(test.Certificate.NotAfter, "NotAfter"),
},
{ label: "Serial Number", value: test.Certificate.SerialNumber },
{ label: "Thumbprint", value: test.Certificate.Thumbprint },
{
label: "DNS Names",
value: getCippFormatting(
test.Certificate.DnsNameList.map((dns) => dns.Unicode),
"DNSName"
),
},
]}
/>
<ResultList
passes={test.ValidationPasses}
warns={test.ValidationWarns}
fails={test.ValidationFails}
/>
<Divider />
</>
))}
</>
),
}
: {};

return (
Expand Down Expand Up @@ -326,6 +382,9 @@ export const CippDomainCards = ({ domain: propDomain = "", fullwidth = false })
});
const [optionsVisible, setOptionsVisible] = useState(false);
const [domain, setDomain] = useState(propDomain);
const [selector, setSelector] = useState("");
const [spfRecord, setSpfRecord] = useState("");
const [subdomains, setSubdomains] = useState("");
const enableHttps = watch("enableHttps");

useEffect(() => {
Expand All @@ -337,13 +396,20 @@ export const CippDomainCards = ({ domain: propDomain = "", fullwidth = false })

const onSubmit = (values) => {
setDomain(values.domain);
setSelector(values.dkimSelector);
setSpfRecord(values.spfRecord);
setSubdomains(values.subdomains);
};

const handleClear = () => {
setValue("domain", "");
setValue("spfRecord", "");
setValue("dkimSelector", "");
setValue("subdomains", "");
setDomain("");
setSelector("");
setSpfRecord("");
setSubdomains("");
};

// API calls with dynamic queryKey using domain
Expand All @@ -370,8 +436,8 @@ export const CippDomainCards = ({ domain: propDomain = "", fullwidth = false })

const { data: spfData, isFetching: spfLoading } = ApiGetCall({
url: "/api/ListDomainHealth",
queryKey: `spf-${domain}`,
data: { Domain: domain, Action: "ReadSPFRecord" },
queryKey: `spf-${domain}-${spfRecord}`,
data: { Domain: domain, Action: "ReadSPFRecord", Record: spfRecord },
waiting: !!domain,
});

Expand All @@ -384,8 +450,8 @@ export const CippDomainCards = ({ domain: propDomain = "", fullwidth = false })

const { data: dkimData, isFetching: dkimLoading } = ApiGetCall({
url: "/api/ListDomainHealth",
queryKey: `dkim-${domain}`,
data: { Domain: domain, Action: "ReadDkimRecord" },
queryKey: `dkim-${domain}-${selector}`,
data: { Domain: domain, Action: "ReadDkimRecord", Selector: selector },
waiting: !!domain,
});

Expand All @@ -403,6 +469,13 @@ export const CippDomainCards = ({ domain: propDomain = "", fullwidth = false })
waiting: !!domain,
});

const { data: httpsData, isFetching: httpsLoading } = ApiGetCall({
url: "/api/ListDomainHealth",
queryKey: `https-${domain}-${subdomains}`,
data: { Domain: domain, Action: "TestHttpsCertificate", Subdomains: subdomains },
waiting: !!domain && enableHttps,
});

// Adjust grid item size based on fullwidth prop
const gridItemSize = fullwidth ? 12 : 4;

Expand Down Expand Up @@ -438,45 +511,50 @@ export const CippDomainCards = ({ domain: propDomain = "", fullwidth = false })
</Grid>
</Grid>
<Collapse in={optionsVisible}>
<Controller
name="spfRecord"
control={control}
render={({ field }) => (
<TextField {...field} fullWidth label="SPF Record" className="mt-2" />
)}
/>
<Controller
name="dkimSelector"
control={control}
render={({ field }) => (
<TextField {...field} fullWidth label="DKIM Selector" className="mt-2" />
)}
/>
<Controller
name="enableHttps"
control={control}
render={({ field }) => (
<Switch {...field} checked={field.value} label="Enable HTTPS check" />
)}
/>
{enableHttps && (
<Stack direction="column" spacing={1} sx={{ mt: 1 }}>
<Controller
name="subdomains"
name="spfRecord"
control={control}
render={({ field }) => (
<TextField {...field} fullWidth label="HTTPS Subdomains" className="mt-2" />
<TextField {...field} fullWidth label="SPF Record" className="mt-2" />
)}
/>
)}
<Button
variant="outlined"
color="error"
startIcon={<ClearIcon />}
onClick={handleClear}
className="mt-2"
>
Clear
</Button>
<Controller
name="dkimSelector"
control={control}
render={({ field }) => (
<TextField {...field} fullWidth label="DKIM Selector" className="mt-2" />
)}
/>
<Controller
name="enableHttps"
control={control}
render={({ field }) => (
<FormControlLabel
control={<Switch {...field} checked={field.value} />}
label="Enable HTTPS check"
/>
)}
/>
{enableHttps && (
<Controller
name="subdomains"
control={control}
render={({ field }) => (
<TextField {...field} fullWidth label="HTTPS Subdomains" className="mt-2" />
)}
/>
)}
<Button
variant="outlined"
color="error"
startIcon={<ClearIcon />}
onClick={handleClear}
className="mt-2"
>
Clear
</Button>
</Stack>
</Collapse>
</CippButtonCard>
</Grid>
Expand Down Expand Up @@ -605,6 +683,25 @@ export const CippDomainCards = ({ domain: propDomain = "", fullwidth = false })
}
/>
</Grid>
{enableHttps && (
<Grid item xs={12} md={gridItemSize}>
<DomainResultCard
title="HTTPS Certificate"
type="HTTPS"
data={httpsData}
isFetching={httpsLoading}
info={
<div>
<ResultList
passes={httpsData?.ValidationPasses}
warns={httpsData?.ValidationWarns}
fails={httpsData?.ValidationFails}
/>
</div>
}
/>
</Grid>
)}
</>
)}
</Grid>
Expand Down
9 changes: 8 additions & 1 deletion src/components/CippCards/CippPropertyListCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export const CippPropertyListCard = (props) => {
};

const setPadding = isLabelPresent ? { py: 0.5, px: 3 } : { py: 1.5, px: 3 };
const handleActionDisabled = (row, action) => {
if (action?.condition) {
return !action.condition(row);
}
return false;
};

return (
<>
Expand Down Expand Up @@ -133,7 +139,7 @@ export const CippPropertyListCard = (props) => {
{actionItems?.length > 0 &&
actionItems.map((item, index) => (
<ActionListItem
key={`${item.label}-index-ActionList-OffCanvas`}
key={`${item.label}-${index}-ActionList-OffCanvas`}
icon={<SvgIcon fontSize="small">{item.icon}</SvgIcon>}
label={item.label}
onClick={
Expand All @@ -148,6 +154,7 @@ export const CippPropertyListCard = (props) => {
createDialog.handleOpen();
}
}
disabled={handleActionDisabled(data, item)}
/>
))}
</ActionList>
Expand Down
9 changes: 8 additions & 1 deletion src/components/CippTable/CippDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ export const CippDataTable = (props) => {
const memoizedColumns = useMemo(() => usedColumns, [usedColumns]);
const memoizedData = useMemo(() => usedData, [usedData]);

const handleActionDisabled = (row, action) => {
if (action?.condition) {
return !action.condition(row);
}
return false;
};

const table = useMaterialReactTable({
mrtTheme: (theme) => ({
baseBackgroundColor: theme.palette.background.paper,
Expand All @@ -173,7 +180,6 @@ export const CippDataTable = (props) => {
) : undefined,
onColumnVisibilityChange: setColumnVisibility,
...modeInfo,

renderRowActionMenuItems: actions
? ({ closeMenu, row }) => [
actions.map((action, index) => (
Expand All @@ -195,6 +201,7 @@ export const CippDataTable = (props) => {
closeMenu();
}
}}
disabled={handleActionDisabled(row.original, action)}
>
<SvgIcon fontSize="small" sx={{ minWidth: "30px" }}>
{action.icon}
Expand Down
14 changes: 14 additions & 0 deletions src/pages/email/administration/mailboxes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Layout as DashboardLayout } from "/src/layouts/index.js";
import { CippTablePage } from "/src/components/CippComponents/CippTablePage.jsx";
import Link from "next/link";
import { Button } from "@mui/material";
import { Row } from "jspdf-autotable";

const Page = () => {
const pageTitle = "Mailboxes";
Expand Down Expand Up @@ -35,6 +36,18 @@ const Page = () => {
ID: "UPN",
},
confirmText: "Are you sure you want to convert this mailbox to a shared mailbox?",
condition: (row) => row.recipientTypeDetails !== "SharedMailbox",
},
{
label: "Convert to User Mailbox",
type: "GET",
url: "/api/ExecConvertToSharedMailbox",
data: {
ID: "UPN",
ConvertToUser: true,
},
confirmText: "Are you sure you want to convert this mailbox to a user mailbox?",
condition: (row) => row.recipientTypeDetails !== "UserMailbox",
},
{
label: "Convert to Room Mailbox",
Expand All @@ -44,6 +57,7 @@ const Page = () => {
ID: "UPN",
},
confirmText: "Are you sure you want to convert this mailbox to a room mailbox?",
condition: (row) => row.recipientTypeDetails !== "RoomMailbox",
},
{
label: "Hide from Global Address List",
Expand Down
2 changes: 2 additions & 0 deletions src/utils/get-cipp-formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export const getCippFormatting = (data, cellName, type, canReceive) => {
"purchaseDate",
"NextOccurrence",
"LastOccurrence",
"NotBefore",
"NotAfter",
];

const matchDateTime = /[dD]ate[tT]ime/;
Expand Down

0 comments on commit 2a8c87f

Please sign in to comment.