/// <summary> /// Returns the permissions for a user /// </summary> /// <param name="userType"></param> /// <returns></returns> public IEnumerable <UserTypePermissionRow> GetUserTypePermissions(IUserType userType) { var items = _sqlHelper.Fetch <UserTypePermissionRow>( "select * from UserTypePermissions where UserTypeId = @0 order by NodeId", userType.Id); return(items); }
public string GetPermissions(IUserType userType, string path) { string defaultPermissions = String.Join(string.Empty, userType.Permissions); var allUserPermissions = GetUserTypePermissions(userType).GroupBy(x => x.NodeId); foreach (string nodeId in path.Split(',')) { var parsedNodeId = int.Parse(nodeId); if (allUserPermissions.Select(x => x.Key).Contains(parsedNodeId)) { var userTypenodePermissions = String.Join(string.Empty, allUserPermissions.FirstOrDefault(x => x.Key == parsedNodeId) .Select(x => x.PermissionId)); if (!string.IsNullOrEmpty(userTypenodePermissions)) { defaultPermissions = userTypenodePermissions; } } } return defaultPermissions; }
/// <inheritdoc /> public async Task <IUserType> CreateUserTypeAsync(IUserType userType, CancellationToken cancellationToken = default(CancellationToken)) => await PostAsync <UserType>(new HttpRequest { Uri = "/api/v1/meta/types/user", Verb = HttpVerb.Post, Payload = userType, }, cancellationToken).ConfigureAwait(false);
public CustomType(System.Type userTypeClass, IDictionary <string, string> parameters) { name = userTypeClass.Name; try { userType = (IUserType)Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(userTypeClass); } catch (ArgumentNullException ane) { throw new MappingException("Argument is a null reference.", ane); } catch (ArgumentException ae) { throw new MappingException("Argument " + userTypeClass.Name + " is not a RuntimeType", ae); } catch (TargetInvocationException tie) { throw new MappingException("The constructor being called throws an exception.", tie); } catch (MethodAccessException mae) { throw new MappingException("The caller does not have permission to call this constructor.", mae); } catch (MissingMethodException mme) { throw new MappingException("No matching constructor was found.", mme); } catch (InvalidCastException ice) { throw new MappingException(userTypeClass.Name + " must implement NHibernate.UserTypes.IUserType", ice); } TypeFactory.InjectParameters(userType, parameters); sqlTypes = userType.SqlTypes; }
protected void Page_Load(object sender, EventArgs e) { try { //Load the created tables from DB if (!IsPostBack) { LoadDataGridView(); //Fill the select (dropDown) with the Table Status created on db this.IUNTGV = new MUserType(); this.sltUserType.DataValueField = "idUserType"; this.sltUserType.DataTextField = "description"; List <UserType> UT = IUNTGV.UserTypeList(); this.sltUserType.DataSource = UT; this.sltUserType.DataBind(); //Fill the select Status } } catch (Exception) { throw; } }
/// <summary> /// Returns the permissions for a user /// </summary> /// <param name="userType"></param> /// <returns></returns> public IEnumerable<UserTypePermissionRow> GetUserTypePermissions(IUserType userType) { var items = _sqlHelper.Fetch<UserTypePermissionRow>( "select * from UserTypePermissions where UserTypeId = @0 order by NodeId", userType.Id); return items; }
/// <summary> /// Gets all users related to the doctype /// </summary> /// <returns></returns> public static IUser[] GetAllRelatedUsers(this IUserType userType) { int total; return(ApplicationContext.Current.Services.UserService .GetAll(0, int.MaxValue, out total).Where(x => x.UserType.Id == userType.Id) .OrderBy(x => x.Name).ToArray()); }
public SecurityService(IUserType userType, IItemAccess itemAccess) { Users = new Dictionary <string, IUser>(); _userTypes = userType; _itemAccess = itemAccess; CurrentUserName = User.AnonymousUserName; UseLogin = false; }
/// <inheritdoc /> public async Task <IUserType> ReplaceUserTypeAsync(IUserType userType, string typeId, CancellationToken cancellationToken = default(CancellationToken)) => await PutAsync <UserType>(new HttpRequest { Uri = "/api/v1/meta/types/user/{typeId}", Verb = HttpVerb.Put, Payload = userType, PathParameters = new Dictionary <string, object>() { ["typeId"] = typeId, }, }, cancellationToken).ConfigureAwait(false);
public void Update(IUserType userType) { Type = userType.Type; if (userType.Users != null) { foreach (var item in userType.Users) { UserEntities.Add(new UserEntity(item)); } } }
public UserTypeEntity(IUserType userType) { Id = Guid.NewGuid(); Type = userType.Type; if (userType.Users != null) { foreach (var item in userType.Users) { UserEntities.Add(new UserEntity(item)); } } }
public UserController() { user = new MUser(); uType = new MUserType(); dc = new MDataCenter(); off = new MOffice(); lab = new MLab(); fac = new MFactory(); other = new MOtherProject(); phaType = new MPhaseType(); proType = new MProjectType(); speed = new MSpeedConnectionType(); }
/// <summary> /// Copies all permissions to related users of the user type. /// </summary> /// <param name="userType">Type of the user.</param> /// <param name="node">The node.</param> public void CopyPermissions(IUserType userType, IContent node) { IEnumerable <char> permissions = GetPermissions(userType, node.Path); foreach (IUser user in userType.GetAllRelatedUsers()) { if (!user.IsAdmin() && !user.Disabled()) { ApplicationContext.Current.Services.UserService .ReplaceUserPermissions(user.Id, permissions, node.Id); } } }
/// <summary> /// Returns the object after possibly passing it to a custom user type manager for conversion. /// </summary> /// <returns> /// The object after custom type conversion, if a custom type for this DB returned object is registered. /// </returns> /// <param name='obj'> /// The value returned by the DB. This CANNOT be null. /// </param> internal static object GetSystemObjectAfterCustomTypeConversion(object obj, Type typeOfSysType, Type typeOfDbType) { TypeKey typeKey = new TypeKey(typeOfSysType, typeOfDbType); // If there is a custom user type if (RegisteredTypes.ContainsKey(typeKey)) { IUserType userType = RegisteredTypes[typeKey]; return(userType.ReadValueFromDb(obj)); } else { return(obj); } }
/// <summary> /// Deletes a UserType /// </summary> /// <param name="userType">UserType to delete</param> public void DeleteUserType(IUserType userType) { using (var uow = UowProvider.GetUnitOfWork()) { if (uow.Events.DispatchCancelable(DeletingUserType, this, new DeleteEventArgs <IUserType>(userType))) { uow.Commit(); return; } var repository = RepositoryFactory.CreateUserTypeRepository(uow); repository.Delete(userType); uow.Commit(); uow.Events.Dispatch(DeletedUserType, this, new DeleteEventArgs <IUserType>(userType, false)); } }
public void UpdateCruds(IUserType userType, IContent node, string permissions) { // do not act on admin user types. if (userType.Alias != "admin") { // delete all settings on the node for this user DeletePermissions(userType, node); // Loop through the permissions and create them foreach (char c in permissions.ToCharArray()) { Insert(userType, node, c); } } }
public UserTypeDto BuildDto(IUserType entity) { var userType = new UserTypeDto { Alias = entity.Alias, DefaultPermissions = entity.Permissions == null ? "" : string.Join("", entity.Permissions), Name = entity.Name }; if (entity.HasIdentity) { userType.Id = short.Parse(entity.Id.ToString()); } return(userType); }
/// <summary> /// Deletes a UserType /// </summary> /// <param name="userType">UserType to delete</param> public void DeleteUserType(IUserType userType) { if (DeletingUserType.IsRaisedEventCancelled(new DeleteEventArgs <IUserType>(userType), this)) { return; } var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateUserTypeRepository(uow)) { repository.Delete(userType); uow.Commit(); } DeletedUserType.RaiseEvent(new DeleteEventArgs <IUserType>(userType, false), this); }
/// <summary> /// Registers a custom type to do conversion before assignment to results. /// </summary> /// <param name='userType'> /// The custom type handler. /// </param> /// <typeparam name='T'> /// The type that will be found in the db, which will be converted. /// </typeparam> public static void RegisterCustomType <SysType, DbType>(IUserType userType) { Type typeOfSysType = typeof(SysType); Type typeOfDbType = typeof(DbType); TypeKey typeKey = new TypeKey(typeOfSysType, typeOfDbType); if (RegisteredTypes.ContainsKey(typeKey)) { // Already exists, overwrite RegisteredTypes[typeKey] = userType; } else { RegisteredTypes.Add(typeKey, userType); } }
public static bool IsExistenceUserType(Guid userTypeId, ICompany company, out IUserType userTypeFromDb) { userTypeFromDb = null; if (userTypeId == null) { return(false); } userTypeFromDb = company.ReadUserType(userTypeId); if (userTypeFromDb == null) { return(false); } else { return(true); } }
public void Insert(IUserType userType, IContent node, char permissionKey) { // Method is synchronized so exists remains consistent (avoiding race condition) bool exists = _sqlHelper.Fetch <int>("SELECT UserTypeId FROM UserTypePermissions WHERE UserTypeId = @0 AND NodeId = @1 AND PermissionId = @2", userType.Id, node.Id, permissionKey.ToString()).Any(); if (!exists) { var newPerms = new UserTypePermissionRow { NodeId = node.Id, PermissionId = permissionKey.ToString(), UserTypeId = userType.Id, }; _sqlHelper.Insert(newPerms); } }
/// <inheritdoc/> public override void VisitUserType(IUserType userType) { if (!userType.IsResolved) { // A field has referenced a type that doesn't exist. For example: // ``` // struct User { // 1: UserType Type // } // ``` this.AddError( CompilerMessageId.UnknownType, userType.Node.IDENTIFIER().Symbol, userType.Name); } base.VisitUserType(userType); }
/// <summary> /// Saves a UserType /// </summary> /// <param name="userType">UserType to save</param> /// <param name="raiseEvents">Optional parameter to raise events. /// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param> public void SaveUserType(IUserType userType, bool raiseEvents = true) { using (var uow = UowProvider.GetUnitOfWork()) { if (raiseEvents && uow.Events.DispatchCancelable(SavingUserType, this, new SaveEventArgs <IUserType>(userType))) { uow.Commit(); return; } var repository = RepositoryFactory.CreateUserTypeRepository(uow); repository.AddOrUpdate(userType); uow.Commit(); if (raiseEvents) { uow.Events.Dispatch(SavedUserType, this, new SaveEventArgs <IUserType>(userType, false)); } } }
internal static IEnumerable <IUser> CreateUser(IUserType userType, int amount, Action <int, IUser> onCreating = null) { var list = new List <IUser>(); for (int i = 0; i < amount; i++) { var name = "Member No-" + i; var user = new User(name, "test" + i + "@test.com", "test" + i, "test" + i, userType); if (onCreating != null) { onCreating(i, user); } user.ResetDirtyProperties(false); list.Add(user); } return(list); }
public void Insert(IUserType userType, IContent node, char permissionKey) { // Method is synchronized so exists remains consistent (avoiding race condition) bool exists = _sqlHelper.Fetch<int>("SELECT UserTypeId FROM UserTypePermissions WHERE UserTypeId = @0 AND NodeId = @1 AND PermissionId = @2", userType.Id, node.Id, permissionKey.ToString()).Any(); if (!exists) { var newPerms = new UserTypePermissionRow { NodeId = node.Id, PermissionId = permissionKey.ToString(), UserTypeId = userType.Id, }; _sqlHelper.Insert(newPerms); } }
public CustomType(System.Type userTypeClass, IDictionary parameters) { name = userTypeClass.Name; try { userType = (IUserType) Activator.CreateInstance(userTypeClass); userTypeAsNullable = userType as INullableUserType; } catch (ArgumentNullException ane) { throw new MappingException("Argument is a null reference.", ane); } catch (ArgumentException ae) { throw new MappingException("Argument " + userTypeClass.Name + " is not a RuntimeType", ae); } catch (TargetInvocationException tie) { throw new MappingException("The constructor being called throws an exception.", tie); } catch (MethodAccessException mae) { throw new MappingException("The caller does not have permission to call this constructor.", mae); } catch (MissingMethodException mme) { throw new MappingException("No matching constructor was found.", mme); } catch (InvalidCastException ice) { throw new MappingException(userTypeClass.Name + " must implement NHibernate.UserTypes.IUserType", ice); } TypeFactory.InjectParameters(userType, parameters); sqlTypes = userType.SqlTypes; if (!userType.ReturnedType.IsSerializable) { LogManager.GetLogger(typeof(CustomType)).Warn("custom type is not Serializable: " + userTypeClass); } }
public CustomType(System.Type userTypeClass, IDictionary<string, string> parameters) { name = userTypeClass.Name; try { userType = (IUserType) Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(userTypeClass); } catch (ArgumentNullException ane) { throw new MappingException("Argument is a null reference.", ane); } catch (ArgumentException ae) { throw new MappingException("Argument " + userTypeClass.Name + " is not a RuntimeType", ae); } catch (TargetInvocationException tie) { throw new MappingException("The constructor being called throws an exception.", tie); } catch (MethodAccessException mae) { throw new MappingException("The caller does not have permission to call this constructor.", mae); } catch (MissingMethodException mme) { throw new MappingException("No matching constructor was found.", mme); } catch (InvalidCastException ice) { throw new MappingException(userTypeClass.Name + " must implement NHibernate.UserTypes.IUserType", ice); } TypeFactory.InjectParameters(userType, parameters); sqlTypes = userType.SqlTypes; if (!userType.ReturnedType.IsSerializable) { LoggerProvider.LoggerFor(typeof(CustomType)).WarnFormat("the custom type '{0}' handled by '{1}' is not Serializable: ", userType.ReturnedType, userTypeClass); } }
/// <summary> /// /// </summary> /// <param name="userTypeClass"></param> public CustomType(System.Type userTypeClass) { name = userTypeClass.Name; try { userType = ( IUserType )Activator.CreateInstance(userTypeClass); } catch (ArgumentNullException ane) { throw new MappingException("Argument is a null reference.", ane); } catch (ArgumentException ae) { throw new MappingException("Argument " + userTypeClass.Name + " is not a RuntimeType", ae); } catch (TargetInvocationException tie) { throw new MappingException("The constructor being called throws an exception.", tie); } catch (MethodAccessException mae) { throw new MappingException("The caller does not have permission to call this constructor.", mae); } catch (MissingMethodException mme) { throw new MappingException("No matching constructor was found.", mme); } catch (InvalidCastException ice) { throw new MappingException(userTypeClass.Name + " must implement NHibernate.IUserType", ice); } sqlTypes = userType.SqlTypes; if (!userType.ReturnedType.IsSerializable) { LogManager.GetLogger(typeof(CustomType)).Warn("custom type is not Serializable: " + userTypeClass); } }
/// <summary> /// Saves a UserType /// </summary> /// <param name="userType">UserType to save</param> /// <param name="raiseEvents">Optional parameter to raise events. /// Default is <c>True</c> otherwise set to <c>False</c> to not raise events</param> public void SaveUserType(IUserType userType, bool raiseEvents = true) { if (raiseEvents) { if (SavingUserType.IsRaisedEventCancelled(new SaveEventArgs <IUserType>(userType), this)) { return; } } var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateUserTypeRepository(uow)) { repository.AddOrUpdate(userType); uow.Commit(); } if (raiseEvents) { SavedUserType.RaiseEvent(new SaveEventArgs <IUserType>(userType, false), this); } }
internal static User CreateUser(IUserType userType = null, string suffix = "", params string[] allowedSections) { if (userType == null) { userType = MockedUserType.CreateUserType(); } var user = new User(userType) { Language = "en", IsApproved = true, Name = "TestUser" + suffix, Password = "******", NoConsole = false, DefaultPermissions = "ABC", StartContentId = -1, StartMediaId = -1, DefaultToLiveEditing = false, Email = "test" + suffix + "@test.com", Username = "******" + suffix }; if (allowedSections.Any()) { foreach (var s in allowedSections) { user.AddAllowedSection(s); } } else { user.AddAllowedSection("content"); user.AddAllowedSection("media"); } return(user); }
internal static User CreateUser(IUserType userType = null, string suffix = "", params string[] allowedSections) { if (userType == null) { userType = MockedUserType.CreateUserType(); } var user = new User(userType) { Language = "en", IsApproved = true, Name = "TestUser" + suffix, Password = "******", NoConsole = false, DefaultPermissions = "ABC", StartContentId = -1, StartMediaId = -1, DefaultToLiveEditing = false, Email = "test" + suffix + "@test.com", Username = "******" + suffix }; if (allowedSections.Any()) { foreach (var s in allowedSections) { user.AddAllowedSection(s); } } else { user.AddAllowedSection("content"); user.AddAllowedSection("media"); } return user; }
public string GetPermissions(IUserType userType, string path) { string defaultPermissions = String.Join(string.Empty, userType.Permissions); var allUserPermissions = GetUserTypePermissions(userType).GroupBy(x => x.NodeId); foreach (string nodeId in path.Split(',')) { var parsedNodeId = int.Parse(nodeId); if (allUserPermissions.Select(x => x.Key).Contains(parsedNodeId)) { var userTypenodePermissions = String.Join(string.Empty, allUserPermissions.FirstOrDefault(x => x.Key == parsedNodeId) .Select(x => x.PermissionId)); if (!string.IsNullOrEmpty(userTypenodePermissions)) { defaultPermissions = userTypenodePermissions; } } } return(defaultPermissions); }
public User(IUserType userType) { if (userType == null) { throw new ArgumentNullException("userType"); } _userType = userType; _defaultPermissions = _userType.Permissions == null?Enumerable.Empty <string>() : new List <string>(_userType.Permissions); //Groups = new List<object> { userType }; SessionTimeout = 60; _sectionCollection = new ObservableCollection <string>(); _addedSections = new List <string>(); _removedSections = new List <string>(); _language = GlobalSettings.DefaultUILanguage; _sectionCollection.CollectionChanged += SectionCollectionChanged; _isApproved = true; _isLockedOut = false; _startContentId = -1; _startMediaId = -1; //cannot be null _rawPasswordValue = ""; }
public bool SaveUserTypes(IUserType userType) { //var userSession = new UserSession //{ // UserId = "12345" //}; //// First add into the db //_demoDbContext.UserTypes.Add(userType as UserType); //_demoDbContext.UserTypes.Add(userType as UserType); //// Second update operation //var type = _demoDbContext.UserTypes.FirstOrDefault(x => x.Id == 1); //type.Name = "Updated Name"; //var deleteType = _demoDbContext.UserTypes.FirstOrDefault(x => x.Id == 2); //_demoDbContext.UserTypes.Remove(deleteType); //_demoDbContext.SaveChanges(userSession); var user = _demoDbContext.Users.FirstOrDefault(x => x.UserType.Id == 1); return(true); }
/// <summary> /// deletes all permissions for the user /// </summary> /// <param name="userType"></param> public void DeletePermissions(IUserType userType) { // delete all settings on the node for this user _sqlHelper.Execute("delete from UserTypePermissions where UserTypeId=@0 ", userType.Id); }
/// <summary> /// Copies all permissions to related users of the user type. /// </summary> /// <param name="userType">Type of the user.</param> /// <param name="node">The node.</param> public void CopyPermissions(IUserType userType, IContent node) { IEnumerable<char>permissions = GetPermissions(userType, node.Path); foreach (IUser user in userType.GetAllRelatedUsers()) { if (!user.IsAdmin() && !user.Disabled()) { ApplicationContext.Current.Services.UserService .ReplaceUserPermissions(user.Id, permissions, node.Id); } } }
/// <summary> /// Creates a new user for logging into the umbraco backoffice /// </summary> /// <param name="name"></param> /// <param name="login"></param> /// <param name="password"></param> /// <param name="userType"></param> /// <param name="email"></param> /// <returns></returns> public IMembershipUser CreateMembershipUser(string name, string login, string password, IUserType userType, string email = "") { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateUserRepository(uow)) { var loginExists = uow.Database.ExecuteScalar<int>("SELECT COUNT(id) FROM umbracoUser WHERE userLogin = @Login", new { Login = login }) != 0; if (loginExists) throw new ArgumentException("Login already exists"); var user = new User(userType) { DefaultToLiveEditing = false, Email = email, Language = Umbraco.Core.Configuration.GlobalSettings.DefaultUILanguage, Name = name, Password = password, DefaultPermissions = userType.Permissions, Username = login, StartContentId = -1, StartMediaId = -1, NoConsole = false, IsApproved = true }; repository.AddOrUpdate(user); uow.Commit(); return user; } }
public User(IUserType userType) { Groups = new List<object> { userType }; }
public UserFactory(IUserType userType) { _userType = userType; }
public void UpdateCruds(IUserType userType, IContent node, string permissions) { // do not act on admin user types. if (userType.Alias != "admin") { // delete all settings on the node for this user DeletePermissions(userType, node); // Loop through the permissions and create them foreach (char c in permissions.ToCharArray()) Insert(userType, node, c); } }