diff --git a/src/Umbraco.Core/Services/IUserService.cs b/src/Umbraco.Core/Services/IUserService.cs index 191f9085f6..ce3863ce0a 100644 --- a/src/Umbraco.Core/Services/IUserService.cs +++ b/src/Umbraco.Core/Services/IUserService.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Web; using Umbraco.Core.Models.Membership; namespace Umbraco.Core.Services @@ -12,18 +11,18 @@ namespace Umbraco.Core.Services /// /// This is simply a helper method which essentially just wraps the MembershipProvider's ChangePassword method /// - /// The user to save the password for - /// /// /// This method exists so that Umbraco developers can use one entry point to create/update users if they choose to. /// + /// The user to save the password for + /// The password to save void SavePassword(IUser user, string password); /// - /// To permanently delete the user pass in true, otherwise they will just be disabled + /// Deletes or disables a User /// - /// - /// + /// to delete + /// True to permanently delete the user, False to disable the user void Delete(IUser user, bool deletePermanently); /// @@ -34,79 +33,86 @@ namespace Umbraco.Core.Services IProfile GetProfileById(int id); /// - /// Get profile by username + /// Gets a profile by username /// - /// - /// + /// Username + /// IProfile GetProfileByUserName(string username); /// - /// Get user by Id + /// Gets a user by Id /// - /// - /// + /// Id of the user to retrieve + /// IUser GetUserById(int id); /// - /// This is useful when an entire section is removed from config + /// Removes a specific section from all users /// - /// + /// This is useful when an entire section is removed from config + /// Alias of the section to remove void DeleteSectionFromAllUsers(string sectionAlias); /// - /// Get permissions set for user and specified node ids + /// Get permissions set for a user and optional node ids /// - /// - /// - /// Specifiying nothing will return all user permissions for all nodes - /// - /// + /// If no permissions are found for a particular entity then the user's default permissions will be applied + /// User to retrieve permissions for + /// Specifiying nothing will return all user permissions for all nodes + /// An enumerable list of IEnumerable GetPermissions(IUser user, params int[] nodeIds); /// /// Replaces the same permission set for a single user to any number of entities /// - /// - /// - /// + /// Note: If no 'entityIds' are specified all permissions will be removed for the specified user. + /// Id of the user + /// Permissions as enumerable list of + /// Specify the nodes to replace permissions for. If nothing is specified all permissions are removed. void ReplaceUserPermissions(int userId, IEnumerable permissions, params int[] entityIds); #region User types + /// + /// Gets all UserTypes or thosed specified as parameters + /// + /// Optional Ids of UserTypes to retrieve + /// An enumerable list of IEnumerable GetAllUserTypes(params int[] ids); /// - /// Gets an IUserType by its Alias + /// Gets a UserType by its Alias /// /// Alias of the UserType to retrieve /// IUserType GetUserTypeByAlias(string alias); /// - /// Gets an IUserType by its Id + /// Gets a UserType by its Id /// - /// - /// + /// Id of the UserType to retrieve + /// IUserType GetUserTypeById(int id); /// - /// Gets an IUserType by its Name + /// Gets a UserType by its Name /// /// Name of the UserType to retrieve /// IUserType GetUserTypeByName(string name); /// - /// Saves an IUserType + /// Saves a UserType /// - /// - /// + /// UserType to save + /// Optional parameter to raise events. + /// Default is True otherwise set to False to not raise events void SaveUserType(IUserType userType, bool raiseEvents = true); /// - /// Deletes an IUserType + /// Deletes a UserType /// - /// + /// UserType to delete void DeleteUserType(IUserType userType); #endregion diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index 3b426a2a0d..bb34c9ef5e 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -1,11 +1,8 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using Umbraco.Core.Events; -using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; -using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Persistence.UnitOfWork; @@ -78,6 +75,14 @@ namespace Umbraco.Core.Services } } + /// + /// Creates a new User + /// + /// The user will be saved in the database and returned with an Id + /// Username of the user to create + /// Email of the user to create + /// which the User should be based on + /// public IUser CreateUserWithIdentity(string username, string email, IUserType userType) { return CreateUserWithIdentity(username, email, "", userType); @@ -165,11 +170,11 @@ namespace Umbraco.Core.Services } } - public IUser GetByUsername(string login) + public IUser GetByUsername(string username) { using (var repository = _repositoryFactory.CreateUserRepository(_uowProvider.GetUnitOfWork())) { - var query = Query.Builder.Where(x => x.Username.Equals(login)); + var query = Query.Builder.Where(x => x.Username.Equals(username)); return repository.GetByQuery(query).FirstOrDefault(); } } @@ -197,11 +202,11 @@ namespace Umbraco.Core.Services /// /// This is simply a helper method which essentially just wraps the MembershipProvider's ChangePassword method /// - /// The user to save the password for - /// /// /// This method exists so that Umbraco developers can use one entry point to create/update users if they choose to. /// + /// The user to save the password for + /// The password to save public void SavePassword(IUser user, string password) { if (user == null) throw new ArgumentNullException("user"); @@ -225,10 +230,10 @@ namespace Umbraco.Core.Services } /// - /// To permanently delete the user pass in true, otherwise they will just be disabled + /// Deletes or disables a User /// - /// - /// + /// to delete + /// True to permanently delete the user, False to disable the user public void Delete(IUser user, bool deletePermanently) { if (deletePermanently == false) @@ -417,12 +422,22 @@ namespace Umbraco.Core.Services return user.ProfileData; } - public IProfile GetProfileByUserName(string login) + /// + /// Gets a profile by username + /// + /// Username + /// + public IProfile GetProfileByUserName(string username) { - var user = GetByUsername(login); + var user = GetByUsername(username); return user.ProfileData; } - + + /// + /// Gets a user by Id + /// + /// Id of the user to retrieve + /// public IUser GetUserById(int id) { using (var repository = _repositoryFactory.CreateUserRepository(_uowProvider.GetUnitOfWork())) @@ -430,13 +445,14 @@ namespace Umbraco.Core.Services return repository.Get(id); } } - + /// /// Replaces the same permission set for a single user to any number of entities /// - /// - /// - /// + /// Note: If no 'entityIds' are specified all permissions will be removed for the specified user. + /// Id of the user + /// Permissions as enumerable list of + /// Specify the nodes to replace permissions for. If nothing is specified all permissions are removed. public void ReplaceUserPermissions(int userId, IEnumerable permissions, params int[] entityIds) { var uow = _uowProvider.GetUnitOfWork(); @@ -446,6 +462,11 @@ namespace Umbraco.Core.Services } } + /// + /// Gets all UserTypes or thosed specified as parameters + /// + /// Optional Ids of UserTypes to retrieve + /// An enumerable list of public IEnumerable GetAllUserTypes(params int[] ids) { var uow = _uowProvider.GetUnitOfWork(); @@ -456,7 +477,7 @@ namespace Umbraco.Core.Services } /// - /// Gets an IUserType by its Alias + /// Gets a UserType by its Alias /// /// Alias of the UserType to retrieve /// @@ -470,6 +491,11 @@ namespace Umbraco.Core.Services } } + /// + /// Gets a UserType by its Id + /// + /// Id of the UserType to retrieve + /// public IUserType GetUserTypeById(int id) { using (var repository = _repositoryFactory.CreateUserTypeRepository(_uowProvider.GetUnitOfWork())) @@ -479,7 +505,7 @@ namespace Umbraco.Core.Services } /// - /// Gets an IUserType by its Name + /// Gets a UserType by its Name /// /// Name of the UserType to retrieve /// @@ -493,6 +519,12 @@ namespace Umbraco.Core.Services } } + /// + /// Saves a UserType + /// + /// UserType to save + /// Optional parameter to raise events. + /// Default is True otherwise set to False to not raise events public void SaveUserType(IUserType userType, bool raiseEvents = true) { if (raiseEvents) @@ -512,6 +544,10 @@ namespace Umbraco.Core.Services SavedUserType.RaiseEvent(new SaveEventArgs(userType, false), this); } + /// + /// Deletes a UserType + /// + /// UserType to delete public void DeleteUserType(IUserType userType) { if (DeletingUserType.IsRaisedEventCancelled(new DeleteEventArgs(userType), this)) @@ -528,9 +564,10 @@ namespace Umbraco.Core.Services } /// - /// This is useful for when a section is removed from config + /// Removes a specific section from all users /// - /// + /// This is useful when an entire section is removed from config + /// Alias of the section to remove public void DeleteSectionFromAllUsers(string sectionAlias) { var uow = _uowProvider.GetUnitOfWork(); @@ -548,14 +585,12 @@ namespace Umbraco.Core.Services } /// - /// Returns permissions for a given user for any number of nodes + /// Get permissions set 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 - /// + /// If no permissions are found for a particular entity then the user's default permissions will be applied + /// User to retrieve permissions for + /// Specifiying nothing will return all user permissions for all nodes + /// An enumerable list of public IEnumerable GetPermissions(IUser user, params int[] nodeIds) { var uow = _uowProvider.GetUnitOfWork();