Skip to content

Commit

Permalink
Feilhåndtering for Planner-konfigurasjon dersom bruker ikke er både e…
Browse files Browse the repository at this point in the history
…ier og medlem #1593 (#1595)
  • Loading branch information
olemp authored Jan 14, 2025
1 parent 134e1d1 commit 556e8da
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 49 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Sjekk ut [release notes](./releasenotes/1.10.0.md) for høydepunkter og mer deta
### Forbedringer

- Forbedret feilhåndtering for redigeringspanel for statusrapport [#1578](https://github.com/Puzzlepart/prosjektportalen365/issues/1578)
- Forbedret feilhåndtering for provisjonering av Planner-oppgaver [#1593](https://github.com/Puzzlepart/prosjektportalen365/issues/1593)

## 1.10.1 - TBA

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import { useTemplateConfigMessage } from './useTemplateConfigMessage'
import { UserMessage } from 'pp365-shared-library'

export const TemplateConfigMessage: FC<ITemplateConfigMessageProps> = (props) => {
const { hidden, message } = useTemplateConfigMessage(props)

const messages = useTemplateConfigMessage(props)
return (
<div className={styles.root} hidden={hidden}>
<UserMessage text={message} />
<div className={styles.root}>
{messages.map((message, index) => (
<div key={index} hidden={message.hidden}>
<UserMessage
key={index}
text={message.text}
intent={message.intent} />
</div>
))}
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './TemplateConfigMessage'
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { format } from '@fluentui/react'
import { IUserMessageProps } from 'pp365-shared-library'
import strings from 'ProjectExtensionsStrings'
import { isEmpty } from 'underscore'
import { ProjectSetupValidation } from '../../../projectSetup/types'
import { useProjectSetupDialogContext } from '../context'
import { ITemplateConfigMessageProps } from './types'

/**
* Component logic hook for `TemplateConfigMessage`
*
* @returns `hidden` and `text`
*/
export function useTemplateConfigMessage({ section }: ITemplateConfigMessageProps) {
const context = useProjectSetupDialogContext()
const templateHasExtensions = !isEmpty(context.state.selectedTemplate?.extensions)
const templateHasContentConfig = !isEmpty(context.state.selectedTemplate?.contentConfig)

const messages: IUserMessageProps[] = [
{
text: strings.PlannerMemberWarningMessage,
intent: 'warning',
hidden: context.props.validation !== ProjectSetupValidation.UserNotGroupMember
},
{
text: format(
strings.TemplateConfigMessage,
context.state.selectedTemplate?.text,
[
templateHasExtensions && strings.ExtensionsSectionHeaderText,
templateHasContentConfig && strings.ContentConfigSectionHeaderText
]
.filter(Boolean)
.join(' og ')
.toLowerCase()
),
hidden: !(
(section === 'ExtensionsSection' && templateHasExtensions) ||
(section === 'ContentConfigSection' && templateHasContentConfig) ||
(section === 'TemplateSelector' && (templateHasExtensions || templateHasContentConfig))
)
}
]

return messages
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContentConfig, ProjectExtension, ProjectTemplate } from 'pp365-shared-library'
import { IProjectSetupData } from 'projectSetup/types'
import { IProjectSetupData, ProjectSetupValidation } from 'projectSetup/types'
import { FC, HTMLProps } from 'react'
import { IBaseDialogProps } from '../@BaseDialog/types'

Expand All @@ -23,6 +23,11 @@ export interface IProjectSetupDialogProps extends IBaseDialogProps {
* Tasks to execute
*/
tasks?: string[]

/**
* Validation for the project setup
*/
validation?: ProjectSetupValidation
}

export interface IProjectSetupDialogState {
Expand Down
1 change: 1 addition & 0 deletions SharePointFramework/ProjectExtensions/src/loc/_/en-us.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ define([], function () {
SummaryMessage: '{0} document(s) were copied to the project.',
SyncLocalProjectPropertiesListText: 'Synchronizing list for project properties',
TemplateConfigMessage: 'The selected project template **{0}** contains configuration for {1}. These are selected by default.',
PlannerMemberWarningMessage: 'You must be a member of the Microsoft 365 group to configure Planner. Please add yourself as a member or ask an administrator and try again.',
TemplateLibrarySelectModalTitle: 'Hent dokumentmal',
TemplateSelectDialogInfoText: 'Setting up the project takes about 10 minutes. Do not close the browser window while the site is being set up. It is not recommended to set up several sites at the same time.',
TemplateSelectDialogSubmitButtonText: 'Set up the site',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ declare interface IProjectExtensionsStrings {
SummaryMessage: string
SyncLocalProjectPropertiesListText: string
TemplateConfigMessage: string
PlannerMemberWarningMessage: string
TemplateLibrarySelectModalTitle: string
TemplateSelectDialogInfoText: string
TemplateSelectDialogSubmitButtonText: string
Expand Down
1 change: 1 addition & 0 deletions SharePointFramework/ProjectExtensions/src/loc/nb-no.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ define([], function () {
SummaryMessage: '{0} dokument(er) ble kopiert til prosjektområdet.',
SyncLocalProjectPropertiesListText: 'Synkroniserer liste for prosjektegenskaper',
TemplateConfigMessage: 'Den valgte prosjektmalen **{0}** inneholder konfigurasjon for {1}. Disse er valgt som standard.',
PlannerMemberWarningMessage: 'Du må være medlem av Microsoft 365 gruppa for å kunne konfigurere Planner. Vennligst legg deg selv til som medlem eller spør en administrator og prøv deretter igjen.',
TemplateLibrarySelectModalTitle: 'Hent dokumentmal',
TemplateSelectDialogInfoText: 'Oppsettet av prosjektområdet tar omtrent 10 minutter. Ikke lukk nettleservinduet mens området settes opp. Det anbefales ikke å sette opp flere områder samtidig.',
TemplateSelectDialogSubmitButtonText: 'Sett opp området',
Expand Down
24 changes: 14 additions & 10 deletions SharePointFramework/ProjectExtensions/src/projectSetup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IMenuNode } from '@pnp/sp/navigation'
import { format, getId } from '@uifabric/utilities'
import * as strings from 'ProjectExtensionsStrings'
import { SPDataAdapter } from 'data'
import { default as MSGraphHelper } from 'msgraph-helper'
import msgraph from 'msgraph-helper'
import {
ContentConfig,
ListLogger,
Expand Down Expand Up @@ -50,14 +50,15 @@ export default class ProjectSetup extends BaseApplicationCustomizer<IProjectSetu
ProgressDialog: getId('progressdialog'),
TemplateSelectDialog: getId('templateselectdialog')
}
private _validation: ProjectSetupValidation

@override
public async onInit(): Promise<void> {
this.sp = createSpfiInstance(this.context)

await msgraph.Init(this.context.msGraphClientFactory)
try {
this._isSetup = await this._isProjectSetup()

this._validation = await this._validateProjectSetup()
// eslint-disable-next-line default-case
switch (this._validation) {
case ProjectSetupValidation.NotSiteAdmin: {
Expand Down Expand Up @@ -166,7 +167,7 @@ export default class ProjectSetup extends BaseApplicationCustomizer<IProjectSetu
await this._startSetup(taskParams, data)

if (!stringIsNullOrEmpty(this.properties.forceTemplate)) {
await this.recreateNavMenu()
await this.initializeQuickLaunchMenu()
await this.sp.web.lists
.getByTitle(strings.ProjectPropertiesListName)
.items.getById(1)
Expand All @@ -186,7 +187,7 @@ export default class ProjectSetup extends BaseApplicationCustomizer<IProjectSetu
/**
* Adds the old custom navigation nodes to the quick launch menu
*/
private async recreateNavMenu() {
private async initializeQuickLaunchMenu() {
const oldNodes: IMenuNode[] = await JSON.parse(localStorage.getItem('pp_navigationNodes'))
const navigationNodes = _.uniq([...oldNodes])
for await (const node of navigationNodes) {
Expand Down Expand Up @@ -257,7 +258,8 @@ export default class ProjectSetup extends BaseApplicationCustomizer<IProjectSetu
strings.SetupAbortedText
)
)
}
},
validation: this._validation
})
render(element, placeholder)
}
Expand Down Expand Up @@ -426,12 +428,10 @@ export default class ProjectSetup extends BaseApplicationCustomizer<IProjectSetu
}

/**
* Fetch data from SharePoint and initializes the `MSGraphHelper`. This is
* called when the component is first loaded.
* Fetch data from SharePoint.
*/
private async _fetchData(): Promise<IProjectSetupData> {
try {
await MSGraphHelper.Init(this.context.msGraphClientFactory)
const data: IProjectSetupData = {}
this._portalDataService = await new PortalDataService().configure({
spfxContext: this.context
Expand Down Expand Up @@ -488,9 +488,13 @@ export default class ProjectSetup extends BaseApplicationCustomizer<IProjectSetu
/**
* Get validation
*/
private get _validation(): ProjectSetupValidation {
private async _validateProjectSetup(): Promise<ProjectSetupValidation> {
const { isSiteAdmin, groupId, hubSiteId, siteId } = this.context.pageContext.legacyPageContext

const members = await msgraph.Get<any[]>(`groups/${groupId}/members`)
if (!members.some(({ mail }) => mail === this.context.pageContext.user.email)) {
return ProjectSetupValidation.UserNotGroupMember
}
if (!isSiteAdmin) return ProjectSetupValidation.NotSiteAdmin
if (!groupId) return ProjectSetupValidation.NoGroupId
if (this.context.pageContext.web.language !== 1044)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,12 @@ export enum ProjectSetupValidation {
/**
* The current user is not site admin
*/
NotSiteAdmin
NotSiteAdmin,

/**
* The current user is not a member of the Microsoft
* 365 group. This will cause issues
* provisioning Planner resources.
*/
UserNotGroupMember,
}

0 comments on commit 556e8da

Please sign in to comment.