/// <summary>
        /// Function to share the matter.
        /// </summary>
        /// <param name="requestObject">Request Object containing SharePoint App Token</param>
        /// <param name="client">Client object containing Client data</param>
        /// <param name="matter">Matter object</param>
        /// <param name="matterDetails">Matter object containing Matter data details</param>
        /// <param name="mailSiteURL">URL of the site</param>
        /// <param name="centralMailListURL">URL of the Send Mail list</param>
        /// <param name="matterLandingFlag">Flag to determine if Matter landing page exists</param>
        /// <param name="matterConfigurations">Object holding configuration for the matter</param>
        /// <returns>Result of operation: Matter Shared successfully or not</returns>        
        internal static string ShareMatterUtility(RequestObject requestObject, Client client, Matter matter, MatterDetails matterDetails, string mailSiteURL, string centralMailListURL, string matterLandingFlag, MatterConfigurations matterConfigurations)
        {
            string shareFlag = ConstantStrings.FALSE;
            string mailListName = centralMailListURL.Substring(centralMailListURL.LastIndexOf(ConstantStrings.ForwardSlash, StringComparison.OrdinalIgnoreCase) + 1);
            string matterLocation = string.Concat(client.Url, ConstantStrings.ForwardSlash, matter.Name);
            string ProvisionMatterValidation = string.Empty;
            if (!string.IsNullOrWhiteSpace(mailSiteURL))
            {
                using (ClientContext clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(mailSiteURL), requestObject.RefreshToken))
                {

                    ProvisionMatterValidation = ValidationHelperFunctions.ProvisionMatterValidation(requestObject, client, clientContext, matter, null, int.Parse(ConstantStrings.ProvisionMatterShareMatter, CultureInfo.InvariantCulture), matterConfigurations);
                    if (string.IsNullOrWhiteSpace(ProvisionMatterValidation))
                    {
                        // Get the current logged in User
                        clientContext.Load(clientContext.Web.CurrentUser);
                        clientContext.ExecuteQuery();
                        string matterMailBody, blockUserNames;
                        // Generate Mail Subject
                        string matterMailSubject = string.Format(CultureInfo.InvariantCulture, TextConstants.MatterMailSubject, matter.Id, matter.Name, clientContext.Web.CurrentUser.Title);

                        // Logic to Create Mail body
                        // Step 1: Create Matter Information
                        // Step 2: Create Team Information
                        // Step 3: Create Access Information
                        // Step 4: Create Conflict check Information based on the conflict check flag and create mail body

                        // Step 1: Create Matter Information
                        string defaultContentType = string.Format(CultureInfo.InvariantCulture, TextConstants.MatterMailDefaultContentTypeHtmlChunk, matter.DefaultContentType);
                        string matterType = string.Join(";", matter.ContentTypes.ToArray()).TrimEnd(';').Replace(matter.DefaultContentType, defaultContentType);

                        // Step 2: Create Team Information
                        string secureMatter = ConstantStrings.FALSE.ToUpperInvariant() == matter.Conflict.SecureMatter.ToUpperInvariant() ? ConstantStrings.NO : ConstantStrings.YES;
                        string mailBodyTeamInformation = string.Empty;
                        mailBodyTeamInformation = TeamMembersPermissionInformation(matterDetails, mailBodyTeamInformation);

                        // Step 3: Create Access Information
                        if (ConstantStrings.TRUE == matterLandingFlag)
                        {
                            matterLocation = string.Concat(client.Url, ConstantStrings.ForwardSlash, ServiceConstantStrings.MatterLandingPageRepositoryName.Replace(ConstantStrings.Space, string.Empty), ConstantStrings.ForwardSlash, matter.MatterGuid, ConstantStrings.AspxExtension);
                        }
                        string oneNotePath = string.Concat(client.Url, ConstantStrings.ForwardSlash, matter.MatterGuid, ServiceConstantStrings.OneNoteLibrarySuffix, ConstantStrings.ForwardSlash, matter.MatterGuid, ConstantStrings.ForwardSlash, matter.MatterGuid);

                        // Step 4: Create Conflict check Information based on the conflict check flag and create mail body
                        if (matterConfigurations.IsConflictCheck)
                        {
                            string conflictIdentified = ConstantStrings.FALSE.ToUpperInvariant() == matter.Conflict.Identified.ToUpperInvariant() ? ConstantStrings.NO : ConstantStrings.YES;
                            blockUserNames = string.Join(";", matter.BlockUserNames.ToArray()).Trim().TrimEnd(';');

                            blockUserNames = !String.IsNullOrEmpty(blockUserNames) ? string.Format(CultureInfo.InvariantCulture, "<div>{0}: {1}</div>", "Conflicted User", blockUserNames) : string.Empty;
                            matterMailBody = string.Format(CultureInfo.InvariantCulture, TextConstants.MatterMailBodyMatterInformation, client.Name, client.Id, matter.Name, matter.Id, matter.Description, matterType) + string.Format(CultureInfo.InvariantCulture, TextConstants.MatterMailBodyConflictCheck, ConstantStrings.YES, matter.Conflict.CheckBy, Convert.ToDateTime(matter.Conflict.CheckOn, CultureInfo.InvariantCulture).ToString(ServiceConstantStrings.MatterCenterDateFormat, CultureInfo.InvariantCulture), conflictIdentified) + string.Format(CultureInfo.InvariantCulture, TextConstants.MatterMailBodyTeamMembers, secureMatter, mailBodyTeamInformation, blockUserNames, client.Url, oneNotePath, matter.Name, matterLocation, matter.Name);
                        }
                        else
                        {
                            blockUserNames = string.Empty;
                            matterMailBody = string.Format(CultureInfo.InvariantCulture, TextConstants.MatterMailBodyMatterInformation, client.Name, client.Id, matter.Name, matter.Id, matter.Description, matterType) + string.Format(CultureInfo.InvariantCulture, TextConstants.MatterMailBodyTeamMembers, secureMatter, mailBodyTeamInformation, blockUserNames, client.Url, oneNotePath, matter.Name, matterLocation, matter.Name);
                        }

                        Web web = clientContext.Web;
                        List mailList = web.Lists.GetByTitle(mailListName);
                        List<FieldUserValue> userList = new List<FieldUserValue>();
                        List<FieldUserValue> userEmailList = ProvisionHelperFunctions.GenerateMailList(matter, clientContext, ref userList);
                        ///// Add the Matter URL in list
                        FieldUrlValue matterPath = new FieldUrlValue()
                        {
                            Url = string.Concat(client.Url.Replace(String.Concat(ConstantStrings.HTTPS, ConstantStrings.COLON, ConstantStrings.ForwardSlash, ConstantStrings.ForwardSlash), String.Concat(ConstantStrings.HTTP, ConstantStrings.COLON, ConstantStrings.ForwardSlash, ConstantStrings.ForwardSlash)), ConstantStrings.ForwardSlash, matter.Name, ConstantStrings.ForwardSlash, matter.Name),
                            Description = matter.Name
                        };
                        List<string> columnNames = new List<string>() { ServiceConstantStrings.ShareListColumnMatterPath, ServiceConstantStrings.ShareListColumnMailList, TextConstants.ShareListColumnMailBody, TextConstants.ShareListColumnMailSubject };
                        List<object> columnValues = new List<object>() { matterPath, userEmailList, matterMailBody, matterMailSubject };
                        // To avoid the invalid symbol error while parsing the JSON, return the response in lower case
                        shareFlag = Convert.ToString(Lists.AddItem(clientContext, mailList, columnNames, columnValues), CultureInfo.CurrentCulture).ToLower(CultureInfo.CurrentUICulture);
                    }
                }
            }
            return shareFlag;
        }
        /// <summary>
        /// Provides the team members and their respective permission details.
        /// </summary>
        /// <param name="matterDetails">Matter Details object</param>
        /// <param name="mailBodyTeamInformation">Team members permission information</param>
        /// <returns>Team members permission information</returns>
        private static string TeamMembersPermissionInformation(MatterDetails matterDetails, string mailBodyTeamInformation)
        {
            if (null != matterDetails && !string.IsNullOrWhiteSpace(matterDetails.RoleInformation))
            {
                Dictionary<string, string> roleInformation = JsonConvert.DeserializeObject<Dictionary<string, string>>(matterDetails.RoleInformation);

                foreach (KeyValuePair<string, string> entry in roleInformation)
                {
                    mailBodyTeamInformation = string.Format(CultureInfo.InvariantCulture, ConstantStrings.RoleInfoHtmlChunk, entry.Key, entry.Value) + mailBodyTeamInformation;
                }
            }
            return mailBodyTeamInformation;
        }
        /// <summary>
        /// Function to create dictionary object for stamp property 
        /// </summary>
        /// <param name="client">Client object containing Client data</param>
        /// <param name="matter">Matter object containing Matter data</param>
        /// <param name="matterDetails">Matter details object which has data of properties to be stamped</param>
        /// <returns>returns dictionary object</returns>
        internal static Dictionary<string, string> SetStampProperty(Client client, Matter matter, MatterDetails matterDetails)
        {
            string matterCenterPermission = string.Join(ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR, matter.Permissions);
            string matterCenterRoles = string.Join(ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR, matter.Roles);
            string documentTemplateCount = string.Join(ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR, matter.DocumentTemplateCount);
            string matterCenterUsers = string.Empty;
            string matterCenterUserEmails = string.Empty;
            string separator = ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR;
            foreach (IList<string> userNames in matter.AssignUserNames)
            {
                matterCenterUsers += string.Join(ConstantStrings.Semicolon, userNames.Where(user => !string.IsNullOrWhiteSpace(user))) + separator;
            }
            // Removed $|$ from end of the string
            matterCenterUsers = matterCenterUsers.Substring(0, matterCenterUsers.Length - separator.Length);
            foreach (IList<string> userEmails in matter.AssignUserEmails)
            {
                matterCenterUserEmails += string.Join(ConstantStrings.Semicolon, userEmails.Where(user => !string.IsNullOrWhiteSpace(user))) + separator;
            }
            // Removed $|$ from end of the string
            matterCenterUserEmails = matterCenterUserEmails.Substring(0, matterCenterUserEmails.Length - separator.Length);
            List<string> keys = new List<string>();
            Dictionary<string, string> propertyList = new Dictionary<string, string>();
            keys.Add(ServiceConstantStrings.StampedPropertyPracticeGroup);
            keys.Add(ServiceConstantStrings.StampedPropertyAreaOfLaw);
            keys.Add(ServiceConstantStrings.StampedPropertySubAreaOfLaw);
            keys.Add(ServiceConstantStrings.StampedPropertyMatterName);
            keys.Add(ServiceConstantStrings.StampedPropertyMatterID);
            keys.Add(ServiceConstantStrings.StampedPropertyClientName);
            keys.Add(ServiceConstantStrings.StampedPropertyClientID);
            keys.Add(ServiceConstantStrings.StampedPropertyResponsibleAttorney);
            keys.Add(ServiceConstantStrings.StampedPropertyResponsibleAttorneyEmail);
            keys.Add(ServiceConstantStrings.StampedPropertyTeamMembers);
            keys.Add(ServiceConstantStrings.StampedPropertyIsMatter);
            keys.Add(ServiceConstantStrings.StampedPropertyOpenDate);
            keys.Add(ServiceConstantStrings.StampedPropertySecureMatter);
            keys.Add(ServiceConstantStrings.StampedPropertyBlockedUploadUsers);
            keys.Add(ServiceConstantStrings.StampedPropertyMatterDescription);
            keys.Add(ServiceConstantStrings.StampedPropertyConflictCheckDate);
            keys.Add(ServiceConstantStrings.StampedPropertyConflictCheckBy);
            keys.Add(ServiceConstantStrings.StampedPropertyMatterCenterRoles);
            keys.Add(ServiceConstantStrings.StampedPropertyMatterCenterPermissions);
            keys.Add(ServiceConstantStrings.StampedPropertyMatterCenterUsers);
            keys.Add(ServiceConstantStrings.StampedPropertyMatterCenterUserEmails);
            keys.Add(ServiceConstantStrings.StampedPropertyDefaultContentType);
            keys.Add(ServiceConstantStrings.StampedPropertyIsConflictIdentified);
            keys.Add(ServiceConstantStrings.StampedPropertyDocumentTemplateCount);
            keys.Add(ServiceConstantStrings.StampedPropertyBlockedUsers);
            keys.Add(ServiceConstantStrings.StampedPropertyMatterGUID);

            propertyList.Add(ServiceConstantStrings.StampedPropertyPracticeGroup, Encoder.HtmlEncode(matterDetails.PracticeGroup));
            propertyList.Add(ServiceConstantStrings.StampedPropertyAreaOfLaw, Encoder.HtmlEncode(matterDetails.AreaOfLaw));
            propertyList.Add(ServiceConstantStrings.StampedPropertySubAreaOfLaw, Encoder.HtmlEncode(matterDetails.SubareaOfLaw));
            propertyList.Add(ServiceConstantStrings.StampedPropertyMatterName, Encoder.HtmlEncode(matter.Name));
            propertyList.Add(ServiceConstantStrings.StampedPropertyMatterID, Encoder.HtmlEncode(matter.Id));
            propertyList.Add(ServiceConstantStrings.StampedPropertyClientName, Encoder.HtmlEncode(client.Name));
            propertyList.Add(ServiceConstantStrings.StampedPropertyClientID, Encoder.HtmlEncode(client.Id));
            propertyList.Add(ServiceConstantStrings.StampedPropertyResponsibleAttorney, Encoder.HtmlEncode(matterDetails.ResponsibleAttorney));
            propertyList.Add(ServiceConstantStrings.StampedPropertyResponsibleAttorneyEmail, Encoder.HtmlEncode(matterDetails.ResponsibleAttorneyEmail));
            propertyList.Add(ServiceConstantStrings.StampedPropertyTeamMembers, Encoder.HtmlEncode(matterDetails.TeamMembers));
            propertyList.Add(ServiceConstantStrings.StampedPropertyIsMatter, ConstantStrings.TRUE);
            propertyList.Add(ServiceConstantStrings.StampedPropertyOpenDate, Encoder.HtmlEncode(DateTime.Now.ToString(ServiceConstantStrings.ValidDateFormat, CultureInfo.InvariantCulture)));
            propertyList.Add(ServiceConstantStrings.PropertyNameVtiIndexedPropertyKeys, Encoder.HtmlEncode(ServiceUtility.GetEncodedValueForSearchIndexProperty(keys)));
            propertyList.Add(ServiceConstantStrings.StampedPropertySecureMatter, (matter.Conflict != null) ? (matter.Conflict.SecureMatter != null) ? Encoder.HtmlEncode(matter.Conflict.SecureMatter) : "False" : "False");
            propertyList.Add(ServiceConstantStrings.StampedPropertyBlockedUploadUsers, Encoder.HtmlEncode(string.Join(";", matterDetails.UploadBlockedUsers)));
            propertyList.Add(ServiceConstantStrings.StampedPropertyMatterDescription, Encoder.HtmlEncode(matter.Description));
            propertyList.Add(ServiceConstantStrings.StampedPropertyConflictCheckDate, (string.IsNullOrEmpty(matter.Conflict.CheckOn)) ? "" : Encoder.HtmlEncode(Convert.ToDateTime(matter.Conflict.CheckOn, CultureInfo.InvariantCulture).ToString(ServiceConstantStrings.ValidDateFormat, CultureInfo.InvariantCulture)));
            propertyList.Add(ServiceConstantStrings.StampedPropertyConflictCheckBy, Encoder.HtmlEncode(matter.Conflict.CheckBy));
            propertyList.Add(ServiceConstantStrings.StampedPropertyMatterCenterRoles, Encoder.HtmlEncode(matterCenterRoles));
            propertyList.Add(ServiceConstantStrings.StampedPropertyMatterCenterPermissions, Encoder.HtmlEncode(matterCenterPermission));
            propertyList.Add(ServiceConstantStrings.StampedPropertyMatterCenterUsers, Encoder.HtmlEncode(matterCenterUsers));
            propertyList.Add(ServiceConstantStrings.StampedPropertyMatterCenterUserEmails, Encoder.HtmlEncode(matterCenterUserEmails));
            propertyList.Add(ServiceConstantStrings.StampedPropertyDefaultContentType, Encoder.HtmlEncode(matter.DefaultContentType));
            propertyList.Add(ServiceConstantStrings.StampedPropertyIsConflictIdentified, Encoder.HtmlEncode(matter.Conflict.Identified));
            propertyList.Add(ServiceConstantStrings.StampedPropertyDocumentTemplateCount, Encoder.HtmlEncode(documentTemplateCount));
            propertyList.Add(ServiceConstantStrings.StampedPropertyBlockedUsers, Encoder.HtmlEncode(string.Join(";", matter.BlockUserNames)));
            propertyList.Add(ServiceConstantStrings.StampedPropertyMatterGUID, Encoder.HtmlEncode(matter.MatterGuid));
            propertyList.Add(ServiceConstantStrings.StampedPropertySuccess, ConstantStrings.TRUE);
            return propertyList;
        }
        /// <summary>
        /// Creates an item in the specific list with the list of users to whom the matter will be shared.
        /// </summary>
        /// <param name="requestObject">Request Object containing SharePoint App Token</param>
        /// <param name="client">Client object containing Client data</param>
        /// <param name="matter">Matter object</param>
        /// <param name="matterDetails">Details of matter</param>
        /// <param name="matterLandingFlag">Flag to determine if Matter landing page exists</param>
        /// <param name="matterConfigurations">Object holding configuration for the matter</param>
        /// <returns>true if success else false</returns>
        internal static string ShareMatter(RequestObject requestObject, Client client, Matter matter, MatterDetails matterDetails, string matterLandingFlag, MatterConfigurations matterConfigurations)
        {
            string returnFlag = ConstantStrings.FALSE;

            if (null != requestObject && null != client && null != matter && null != matterDetails)
            {
                try
                {

                    Uri mailListURL = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}", ConstantStrings.ProvisionMatterAppURL, ConstantStrings.ForwardSlash, ConstantStrings.Lists, ConstantStrings.ForwardSlash, ConstantStrings.SendMailListName));
                    string centralMailListURL = Convert.ToString(mailListURL, CultureInfo.InvariantCulture);
                    string mailSiteURL = centralMailListURL.Substring(0, centralMailListURL.LastIndexOf(string.Concat(ConstantStrings.ForwardSlash, ConstantStrings.Lists, ConstantStrings.ForwardSlash), StringComparison.OrdinalIgnoreCase));
                    ///// Retrieve the specific site where the Mail List is present along with the required List Name
                    if (null != mailListURL && null != client.Url)
                    {
                        if (!string.IsNullOrWhiteSpace(mailSiteURL))
                        {
                            returnFlag = ProvisionHelperFunctions.ShareMatterUtility(requestObject, client, matter, matterDetails, mailSiteURL, centralMailListURL, matterLandingFlag, matterConfigurations);
                        }
                    }
                }

                catch (Exception exception)
                {
                    Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
                }
            }
            return returnFlag;
        }
