public UserList GetUserList(string token, UserSearchCriteria criteria) { throw new NotImplementedException(); }
/// <summary> /// Finds the users matching <paramref name="criteria"/>. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns>The users matching <paramref name="criteria"/>.</returns> public List<OptionSourceUser> FindUsers(UserSearchCriteria criteria) { return this.dataAccess.FindUsers(criteria); }
/// <summary> /// Finds the list of users that match the criteria. /// </summary> /// <param name="filter">Filters the results to only users that match.</param> /// <param name="tablesorterMetadata">The tablesorter metadata.</param> /// <returns> /// The list of users that match the criteria. /// </returns> protected override UserList DoFindUsers(UserSearchCriteria filter, TablesorterMetadata tablesorterMetadata = null) { MongoCollection<BsonDocument> collection = this.database.GetCollection(iApplyDb.UserAccess._COLLECTION_NAME); QueryDocument outerQuery = new QueryDocument(); List<IMongoQuery> orQueries = new List<IMongoQuery>(); if (filter.OrganisationIds != null && filter.OrganisationIds.Any()) { orQueries.AddRange(filter.OrganisationIds.Select(organisationId => Query.Exists(string.Format("{0}.{1}", iApplyDb.UserAccess.ORGANISATIONS, organisationId)))); } if (filter.IncludeNoOrganisationUsers) { orQueries.Add(Query.NotExists(iApplyDb.UserAccess.ORGANISATIONS)); orQueries.Add(Query.EQ(iApplyDb.UserAccess.ORGANISATIONS, new BsonDocument())); } if (!filter.IncludeServiceUsers) { outerQuery.AddRange(Query.NE(iApplyDb.UserAccess.ACCOUNT_TYPE, new BsonString(AccountType.Service.ToString())).ToBsonDocument()); } if (filter.RoleIds != null && filter.RoleIds.Any()) { orQueries.AddRange(filter.RoleIds.Select(roleId => Query.Exists(string.Format("{0}.{1}", iApplyDb.UserAccess.ROLES, roleId)))); } IMongoQuery subQuery; if (orQueries.Count > 0) { subQuery = Query.Or(orQueries); outerQuery.AddRange(subQuery.ToBsonDocument()); } if (filter.UserIds != null && filter.UserIds.Any()) { BsonArray bsonUserIds = new BsonArray(); bsonUserIds.AddRange(filter.UserIds.Select(u => new BsonObjectId(new ObjectId(u)))); subQuery = Query.In(iApplyDb.UserAccess._ID, bsonUserIds); outerQuery.AddRange(subQuery.ToBsonDocument()); } if (filter.Usernames != null && filter.Usernames.Any()) { BsonArray bsonUserNames = new BsonArray(); bsonUserNames.AddRange(filter.Usernames.Select(u => new BsonString(u))); subQuery = Query.In(iApplyDb.UserAccess.USERNAME, bsonUserNames); outerQuery.AddRange(subQuery.ToBsonDocument()); } if (filter.ExternalIds != null && filter.ExternalIds.Any()) { BsonArray bsonExternalIds = new BsonArray(); bsonExternalIds.AddRange(filter.ExternalIds.Select(u => new BsonString(u))); subQuery = Query.In(iApplyDb.UserAccess.EXTERNAL_ID, bsonExternalIds); outerQuery.AddRange(subQuery.ToBsonDocument()); } if (tablesorterMetadata != null && tablesorterMetadata.SearchFilters != null) { for (int i = 0; i < tablesorterMetadata.SearchFilters.Length; i++) { var fieldName = tablesorterMetadata.HeaderList[i]; var searchTerm = tablesorterMetadata.SearchFilters[i]; if (string.IsNullOrWhiteSpace(fieldName) || string.IsNullOrWhiteSpace(searchTerm)) { continue; } subQuery = Query.EQ(fieldName, new BsonRegularExpression(searchTerm.Trim(), "i")); outerQuery.AddRange(subQuery.ToBsonDocument()); } } MongoCursor<BsonDocument> documents = collection.Find(outerQuery); if (tablesorterMetadata != null) { tablesorterMetadata.TotalRows = Convert.ToInt32(collection.Count(outerQuery)); documents.SetSkip(tablesorterMetadata.PageSize * tablesorterMetadata.PageIndex).SetLimit(tablesorterMetadata.PageSize); if (tablesorterMetadata.SortOrder != null) { SortByBuilder newSortByBuilder = new SortByBuilder(); foreach (int[] sortCriteria in tablesorterMetadata.SortOrder) { var columnNum = sortCriteria[0]; var sortOrder = sortCriteria[1]; if (sortOrder == 1) { newSortByBuilder.Descending(tablesorterMetadata.HeaderList[columnNum]); } else { newSortByBuilder.Ascending(tablesorterMetadata.HeaderList[columnNum]); } } documents.SetSortOrder(newSortByBuilder); } } UserList users = BsonConverter.ConvertToObjectViaJson<UserList>(documents); return users; }
/// <summary> /// Gets the list of users. /// </summary> /// <param name="token">The security token.</param> /// <param name="criteria">The criteria.</param> /// <returns> /// The list of users. /// </returns> protected abstract UserList DoGetUserList(string token, UserSearchCriteria criteria = null);
/// <summary> /// Gets the list of users. /// </summary> /// <param name="token">The security token.</param> /// <param name="criteria">The user search criteria.</param> /// <returns> /// The list of users. /// </returns> public UserList GetUserList(string token, UserSearchCriteria criteria = null) { return this.DoGetUserList(token, criteria); }
/// <summary> /// Validates the <paramref name="migrationData"/> and returns the results as a list of messages. /// </summary> /// <param name="migrationData">The migration data to validate.</param> /// <returns>A list of warnings resulting from the validation.</returns> public MigrationDataResults Validate(MigrationData migrationData) { MigrationDataResults results = new MigrationDataResults(); Version currentSystemVersion = this.dataAccess.GetSystemVersion(); if (migrationData.SystemVersion != null && currentSystemVersion.CompareTo(migrationData.SystemVersion, 2) != 0) { string message = currentSystemVersion.CompareTo(migrationData.SystemVersion, 2) > 0 ? string.Format(Messages.Validate_TargetSystemVersionTooHigh, currentSystemVersion.ToString(2), migrationData.SystemVersion.ToString(2)) : string.Format(Messages.Validate_TargetSystemVersionTooLow, currentSystemVersion.ToString(2), migrationData.SystemVersion.ToString(2)); throw new MigrationVersionException(message); } if (migrationData.SystemVersion == null) { string message = string.Format(Messages.Validate_ExportMissingVersion, currentSystemVersion.ToString(2)); throw new MigrationVersionException(message); } this.ValidateProducts(migrationData, results); if (migrationData.Users.Count > 0) { IEnumerable<string> usernames = migrationData.Users.Select(p => p.Username); OrganisationList orgList = this.dataAccess.GetOrganisationList(); UserSearchCriteria filter = new UserSearchCriteria { OrganisationIds = orgList.Select(x => x.Id).ToList(), Usernames = usernames.ToList() }; UserList foundUsers = this.dataAccess.FindUsers(filter); foreach (User u in foundUsers) { results.AddNotification(migrationData.Users.FirstOrDefault(user => user.Username == u.Username), MessageType.Error, string.Format(Messages.Validate_UserExistsUsername, u.Username)); } } if (migrationData.Roles.Count > 0) { RoleList allRoles = this.dataAccess.GetRoleList(); foreach (Role r in allRoles.Where(r => !r.SystemDefined)) { if (migrationData.Roles.Contains(r.Id)) { results.AddNotification(r, MessageType.Error, string.Format(Messages.Validate_RoleExistsId, r.RoleName)); } } } if (migrationData.Organisations.Count > 0) { OrganisationList allOrganisations = this.dataAccess.GetOrganisationList(); foreach (Organisation org in allOrganisations) { MigrationOrganisation migrationOrgMatchId = migrationData.Organisations.FirstOrDefault(o => o.Id == org.Id); if (migrationOrgMatchId != null) { results.AddNotification(migrationOrgMatchId, MessageType.Error, string.Format(Messages.Validate_OrgExistsId, org.Name)); } else { MigrationOrganisation migrationOrgMatchName = migrationData.Organisations.FirstOrDefault(o => o.Name == org.Name); if (migrationOrgMatchName != null) { results.AddNotification(migrationOrgMatchName, MessageType.Warning, string.Format(Messages.Validate_OrgExistsId, org.Name)); } } } } if (migrationData.ServiceEndpoints.Count > 0) { ServiceEndpointList allEndpoints = this.dataAccess.GetServiceEndpointList(); foreach (ServiceEndpoint endpoint in allEndpoints) { if (migrationData.ServiceEndpoints.Contains(endpoint.Id)) { results.AddNotification(endpoint, MessageType.Error, string.Format(Messages.Validate_ServiceEndpointExistsId, endpoint.Name, endpoint.Id)); } } } if (migrationData.DataSets.Count > 0) { GenericDataSetList allDataSets = this.dataAccess.GetDataSetList(false); foreach (GenericDataSet dataSet in allDataSets) { if (migrationData.DataSets.Any(x => x.Id == dataSet.Id)) { results.AddNotification(dataSet, MessageType.Warning, string.Format(Messages.Validate_DataSetExistsId, dataSet.Name, dataSet.Id)); } } } return results; }
/// <summary> /// Gets the list of users. /// </summary> /// <param name="token">The security token.</param> /// <param name="criteria">The criteria.</param> /// <returns> /// The list of users. /// </returns> protected override UserList DoGetUserList(string token, UserSearchCriteria criteria = null) { criteria = criteria ?? new UserSearchCriteria(); string jsonString = this.AddTokenAndInvoke(token, new Func<string, string, string>(this.workbenchClient.FindUsers), JsonConvert.SerializeObject(criteria), null); string users = JObject.Parse(jsonString).SelectToken("Users").ToString(); UserList value = JsonConvert.DeserializeObject<UserList>(users); return value; }
/// <summary> /// Finds the list of users that match the criteria. /// </summary> /// <param name="filter">Filters the results to only users that match.</param> /// <param name="tablesorterMetadata">The tablesorter metadata.</param> /// <returns> /// The list of users that match the criteria. /// </returns> public UserList FindUsers(UserSearchCriteria filter, TablesorterMetadata tablesorterMetadata = null) { return this.DoFindUsers(filter, tablesorterMetadata); }
/// <summary> /// Finds the list of users that match the criteria. /// </summary> /// <param name="filter">Filters the results to only users that match.</param> /// <param name="tablesorterMetadata">The tablesorter metadata.</param> /// <returns> /// The list of users that match the criteria. /// </returns> protected abstract UserList DoFindUsers(UserSearchCriteria filter, TablesorterMetadata tablesorterMetadata = null);
/// <summary> /// Updates the users. /// </summary> /// <param name="session">The session.</param> /// <param name="userList">The user list.</param> /// <returns>The results of updating the users.</returns> public UpdateDataResult UpdateUsers(SessionData session, List<UpdateUser> userList) { UpdateDataResult results = new UpdateDataResult(); foreach (UpdateUser updateUser in userList) { try { User existingUser = null; if (!string.IsNullOrEmpty(updateUser.Id)) { existingUser = this.workbenchManager.GetUser(session.UserId, updateUser.Id); } else if (!string.IsNullOrEmpty(updateUser.Username)) { var search = new UserSearchCriteria { Usernames = new List<string> { updateUser.Username } }; UserList users = this.workbenchManager.FindUsers(session.UserId, search); if (users.Count >= 1) { existingUser = users.First(); } } if (existingUser == null) { results.AddNotification(updateUser, updateUser.Id ?? updateUser.Username, UpdateMessageType.Error, string.Format(UpdateUserMessages.UserNotFound, updateUser.Username)); continue; } bool updatedUserDetails = existingUser.MapUserData(updateUser); RoleList roles = this.workbenchManager.GetRoleList(session.UserId); bool updatedRoles = existingUser.UpdateRoles(updateUser, roles); bool updatedProperties = existingUser.UpdateExtendedProperties(updateUser); if (updatedUserDetails || updatedRoles || updatedProperties) { this.securityService.SaveUser(session, existingUser); results.AddNotification(existingUser, existingUser.Username, UpdateMessageType.Information, string.Format(UpdateUserMessages.Success, existingUser.Username, existingUser.DisplayName)); } else { results.AddNotification(existingUser, existingUser.Username, UpdateMessageType.Information, string.Format(UpdateUserMessages.NoChange, existingUser.Username, existingUser.DisplayName)); } } catch (Exception e) { results.AddNotification(updateUser, updateUser.Id ?? updateUser.Username, UpdateMessageType.Error, e.Message); } } return results; }
/// <summary> /// Creates a new application in form with ID <paramref name="formId" /> and sets data contained in /// <paramref name="applicationData" />. /// </summary> /// <param name="session">An authenticated session object.</param> /// <param name="formId">The form id.</param> /// <param name="applicationData">The application data to be updated.</param> /// <param name="submit">Whether the application should be submitted.</param> /// <param name="originator">The application originator to be set.</param> /// <returns> /// The created application. /// </returns> public Application CreateApplication(SecureSession session, string formId, ApplicationData applicationData, bool submit, Originator originator) { Application newApplication = this.formGateway.CreateApplication(session, formId); newApplication.ApplicationData = applicationData; newApplication = !submit ? this.formGateway.SaveApplication(session, newApplication) : this.formGateway.SubmitApplication(session, newApplication, newApplication.WorkflowState); if (originator == null) { return newApplication; } UserSearchCriteria filter = new UserSearchCriteria { IncludeNoOrganisationUsers = true, UserIds = new List<string>(), Usernames = new List<string>(), ExternalIds = new List<string>() }; if (!string.IsNullOrWhiteSpace(originator.Id)) { filter.UserIds.Add(originator.Id); } else if (!string.IsNullOrWhiteSpace(originator.Username)) { filter.Usernames.Add(originator.Username); } else if (!string.IsNullOrWhiteSpace(originator.ExternalId)) { filter.ExternalIds.Add(originator.ExternalId); } else { return newApplication; } UserList users = this.workbenchManager.FindUsers(session.AuthenticatedUser.Id, filter); User user = users.FirstOrDefault(); if (user == null) { return newApplication; } AuthenticatedApplicationUser originatorUser = new IUserMapper().Map(user, new AuthenticatedApplicationUser()); newApplication = this.apiDataAccess.UpdateOriginator(newApplication.ApplicationId, originatorUser); if (newApplication == null) { throw new Exception(ExceptionMessages.UpdateOriginatorError); } return newApplication; }
/// <summary> /// Gets the list of users. /// </summary> /// <param name="token">The security token.</param> /// <param name="criteria">The criteria.</param> /// <returns> /// The list of users. /// </returns> public UserList GetUserList(string token, UserSearchCriteria criteria = null) { return this.WrappedGateway.GetUserList(token, criteria); }