From 052a979f4fc2e94a51ff59964981c308618a22ee Mon Sep 17 00:00:00 2001 From: Bert Jansen Date: Thu, 15 Feb 2024 18:43:04 +0100 Subject: [PATCH] GetUserEffectivePermissions not working with External accounts #1350 --- src/sdk/CHANGELOG.md | 1 + ...rnalUserPermissionsAsyncTest-0-00000.response.json | 1 + ...rnalUserPermissionsAsyncTest-0-00001.response.json | 1 + ...rnalUserPermissionsAsyncTest-0-00002.response.json | 1 + src/sdk/PnP.Core.Test/SharePoint/WebTests.cs | 11 +++++++++++ .../PnP.Core/Model/SharePoint/Core/Internal/Web.cs | 2 +- 6 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00000.response.json create mode 100644 src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00001.response.json create mode 100644 src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00002.response.json diff --git a/src/sdk/CHANGELOG.md b/src/sdk/CHANGELOG.md index cf8182743f..f4ca0446b0 100644 --- a/src/sdk/CHANGELOG.md +++ b/src/sdk/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Admin library: Add code to set sensitivity label to a group via updating associated site properties #1389 [wilecoyotegenius - Konrad K.] - Expose the `BatchRequest.Id` property and include it in the corresponding `BatchResponse` to enable more advanced batch handling scenarios #1374 [jansenbe - Bert Jansen] - Admin library: fixed issues with loading SharePoint Add-In and Azure ACS principal permissions when the payload exceeded 500 items [jansenbe - Bert Jansen] +- GetUserEffectivePermissions not working with External accounts #1350 [jansenbe - Bert Jansen] ## [1.11.0] diff --git a/src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00000.response.json b/src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00000.response.json new file mode 100644 index 0000000000..6f4f2fe4f4 --- /dev/null +++ b/src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00000.response.json @@ -0,0 +1 @@ +{"IsSuccessStatusCode":true,"StatusCode":200,"Headers":{"SPRequestGuid":"82000ca1-001d-8000-23ec-98b49e054fd3","SPClientServiceRequestDuration":"9","X-SharePointHealthScore":"3","X-SP-SERVERSTATE":"ReadOnly=0"},"Response":"{\u0022RegionalSettings\u0022:{\u0022TimeZone\u0022:{\u0022Description\u0022:\u0022(UTC-08:00) Pacific Time (US and Canada)\u0022,\u0022Id\u0022:13,\u0022Information\u0022:{\u0022Bias\u0022:480,\u0022DaylightBias\u0022:-60,\u0022StandardBias\u0022:0}},\u0022AdjustHijriDays\u0022:0,\u0022AlternateCalendarType\u0022:0,\u0022AM\u0022:\u0022AM\u0022,\u0022CalendarType\u0022:1,\u0022Collation\u0022:25,\u0022CollationLCID\u0022:2070,\u0022DateFormat\u0022:0,\u0022DateSeparator\u0022:\u0022/\u0022,\u0022DecimalSeparator\u0022:\u0022.\u0022,\u0022DigitGrouping\u0022:\u00223;0\u0022,\u0022FirstDayOfWeek\u0022:0,\u0022FirstWeekOfYear\u0022:0,\u0022IsEastAsia\u0022:false,\u0022IsRightToLeft\u0022:false,\u0022IsUIRightToLeft\u0022:false,\u0022ListSeparator\u0022:\u0022,\u0022,\u0022LocaleId\u0022:1033,\u0022NegativeSign\u0022:\u0022-\u0022,\u0022NegNumberMode\u0022:1,\u0022PM\u0022:\u0022PM\u0022,\u0022PositiveSign\u0022:\u0022\u0022,\u0022ShowWeeks\u0022:false,\u0022ThousandSeparator\u0022:\u0022,\u0022,\u0022Time24\u0022:false,\u0022TimeMarkerPosition\u0022:0,\u0022TimeSeparator\u0022:\u0022:\u0022,\u0022WorkDayEndHour\u0022:1020,\u0022WorkDays\u0022:62,\u0022WorkDayStartHour\u0022:480},\u0022Id\u0022:\u00222c99a486-d6c9-4a4b-8d6f-a9faa364c92c\u0022,\u0022Url\u0022:\u0022https://bertonline.sharepoint.com/sites/prov-2\u0022}"} \ No newline at end of file diff --git a/src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00001.response.json b/src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00001.response.json new file mode 100644 index 0000000000..b90ace3280 --- /dev/null +++ b/src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00001.response.json @@ -0,0 +1 @@ +{"IsSuccessStatusCode":true,"StatusCode":200,"Headers":{"SPRequestGuid":"82000ca1-a02b-8000-23ec-95f0eec3f8ef","SPClientServiceRequestDuration":"11","X-SharePointHealthScore":"2","X-SP-SERVERSTATE":"ReadOnly=0"},"Response":"{\u0022GroupId\u0022:\u0022d40d729b-df60-4b57-ac8f-102595090e0a\u0022,\u0022Id\u0022:\u0022f92f9e40-1110-43ef-aa0e-0822e13fb7ba\u0022}"} \ No newline at end of file diff --git a/src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00002.response.json b/src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00002.response.json new file mode 100644 index 0000000000..d55589df03 --- /dev/null +++ b/src/sdk/PnP.Core.Test/SharePoint/MockData/WebTests/GetEffectiveExternalUserPermissionsAsyncTest-0-00002.response.json @@ -0,0 +1 @@ +{"IsSuccessStatusCode":true,"StatusCode":200,"Headers":{"SPRequestGuid":"82000ca1-3092-8000-23ec-98493b15be62","SPClientServiceRequestDuration":"378","X-SharePointHealthScore":"0","X-SP-SERVERSTATE":"ReadOnly=0"},"Response":"{\u0022High\u0022:\u0022432\u0022,\u0022Low\u0022:\u00221011030767\u0022}"} \ No newline at end of file diff --git a/src/sdk/PnP.Core.Test/SharePoint/WebTests.cs b/src/sdk/PnP.Core.Test/SharePoint/WebTests.cs index 8f304c45e6..77d86abb2e 100644 --- a/src/sdk/PnP.Core.Test/SharePoint/WebTests.cs +++ b/src/sdk/PnP.Core.Test/SharePoint/WebTests.cs @@ -2239,6 +2239,17 @@ public async Task GetEffectiveUserPermissionsAsyncTest() } } + [TestMethod] + public async Task GetEffectiveExternalUserPermissionsAsyncTest() + { + TestCommon.Instance.Mocking = false; + using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite)) + { + var basePermissions = await context.Web.GetUserEffectivePermissionsAsync("bjansen_microsoft.com#ext#@bertonline.onmicrosoft.com"); + + Assert.IsNotNull(basePermissions); + } + } [TestMethod] public async Task CheckIfUserHasPermissionsAsyncTest() diff --git a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/Web.cs b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/Web.cs index 24c0b67325..85e721f126 100644 --- a/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/Web.cs +++ b/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/Web.cs @@ -2386,7 +2386,7 @@ public async Task GetUserEffectivePermissionsAsync(string user private static ApiCall BuildGetUserEffectivePermissionsApiCall(string userPrincipalName) { - return new ApiCall($"_api/web/getusereffectivepermissions('{HttpUtility.UrlEncode("i:0#.f|membership|")}{userPrincipalName}')", ApiType.SPORest); + return new ApiCall($"_api/web/getusereffectivepermissions('{HttpUtility.UrlEncode("i:0#.f|membership|" + userPrincipalName)}')", ApiType.SPORest); } public bool CheckIfUserHasPermissions(string userPrincipalName, PermissionKind permissionKind)