예제 #5
0
 public string UpdateMatterDetails(RequestObject requestObject, Client client, Matter matter, MatterDetails matterDetails, string editMode, IList<string> userId)
 {
     string result = ConstantStrings.TRUE;
     if (null != requestObject && null != client && null != matter && null != matterDetails && (null != requestObject.RefreshToken || null != requestObject.SPAppToken) && ValidationHelperFunctions.CheckRequestValidatorToken())
     {
         IEnumerable<RoleAssignment> userPermissionOnLibrary = null;
         PropertyValues matterStampedProperties = null;
         int listItemId = -1;
         bool isEditMode = false;
         string editMatterValidation = string.Empty;
         string loggedInUserName = string.Empty;
         try
         {
             isEditMode = Convert.ToBoolean(editMode, CultureInfo.InvariantCulture);
             using (ClientContext clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(client.Url), requestObject.RefreshToken))
             {
                 List<string> listExists = ProvisionHelperFunctions.CheckListsExist(clientContext, matter.Name);
                 bool hasFullPermission = false;
                 try
                 {
                     editMatterValidation = ValidationHelperFunctions.ProvisionMatterValidation(requestObject, client, clientContext, matter, matterDetails, int.Parse(ConstantStrings.EditMatterPermission, CultureInfo.InvariantCulture), null);
                     if (string.IsNullOrWhiteSpace(editMatterValidation))
                     {
                         if (null != matter.Conflict && !string.IsNullOrWhiteSpace(matter.Conflict.Identified))
                         {
                             if (0 == matter.AssignUserEmails.Count())
                             {
                                 result = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputUserNamesCode, TextConstants.IncorrectInputUserNamesMessage);
                             }
                             else
                             {
                                 result = EditMatterHelperFunctions.ValidateTeamMembers(clientContext, matter, userId);
                                 if (string.IsNullOrEmpty(result))
                                 {
                                     result = ConstantStrings.TRUE;
                                     if (null != matter.Conflict && !string.IsNullOrWhiteSpace(matter.Conflict.Identified))
                                     {
                                         if (Convert.ToBoolean(matter.Conflict.Identified, CultureInfo.InvariantCulture))
                                         {
                                             result = EditMatterHelperFunctions.CheckSecurityGroupInTeamMembers(clientContext, matter, userId);
                                         }
                                     }
                                     else
                                     {
                                         result = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputConflictIdentifiedCode, TextConstants.IncorrectInputConflictIdentifiedMessage);
                                     }
                                 }
                             }
                         }
                         else
                         {
                             result = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputConflictIdentifiedCode, TextConstants.IncorrectInputConflictIdentifiedMessage);
                         }
                         if (string.Equals(result, ConstantStrings.TRUE, StringComparison.OrdinalIgnoreCase))
                         {
                             // Get matter stamped properties
                             matterStampedProperties = EditMatterHelperFunctions.FetchMatterStampedProperties(clientContext, matter.Name);
                             loggedInUserName = EditMatterHelperFunctions.GetUserUpdatingMatter(clientContext);
                             bool isFullControlPresent = EditMatterHelperFunctions.ValidateFullControlPermission(matter);
                             if (isFullControlPresent)
                             {
                                 // Get matter library current permissions
                                 userPermissionOnLibrary = EditMatterHelperFunctions.FetchUserPermission(clientContext, matter.Name);
                                 // Check if OneNote library, calendar, and matter landing page exists as separate objects
                                 string originalMatterName = EditMatterHelperFunctions.GetMatterName(clientContext, matter.Name);
                                 listItemId = Lists.RetrieveItemId(clientContext, ServiceConstantStrings.MatterLandingPageRepositoryName, originalMatterName);
                                 List<string> usersToRemove = EditMatterHelperFunctions.RetrieveMatterUsers(userPermissionOnLibrary);
                                 // Provide logged in user as full control on matter
                                 // 	Check whether logged in user has full permission on new permission changes
                                 hasFullPermission = EditMatterHelperFunctions.CheckFullPermissionInAssignList(matter.AssignUserEmails, matter.Permissions, loggedInUserName);
                                 EditMatterHelperFunctions.AssignRemoveFullControl(clientContext, matter, loggedInUserName, listItemId, listExists, true, hasFullPermission);
                                 if (listExists.Contains(matter.Name))
                                 {
                                     result = EditMatterHelperFunctions.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name, -1, isEditMode);
                                 }
                                 if (listExists.Contains(matter.Name + ServiceConstantStrings.OneNoteLibrarySuffix))
                                 {
                                     result = EditMatterHelperFunctions.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name + ServiceConstantStrings.OneNoteLibrarySuffix, -1, isEditMode);
                                 }
                                 if (listExists.Contains(matter.Name + ServiceConstantStrings.CalendarNameSuffix))
                                 {
                                     result = EditMatterHelperFunctions.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name + ServiceConstantStrings.CalendarNameSuffix, -1, isEditMode);
                                 }
                                 if (listExists.Contains(matter.Name + ServiceConstantStrings.TaskNameSuffix))
                                 {
                                     result = EditMatterHelperFunctions.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name + ServiceConstantStrings.TaskNameSuffix, -1, isEditMode);
                                 }
                                 result = EditMatterHelperFunctions.UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, true, ServiceConstantStrings.MatterLandingPageRepositoryName, listItemId, isEditMode);
                                 // Update matter metadata
                                 result = EditMatterHelperFunctions.UpdateMatterStampedProperties(clientContext, matterDetails, matter, matterStampedProperties, isEditMode);
                             }
                             else
                             {
                                 result = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, ServiceConstantStrings.IncorrectInputSelfPermissionRemoval, ServiceConstantStrings.ErrorEditMatterMandatoryPermission);
                             }
                         }
                     }
                     else
                     {
                         result = editMatterValidation;
                     }
                 }
                 catch (Exception exception)
                 {
                     MatterRevertList matterRevertListObject = new MatterRevertList()
                     {
                         MatterLibrary = matter.Name,
                         MatterOneNoteLibrary = matter.Name + ServiceConstantStrings.OneNoteLibrarySuffix,
                         MatterCalendar = matter.Name + ServiceConstantStrings.CalendarNameSuffix,
                         MatterTask = matter.Name + ServiceConstantStrings.TaskNameSuffix,
                         MatterSitePages = ServiceConstantStrings.MatterLandingPageRepositoryName
                     };
                     EditMatterHelperFunctions.RevertMatterUpdates(requestObject, client, matter, clientContext, matterRevertListObject, loggedInUserName, userPermissionOnLibrary, listItemId, isEditMode);
                     result = Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
                 }
                 finally
                 {
                     // Remove full control for logged in users
                     EditMatterHelperFunctions.AssignRemoveFullControl(clientContext, matter, loggedInUserName, listItemId, listExists, false, hasFullPermission);
                 }
             }
         }
         catch (Exception exception)
         {
             result = Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
         }
     }
     else
     {
         result = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, string.Empty, TextConstants.MessageNoInputs);
     }
     return result;
 }
