using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Membership; using Umbraco.Cms.Core.Persistence.Querying; using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Services.OperationStatus; namespace Umbraco.Cms.Core.Services; /// /// Defines the UserService, which is an easy access to operations involving and eventually /// Users. /// public interface IUserService : IMembershipUserService { /// /// Creates a database entry for starting a new login session for a user /// /// /// /// Guid CreateLoginSession(int userId, string requestingIpAddress); /// /// Validates that a user login session is valid/current and hasn't been closed /// /// /// /// bool ValidateLoginSession(int userId, Guid sessionId); /// /// Removes the session's validity /// /// void ClearLoginSession(Guid sessionId); /// /// Removes all valid sessions for the user /// /// int ClearLoginSessions(int userId); /// /// This is basically facets of UserStates key = state, value = count /// IDictionary GetUserStates(); /// /// Creates a user based in a create model and persists it to the database. /// /// /// This creates both the Umbraco user and the identity user. /// /// The key of the user performing the operation. /// Model to create the user from. /// Specifies if the user should be enabled be default. Defaults to false. /// An attempt indicating if the operation was a success as well as a more detailed . Task> CreateAsync(Guid performingUserKey, UserCreateModel model, bool approveUser = false); Task> InviteAsync(Guid performingUserKey, UserInviteModel model); Task> VerifyInviteAsync(Guid userKey, string token); Task> CreateInitialPasswordAsync(Guid userKey, string token, string password); Task> UpdateAsync(Guid performingUserKey, UserUpdateModel model); Task SetAvatarAsync(Guid userKey, Guid temporaryFileKey); Task DeleteAsync(Guid performingUserKey, ISet keys); Task DeleteAsync(Guid performingUserKey, Guid key) => DeleteAsync(performingUserKey, new HashSet { key }); Task DisableAsync(Guid performingUserKey, ISet keys); Task EnableAsync(Guid performingUserKey, ISet keys); Task> UnlockAsync(Guid performingUserKey, params Guid[] keys); Task> ChangePasswordAsync(Guid performingUserKey, ChangeUserPasswordModel model); Task ClearAvatarAsync(Guid userKey); Task, UserOperationStatus>> GetLinkedLoginsAsync(Guid userKey); /// /// Gets all users that the requesting user is allowed to see. /// /// The Key of the user requesting the users. /// Amount to skip. /// Amount to take. /// All users that the user is allowed to see. Task?, UserOperationStatus>> GetAllAsync(Guid performingUserKey, int skip, int take) => throw new NotImplementedException(); public Task, UserOperationStatus>> FilterAsync( Guid userKey, UserFilter filter, int skip = 0, int take = 100, UserOrder orderBy = UserOrder.UserName, Direction orderDirection = Direction.Ascending) => throw new NotImplementedException(); /// /// Get paged users /// /// /// /// /// /// /// /// /// A filter to only include user that belong to these user groups /// /// /// A filter to only include users that do not belong to these user groups /// /// /// IEnumerable GetAll( long pageIndex, int pageSize, out long totalRecords, string orderBy, Direction orderDirection, UserState[]? userState = null, string[]? includeUserGroups = null, string[]? excludeUserGroups = null, IQuery? filter = null); /// /// Get paged users /// /// /// /// /// /// /// /// /// A filter to only include user that belong to these user groups /// /// /// IEnumerable GetAll( long pageIndex, int pageSize, out long totalRecords, string orderBy, Direction orderDirection, UserState[]? userState = null, string[]? userGroups = null, string? filter = null); /// /// Deletes or disables a User /// /// to delete /// True to permanently delete the user, False to disable the user void Delete(IUser user, bool deletePermanently); /// /// Gets an IProfile by User Id. /// /// Id of the User to retrieve /// /// /// IProfile? GetProfileById(int id); /// /// Gets a profile by username /// /// Username /// /// /// IProfile? GetProfileByUserName(string username); /// /// Get a user by its key. /// /// The GUID key of the user. /// The found user, or null if nothing was found. Task GetAsync(Guid key) => Task.FromResult(GetAll(0, int.MaxValue, out _).FirstOrDefault(x=>x.Key == key)); Task> GetAsync(IEnumerable keys) => Task.FromResult(GetAll(0, int.MaxValue, out _).Where(x => keys.Contains(x.Key))); /// /// Gets a user by Id /// /// Id of the user to retrieve /// /// /// IUser? GetUserById(int id); /// /// Gets a users by Id /// /// Ids of the users to retrieve /// /// /// IEnumerable GetUsersById(params int[]? ids); /// /// Removes a specific section from all user groups /// /// This is useful when an entire section is removed from config /// Alias of the section to remove void DeleteSectionFromAllUserGroups(string sectionAlias); /// /// Get explicitly assigned permissions for a user and node keys. /// /// Key of user to retrieve permissions for. /// The keys of the nodes to get permissions for. /// An enumerable list of . Task, UserOperationStatus>> GetPermissionsAsync(Guid userKey, params Guid[] nodeKeys); /// /// Get explicitly assigned content permissions for a user and node keys. /// /// Key of user to retrieve permissions for. /// The keys of the media to get permissions for. /// An attempt indicating if the operation was a success as well as a more detailed , and an enumerable of permissions. Task, UserOperationStatus>> GetMediaPermissionsAsync(Guid userKey, IEnumerable mediaKeys); /// /// Get explicitly assigned media permissions for a user and node keys. /// /// Key of user to retrieve permissions for. /// The keys of the content to get permissions for. /// An attempt indicating if the operation was a success as well as a more detailed , and an enumerable of permissions. Task, UserOperationStatus>> GetDocumentPermissionsAsync(Guid userKey, IEnumerable contentKeys); /// /// Get explicitly assigned permissions for a user and optional node ids /// /// If no permissions are found for a particular entity then the user's default permissions will be applied /// User to retrieve permissions for /// /// Specifying nothing will return all user permissions for all nodes that have explicit permissions /// defined /// /// An enumerable list of /// /// This will return the default permissions for the user's groups for node ids that don't have explicitly defined /// permissions /// EntityPermissionCollection GetPermissions(IUser? user, params int[] nodeIds); /// /// Get explicitly assigned permissions for groups and optional node Ids /// /// /// /// Flag indicating if we want to include the default group permissions for each result if there are not explicit /// permissions set /// /// Specifying nothing will return all permissions for all nodes /// An enumerable list of EntityPermissionCollection GetPermissions(IUserGroup?[] groups, bool fallbackToDefaultPermissions, params int[] nodeIds); /// /// Gets the implicit/inherited permissions for the user for the given path /// /// User to check permissions for /// Path to check permissions for EntityPermissionSet GetPermissionsForPath(IUser? user, string? path); /// /// Gets the permissions for the provided groups and path /// /// /// Path to check permissions for /// /// Flag indicating if we want to include the default group permissions for each result if there are not explicit /// permissions set /// EntityPermissionSet GetPermissionsForPath(IUserGroup[] groups, string path, bool fallbackToDefaultPermissions = false); /// /// Replaces the same permission set for a single group to any number of entities /// /// Id of the group /// /// Permissions as enumerable list of , /// if no permissions are specified then all permissions for this node are removed for this group /// /// /// Specify the nodes to replace permissions for. If nothing is specified all permissions are /// removed. /// /// If no 'entityIds' are specified all permissions will be removed for the specified group. void ReplaceUserGroupPermissions(int groupId, ISet permissions, params int[] entityIds); /// /// Assigns the same permission set for a single user group to any number of entities /// /// Id of the group /// /// Specify the nodes to replace permissions for void AssignUserGroupPermission(int groupId, string permission, params int[] entityIds); /// /// Gets a list of objects associated with a given group /// /// Id of group /// /// /// IEnumerable GetAllInGroup(int? groupId); /// /// Gets a list of objects not associated with a given group /// /// Id of group /// /// /// IEnumerable GetAllNotInGroup(int groupId); /// /// Verifies the reset code sent from the reset password mail for a given user. /// /// The unique key of the user. /// The reset password token. Task> VerifyPasswordResetAsync(Guid userKey, string token); /// /// Changes the user's password. /// /// The unique key of the user. /// The reset password token. /// The new password of the user. Task> ResetPasswordAsync(Guid userKey, string token, string password); /// /// Sends an email with a link to reset user's password. /// /// The email address of the user. Task> SendResetPasswordEmailAsync(string userEmail); Task> ResendInvitationAsync(Guid performingUserKey, UserResendInviteModel model); Task> ResetPasswordAsync(Guid performingUserKey, Guid userKey); Task AddClientIdAsync(Guid userKey, string clientId); Task RemoveClientIdAsync(Guid userKey, string clientId); Task FindByClientIdAsync(string clientId); Task> GetClientIdsAsync(Guid userKey); }