Ejemplo n.º 1
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;
 }
        /// <summary>
        /// Reverts the permission of users from matter, OneNote, Calendar libraries and matter landing page
        /// </summary>
        /// <param name="requestObject">Request object</param>
        /// <param name="client">Client object</param>
        /// <param name="matter">Matter object</param>
        /// <param name="clientContext">ClientContext object</param>
        /// <param name="matterRevertListObject">MatterRevertObjectList object</param>
        /// <param name="loggedInUserTitle">Logged-in user title</param>
        /// <param name="oldUserPermissions">Old library users</param>
        /// <param name="matterLandingPageId">List item id</param>
        /// <param name="isEditMode">Add/ Edit mode</param>
        /// <returns>Status of operation</returns>
        internal static string RevertMatterUpdates(RequestObject requestObject, Client client, Matter matter, ClientContext clientContext, MatterRevertList matterRevertListObject, string loggedInUserTitle, IEnumerable<RoleAssignment> oldUserPermissions, int matterLandingPageId, bool isEditMode)
        {
            bool result = false;
            try
            {
                if (null != requestObject && null != client && null != matter && null != clientContext && null != matterRevertListObject)
                {
                    List<string> users = new List<string>();
                    users = matter.AssignUserNames.SelectMany(user => user).Distinct().ToList();

                    // Remove recently added users
                    if (null != matterRevertListObject.MatterLibrary)
                    {
                        RemoveSpecificUsers(clientContext, users, loggedInUserTitle, false, matterRevertListObject.MatterLibrary, -1);
                    }
                    if (null != matterRevertListObject.MatterCalendar)
                    {
                        RemoveSpecificUsers(clientContext, users, loggedInUserTitle, false, matterRevertListObject.MatterCalendar, -1);
                    }
                    if (null != matterRevertListObject.MatterOneNoteLibrary)
                    {
                        RemoveSpecificUsers(clientContext, users, loggedInUserTitle, false, matterRevertListObject.MatterOneNoteLibrary, -1);
                    }
                    if (null != matterRevertListObject.MatterTask)
                    {
                        RemoveSpecificUsers(clientContext, users, loggedInUserTitle, false, matterRevertListObject.MatterTask, -1);
                    }
                    if (null != matterRevertListObject.MatterSitePages)
                    {
                        RemoveSpecificUsers(clientContext, users, loggedInUserTitle, true, matterRevertListObject.MatterSitePages, matterLandingPageId);
                    }

                    if (isEditMode)
                    {
                        Matter matterRevertUserPermission = PrepareUserPermission(oldUserPermissions);
                        if (null != matterRevertListObject.MatterLibrary)
                        {
                            result = Lists.SetPermission(clientContext, matterRevertUserPermission.AssignUserNames, matterRevertUserPermission.Permissions, matterRevertListObject.MatterLibrary);
                        }
                        if (null != matterRevertListObject.MatterOneNoteLibrary)
                        {
                            result = Lists.SetPermission(clientContext, matterRevertUserPermission.AssignUserNames, matterRevertUserPermission.Permissions, matterRevertListObject.MatterOneNoteLibrary);
                        }
                        if (null != matterRevertListObject.MatterCalendar)
                        {
                            result = Lists.SetPermission(clientContext, matterRevertUserPermission.AssignUserNames, matterRevertUserPermission.Permissions, matterRevertListObject.MatterCalendar);
                        }
                        if (null != matterRevertListObject.MatterTask)
                        {
                            result = Lists.SetPermission(clientContext, matterRevertUserPermission.AssignUserNames, matterRevertUserPermission.Permissions, matterRevertListObject.MatterTask);
                        }
                        if (null != matterRevertListObject.MatterSitePages && 0 <= matterLandingPageId)
                        {
                            result = Lists.SetItemPermission(clientContext, matterRevertUserPermission.AssignUserNames, ServiceConstantStrings.MatterLandingPageRepositoryName, matterLandingPageId, matterRevertUserPermission.Permissions);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }
            // To avoid the invalid symbol error while parsing the JSON, return the response in lower case
            return Convert.ToString(result,CultureInfo.CurrentCulture).ToLower(CultureInfo.CurrentUICulture);
        }