コード例 #1
0
        public async Task <IActionResult> Get([FromBody] SearchRequestVM searchRequestVM)
        {
            try
            {
                #region Error Checking
                GenericResponseVM genericResponse = null;
                //Input validation
                if (searchRequestVM == null && searchRequestVM.Client == null && searchRequestVM.SearchObject == null)
                {
                    genericResponse = new GenericResponseVM()
                    {
                        Value   = errorSettings.MessageNoInputs,
                        Code    = HttpStatusCode.BadRequest.ToString(),
                        IsError = true
                    };
                    //If the input validation is failed, send GenericResponseVM which contains the error information
                    return(matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.OK));
                }
                #endregion
                ClientContext clientContext = null;
                clientContext = spoAuthorization.GetClientContext(searchRequestVM.Client.Url);
                var searchResultsVM = await documentProvision.GetDocumentsAsync(searchRequestVM, clientContext);

                return(matterCenterServiceFunctions.ServiceResponse(searchResultsVM.DocumentDataList, (int)HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                var errorResponse = customLogger.GenerateErrorResponse(ex);
                return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.OK));
            }
        }
コード例 #2
0
        public async Task <int> GetAllCounts(SearchRequestVM searchRequestVM)
        {
            try
            {
                searchRequestVM.SearchObject.Filters.FilterByMe = 0;
                var searchObject = searchRequestVM.SearchObject;
                // Encode all fields which are coming from js
                SearchUtility.EncodeSearchDetails(searchObject.Filters, false);
                // Encode Search Term
                searchObject.SearchTerm = (searchObject.SearchTerm != null) ?
                                          WebUtility.HtmlEncode(searchObject.SearchTerm).Replace(ServiceConstants.ENCODED_DOUBLE_QUOTES,
                                                                                                 ServiceConstants.DOUBLE_QUOTE) : string.Empty;

                ClientContext clientContext = null;
                clientContext = spoAuthorization.GetClientContext(searchRequestVM.Client.Url);
                var searchResultsVM = await docRepository.GetDocumentsAsync(searchRequestVM, clientContext);

                return(searchResultsVM.TotalRows);
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
コード例 #3
0
ファイル: SPPage.cs プロジェクト: tinsheep/mattercenter
        /// <summary>
        /// Will check whether a url exists in the current site collection or not
        /// </summary>
        /// <param name="client">Contains the url in which we need to check whether a page exists or not</param>
        /// <param name="pageUrl">The page</param>
        /// <returns></returns>
        public bool UrlExists(Client client, string pageUrl)
        {
            bool pageExists = false;

            try
            {
                using (ClientContext clientContext = spoAuthorization.GetClientContext(client.Url))
                {
                    string[] requestedUrls = pageUrl.Split(new string[] { ServiceConstants.DOLLAR + ServiceConstants.PIPE + ServiceConstants.DOLLAR },
                                                           StringSplitOptions.RemoveEmptyEntries);
                    if (1 < requestedUrls.Length)
                    {
                        foreach (string url in requestedUrls)
                        {
                            if (IsFileExists(clientContext, url))
                            {
                                pageExists = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        pageExists = IsFileExists(clientContext, pageUrl) ? true : false;
                    }
                }
                return(pageExists);
            }
            catch (Exception ex)
            {
                customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }
コード例 #4
0
 /// <summary>
 /// This method will return the taxonomy hierarchy either for the practice group term set or for client term sets
 /// </summary>
 /// <typeparam name="T">The return type from this class</typeparam>
 /// <param name="clientContext">The sharepoint client context</param>
 /// <param name="termStoreDetails">The term store deatils that client has passed to we apiu</param>
 /// <param name="generalSettings">The general settings config values</param>
 /// <param name="taxonomySettings">The taxonomy settings config values</param>
 /// <returns></returns>
 public TaxonomyResponseVM GetTaxonomyHierarchy(Client client, TermStoreDetails termStoreDetails)
 {
     try
     {
         using (clientContext = spoAuthorization.GetClientContext(client.Url))
         {
             TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
             TermStore       termStore;
             clientContext.Load(taxonomySession.TermStores);
             clientContext.ExecuteQuery();
             termStore = taxonomySession.TermStores[0];
             clientContext.Load(
                 termStore,
                 store => store.Name,
                 store => store.Groups.Include(
                     group => group.Name));
             clientContext.ExecuteQuery();
             taxonomyResponseVM = GetTaxonomyHierarchy(termStore, termStoreDetails);
         }
     }
     catch (Exception ex)
     {
         customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
         throw;
     }
     return(taxonomyResponseVM);
 }
コード例 #5
0
 /// <summary>
 /// This method will check whether user exists in a sharepoint site or not
 /// </summary>
 /// <param name="clientUrl"></param>
 /// <param name="email"></param>
 /// <returns></returns>
 public bool CheckUserPresentInMatterCenter(string clientUrl, string email)
 {
     try
     {
         //If the current email is part of current organization, no need to check for validity of the user
         if (email.Trim().ToLower().IndexOf(generalSettings.Tenant.Trim().ToLower()) > 0)
         {
             return(true);
         }
         var clientContext = spoAuthorization.GetClientContext(clientUrl);
         return(CheckUserPresentInMatterCenter(clientContext, email));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
コード例 #6
0
        public string GetCurrentSite(Client client)
        {
            clientContext = spoAuthorization.GetClientContext(client.Url);
            var spWeb = clientContext.Web;

            clientContext.Load(spWeb);
            clientContext.ExecuteQuery();
            return(spWeb.Title.ToString());
        }
コード例 #7
0
        /// <summary>
        /// This method will send notifications to external users
        /// </summary>
        /// <param name="externalSharingRequest"></param>
        /// <returns></returns>
        private GenericResponseVM SendExternalNotification(MatterInformationVM matterInformation, string permission, string externalEmail)
        {
            var clientUrl = $"{matterInformation.Client.Url}";

            try
            {
                var users = new List <UserRoleAssignment>();
                UserRoleAssignment userRole = new UserRoleAssignment();
                userRole.UserId = externalEmail;
                switch (permission.ToLower())
                {
                case "full control":
                    userRole.Role = SharePoint.Client.Sharing.Role.Owner;
                    break;

                case "contribute":
                    userRole.Role = SharePoint.Client.Sharing.Role.Edit;
                    break;

                case "read":
                    userRole.Role = SharePoint.Client.Sharing.Role.View;
                    break;
                }
                users.Add(userRole);
                #region Doc Sharing API
                //Need to use MatterGuid instead of Id
                string matterLandingPageUrl        = $"{clientUrl}/sitepages/{matterInformation.Matter.MatterGuid + ServiceConstants.ASPX_EXTENSION}";
                string catalogSiteAssetsLibraryUrl = $"{generalSettings.CentralRepositoryUrl}/SitePages/home.aspx";
                using (var clientContext = spoAuthorization.GetClientContext(clientUrl))
                {
                    //Send notification to the matter landing page url with permission the user has selected
                    IList <UserSharingResult> matterLandingPageResult = DocumentSharingManager.UpdateDocumentSharingInfo(clientContext,
                                                                                                                         matterLandingPageUrl,
                                                                                                                         users, true, true, true, "The following matter page has been shared with you", true, true);
                    clientContext.ExecuteQuery();
                }
                return(null);

                #endregion
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #8
0
 /// <summary>
 /// This method will upload uiconfigforspo.js into sharepoint catalog site collection
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="clientUrl"></param>
 public void UploadConfigFileToSPO(string filePath, string clientUrl)
 {
     using (ClientContext clientContext = spoAuthorization.GetClientContext(clientUrl))
     {
         var web     = clientContext.Web;
         var newFile = new FileCreationInformation
         {
             Content   = System.IO.File.ReadAllBytes(filePath),
             Overwrite = true,
             //The root at which the uiconfigforspo.js needs to be uploaded
             Url = Path.Combine("SiteAssets/Matter Center Assets/Common Assets/Scripts/", Path.GetFileName(filePath))
         };
         //The document library names under which the uiconfigforspo.js has to be uploaded
         var docs = web.Lists.GetByTitle("Site Assets");
         Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
         clientContext.Load(uploadFile);
         clientContext.ExecuteQuery();
         //After uploading the file to sharepoint site collection, delete the file from the app root
         if (!filePath.EndsWith("config.js"))
         {
             System.IO.File.Delete(filePath);
         }
     }
 }
コード例 #9
0
        public GenericResponseVM UpdateMatter(MatterInformationVM matterInformation)
        {
            var           matter           = matterInformation.Matter;
            var           matterDetails    = matterInformation.MatterDetails;
            var           client           = matterInformation.Client;
            int           listItemId       = -1;
            string        loggedInUserName = "";
            bool          isEditMode       = matterInformation.EditMode;
            ClientContext clientContext    = null;
            IEnumerable <RoleAssignment> userPermissionOnLibrary = null;
            GenericResponseVM            genericResponse         = null;

            try
            {
                clientContext = spoAuthorization.GetClientContext(matterInformation.Client.Url);
                PropertyValues matterStampedProperties = matterRepositoy.GetStampedProperties(clientContext, matter.Name);
                loggedInUserName = matterRepositoy.GetLoggedInUserDetails(clientContext).Name;
                bool isFullControlPresent = editFunctions.ValidateFullControlPermission(matter);

                if (!isFullControlPresent)
                {
                    return(ServiceUtility.GenericResponse(errorSettings.IncorrectInputSelfPermissionRemoval, errorSettings.ErrorEditMatterMandatoryPermission));
                }

                // Get matter library current permissions
                userPermissionOnLibrary = matterRepositoy.FetchUserPermissionForLibrary(clientContext, matter.Name);
                string originalMatterName = matterRepositoy.GetMatterName(clientContext, matter.Name);
                listItemId = matterRepositoy.RetrieveItemId(clientContext, matterSettings.MatterLandingPageRepositoryName, originalMatterName);
                List <string> usersToRemove     = RetrieveMatterUsers(userPermissionOnLibrary);
                bool          hasFullPermission = CheckFullPermissionInAssignList(matter.AssignUserNames, matter.Permissions, loggedInUserName);
                List <string> listExists        = matterRepositoy.MatterAssociatedLists(clientContext, matter.Name);
                matterRepositoy.AssignRemoveFullControl(clientContext, matter, loggedInUserName, listItemId, listExists, true, hasFullPermission);
                bool result = false;
                if (listExists.Contains(matter.Name))
                {
                    result = matterRepositoy.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name, -1, isEditMode);
                }
                if (listExists.Contains(matter.Name + matterSettings.OneNoteLibrarySuffix))
                {
                    result = matterRepositoy.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name + matterSettings.OneNoteLibrarySuffix, -1, isEditMode);
                }
                if (listExists.Contains(matter.Name + matterSettings.CalendarNameSuffix))
                {
                    result = matterRepositoy.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name + matterSettings.CalendarNameSuffix, -1, isEditMode);
                }
                if (listExists.Contains(matter.Name + matterSettings.TaskNameSuffix))
                {
                    result = matterRepositoy.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name + matterSettings.TaskNameSuffix, -1, isEditMode);
                }
                if (0 <= listItemId)
                {
                    result = matterRepositoy.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, true, matterSettings.MatterLandingPageRepositoryName, listItemId, isEditMode);
                }
                // Update matter metadata
                result = matterRepositoy.UpdateMatterStampedProperties(clientContext, matterDetails, matter, matterStampedProperties, isEditMode);
                if (result)
                {
                    return(genericResponse);
                }
            }
            catch (Exception ex)
            {
                MatterRevertList matterRevertListObject = new MatterRevertList()
                {
                    MatterLibrary        = matter.Name,
                    MatterOneNoteLibrary = matter.Name + matterSettings.OneNoteLibrarySuffix,
                    MatterCalendar       = matter.Name + matterSettings.CalendarNameSuffix,
                    MatterTask           = matter.Name + matterSettings.TaskNameSuffix,
                    MatterSitePages      = matterSettings.MatterLandingPageRepositoryName
                };
                matterRepositoy.RevertMatterUpdates(client, matter, clientContext, matterRevertListObject, loggedInUserName,
                                                    userPermissionOnLibrary, listItemId, isEditMode);
            }
            return(ServiceUtility.GenericResponse("9999999", "Error in updating matter information"));
        }
コード例 #10
0
        /// <summary>
        /// This method will send notifications to external users
        /// </summary>
        /// <param name="externalSharingRequest"></param>
        /// <returns></returns>
        private GenericResponseVM SendExternalNotification(MatterInformationVM matterInformation, string permission, string externalEmail)
        {
            var clientUrl = $"{matterInformation.Client.Url}";

            try
            {
                string roleId = "";
                switch (permission.ToLower())
                {
                case "full control":
                    roleId = ((int)SPORoleIdMapping.FullControl).ToString();
                    break;

                case "contribute":
                    roleId = ((int)SPORoleIdMapping.Contribute).ToString();
                    break;

                case "read":
                    roleId = ((int)SPORoleIdMapping.Read).ToString();
                    break;
                }

                PeoplePickerUser peoplePickerUser = new PeoplePickerUser();
                peoplePickerUser.Key                 = externalEmail;
                peoplePickerUser.Description         = externalEmail;
                peoplePickerUser.DisplayText         = externalEmail;
                peoplePickerUser.EntityType          = "";
                peoplePickerUser.ProviderDisplayName = "";
                peoplePickerUser.ProviderName        = "";
                peoplePickerUser.IsResolved          = true;

                EntityData entityData = new EntityData();
                entityData.SPUserID         = externalEmail;
                entityData.Email            = externalEmail;
                entityData.IsBlocked        = "False";
                entityData.PrincipalType    = "UNVALIDATED_EMAIL_ADDRESS";
                entityData.AccountName      = externalEmail;
                entityData.SIPAddress       = externalEmail;
                peoplePickerUser.EntityData = entityData;

                string peoplePicker = Newtonsoft.Json.JsonConvert.SerializeObject(peoplePickerUser);
                peoplePicker = $"[{peoplePicker}]";
                string roleValue = $"role:{roleId}";

                bool sendEmail = true;

                bool   includeAnonymousLinkInEmail = false;
                bool   propagateAcl         = false;
                bool   useSimplifiedRoles   = true;
                string matterLandingPageUrl = $"{clientUrl}/sitepages/{matterInformation.Matter.MatterGuid + ServiceConstants.ASPX_EXTENSION}";
                string url          = matterLandingPageUrl;
                string emailBody    = $"The following information has been shared with you {matterInformation.Matter.Name}";
                string emailSubject = $"The following information has been shared with you {matterInformation.Matter.Name}";
                #region Doc Sharing API
                SharingResult sharingResult = null;
                using (var clientContext = spoAuthorization.GetClientContext(clientUrl))
                {
                    sharingResult = Microsoft.SharePoint.Client.Web.ShareObject(clientContext, url, peoplePicker, roleValue, 0, propagateAcl, sendEmail, includeAnonymousLinkInEmail, emailSubject, emailBody, useSimplifiedRoles);
                    clientContext.Load(sharingResult);
                    clientContext.ExecuteQuery();
                }
                return(null);

                #endregion
            }
            catch (Exception ex)
            {
                throw;
            }
        }