public virtual void AssignDefaultPermission(ISession session, IEnumerable <UserPermission> permissions = null) { if (permissions == null) { permissions = new UserPermission[0]; } var availability = UserPermissionAvailability.Supplier; if (Client != null) { availability = UserPermissionAvailability.Drugstore; } var defaultPermissions = UserPermission.DefaultPermissions(session, availability); permissions = permissions.Concat(defaultPermissions) .Distinct() .Except(AssignedPermissions) .ToArray(); foreach (var permission in permissions) { AssignedPermissions.Add(permission); } }
/// <summary> /// Assigns one permission to an entity for multiple users /// </summary> /// <param name="entity"></param> /// <param name="permission"></param> /// <param name="userIds"></param> public void AssignEntityPermission(TEntity entity, char permission, IEnumerable <int> userIds) { var db = _unitOfWork.Database; using (var trans = db.GetTransaction()) { db.Execute("DELETE FROM umbracoUser2NodePermission WHERE nodeId=@nodeId AND permission=@permission AND userId in (@userIds)", new { nodeId = entity.Id, permission = permission.ToString(CultureInfo.InvariantCulture), userIds = userIds }); var actions = userIds.Select(id => new User2NodePermissionDto { NodeId = entity.Id, Permission = permission.ToString(CultureInfo.InvariantCulture), UserId = id }).ToArray(); _unitOfWork.Database.BulkInsertRecords(actions, trans); trans.Complete(); //Raise the event AssignedPermissions.RaiseEvent( new SaveEventArgs <EntityPermission>(ConvertToPermissionList(actions), false), this); } }
public virtual void PrepareSave(ISession session) { if (Client != null) { if (AssignedPermissions.FirstOrDefault(p => p.Shortcut == "ConfigureMatrixAssortment") != null && Client.Settings.BuyingMatrix == null) { var matrix = new Matrix(); session.Save(matrix); Client.Settings.BuyingMatrix = matrix; Client.Settings.BuyingMatrixType = MatrixType.BlackList; Client.Settings.BuyingMatrixAction = MatrixAction.Delete; session.Save(Client.Settings); } } //Проверяем поле доступа к фтп и изменяем доступ в случае необходимости var oldFtpAccess = session.OldValue(this, u => u.FtpAccess); if (oldFtpAccess != FtpAccess) { SetFtpAccess(FtpAccess); } }
/// <summary> /// Assigns permissions to an entity for multiple users/permission entries /// </summary> /// <param name="permissionSet"> /// </param> /// <remarks> /// This will first clear the permissions for this entity then re-create them /// </remarks> public void ReplaceEntityPermissions(EntityPermissionSet permissionSet) { var db = _unitOfWork.Database; using (var trans = db.GetTransaction()) { db.Execute("DELETE FROM umbracoUser2NodePermission WHERE nodeId=@nodeId", new { nodeId = permissionSet.EntityId }); var actions = permissionSet.UserPermissionsSet.Select(p => new User2NodePermissionDto { NodeId = permissionSet.EntityId, Permission = p.Permission, UserId = p.UserId }).ToArray(); _unitOfWork.Database.BulkInsertRecords(actions, trans); trans.Complete(); //Raise the event AssignedPermissions.RaiseEvent( new SaveEventArgs <EntityPermission>(ConvertToPermissionList(actions), false), this); } }
/// <summary> /// Assigns the same permission set for a single user to any number of entities /// </summary> /// <param name="userId"></param> /// <param name="permissions"></param> /// <param name="entityIds"></param> /// <remarks> /// This will first clear the permissions for this user and entities and recreate them /// </remarks> public void ReplaceUserPermissions(int userId, IEnumerable <char> permissions, params int[] entityIds) { var db = _unitOfWork.Database; using (var trans = db.GetTransaction()) { //we need to batch these in groups of 2000 so we don't exceed the max 2100 limit foreach (var idGroup in entityIds.InGroupsOf(2000)) { db.Execute("DELETE FROM umbracoUser2NodePermission WHERE userId=@userId AND nodeId in (@nodeIds)", new { userId = userId, nodeIds = idGroup }); } var toInsert = new List <User2NodePermissionDto>(); foreach (var p in permissions) { foreach (var e in entityIds) { toInsert.Add(new User2NodePermissionDto { NodeId = e, Permission = p.ToString(CultureInfo.InvariantCulture), UserId = userId }); } } _unitOfWork.Database.BulkInsertRecords(toInsert, trans); trans.Complete(); //Raise the event AssignedPermissions.RaiseEvent( new SaveEventArgs <EntityPermission>(ConvertToPermissionList(toInsert), false), this); } }
public virtual bool IsPermissionAssigned(UserPermission permission) { return(AssignedPermissions.Any(p => permission.Shortcut == p.Shortcut)); }
public virtual bool UserHasPermission(uint id) { return(AssignedPermissions.SingleOrDefault(p => p.Id == id) != null); }