diff --git a/samples/react-questions-and-answers/config/package-solution.json b/samples/react-questions-and-answers/config/package-solution.json index 29d848e7c..168b714e2 100644 --- a/samples/react-questions-and-answers/config/package-solution.json +++ b/samples/react-questions-and-answers/config/package-solution.json @@ -3,7 +3,7 @@ "solution": { "name": "Questions and Answers", "id": "6feb4c2f-341b-499c-998c-9b2ebd95435c", - "version": "1.0.0.0", + "version": "1.0.1.0", "skipFeatureDeployment": false, "iconPath": "images/Feedback_Icon.png", "includeClientSideAssets": true, diff --git a/samples/react-questions-and-answers/package-lock.json b/samples/react-questions-and-answers/package-lock.json index a96e99da8..e1f97dd1c 100644 --- a/samples/react-questions-and-answers/package-lock.json +++ b/samples/react-questions-and-answers/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-questions-and-answers", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/samples/react-questions-and-answers/package.json b/samples/react-questions-and-answers/package.json index c8b4c7ee9..04abe059f 100644 --- a/samples/react-questions-and-answers/package.json +++ b/samples/react-questions-and-answers/package.json @@ -1,6 +1,6 @@ { "name": "react-questions-and-answers", - "version": "1.0.0", + "version": "1.0.1", "private": true, "engines": { "node": ">=0.10.0" diff --git a/samples/react-questions-and-answers/src/services/permission.service.ts b/samples/react-questions-and-answers/src/services/permission.service.ts index 01c40c2f4..7f759cc7f 100644 --- a/samples/react-questions-and-answers/src/services/permission.service.ts +++ b/samples/react-questions-and-answers/src/services/permission.service.ts @@ -1,6 +1,11 @@ -import { sp, PermissionKind, RoleType } from '@pnp/sp/presets/all'; +import { sp } from '@pnp/sp'; +import "@pnp/sp/webs"; +import "@pnp/sp/site-groups/web"; +import { PermissionKind } from "@pnp/sp/security"; import { BaseService } from './base.service'; import { LogHelper, ListTitles } from 'utilities'; +import { RoleType } from '@pnp/sp/sharing'; +import { _RoleAssignment, _RoleDefinition } from '@pnp/sp/security/types'; export class PermissionService extends BaseService { @@ -10,12 +15,22 @@ export class PermissionService extends BaseService { LogHelper.verbose(this.constructor.name, 'canVisitorsAskQuestions', ''); let canAsk: boolean = false; - debugger; - let visitorGroup = await sp.web.associatedVisitorGroup(); - let perms = await sp.web.lists.getByTitle(this.listTitle).getUserEffectivePermissions(visitorGroup.LoginName); - if(sp.web.hasPermissions(perms, PermissionKind.AddListItems)) { - canAsk = true; + + console.log(visitorGroup.Id); + + let roles = await sp.web.lists.getByTitle(this.listTitle).roleAssignments + .expand('Member', 'RoleDefinitionBindings') + .get(); + + let visitorRole: any = roles.find(r => r.PrincipalId === visitorGroup.Id); + + if(visitorRole) { + for (let def of visitorRole.RoleDefinitionBindings) { + if (sp.web.hasPermissions(def.BasePermissions, PermissionKind.AddListItems)) { + canAsk = true; + } + } } return canAsk;