Example #1
0
        public void AddUser()
        {
            User user = new User();
            user.Account = "test-adduser-" + StringFactory.NewGuid().Substring(0, 4);
            user.Name = "test-add-user";
            user.IsActive = true;
            user.Save();

            Organization org = Organization.Create();
            org.Code = StringFactory.NewGuid();
            org.Name = "org-test-name";
            org.FullName = "org-test-fullname";
            org.Save();

            Position position = Position.Create();
            position.Code = StringFactory.NewGuid();
            position.OrganizationId = org.Id;
            position.Name = "test-add-Postion";
            position.Save();

            position.AddUser(user);

            var userInfo = position.UserList.FirstOrDefault(u => u.Account == user.Account);

            Assert.IsNotNull(userInfo);

            user.Delete();
            position.RemoveUser(user);
            position.Delete();
            org.Delete();
        }
Example #2
0
        public void CheckPermission()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Operation target = new Operation();
            target.Code = StringFactory.NewGuid();
            target.AppId = StringFactory.NewGuid();
            target.TargetId = StringFactory.NewGuid();
            target.Name = "test-add-RoleTargetOperation";

            bool b = user.CheckPermission(target);
            Assert.IsFalse(b);

            User user1 = new User();
            user1.Name = "test-add-user";
            user1.Account = StringFactory.NewGuid();
            user1.Save();

            Role role = Role.Create();
            role.Name = "test-giverole-role";
            role.Save();

            role.GivePermission(target);
            user.GiveRole(role);

            User user2 = User.GetUser(user.Account);
            var b1 = user2.CheckPermission(target);
            Assert.IsTrue(b1);

            role.Delete();
            user1.CancelRole(role);
            role.CancelPermission(target);
            user.Delete();
            user1.Delete();
        }
Example #3
0
        public void CancelRole()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Role role = Role.Create();
            role.Code = StringFactory.NewGuid();
            role.Name = "test-giverole-role";
            role.Save();

            user.GiveRole(role);
            User user1 = User.GetUser(user.Account);
            var user2 = user1.RoleList.Where(r => r.Code == role.Code).ToList();
            Assert.AreEqual(1, user2.Count);

            user1.CancelRole(role);
            var user3 = user1.RoleList.Where(r => r.Code == role.Code).ToList();
            Assert.AreEqual(0, user3.Count);

            role.Delete();
            user.Delete();
        }
Example #4
0
        public void AddUser()
        {
            Organization org1 = Organization.Create();
            org1.Code = StringFactory.NewGuid();
            org1.Name = "org-test-name";
            org1.FullName = "org-test-fullname";
            org1.Save();
            Assert.IsNotNull(org1);

            User user1 = new User();
            user1.Account = "test-user-add" + StringFactory.NewGuid().Substring(0, 4);
            user1.Name = "test-user-name";
            user1.IsActive = true;
            user1.Save();

            org1.AddUser(user1);

            var positionuser = org1.UserList.Where(pu => pu.Account == user1.Account).ToList();
            Assert.AreEqual(1, positionuser.Count);

            user1.Delete();
            org1.Delete();
            org1.RemoveUser(user1);
        }
Example #5
0
 public User RemoveUser(User user)
 {
     if (!PositionInfoRepo.Exists(this.MappingTo<PositionInfo>()))
     {
         throw new Exception("岗位不存在");
     }
     List<PositionUserInfo> piList = PositionUserInfoRepo.Read()
         .Where(pu => pu.UserId == user.Id
         && pu.OrganizationId == this.OrganizationId
         && pu.PositionId == this.Id)
         .ToList();
     foreach (var pi in piList)
     {
         PositionUserInfoRepo.Delete(pi);
     }
     return user;
 }
Example #6
0
 public User AddUser(User user)
 {
     if (!PositionInfoRepo.Exists(this.MappingTo<PositionInfo>()))
     {
         throw new Exception("岗位不存在");
     }
     if (!User.UserInfoRepo.Exists(user.MappingTo<UserInfo>()))
     {
         throw new Exception("用户不存在");
     }
     PositionUserInfo pu = new PositionUserInfo();
     pu.UserId = user.Id;
     pu.OrganizationId = this.OrganizationId;
     pu.PositionId = this.Id;
     PositionUserInfoRepo.Save(pu);
     return user;
 }
Example #7
0
        public void TargetOperationList()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Operation operation = new Operation();
            operation.Code = StringFactory.NewGuid();
            operation.AppId = StringFactory.NewGuid();
            operation.TargetId = StringFactory.NewGuid();
            operation.Name = "test-add-RoleTargetOperation";
            operation.Save();

            User user1 = new User();
            user1.Name = "test-add-user";
            user1.Account = StringFactory.NewGuid();
            user1.Save();

            Role role = Role.Create();
            role.Name = "test-giverole-role";
            role.Save();

            role.GivePermission(operation);
            user.GiveRole(role);

            User user2 = User.GetUser(user.Account);
            Assert.AreEqual(1, user2.OperationList.Count);

            role.Delete();
            user1.CancelRole(role);
            role.CancelPermission(operation);
            operation.Delete();
            user.Delete();
            user1.Delete();
        }
