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 userKey, UserCreateModel model, bool approveUser = false);
Task> InviteAsync(Guid userKey, UserInviteModel model);
Task> VerifyInviteAsync(Guid userKey, string token);
Task> CreateInitialPasswordAsync(Guid userKey, string token, string password);
Task> UpdateAsync(Guid userKey, UserUpdateModel model);
Task SetAvatarAsync(Guid userKey, Guid temporaryFileKey);
Task DeleteAsync(Guid key);
Task DisableAsync(Guid userKey, ISet keys);
Task EnableAsync(Guid userKey, ISet keys);
Task> UnlockAsync(Guid userKey, params Guid[] keys);
Task> ChangePasswordAsync(Guid userKey, 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 userKey, 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, IEnumerable? 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, char 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);
IEnumerable GetNextUsers(int id, int count);
#region User groups
///
/// Gets all UserGroups or those specified as parameters
///
/// Optional Ids of UserGroups to retrieve
/// An enumerable list of
[Obsolete("Use IUserGroupService.GetAsync instead, scheduled for removal in V15.")]
IEnumerable GetAllUserGroups(params int[] ids);
///
/// Gets a UserGroup by its Alias
///
/// Alias of the UserGroup to retrieve
///
///
///
[Obsolete("Use IUserGroupService.GetAsync instead, scheduled for removal in V15.")]
IEnumerable GetUserGroupsByAlias(params string[] alias);
///
/// Gets a UserGroup by its Alias
///
/// Name of the UserGroup to retrieve
///
///
///
[Obsolete("Use IUserGroupService.GetAsync instead, scheduled for removal in V15.")]
IUserGroup? GetUserGroupByAlias(string name);
///
/// Gets a UserGroup by its Id
///
/// Id of the UserGroup to retrieve
///
///
///
[Obsolete("Use IUserGroupService.GetAsync instead, scheduled for removal in V15.")]
IUserGroup? GetUserGroupById(int id);
///
/// Saves a UserGroup
///
/// UserGroup to save
///
/// If null than no changes are made to the users who are assigned to this group, however if a value is passed in
/// than all users will be removed from this group and only these users will be added
///
[Obsolete("Use IUserGroupService.CreateAsync and IUserGroupService.UpdateAsync instead, scheduled for removal in V15.")]
void Save(IUserGroup userGroup, int[]? userIds = null);
///
/// Deletes a UserGroup
///
/// UserGroup to delete
[Obsolete("Use IUserGroupService.DeleteAsync instead, scheduled for removal in V15.")]
void DeleteUserGroup(IUserGroup userGroup);
#endregion
}