예제 #6
0
        public string UpdateMetadataForList(RequestObject requestObject, Client client, Matter matter, MatterDetails matterDetails, MatterProvisionFlags matterProvisionChecks, MatterConfigurations matterConfigurations)
        {
            string result = ConstantStrings.FALSE;
            string properties = ConstantStrings.FALSE;
            string ProvisionMatterValidation = string.Empty;
            if (null != requestObject && null != client && null != matter && null != matterDetails && (null != requestObject.RefreshToken || null != requestObject.SPAppToken) && (null != matterProvisionChecks) && ValidationHelperFunctions.CheckRequestValidatorToken())
            {
                using (ClientContext clientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(client.Url), requestObject.RefreshToken))
                {
                    string shareMatterFlag = string.Empty;
                    ProvisionMatterValidation = ValidationHelperFunctions.ProvisionMatterValidation(requestObject, client, clientContext, matter, matterDetails, int.Parse(ConstantStrings.ProvisionMatterUpdateMetadataForList, CultureInfo.InvariantCulture), matterConfigurations);
                    if (string.IsNullOrWhiteSpace(ProvisionMatterValidation))
                    {
                        try
                        {
                            var props = clientContext.Web.Lists.GetByTitle(matter.Name).RootFolder.Properties;
                            Dictionary<string, string> propertyList = new Dictionary<string, string>();
                            propertyList = ProvisionHelperFunctions.SetStampProperty(client, matter, matterDetails);
                            clientContext.Load(props);
                            clientContext.ExecuteQuery();
                            Lists.SetPropertBagValuesForList(clientContext, props, matter.Name, propertyList);
                            if (matterProvisionChecks.SendEmailFlag)
                            {
                                shareMatterFlag = ProvisionHelperFunctions.ShareMatter(requestObject, client, matter, matterDetails, matterProvisionChecks.MatterLandingFlag, matterConfigurations);
                            }
                            else
                            {
                                shareMatterFlag = ConstantStrings.TRUE;
                            }
                            properties = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, string.Empty, shareMatterFlag);
                        }

                        catch (Exception exception)
                        {
                            properties = Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
                            ProvisionHelperFunctions.DeleteMatter(requestObject, client, matter);
                        }
                    }
                    else
                    {
                        ProvisionHelperFunctions.DeleteMatter(requestObject, client, matter);
                        properties = ProvisionMatterValidation;
                    }
                    result = properties;
                }
            }
            else
            {
                result = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, string.Empty, TextConstants.MessageNoInputs);
            }
            return result;
        }
 /// <summary>
 /// Validates the inputs for matter provision app and returns the validation status (success/failure).
 /// </summary>
 /// <param name="requestObject">Request Object containing SharePoint App Token</param>
 /// <param name="client">Client object containing Client data</param>
 /// <param name="clientContext">Client context object for SharePoint</param>
 /// <param name="matter">Matter object containing Matter data</param>
 /// <param name="matterDetails">Matter details object which has data of properties to be stamped</param>
 /// <param name="methodNumber">Number indicating which method needs to be validated</param>
 /// <returns>A string value indicating whether validations passed or fail</returns>
 internal static string ProvisionMatterValidation(RequestObject requestObject, Client client, ClientContext clientContext, Matter matter, MatterDetails matterDetails, int methodNumber, MatterConfigurations matterConfigurations)
 {
     if (int.Parse(ConstantStrings.ProvisionMatterCreateMatter, CultureInfo.InvariantCulture) <= methodNumber && int.Parse(ConstantStrings.EditMatterPermission, CultureInfo.InvariantCulture) >= methodNumber && !Lists.CheckPermissionOnList(ServiceUtility.GetClientContext(null, new Uri(ConstantStrings.ProvisionMatterAppURL), requestObject.RefreshToken), ConstantStrings.SendMailListName, PermissionKind.EditListItems))
     {
         return string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, ServiceConstantStrings.IncorrectInputUserAccessCode, ServiceConstantStrings.IncorrectInputUserAccessMessage);
     }
     else
     {
         if (null != requestObject)
         {
             if (string.IsNullOrWhiteSpace(requestObject.RefreshToken) && string.IsNullOrWhiteSpace(requestObject.SPAppToken))
             {
                 return string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputRequestObjectCode, TextConstants.IncorrectInputRequestObjectMessage);
             }
         }
         if (null != client)
         {
             string result = ValidateClientInformation(client, methodNumber);
             if (!string.IsNullOrEmpty(result))
             {
                 return result;
             }
         }
         if (null != matter)
         {
             string MatterMetadataValidationResponse = MatterMetadataValidation(matter, clientContext, methodNumber, matterConfigurations);
             if (!string.IsNullOrEmpty(MatterMetadataValidationResponse))
             {
                 return MatterMetadataValidationResponse;
             }
             if (int.Parse(ConstantStrings.EditMatterPermission, CultureInfo.InvariantCulture) == methodNumber)
             {
                 string roleCheck = ValidationHelperFunctions.RoleCheck(requestObject, matter, client);
                 if (!string.IsNullOrEmpty(roleCheck))
                 {
                     return roleCheck;
                 }
             }
             if (null != matter.Permissions)
             {
                 bool isFullControlPresent = EditMatterHelperFunctions.ValidateFullControlPermission(matter);
                 if (!isFullControlPresent)
                 {
                     return string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, ServiceConstantStrings.IncorrectInputUserAccessCode, ServiceConstantStrings.ErrorEditMatterMandatoryPermission);
                 }
             }
         }
         if (null != matterDetails && !(int.Parse(ConstantStrings.EditMatterPermission, CultureInfo.InvariantCulture) == methodNumber))
         {
             if (string.IsNullOrWhiteSpace(matterDetails.PracticeGroup))
             {
                 return string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputPracticeGroupCode, TextConstants.IncorrectInputPracticeGroupMessage);
             }
             if (string.IsNullOrWhiteSpace(matterDetails.AreaOfLaw))
             {
                 return string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputAreaOfLawCode, TextConstants.IncorrectInputAreaOfLawMessage);
             }
             if (string.IsNullOrWhiteSpace(matterDetails.SubareaOfLaw))
             {
                 return string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputSubareaOfLawCode, TextConstants.IncorrectInputSubareaOfLawMessage);
             }
             try
             {
                 if (string.IsNullOrWhiteSpace(matterDetails.ResponsibleAttorney))
                 {
                     return string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputResponsibleAttorneyCode, TextConstants.IncorrectInputResponsibleAttorneyMessage);
                 }
                 else
                 {
                     IList<string> userNames = matterDetails.ResponsibleAttorney.Split(';').ToList<string>();
                     SharePointHelper.ResolveUserNames(clientContext, userNames).FirstOrDefault();
                 }
             }
             catch (Exception)
             {
                 return string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputResponsibleAttorneyCode, TextConstants.IncorrectInputResponsibleAttorneyMessage);
             }
         }
     }
     return string.Empty;
 }
 /// <summary>
 /// Extracts matter details from matter library property bag.
 /// </summary>
 /// <param name="stampedPropertyValues">Dictionary object containing matter property bag key/value pairs</param>
 /// <returns>Matter details from matter library property bag</returns>
 internal static MatterDetails ExtractMatterDetails(Dictionary<string, object> stampedPropertyValues)
 {
     MatterDetails matterDetails = new MatterDetails()
     {
         PracticeGroup = GetStampPropertyValue(stampedPropertyValues, ServiceConstantStrings.StampedPropertyPracticeGroup),
         AreaOfLaw = GetStampPropertyValue(stampedPropertyValues, ServiceConstantStrings.StampedPropertyAreaOfLaw),
         SubareaOfLaw = GetStampPropertyValue(stampedPropertyValues, ServiceConstantStrings.StampedPropertySubAreaOfLaw),
         ResponsibleAttorney = GetStampPropertyValue(stampedPropertyValues, ServiceConstantStrings.StampedPropertyResponsibleAttorney),
         TeamMembers = GetStampPropertyValue(stampedPropertyValues, ServiceConstantStrings.StampedPropertyTeamMembers),
         UploadBlockedUsers = GetStampPropertyValue(stampedPropertyValues, ServiceConstantStrings.StampedPropertyBlockedUploadUsers).Split(new string[] { ConstantStrings.Semicolon }, StringSplitOptions.RemoveEmptyEntries).ToList()
     };
     return matterDetails;
 }
        /// <summary>
        /// Updates the matter stamped properties with new details for user permissions.
        /// </summary>
        /// <param name="clientContext">ClientContext object</param>
        /// <param name="matterDetails">MatterDetails object</param>
        /// <param name="matter">Matter object</param>
        /// <param name="matterStampedProperties">Matter stamped properties</param>
        /// <param name="isEditMode">Page opened in edit mode</param>
        /// <returns>Status of operation</returns>
        internal static string UpdateMatterStampedProperties(ClientContext clientContext, MatterDetails matterDetails, Matter matter, PropertyValues matterStampedProperties, bool isEditMode)
        {
            string result = ConstantStrings.FALSE;
            try
            {
                if (null != clientContext && null != matter && null != matterDetails && (0 < matterStampedProperties.FieldValues.Count))
                {
                    Dictionary<string, string> propertyList = new Dictionary<string, string>();

                    // Get existing stamped properties
                    string stampedUsers = GetStampPropertyValue(matterStampedProperties.FieldValues, ServiceConstantStrings.StampedPropertyMatterCenterUsers);
                    string stampedPermissions = GetStampPropertyValue(matterStampedProperties.FieldValues, ServiceConstantStrings.StampedPropertyMatterCenterPermissions);
                    string stampedRoles = GetStampPropertyValue(matterStampedProperties.FieldValues, ServiceConstantStrings.StampedPropertyMatterCenterRoles);
                    string stampedResponsibleAttorneys = GetStampPropertyValue(matterStampedProperties.FieldValues, ServiceConstantStrings.StampedPropertyResponsibleAttorney);
                    string stampedTeamMembers = GetStampPropertyValue(matterStampedProperties.FieldValues, ServiceConstantStrings.StampedPropertyTeamMembers);
                    string stampedBlockedUploadUsers = GetStampPropertyValue(matterStampedProperties.FieldValues, ServiceConstantStrings.StampedPropertyBlockedUploadUsers);

                    string currentPermissions = string.Join(ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR, matter.Permissions.Where(user => !string.IsNullOrWhiteSpace(user)));
                    string currentRoles = string.Join(ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR, matter.Roles.Where(user => !string.IsNullOrWhiteSpace(user)));
                    string currentBlockedUploadUsers = string.Join(ConstantStrings.Semicolon, matterDetails.UploadBlockedUsers.Where(user => !string.IsNullOrWhiteSpace(user)));
                    string currentUsers = GetMatterAssignedUsers(matter);

                    string finalMatterPermissions = string.IsNullOrWhiteSpace(stampedPermissions) || isEditMode ? currentPermissions : string.Concat(stampedPermissions, ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR, currentPermissions);
                    string finalMatterRoles = string.IsNullOrWhiteSpace(stampedRoles) || isEditMode ? currentRoles : string.Concat(stampedRoles, ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR, currentRoles);
                    string finalResponsibleAttorneys = string.IsNullOrWhiteSpace(stampedResponsibleAttorneys) || isEditMode ? matterDetails.ResponsibleAttorney : string.Concat(stampedResponsibleAttorneys, ConstantStrings.Semicolon, matterDetails.ResponsibleAttorney);
                    string finalTeamMembers = string.IsNullOrWhiteSpace(stampedTeamMembers) || isEditMode ? matterDetails.TeamMembers : string.Concat(stampedTeamMembers, ConstantStrings.Semicolon, matterDetails.TeamMembers);
                    string finalMatterCenterUsers = string.IsNullOrWhiteSpace(stampedUsers) || isEditMode ? currentUsers : string.Concat(stampedUsers, ConstantStrings.DOLLAR + ConstantStrings.Pipe + ConstantStrings.DOLLAR, currentUsers);
                    string finalBlockedUploadUsers = string.IsNullOrWhiteSpace(stampedBlockedUploadUsers) || isEditMode ? currentBlockedUploadUsers : string.Concat(stampedBlockedUploadUsers, ConstantStrings.Semicolon, currentBlockedUploadUsers);

                    propertyList.Add(ServiceConstantStrings.StampedPropertyResponsibleAttorney, Encoder.HtmlEncode(finalResponsibleAttorneys));
                    propertyList.Add(ServiceConstantStrings.StampedPropertyTeamMembers, Encoder.HtmlEncode(finalTeamMembers));
                    propertyList.Add(ServiceConstantStrings.StampedPropertyBlockedUploadUsers, Encoder.HtmlEncode(finalBlockedUploadUsers));
                    propertyList.Add(ServiceConstantStrings.StampedPropertyMatterCenterRoles, Encoder.HtmlEncode(finalMatterRoles));
                    propertyList.Add(ServiceConstantStrings.StampedPropertyMatterCenterPermissions, Encoder.HtmlEncode(finalMatterPermissions));
                    propertyList.Add(ServiceConstantStrings.StampedPropertyMatterCenterUsers, Encoder.HtmlEncode(finalMatterCenterUsers));

                    Lists.SetPropertBagValuesForList(clientContext, matterStampedProperties, matter.Name, propertyList);
                    result = ConstantStrings.TRUE;
                }
            }
            catch (Exception)
            {
                throw; //// This will transfer control to catch block of parent function.
            }
            return result;
        }