* Add UserResponseModel * Add factory to created UserResponseModel * Add GetByKey controller * Add GetAllUsers endpoint * User proper response model * Make naming consistent * Order by username in GetAll * Add user filter endpoint * Fix includer user states * Remove gravatar from the backend * Send user avatars in response * Add create user model * start working on create * Validate the create model * Add authorization to create * Use UserRepository instead of UserService to ValidateSessíonId * Create IBackofficeUserStore interface This is essentially a core-friendly version of the BackOfficeUserStore, additionally it contains basic methods for managing users, I.E. Get users, save users, create users, etc. * Remove more usages of user service * Remove usages of IUserService in BackofficeUserStore * Add documentation * Fix tests and DI * add IBackOfficeUserStoreAccessor to resolve it in singleton services * Resolve circular dependency * Remove obsolete constructor * Add core friendly user manager * Finish createasync in user service * Add WIP create endpoint * Save newly creates users user groups * Use service scope for user service * Remove now unnecessary accessors * Add response types * Add update user endpoint * Add EmailUserInviteSender * Add technology free way of creating confirmation token * Add invite uri provider * Add invite user to user service * Add invite user controller * Add delete endpoint * Add operation status responses * Add operation status responses * Added temporary file uploads including a repository implementation using local temp folder. * Add Disable users endpoint * missing files * Fixed copy paste error * Fix create users return type * Updated OpenApi.json * Updated OpenApi.json * Handle if created failed in identity * Add enable user * Make users plural in enable/disable We're doing the operation on multiple entities * Added file extension check * Add unlock user endpoint * Clean up. Removed old TemporaryFileService and UploadFileService and updated dictionary items to use this new items * Clean up * Add reset password * Add UpdateUserGroupsOnUsers method * Add UpdateUserGroups * Get rid of stream directly on TemporaryFileModel, and use delegate to open stream instead. * Fix post merge * Use keys instead of IDs * Add ClearAvatar endpoint * Review changes * Moved models to their own files * Reverted launch settings * Move enlist extension to its own namespace * Create set avatar endpoint * Add reponse types * Remove infrastructure extension after merge * Add Cmapatibility suppressions * Add test suppression * Add integration tests * Fix issue found in tests * Add invited user to UserInvitationResult * Add more tests * Add update tests * Hide different tests under parent * Return DuplicatUserName user operation status if username matches an email * Add update tests * Change sorted set to HashSet It doesn't work if it's not IComparable * Change ID to Key when checking super * Add get tests * Add more GetAllTests * Move tests to the right namespace * Add filter test * Fix including disabled users bug found by test * Add test to ensure invited user state * Add test case for UserState.All * Add more filter tests * Add enable disable tests * Add resolver for keys and ids * Replace usages of IUserService with IUserIdKeyResolver * Add CompatibilitySuppressions * Add UserIdKeyResolverTests * Fix UserIdKeyResolver * Add missing user operation results * Updates from review * ID not key * Post instead of patch * Use set instead of params for enable/disable * Don't call to array * Use sets for usergroup keys and user keys instead * LanguageIsoCode instead of Language * Update CompatibilitySuppressions after changin enumerable to set --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> Co-authored-by: kjac <kja@umbraco.dk>
353 lines
14 KiB
C#
353 lines
14 KiB
C#
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Models.Membership;
|
|
using Umbraco.Cms.Core.Persistence.Querying;
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
|
using Umbraco.New.Cms.Core.Models;
|
|
|
|
namespace Umbraco.Cms.Core.Services;
|
|
|
|
/// <summary>
|
|
/// Defines the UserService, which is an easy access to operations involving <see cref="IProfile" /> and eventually
|
|
/// Users.
|
|
/// </summary>
|
|
public interface IUserService : IMembershipUserService
|
|
{
|
|
/// <summary>
|
|
/// Creates a database entry for starting a new login session for a user
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <param name="requestingIpAddress"></param>
|
|
/// <returns></returns>
|
|
Guid CreateLoginSession(int userId, string requestingIpAddress);
|
|
|
|
/// <summary>
|
|
/// Validates that a user login session is valid/current and hasn't been closed
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <param name="sessionId"></param>
|
|
/// <returns></returns>
|
|
bool ValidateLoginSession(int userId, Guid sessionId);
|
|
|
|
/// <summary>
|
|
/// Removes the session's validity
|
|
/// </summary>
|
|
/// <param name="sessionId"></param>
|
|
void ClearLoginSession(Guid sessionId);
|
|
|
|
/// <summary>
|
|
/// Removes all valid sessions for the user
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
int ClearLoginSessions(int userId);
|
|
|
|
/// <summary>
|
|
/// This is basically facets of UserStates key = state, value = count
|
|
/// </summary>
|
|
IDictionary<UserState, int> GetUserStates();
|
|
|
|
/// <summary>
|
|
/// Creates a user based in a create model and persists it to the database.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This creates both the Umbraco user and the identity user.
|
|
/// </remarks>
|
|
/// <param name="performingUserKey">The key of the user performing the operation.</param>
|
|
/// <param name="model">Model to create the user from.</param>
|
|
/// <param name="approveUser">Specifies if the user should be enabled be default. Defaults to false.</param>
|
|
/// <returns>An attempt indicating if the operation was a success as well as a more detailed <see cref="UserOperationStatus"/>.</returns>
|
|
Task<Attempt<UserCreationResult, UserOperationStatus>> CreateAsync(Guid performingUserKey, UserCreateModel model, bool approveUser = false);
|
|
|
|
Task<Attempt<UserInvitationResult, UserOperationStatus>> InviteAsync(Guid performingUserKey, UserInviteModel model);
|
|
|
|
Task<Attempt<IUser, UserOperationStatus>> UpdateAsync(Guid performingUserKey, UserUpdateModel model);
|
|
|
|
Task<UserOperationStatus> SetAvatarAsync(IUser user, Guid temporaryFileKey);
|
|
|
|
Task<UserOperationStatus> DeleteAsync(Guid key);
|
|
|
|
Task<UserOperationStatus> DisableAsync(Guid performingUserKey, ISet<Guid> keys);
|
|
|
|
Task<UserOperationStatus> EnableAsync(Guid performingUserKey, ISet<Guid> keys);
|
|
|
|
Task<Attempt<UserUnlockResult, UserOperationStatus>> UnlockAsync(Guid performingUserKey, params Guid[] keys);
|
|
|
|
Task<Attempt<PasswordChangedModel, UserOperationStatus>> ChangePasswordAsync(Guid performingUserKey, ChangeBackofficeUserPasswordModel model);
|
|
|
|
Task<UserOperationStatus> ClearAvatarAsync(Guid userKey);
|
|
|
|
/// <summary>
|
|
/// Gets all users that the requesting user is allowed to see.
|
|
/// </summary>
|
|
/// <param name="requestingUserKey">The Key of the user requesting the users.</param>
|
|
/// <returns></returns>
|
|
Task<Attempt<PagedModel<IUser>?, UserOperationStatus>> GetAllAsync(Guid requestingUserKey, int skip, int take) => throw new NotImplementedException();
|
|
|
|
public Task<Attempt<PagedModel<IUser>, UserOperationStatus>> FilterAsync(
|
|
Guid requestingUserKey,
|
|
UserFilter filter,
|
|
int skip = 0,
|
|
int take = 100,
|
|
UserOrder orderBy = UserOrder.UserName,
|
|
Direction orderDirection = Direction.Ascending) => throw new NotImplementedException();
|
|
|
|
/// <summary>
|
|
/// Get paged users
|
|
/// </summary>
|
|
/// <param name="pageIndex"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <param name="totalRecords"></param>
|
|
/// <param name="orderBy"></param>
|
|
/// <param name="orderDirection"></param>
|
|
/// <param name="userState"></param>
|
|
/// <param name="includeUserGroups">
|
|
/// A filter to only include user that belong to these user groups
|
|
/// </param>
|
|
/// <param name="excludeUserGroups">
|
|
/// A filter to only include users that do not belong to these user groups
|
|
/// </param>
|
|
/// <param name="filter"></param>
|
|
/// <returns></returns>
|
|
IEnumerable<IUser> GetAll(
|
|
long pageIndex,
|
|
int pageSize,
|
|
out long totalRecords,
|
|
string orderBy,
|
|
Direction orderDirection,
|
|
UserState[]? userState = null,
|
|
string[]? includeUserGroups = null,
|
|
string[]? excludeUserGroups = null,
|
|
IQuery<IUser>? filter = null);
|
|
|
|
/// <summary>
|
|
/// Get paged users
|
|
/// </summary>
|
|
/// <param name="pageIndex"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <param name="totalRecords"></param>
|
|
/// <param name="orderBy"></param>
|
|
/// <param name="orderDirection"></param>
|
|
/// <param name="userState"></param>
|
|
/// <param name="userGroups">
|
|
/// A filter to only include user that belong to these user groups
|
|
/// </param>
|
|
/// <param name="filter"></param>
|
|
/// <returns></returns>
|
|
IEnumerable<IUser> GetAll(
|
|
long pageIndex,
|
|
int pageSize,
|
|
out long totalRecords,
|
|
string orderBy,
|
|
Direction orderDirection,
|
|
UserState[]? userState = null,
|
|
string[]? userGroups = null,
|
|
string? filter = null);
|
|
|
|
/// <summary>
|
|
/// Deletes or disables a User
|
|
/// </summary>
|
|
/// <param name="user"><see cref="IUser" /> to delete</param>
|
|
/// <param name="deletePermanently"><c>True</c> to permanently delete the user, <c>False</c> to disable the user</param>
|
|
void Delete(IUser user, bool deletePermanently);
|
|
|
|
/// <summary>
|
|
/// Gets an IProfile by User Id.
|
|
/// </summary>
|
|
/// <param name="id">Id of the User to retrieve</param>
|
|
/// <returns>
|
|
/// <see cref="IProfile" />
|
|
/// </returns>
|
|
IProfile? GetProfileById(int id);
|
|
|
|
/// <summary>
|
|
/// Gets a profile by username
|
|
/// </summary>
|
|
/// <param name="username">Username</param>
|
|
/// <returns>
|
|
/// <see cref="IProfile" />
|
|
/// </returns>
|
|
IProfile? GetProfileByUserName(string username);
|
|
|
|
/// <summary>
|
|
/// Get a user by its key.
|
|
/// </summary>
|
|
/// <param name="key">The GUID key of the user.</param>
|
|
/// <returns>The found user, or null if nothing was found.</returns>
|
|
Task<IUser?> GetAsync(Guid key) => Task.FromResult(GetAll(0, int.MaxValue, out _).FirstOrDefault(x=>x.Key == key));
|
|
|
|
Task<IEnumerable<IUser>> GetAsync(IEnumerable<Guid> keys) => Task.FromResult(GetAll(0, int.MaxValue, out _).Where(x => keys.Contains(x.Key)));
|
|
|
|
/// <summary>
|
|
/// Gets a user by Id
|
|
/// </summary>
|
|
/// <param name="id">Id of the user to retrieve</param>
|
|
/// <returns>
|
|
/// <see cref="IUser" />
|
|
/// </returns>
|
|
IUser? GetUserById(int id);
|
|
|
|
/// <summary>
|
|
/// Gets a users by Id
|
|
/// </summary>
|
|
/// <param name="ids">Ids of the users to retrieve</param>
|
|
/// <returns>
|
|
/// <see cref="IUser" />
|
|
/// </returns>
|
|
IEnumerable<IUser> GetUsersById(params int[]? ids);
|
|
|
|
/// <summary>
|
|
/// Removes a specific section from all user groups
|
|
/// </summary>
|
|
/// <remarks>This is useful when an entire section is removed from config</remarks>
|
|
/// <param name="sectionAlias">Alias of the section to remove</param>
|
|
void DeleteSectionFromAllUserGroups(string sectionAlias);
|
|
|
|
/// <summary>
|
|
/// Get explicitly assigned permissions for a user and optional node ids
|
|
/// </summary>
|
|
/// <remarks>If no permissions are found for a particular entity then the user's default permissions will be applied</remarks>
|
|
/// <param name="user">User to retrieve permissions for</param>
|
|
/// <param name="nodeIds">
|
|
/// Specifying nothing will return all user permissions for all nodes that have explicit permissions
|
|
/// defined
|
|
/// </param>
|
|
/// <returns>An enumerable list of <see cref="EntityPermission" /></returns>
|
|
/// <remarks>
|
|
/// This will return the default permissions for the user's groups for node ids that don't have explicitly defined
|
|
/// permissions
|
|
/// </remarks>
|
|
EntityPermissionCollection GetPermissions(IUser? user, params int[] nodeIds);
|
|
|
|
/// <summary>
|
|
/// Get explicitly assigned permissions for groups and optional node Ids
|
|
/// </summary>
|
|
/// <param name="groups"></param>
|
|
/// <param name="fallbackToDefaultPermissions">
|
|
/// Flag indicating if we want to include the default group permissions for each result if there are not explicit
|
|
/// permissions set
|
|
/// </param>
|
|
/// <param name="nodeIds">Specifying nothing will return all permissions for all nodes</param>
|
|
/// <returns>An enumerable list of <see cref="EntityPermission" /></returns>
|
|
EntityPermissionCollection GetPermissions(IUserGroup?[] groups, bool fallbackToDefaultPermissions, params int[] nodeIds);
|
|
|
|
/// <summary>
|
|
/// Gets the implicit/inherited permissions for the user for the given path
|
|
/// </summary>
|
|
/// <param name="user">User to check permissions for</param>
|
|
/// <param name="path">Path to check permissions for</param>
|
|
EntityPermissionSet GetPermissionsForPath(IUser? user, string? path);
|
|
|
|
/// <summary>
|
|
/// Gets the permissions for the provided groups and path
|
|
/// </summary>
|
|
/// <param name="groups"></param>
|
|
/// <param name="path">Path to check permissions for</param>
|
|
/// <param name="fallbackToDefaultPermissions">
|
|
/// Flag indicating if we want to include the default group permissions for each result if there are not explicit
|
|
/// permissions set
|
|
/// </param>
|
|
EntityPermissionSet GetPermissionsForPath(IUserGroup[] groups, string path, bool fallbackToDefaultPermissions = false);
|
|
|
|
/// <summary>
|
|
/// Replaces the same permission set for a single group to any number of entities
|
|
/// </summary>
|
|
/// <param name="groupId">Id of the group</param>
|
|
/// <param name="permissions">
|
|
/// Permissions as enumerable list of <see cref="char" />,
|
|
/// if no permissions are specified then all permissions for this node are removed for this group
|
|
/// </param>
|
|
/// <param name="entityIds">
|
|
/// Specify the nodes to replace permissions for. If nothing is specified all permissions are
|
|
/// removed.
|
|
/// </param>
|
|
/// <remarks>If no 'entityIds' are specified all permissions will be removed for the specified group.</remarks>
|
|
void ReplaceUserGroupPermissions(int groupId, IEnumerable<char>? permissions, params int[] entityIds);
|
|
|
|
/// <summary>
|
|
/// Assigns the same permission set for a single user group to any number of entities
|
|
/// </summary>
|
|
/// <param name="groupId">Id of the group</param>
|
|
/// <param name="permission"></param>
|
|
/// <param name="entityIds">Specify the nodes to replace permissions for</param>
|
|
void AssignUserGroupPermission(int groupId, char permission, params int[] entityIds);
|
|
|
|
/// <summary>
|
|
/// Gets a list of <see cref="IUser" /> objects associated with a given group
|
|
/// </summary>
|
|
/// <param name="groupId">Id of group</param>
|
|
/// <returns>
|
|
/// <see cref="IEnumerable{IUser}" />
|
|
/// </returns>
|
|
IEnumerable<IUser> GetAllInGroup(int? groupId);
|
|
|
|
/// <summary>
|
|
/// Gets a list of <see cref="IUser" /> objects not associated with a given group
|
|
/// </summary>
|
|
/// <param name="groupId">Id of group</param>
|
|
/// <returns>
|
|
/// <see cref="IEnumerable{IUser}" />
|
|
/// </returns>
|
|
IEnumerable<IUser> GetAllNotInGroup(int groupId);
|
|
|
|
IEnumerable<IUser> GetNextUsers(int id, int count);
|
|
|
|
#region User groups
|
|
|
|
/// <summary>
|
|
/// Gets all UserGroups or those specified as parameters
|
|
/// </summary>
|
|
/// <param name="ids">Optional Ids of UserGroups to retrieve</param>
|
|
/// <returns>An enumerable list of <see cref="IUserGroup" /></returns>
|
|
[Obsolete("Use IUserGroupService.GetAsync instead, scheduled for removal in V15.")]
|
|
IEnumerable<IUserGroup> GetAllUserGroups(params int[] ids);
|
|
|
|
/// <summary>
|
|
/// Gets a UserGroup by its Alias
|
|
/// </summary>
|
|
/// <param name="alias">Alias of the UserGroup to retrieve</param>
|
|
/// <returns>
|
|
/// <see cref="IUserGroup" />
|
|
/// </returns>
|
|
[Obsolete("Use IUserGroupService.GetAsync instead, scheduled for removal in V15.")]
|
|
IEnumerable<IUserGroup> GetUserGroupsByAlias(params string[] alias);
|
|
|
|
/// <summary>
|
|
/// Gets a UserGroup by its Alias
|
|
/// </summary>
|
|
/// <param name="name">Name of the UserGroup to retrieve</param>
|
|
/// <returns>
|
|
/// <see cref="IUserGroup" />
|
|
/// </returns>
|
|
[Obsolete("Use IUserGroupService.GetAsync instead, scheduled for removal in V15.")]
|
|
IUserGroup? GetUserGroupByAlias(string name);
|
|
|
|
/// <summary>
|
|
/// Gets a UserGroup by its Id
|
|
/// </summary>
|
|
/// <param name="id">Id of the UserGroup to retrieve</param>
|
|
/// <returns>
|
|
/// <see cref="IUserGroup" />
|
|
/// </returns>
|
|
[Obsolete("Use IUserGroupService.GetAsync instead, scheduled for removal in V15.")]
|
|
IUserGroup? GetUserGroupById(int id);
|
|
|
|
/// <summary>
|
|
/// Saves a UserGroup
|
|
/// </summary>
|
|
/// <param name="userGroup">UserGroup to save</param>
|
|
/// <param name="userIds">
|
|
/// 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
|
|
/// </param>
|
|
[Obsolete("Use IUserGroupService.CreateAsync and IUserGroupService.UpdateAsync instead, scheduled for removal in V15.")]
|
|
void Save(IUserGroup userGroup, int[]? userIds = null);
|
|
|
|
/// <summary>
|
|
/// Deletes a UserGroup
|
|
/// </summary>
|
|
/// <param name="userGroup">UserGroup to delete</param>
|
|
[Obsolete("Use IUserGroupService.DeleteAsync instead, scheduled for removal in V15.")]
|
|
void DeleteUserGroup(IUserGroup userGroup);
|
|
|
|
#endregion
|
|
}
|