/// <summary> /// Gets a collection of all the users in the database. The users may be returned from a cache. /// </summary> /// <returns>Returns a collection of all the users in the database.</returns> public static IUserAccountCollection GetAllUsers() { IUserAccountCollection usersCache = (IUserAccountCollection)HelperFunctions.GetCache(CacheItem.Users); if (usersCache == null) { usersCache = new UserAccountCollection(); int totalRecords; foreach (MembershipUser user in MembershipGsp.GetAllUsers(0, 0x7fffffff, out totalRecords)) { usersCache.Add(ToUserAccount(user)); } HelperFunctions.SetCache(CacheItem.Users, usersCache); } return usersCache; }
/// <summary> /// Determine the users the currently logged on user can view. /// </summary> /// <param name="userIsSiteAdmin">If set to <c>true</c>, the currently logged on user is a site administrator.</param> /// <param name="userIsGalleryAdmin">If set to <c>true</c>, the currently logged on user is a gallery administrator for the current gallery.</param> /// <returns>Returns an <see cref="IUserAccountCollection"/> containing a list of roles the user has permission to view.</returns> private static IUserAccountCollection DetermineUsersCurrentUserCanView(bool userIsSiteAdmin, bool userIsGalleryAdmin) { if (userIsSiteAdmin || (userIsGalleryAdmin && AppSetting.Instance.AllowGalleryAdminToViewAllUsersAndRoles)) { return UserController.GetAllUsers(); } // Filter the accounts so that only users in galleries where // the current user is a gallery admin are shown. IGalleryCollection adminGalleries = UserController.GetGalleriesCurrentUserCanAdminister(); IUserAccountCollection users = new UserAccountCollection(); foreach (IUserAccount user in UserController.GetAllUsers()) { foreach (IGalleryServerRole role in RoleController.GetGalleryServerRolesForUser(user.UserName)) { bool userHasBeenAdded = false; foreach (IGallery gallery in role.Galleries) { if (adminGalleries.Contains(gallery)) { // User belongs to a gallery that the current user is a gallery admin for. Include the account. users.Add(user); userHasBeenAdded = true; break; } } if (userHasBeenAdded) break; } } return users; }