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": { "solution": {
"name": "Questions and Answers", "name": "Questions and Answers",
"id": "6feb4c2f-341b-499c-998c-9b2ebd95435c", "id": "6feb4c2f-341b-499c-998c-9b2ebd95435c",
"version": "1.0.0.0", "version": "1.0.1.0",
"skipFeatureDeployment": false, "skipFeatureDeployment": false,
"iconPath": "images/Feedback_Icon.png", "iconPath": "images/Feedback_Icon.png",
"includeClientSideAssets": true, "includeClientSideAssets": true,

View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "react-questions-and-answers", "name": "react-questions-and-answers",
"version": "1.0.0", "version": "1.0.1",
"private": true, "private": true,
"engines": { "engines": {
"node": ">=0.10.0" "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 { BaseService } from './base.service';
import { LogHelper, ListTitles } from 'utilities'; import { LogHelper, ListTitles } from 'utilities';
import { RoleType } from '@pnp/sp/sharing';
import { _RoleAssignment, _RoleDefinition } from '@pnp/sp/security/types';
export class PermissionService extends BaseService { export class PermissionService extends BaseService {
@ -10,13 +15,23 @@ export class PermissionService extends BaseService {
LogHelper.verbose(this.constructor.name, 'canVisitorsAskQuestions', ''); LogHelper.verbose(this.constructor.name, 'canVisitorsAskQuestions', '');
let canAsk: boolean = false; let canAsk: boolean = false;
debugger;
let visitorGroup = await sp.web.associatedVisitorGroup(); 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)) { 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; canAsk = true;
} }
}
}
return canAsk; return canAsk;
} }