Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Part V of Security Classification - Real Hyperlink
import * as React from "react";
import {
IClassificationHeaderProps,
IClassificationHeaderState,
DefaultClassification,
DefaultHandlingUrl
} from "./ClassificationHeader.types";
import { MessageBar, MessageBarType } from "office-ui-fabric-react/lib/MessageBar";
import { Link } from "office-ui-fabric-react/lib/Link";
import { Web } from "sp-pnp-js/lib/pnp";
import { ClassificationPropertyBag } from "../../../../lib/extensions/classificationExtension/components/ClassificationHeader.types";
export default class ClassificationHeader extends React.Component<IClassificationHeaderProps, IClassificationHeaderState> {
constructor(props: IClassificationHeaderProps) {
super(props);
this.state = {
isLoading: true,
businessImpact: null
};
}
public componentDidMount(): void {
this.setState({
isLoading: true,
businessImpact: null
});
const web: Web = new Web(this.props.context.pageContext.web.absoluteUrl);
web.select("Title", "AllProperties")
.expand("AllProperties")
.get()
.then(r => {
var businessImpact: string = DefaultClassification;
// handle the default situation where there is no classification
if (r.AllProperties && r.AllProperties[ClassificationPropertyBag]) {
businessImpact = r.AllProperties[ClassificationPropertyBag];
}
this.setState({
isLoading: false,
businessImpact: businessImpact
});
console.log("All properties results", r);
});
}
public render(): React.ReactElement<IClassificationHeaderProps> {
// get the business impact from the state
let { businessImpact } = this.state;
// ge the default handling URL
let handlingUrl: string = DefaultHandlingUrl;
// change this switch statement to suit your security classification
var barType: MessageBarType;
switch (businessImpact) {
case "MBI":
// if you'd like to display a different URL per classification, override the handlingUrl variable here
// handlingUrl = "/SitePages/Handling-instructions-MBI.aspx"
barType = MessageBarType.warning;
break;
case "HBI":
barType = MessageBarType.severeWarning;
break;
case "LBI":
barType = MessageBarType.info;
break;
default:
barType = undefined;
}
// if no security classification, do not display a header
if (barType === undefined) {
return null;
}
return (
<MessageBar
messageBarType={barType}
>
This site is classified as {this.state.businessImpact}.
{handlingUrl && handlingUrl !== undefined ?
<Link
href={handlingUrl}
> Learn more about the proper handling procedures.</Link>
: null
}
</MessageBar>
);
}
}
import { ExtensionContext } from "@microsoft/sp-extension-base";
export interface IClassificationHeaderProps {
context: ExtensionContext;
}
export interface IClassificationHeaderState {
isLoading: boolean;
businessImpact: string;
}
// change this value to whatever you want to use as the property bag value name
export const ClassificationPropertyBag: string = "sc_x005f_BusinessImpact";
// change this value to whatever you want the default classification you wish to use. "undefined" means no default.
export const DefaultClassification: string = undefined;
export const DefaultHandlingUrl: string = "/SitePages/Handling-instructions.aspx";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.