SubPointSolutions / spmeta2

SharePoint artifact provision for .NET platform. Supports SharePoint Online, SharePoint 2019, 2016 and 2013 via CSOM/SSOM.
http://subpointsolutions.com/spmeta2
134 stars 56 forks source link

O365 CSOM - AuthorizationFilter is not working. #1139

Open maratbakirov opened 5 years ago

maratbakirov commented 5 years ago

Hello,

Brief description

Please provide short description covering two areas:

SharePoint API

Which version of SharePoint runtime do you use?

SPMeta2 API

Which version of SPMeta2 do you use? Use the following code snippet for your convenience. It shows all the details on SPMeta2 and SharePoint runtime used.

https://www.nuget.org/packages/SPMeta2.CSOM.Foundation-v16/1.2.140?_src=template

var info = SPMeta2Diagnostic.GetDiagnosticInfo();

SPMeta2 model

Optionally, provide SPMeta2 model in which issue occurs. That helps to identify the issue and provide the solution as far as we can.

/// your SPMeta2 definitions and model here

we have web parts that we add to the page. seems that webparts AuthorizationFilter property has been ignored and we have to develop a workaround like this - i did not see a similar code in the spmeta2 csom sources:

    public static void FixAudienceTargeting(Microsoft.SharePoint.Client.File file, 
        SPMeta2.Definitions.WebPartDefinition webPartDefinition)
    {
        var ctx = file.Context;
        var lwpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
        var webParts = lwpm.WebParts;
        ctx.Load(webParts);
        ctx.ExecuteQueryWithIncrementalRetry();
        foreach(var wp in webParts)
        {
            ctx.Load(wp.WebPart, x => x.Title);
        }
        ctx.ExecuteQueryWithIncrementalRetry();
        var theWebPart = webParts.ToArray().Where(x => x.WebPart.Title == webPartDefinition.Title).First();
        theWebPart.WebPart.Properties["AuthorizationFilter"] = webPartDefinition.AuthorizationFilter;

        theWebPart.SaveWebPartChanges();

        file.Update();
        ctx.ExecuteQueryWithIncrementalRetry();
    }