private void saveCodeActivity_Save_ExecuteCode(object sender, EventArgs e) { IUserGroup userGroup = this.GetBinding <IUserGroup>("UserGroup"); List <string> newUserGroupEntityTokens = ActivePerspectiveFormsHelper.GetSelectedSerializedEntityTokens(this.Bindings).ToList(); // If current user belongs to currently edited group -> checking that user won't lost access "Users" perspective if (!ValidateUserPreservesAdminRights(userGroup, newUserGroupEntityTokens)) { return; } UpdateTreeRefresher updateTreeRefresher = CreateUpdateTreeRefresher(this.EntityToken); EntityToken rootEntityToken = ElementFacade.GetRootsWithNoSecurity().Select(f => f.ElementHandle.EntityToken).Single(); IEnumerable <PermissionType> newPermissionTypes = GlobalPermissionsFormsHelper.GetSelectedPermissionTypes(this.Bindings); UserGroupPermissionDefinition userGroupPermissionDefinition = new ConstructorBasedUserGroupPermissionDefinition( userGroup.Id, newPermissionTypes, EntityTokenSerializer.Serialize(rootEntityToken) ); PermissionTypeFacade.SetUserGroupPermissionDefinition(userGroupPermissionDefinition); UserGroupPerspectiveFacade.SetSerializedEntityTokens(userGroup.Id, newUserGroupEntityTokens); SetSaveStatus(true); LoggingService.LogEntry("UserManagement", $"C1 Console user group '{userGroup.Name}' updated by '{UserValidationFacade.GetUsername()}'.", LoggingService.Category.Audit, TraceEventType.Information); if (userGroup.Name != this.GetBinding <string>("OldName")) { DataFacade.Update(userGroup); this.UpdateBinding("OldName", userGroup.Name); updateTreeRefresher.PostRefreshMesseges(userGroup.GetDataEntityToken()); } }
private void saveCodeActivity_Save_ExecuteCode(object sender, EventArgs e) { IUserGroup userGroup = this.GetBinding <IUserGroup>("UserGroup"); List <string> newUserGroupEntityTokens = ActivePerspectiveFormsHelper.GetSelectedSerializedEntityTokens(this.Bindings).ToList(); // If current user belongs to currently edited group -> checking that user won't lost access "Users" perspective if (!ValidateUserPreservesAdminRights(userGroup, newUserGroupEntityTokens)) { return; } UpdateTreeRefresher updateTreeRefresher = CreateUpdateTreeRefresher(this.EntityToken); EntityToken rootEntityToken = ElementFacade.GetRootsWithNoSecurity().Select(f => f.ElementHandle.EntityToken).Single(); IEnumerable <PermissionType> newPermissionTypes = GlobalPermissionsFormsHelper.GetSelectedPermissionTypes(this.Bindings); UserGroupPermissionDefinition userGroupPermissionDefinition = new ConstructorBasedUserGroupPermissionDefinition( userGroup.Id, newPermissionTypes, EntityTokenSerializer.Serialize(rootEntityToken) ); PermissionTypeFacade.SetUserGroupPermissionDefinition(userGroupPermissionDefinition); UserGroupPerspectiveFacade.SetSerializedEntityTokens(userGroup.Id, newUserGroupEntityTokens); List <CultureInfo> selectedUserGroupActiveLocales = ActiveLocalesFormsHelper.GetSelectedLocalesTypes(this.Bindings).ToList(); using (var connection = new DataConnection()) { var existingLocales = connection.Get <IUserGroupActiveLocale>().Where(f => f.UserGroupId == userGroup.Id).ToList(); var toDelete = existingLocales.Where(f => !selectedUserGroupActiveLocales.Contains(new CultureInfo(f.CultureName))); connection.Delete <IUserGroupActiveLocale>(toDelete); foreach (var localeToAdd in selectedUserGroupActiveLocales.Where(f => !existingLocales.Any(g => g.CultureName == f.Name))) { var toAdd = connection.CreateNew <IUserGroupActiveLocale>(); toAdd.Id = Guid.NewGuid(); toAdd.UserGroupId = userGroup.Id; toAdd.CultureName = localeToAdd.Name; connection.Add(toAdd); } } SetSaveStatus(true); LoggingService.LogEntry("UserManagement", $"C1 Console user group '{userGroup.Name}' updated by '{UserValidationFacade.GetUsername()}'.", LoggingService.Category.Audit, TraceEventType.Information); if (userGroup.Name != this.GetBinding <string>("OldName")) { DataFacade.Update(userGroup); this.UpdateBinding("OldName", userGroup.Name); updateTreeRefresher.PostRefreshMesseges(userGroup.GetDataEntityToken()); } }