-
-
Save hugoabernier/e2796b71ac159479d202af32ec84b9ec to your computer and use it in GitHub Desktop.
Part V of Security Classification -- Localization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
import * as strings from "ClassificationExtensionApplicationCustomizerStrings"; | |
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} | |
> | |
{strings.ClassifactionMessage.replace("{0}",this.state.businessImpact)} | |
{handlingUrl && handlingUrl !== undefined ? | |
<Link | |
href={handlingUrl} | |
> {strings.HandlingMessage}</Link> | |
: null | |
} | |
</MessageBar> | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([], function() { | |
return { | |
"Title": "ClassificationExtensionApplicationCustomizer", | |
"ClassifactionMessage": "This site is classified as {0}. ", | |
"HandlingMessage": "Learn more about the proper handling procedures." | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare interface IClassificationExtensionApplicationCustomizerStrings { | |
Title: string; | |
ClassifactionMessage: string; | |
HandlingMessage: string; | |
} | |
declare module 'ClassificationExtensionApplicationCustomizerStrings' { | |
const strings: IClassificationExtensionApplicationCustomizerStrings; | |
export = strings; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment