fix bug with allowing visitors to ask questions

This commit is contained in:
bogeorge 2020-10-01 15:20:34 -04:00
parent 6ad45604e6
commit 513953622d
4 changed files with 24 additions and 9 deletions

View File

@ -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,

View File

@ -1,6 +1,6 @@
{
"name": "react-questions-and-answers",
"version": "1.0.0",
"version": "1.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "react-questions-and-answers",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"engines": {
"node": ">=0.10.0"

View File

@ -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;