Example #8
0
        public void TargetList()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Role role = Role.Create();
            role.Name = "test-giverole-role";
            role.Save();

            user.GiveRole(role);

            Organization org1 = Organization.Create();
            org1.Code = StringFactory.NewGuid();
            org1.Name = "org-test-name";
            org1.FullName = "org-test-fullname";
            org1.Save();
            Assert.IsNotNull(org1);

            org1.GiveRole(role);

            Target target = Target.Create();
            target.Code = StringFactory.NewGuid();
            target.AppId = StringFactory.NewGuid();
            target.Save();

            Operation targetoperation = new Operation();
            targetoperation.Code = StringFactory.NewGuid();
            targetoperation.AppId = StringFactory.NewGuid();
            targetoperation.TargetId = StringFactory.NewGuid();
            target.AddOperation(targetoperation);

            role.GivePermission(targetoperation);

            User user1 = User.GetUser(user.Account);

            Assert.IsNotNull(user.TargetList);

            user.Delete();
            role.Delete();
            org1.Delete();
            org1.CancelRole(role);
            target.Delete();
            target.RemoveOperation(targetoperation);
            role.CancelPermission(targetoperation);
        }
Example #9
0
        public void Save()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            User user2 = User.GetUser(user.Account);
            Assert.IsNull(user2);
            user.Save();

            User user1 = User.GetUser(user.Account);
            Assert.IsNotNull(user1);

            user.Delete();
        }
Example #10
0
        public void PositionList()
        {
            User user = new User();
            user.Account = "test-add-user" + StringFactory.NewGuid().Substring(0, 4);
            user.Save();

            Organization org1 = Organization.Create();
            org1.Code = StringFactory.NewGuid();
            org1.Name = "org-test-name";
            org1.FullName = "org-test-fullname";
            org1.IsActive = true;
            org1.Save();

            Position position = Position.Create();
            position.Name = "test-Position-add";
            position.Code = StringFactory.NewGuid();
            position.OrganizationId = org1.Id;
            position.IsActive = true;
            position.Save();

            position.AddUser(user);

            User user1 = User.GetUser(user.Account);
            Assert.IsNotNull(user1);
            Assert.AreEqual(1, user1.PositionList
                .Where(o => o.OrganizationId == org1.Id)
                .ToList().Count);

            user.Delete();
            position.RemoveUser(user);
            position.Delete();
            org1.Delete();
        }
Example #11
0
        public void DeepRoleList()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Role role = Role.Create();
            role.Name = "test-giverole-role";
            role.Save();

            user.GiveRole(role);
            User user1 = User.GetUser(user.Account);
            var user2 = user1.DeepRoleList.Where(r => r.Code == role.Code); ;
            Assert.IsNotNull(user2);

            user1.CancelRole(role);
            role.Delete();
            user.Delete();
        }
Example #12
0
 public static User Create()
 {
     User user = new User();
     return user;
 }
Example #13
0
        public void GetUserList()
        {
            Organization org1 = Organization.Create();
            org1.Code = StringFactory.NewGuid();
            org1.Name = "org-test-name";
            org1.FullName = "org-test-fullname";
            org1.Save();
            Assert.IsNotNull(org1);

            User user1 = new User();
            user1.Account = "test-user-add" + StringFactory.NewGuid().Substring(0, 4);
            user1.IsActive = true;
            user1.Save();

            org1.AddUser(user1);

            Organization org2 = Organization.GetOrganization(org1.Code);
            Assert.IsNotNull(org2);
            Assert.AreNotEqual(0, org2.UserList.Count);

            org1.Delete();
            org1.RemoveUser(user1);
            user1.Delete();
        }
Example #14
0
 /// <summary>
 /// 移除用户
 /// </summary>
 /// <param name="user"></param>
 public User RemoveUser(User user)
 {
     var positionUserList = PositionUserInfoRepo.Read().Where(pu => pu.OrganizationId == this.Id && pu.UserId == user.Id);
     foreach (var item in positionUserList)
     {
         PositionUserInfoRepo.Delete(item);
     }
     return user;
 }
Example #15
0
 /// <summary>
 /// 新增用户
 /// </summary>
 /// <param name="user"></param>
 public User AddUser(User user)
 {
     if (user == null) return user;
     var positionUserList = PositionUserInfoRepo.Read();
     if (!positionUserList.Exists(pu => pu.OrganizationId == this.Code && pu.UserId == user.Account))
     {
         PositionUserInfo positionUserInfo = new PositionUserInfo();
         positionUserInfo.PositionId = "";
         positionUserInfo.UserId = user.Id;
         positionUserInfo.OrganizationId = this.Id;
         PositionUserInfoRepo.Save(positionUserInfo);
     }
     return user;
 }