public void UpdateUserPermissionsForMatter(MatterInformationVM matterInformation, IConfigurationRoot configuration, System.Security.SecureString securePassword) { 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 = new ClientContext(matterInformation.Client.Url); clientContext.Credentials = new SharePointOnlineCredentials(configuration["General:AdminUserName"], securePassword); //if (null != matter.Conflict && !string.IsNullOrWhiteSpace(matter.Conflict.Identified)) //{ // if (Convert.ToBoolean(matter.Conflict.Identified, System.Globalization.CultureInfo.InvariantCulture)) // { // genericResponse = CheckSecurityGroupInTeamMembers(clientContext, matter, matterInformation.UserIds); // } //} //else //{ // //genericResponse = string.Format(System.Globalization.CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, TextConstants.IncorrectInputConflictIdentifiedCode, TextConstants.IncorrectInputConflictIdentifiedMessage); // return; //} //if (genericResponse == null) //{ PropertyValues matterStampedProperties = SPList.GetListProperties(clientContext, matter.Name); loggedInUserName = SPList.GetLoggedInUserDetails(clientContext).Name; // Get matter library current permissions userPermissionOnLibrary = SPList.FetchUserPermissionForLibrary(clientContext, matter.Name); string originalMatterName = SPList.GetMatterName(clientContext, matter.Name); listItemId = SPList.RetrieveItemId(clientContext, "Site Pages", originalMatterName); List<string> usersToRemove = RetrieveMatterUsers(userPermissionOnLibrary); bool hasFullPermission = CheckFullPermissionInAssignList(matter.AssignUserNames, matter.Permissions, loggedInUserName); List<string> listExists = MatterAssociatedLists(clientContext, matter.Name); AssignRemoveFullControl(clientContext, matter, loggedInUserName, listItemId, listExists, true, hasFullPermission); bool result = false; if (listExists.Contains(matter.Name)) { result = UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name, -1, isEditMode); } if (listExists.Contains(matter.Name + configuration["Matter:OneNoteLibrarySuffix"])) { result = UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name + configuration["Matter:OneNoteLibrarySuffix"], -1, isEditMode); } if (listExists.Contains(matter.Name + configuration["Matter:CalendarNameSuffix"])) { result = UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name + configuration["Matter:CalendarNameSuffix"], -1, isEditMode); } if (listExists.Contains(matter.Name + configuration["Matter:TaskNameSuffix"])) { result = UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, false, matter.Name + configuration["Matter:TaskNameSuffix"], -1, isEditMode); } if (0 <= listItemId) { result = UpdatePermission(clientContext, matter, usersToRemove, loggedInUserName, true, "Site Pages", listItemId, isEditMode); } // Update matter metadata result = UpdateMatterStampedProperties(clientContext, matterDetails, matter, matterStampedProperties, isEditMode, configuration); //} } catch (Exception ex) { MatterRevertList matterRevertListObject = new MatterRevertList() { MatterLibrary = matter.Name, MatterOneNoteLibrary = matter.Name + configuration["Matter:OneNoteLibrarySuffix"], MatterCalendar = matter.Name + configuration["Matter:CalendarNameSuffix"], MatterTask = matter.Name + configuration["Matter:TaskNameSuffix"], MatterSitePages = "Site Pages" }; RevertMatterUpdates(client, matter, clientContext, matterRevertListObject, loggedInUserName, userPermissionOnLibrary, listItemId, isEditMode); } //return ServiceUtility.GenericResponse("9999999", "Error in updating matter information"); }
/// <summary> /// Updates matter /// </summary> /// <param name="client">Client object containing Client data</param> /// <param name="details">Term Store object containing Term store data</param> /// <returns>Returns JSON object to the client</returns> /// public IActionResult Update([FromBody]MatterInformationVM matterInformation) { string editMatterValidation = string.Empty; var matter = matterInformation.Matter; var client = matterInformation.Client; var userid = matterInformation.UserIds; try { spoAuthorization.AccessToken = HttpContext.Request.Headers["Authorization"]; #region Error Checking ErrorResponse errorResponse = null; if (matterInformation.Client == null && matterInformation.Matter == null && matterInformation.MatterDetails == null) { errorResponse = new ErrorResponse() { Message = errorSettings.MessageNoInputs, ErrorCode = HttpStatusCode.BadRequest.ToString(), Description = "No input data is passed" }; return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest); } #endregion #region Validations GenericResponseVM validationResponse = validationFunctions.IsMatterValid(matterInformation, int.Parse(ServiceConstants.EditMatterPermission), null); if(validationResponse != null) { errorResponse = new ErrorResponse() { Message = validationResponse.Value, ErrorCode = validationResponse.Code, }; return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest); } if (null != matter.Conflict && !string.IsNullOrWhiteSpace(matter.Conflict.Identified)) { if (matter.AssignUserNames.Count==0) { errorResponse = new ErrorResponse() { Message = errorSettings.IncorrectInputUserNamesMessage, ErrorCode = errorSettings.IncorrectInputUserNamesCode, }; return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest); } else { if (Convert.ToBoolean(matter.Conflict.Identified, CultureInfo.InvariantCulture)) { validationResponse = editFunctions.CheckSecurityGroupInTeamMembers(client, matter, userid); if (validationResponse != null) { errorResponse = new ErrorResponse() { Message = validationResponse.Value, ErrorCode = validationResponse.Code, }; return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest); } } } } else { errorResponse = new ErrorResponse() { Message = errorSettings.IncorrectInputConflictIdentifiedMessage, ErrorCode = errorSettings.IncorrectInputConflictIdentifiedCode, }; return matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.BadRequest); } #endregion #region Upadte Matter GenericResponseVM genericResponse = matterProvision.UpdateMatter(matterInformation); if(genericResponse==null) { var result = new GenericResponseVM() { Code = "200", Value= "Update Success" }; return matterCenterServiceFunctions.ServiceResponse(result, (int)HttpStatusCode.OK); } else { return matterCenterServiceFunctions.ServiceResponse(genericResponse, (int)HttpStatusCode.NotModified); } #endregion } catch (Exception ex) { MatterRevertList matterRevertListObject = new MatterRevertList() { MatterLibrary = matterInformation.Matter.Name, MatterOneNoteLibrary = matterInformation.Matter.Name + matterSettings.OneNoteLibrarySuffix, MatterCalendar = matterInformation.Matter.Name + matterSettings.CalendarNameSuffix, MatterTask = matterInformation.Matter.Name + matterSettings.TaskNameSuffix, MatterSitePages = matterSettings.MatterLandingPageRepositoryName }; //editFunctions.RevertMatterUpdates(client, matter, matterRevertListObject, loggedInUserName, userPermissionOnLibrary, listItemId, isEditMode); customLogger.LogError(ex, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable); throw; } finally { } }
/// <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> public bool RevertMatterUpdates(Client client, Matter matter, ClientContext clientContext, MatterRevertList matterRevertListObject, string loggedInUserTitle, IEnumerable<RoleAssignment> oldUserPermissions, int matterLandingPageId, bool isEditMode) { bool result = false; try { if (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) { SPList.RemoveSpecificUsers(clientContext, users, loggedInUserTitle, false, matterRevertListObject.MatterLibrary, -1); } if (null != matterRevertListObject.MatterCalendar) { SPList.RemoveSpecificUsers(clientContext, users, loggedInUserTitle, false, matterRevertListObject.MatterCalendar, -1); } if (null != matterRevertListObject.MatterOneNoteLibrary) { SPList.RemoveSpecificUsers(clientContext, users, loggedInUserTitle, false, matterRevertListObject.MatterOneNoteLibrary, -1); } if (null != matterRevertListObject.MatterTask) { SPList.RemoveSpecificUsers(clientContext, users, loggedInUserTitle, false, matterRevertListObject.MatterTask, -1); } if (null != matterRevertListObject.MatterSitePages) { SPList.RemoveSpecificUsers(clientContext, users, loggedInUserTitle, true, matterRevertListObject.MatterSitePages, matterLandingPageId); } if (isEditMode) { Matter matterRevertUserPermission = PrepareUserPermission(oldUserPermissions); if (null != matterRevertListObject.MatterLibrary) { result = SPList.SetPermission(clientContext, matterRevertUserPermission.AssignUserNames, matterRevertUserPermission.Permissions, matterRevertListObject.MatterLibrary); } if (null != matterRevertListObject.MatterOneNoteLibrary) { result = SPList.SetPermission(clientContext, matterRevertUserPermission.AssignUserNames, matterRevertUserPermission.Permissions, matterRevertListObject.MatterOneNoteLibrary); } if (null != matterRevertListObject.MatterCalendar) { result = SPList.SetPermission(clientContext, matterRevertUserPermission.AssignUserNames, matterRevertUserPermission.Permissions, matterRevertListObject.MatterCalendar); } if (null != matterRevertListObject.MatterTask) { result = SPList.SetPermission(clientContext, matterRevertUserPermission.AssignUserNames, matterRevertUserPermission.Permissions, matterRevertListObject.MatterTask); } if (null != matterRevertListObject.MatterSitePages && 0 <= matterLandingPageId) { result = SPList.SetItemPermission(clientContext, matterRevertUserPermission.AssignUserNames, "Site Pages", matterLandingPageId, matterRevertUserPermission.Permissions); } } } return result; } catch (Exception exception) { //Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstants.LogTableName); } // To avoid the invalid symbol error while parsing the JSON, return the response in lower case return result; }
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"); }