AssignPermissionToCatalogLists() public method

public AssignPermissionToCatalogLists ( string listName, ClientContext catalogContext, string userEmail, string role, IConfigurationRoot configuration ) : void
listName string
catalogContext ClientContext
userEmail string
role string
configuration IConfigurationRoot
return void
Example #1
0
        /// <summary>
        /// This method will get all list items from external access requests and process all
        /// requests which are in accpeted state
        /// </summary>
        /// <param name="originalMatter"></param>
        /// <param name="log"></param>
        /// <param name="configuration"></param>
        private static void GetExternalAccessRequestsFromSPO(MatterInformationVM originalMatter,
                                                             TextWriter log,
                                                             IConfigurationRoot configuration)
        {
            try
            {
                foreach (var assignUserEmails in originalMatter.Matter.AssignUserEmails)
                {
                    foreach (string email in assignUserEmails)
                    {
                        using (var ctx = new ClientContext(originalMatter.Client.Url))
                        {
                            SecureString password = Utility.GetEncryptedPassword(configuration["General:AdminPassword"]);
                            ctx.Credentials = new SharePointOnlineCredentials(configuration["General:AdminUserName"], password);
                            //First check whether the user exists in SharePoint or not
                            log.WriteLine($"Checking whether the user {email} has been present in the system or not");
                            if (CheckUserPresentInMatterCenter(ctx, originalMatter.Client.Url, email, configuration, log) == true)
                            {
                                string    requestedForPerson = email;
                                string    matterId           = originalMatter.Matter.MatterGuid;
                                var       listTitle          = configuration["Settings:ExternalAccessRequests"];
                                var       list      = ctx.Web.Lists.GetByTitle(listTitle);
                                CamlQuery camlQuery = CamlQuery.CreateAllItemsQuery();
                                camlQuery.ViewXml = "";
                                ListItemCollection listItemCollection = list.GetItems(camlQuery);
                                ctx.Load(listItemCollection);
                                ctx.ExecuteQuery();
                                log.WriteLine($"Looping all the records from {configuration["Settings:ExternalAccessRequests"]} lists");
                                foreach (ListItem listItem in listItemCollection)
                                {
                                    //The matter id for whom the request has been sent
                                    string requestedObjectTitle = listItem["RequestedObjectTitle"].ToString();
                                    //The person to whom the request has been sent
                                    string requestedFor = listItem["RequestedFor"].ToString();
                                    //The matter url for which the request has been sent
                                    string url = ((FieldUrlValue)listItem["RequestedObjectUrl"]).Url;
                                    //The status of the request whether it has been in pending=0, accepeted=2 or withdrawn=5
                                    string status = listItem["Status"].ToString();
                                    //If the status is accepted and the person and matter in table storage equals to item in Access Requests list
                                    if (requestedFor == requestedForPerson && matterId == requestedObjectTitle && status == "2")
                                    {
                                        log.WriteLine($"The user {email} has been present in the system and he has accepted the invitation and providing permssions to  matter {originalMatter.Matter.Name} from the user {email}");
                                        UpdateMatter umd = new UpdateMatter();
                                        //Update all matter related lists and libraries permissions for external users
                                        umd.UpdateUserPermissionsForMatter(originalMatter, configuration, password);

                                        //Update permissions for external users in Catalog Site Collection
                                        using (var catalogContext = new ClientContext(configuration["General:CentralRepositoryUrl"]))
                                        {
                                            catalogContext.Credentials =
                                                new SharePointOnlineCredentials(configuration["General:AdminUserName"], password);
                                            umd.AssignPermissionToCatalogLists(configuration["Catalog:SiteAssets"], catalogContext,
                                                                               email.Trim(), configuration["Catalog:SiteAssetsPermissions"], configuration);
                                        }
                                        log.WriteLine($"The matter permissions has been updated for the user {email}");
                                        log.WriteLine($"Updating the matter status to Accepted in Azure Table Storage");
                                        Utility.UpdateTableStorageEntity(originalMatter, log, configuration["General:CloudStorageConnectionString"],
                                                                         configuration["Settings:TableStorageForExternalRequests"], "Accepted");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.WriteLine($"Exception occured in the method GetExternalAccessRequestsFromSPO. {ex}");
            }
        }
Example #2
0
        /// <summary>
        /// This method will get all list items from external access requests and process all
        /// requests which are in accpeted state
        /// </summary>
        /// <param name="originalMatter"></param>
        /// <param name="log"></param>
        /// <param name="configuration"></param>
        private static void GetExternalAccessRequestsFromSPO(MatterInformationVM azureTableMatterInformationVMRow, MatterInformationVM originalMatter, 
            TextWriter log, 
            IConfigurationRoot configuration)
        {
            try
            {
                foreach (var assignUserEmails in originalMatter.Matter.AssignUserEmails)
                {
                    foreach (string email in assignUserEmails)
                    {
                        using (var ctx = new ClientContext(originalMatter.Client.Url))
                        {
                            SecureString password = Utility.GetEncryptedPassword(configuration["General:AdminPassword"]);
                            ctx.Credentials = new SharePointOnlineCredentials(configuration["General:AdminUserName"], password);
                            //First check whether the user exists in SharePoint or not
                            log.WriteLine($"Checking whether the user {email} has been present in the system or not");
                            if (CheckUserPresentInMatterCenter(ctx, originalMatter.Client.Url, email, configuration, log) == true)
                            {
                                
                                string requestedForPerson = email;
                                string matterId = originalMatter.Matter.MatterGuid;
                                var listTitle = configuration["Settings:ExternalAccessRequests"];
                                var list = ctx.Web.Lists.GetByTitle(listTitle);
                                CamlQuery camlQuery = CamlQuery.CreateAllItemsQuery();
                                camlQuery.ViewXml = "";
                                ListItemCollection listItemCollection = list.GetItems(camlQuery);
                                ctx.Load(listItemCollection);
                                ctx.ExecuteQuery();
                                log.WriteLine($"Looping all the records from {configuration["Settings:ExternalAccessRequests"]} lists");
                                foreach (ListItem listItem in listItemCollection)
                                {
                                    //The matter id for whom the request has been sent            
                                    string requestedObjectTitle = listItem["RequestedObjectTitle"].ToString();
                                    //The person to whom the request has been sent
                                    string requestedFor = listItem["RequestedFor"].ToString();
                                    //The matter url for which the request has been sent
                                    string url = ((FieldUrlValue)listItem["RequestedObjectUrl"]).Url;
                                    //The status of the request whether it has been in pending=0, accepeted=2 or withdrawn=5
                                    string status = listItem["Status"].ToString();
                                    //If the status is accepted and the person and matter in table storage equals to item in Access Requests list
                                    if (requestedFor == requestedForPerson && matterId == requestedObjectTitle && status == "2")
                                    {
                                        log.WriteLine($"The user {email} has been present in the system and he has accepted the invitation and providing permssions to  matter {originalMatter.Matter.Name} from the user {email}");
                                        UpdateMatter umd = new UpdateMatter();
                                        //Update all matter related lists and libraries permissions for external users
                                        if (azureTableMatterInformationVMRow.MatterUpdateStatus.ToLower() == "pending")
                                        {
                                            umd.UpdateUserPermissionsForMatter(originalMatter, configuration, password);
                                            Utility.UpdateTableStorageEntity(originalMatter, log, configuration["General:CloudStorageConnectionString"],
                                                configuration["Settings:TableStorageForExternalRequests"], "Accepted", "MatterUpdateStatus");
                                        }

                                        //Update permissions for external users in Catalog Site Collection
                                        using (var catalogContext = new ClientContext(configuration["General:CentralRepositoryUrl"]))
                                        {
                                            catalogContext.Credentials =
                                                new SharePointOnlineCredentials(configuration["General:AdminUserName"], password);
                                            umd.AssignPermissionToCatalogLists(configuration["Catalog:SiteAssets"], catalogContext,
                                                email.Trim(), configuration["Catalog:SiteAssetsPermissions"], configuration);
                                        }
                                        log.WriteLine($"The matter permissions has been updated for the user {email}");
                                        log.WriteLine($"Updating the matter status to Accepted in Azure Table Storage");
                                        Utility.UpdateTableStorageEntity(originalMatter, log, configuration["General:CloudStorageConnectionString"], 
                                            configuration["Settings:TableStorageForExternalRequests"], "Accepted", "Status");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                log.WriteLine($"Exception occured in the method GetExternalAccessRequestsFromSPO. {ex}");
            }
        }