Esempio n. 1
0
        public void AddPermissionTest()
        {
            var        menus      = _menuService.GetMenus("");
            Permission permission = new Permission {
                Createtime = DateTime.Now, Deleted = false, Menus = menus, PermissionType = PermissionType.Menu, Updatetime = DateTime.Now, Name = SystemRoleNames.Administrators
            };

            _permissionService.AddPermission(permission);



            permission = new Permission {
                Createtime = DateTime.Now, Deleted = false, Menus = menus, PermissionType = PermissionType.Menu, Updatetime = DateTime.Now, Name = SystemRoleNames.Leader
            };

            _permissionService.AddPermission(permission);



            permission = new Permission {
                Createtime = DateTime.Now, Deleted = false, Menus = menus, PermissionType = PermissionType.Menu, Updatetime = DateTime.Now, Name = SystemRoleNames.Developer
            };

            _permissionService.AddPermission(permission);
        }
Esempio n. 2
0
            public void AddPermission(string PermissionName, bool IsExpectedToBeSuccessful)
            {
                DiSetup.Tests();
                IPermissionService permissionService = DiHelper.GetService <IPermissionService>();

                if (PermissionName.Equals("111") && IsExpectedToBeSuccessful.Equals(true))
                {
                    //only clear the first time
                    permissionService.Clear();
                }
                permissionService.CreateTestData();

                int numberBefore = permissionService.GetPermissions().Count();
                var result       = permissionService.AddPermission(new Permission(PermissionName));
                int numberAfter  = permissionService.GetPermissions().Count();

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(bool));
                if (IsExpectedToBeSuccessful)
                {
                    Assert.AreEqual(true, result);
                    Assert.AreEqual(numberAfter, numberBefore + 1);
                }
                else
                {
                    Assert.AreEqual(false, result);
                    Assert.AreEqual(numberAfter, numberBefore);
                }
            }
        public async Task <ActionResult <Permission> > PostPermission(Permission permission)
        {
            try
            {
                await _permissionService.AddPermission(permission);
            }
            catch (PermissionRoleIsInvalidException e)
            {
                return(BadRequest(e));
            }
            catch (UserDoesNotExistException e)
            {
                return(BadRequest(e));
            }
            catch (PermissionAlreadyExistsException e)
            {
                return(Conflict(e));
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(CreatedAtAction("GetPermission", new { userId = permission.UserId, role = permission.Role }, permission));
        }
Esempio n. 4
0
        public IActionResult AddPermission(Dictionary <int, PermissionModel> data)
        {
            var role = from s in (_roleService.GetRolesByUserId(_workContext.CurrentUser.Id).ToList()) select s.Name;

            if (role.Contains("超级管理员") || _permissionService.Authorize("AddPermission"))
            {
                if (data.Count != 1)
                {
                    return(ErrReturn("* 请选择一个权限进项操作"));
                }
                var model = data.Where(x => true).FirstOrDefault().Value;
                if (string.IsNullOrEmpty(model.Name))
                {
                    return(ErrReturn("name", "* 权限名称必填!"));
                }
                if (string.IsNullOrEmpty(model.SystemName))
                {
                    return(ErrReturn("systemName", "* 控制码必填!"));
                }
                if (string.IsNullOrEmpty(model.Category))
                {
                    return(ErrReturn("category", "* 请选择一个权限类型"));
                }
                if (_permissionService.GetPermissionByName(model.Name) != null)
                {
                    return(ErrReturn("name", "* 已存在相同名称的权限!"));
                }
                if (_permissionService.GetPermissionByCode(model.SystemName) != null)
                {
                    return(ErrReturn("systemName", "* 已存在相同名称的控制码!"));
                }

                try
                {
                    var permission = new Permission
                    {
                        Name       = model.Name,
                        SystemName = model.SystemName,
                        Category   = model.Category,
                        Isvalid    = true,
                        State      = model.State,
                        Remark     = model.Remark
                    };
                    _permissionService.AddPermission(permission);

                    var result = new List <PermissionModel> {
                        _permissionService.GetPermissionByName(model.Name).ToModel()
                    };
                    return(Success(result));
                }
                catch (Exception)
                {
                    return(ErrReturn("添加失败!"));
                }
            }
            else
            {
                return(Error("无操作权限!"));
            }
        }
Esempio n. 5
0
        public IActionResult AddPermission(Dictionary <int, PermissionModel> data)
        {
            if (data.Count != 1)
            {
                return(ErrReturn("* 请选择一个权限进项操作"));
            }
            var model = data.Where(x => true).FirstOrDefault().Value;

            if (string.IsNullOrEmpty(model.Name))
            {
                return(ErrReturn("name", "* 权限名称必填!"));
            }
            if (string.IsNullOrEmpty(model.SystemName))
            {
                return(ErrReturn("systemName", "* 控制码必填!"));
            }
            if (string.IsNullOrEmpty(model.Category))
            {
                return(ErrReturn("category", "* 请选择一个权限类型"));
            }
            if (_permissionService.GetPermissionByName(model.Name) != null)
            {
                return(ErrReturn("name", "* 已存在相同名称的权限!"));
            }
            if (_permissionService.GetPermissionByCode(model.SystemName) != null)
            {
                return(ErrReturn("systemName", "* 已存在相同名称的控制码!"));
            }

            try
            {
                var permission = new Permission
                {
                    Name       = model.Name,
                    SystemName = model.SystemName,
                    Category   = model.Category,
                    Isvalid    = true,
                    State      = model.State,
                    Remark     = model.Remark
                };
                _permissionService.AddPermission(permission);

                var result = new List <PermissionModel> {
                    _permissionService.GetPermissionByName(model.Name).ToModel()
                };
                return(Success(result));
            }
            catch (Exception)
            {
                return(ErrReturn("添加失败!"));
            }
        }
Esempio n. 6
0
    public async Task <ActionResult <PermissionDto> > Post([FromBody] PermissionDto permissionDto)
    {
        var result = await _permissionService.AddPermission(permissionDto);

        return(Ok(result));
    }
 public ContentResult Add(PermissionDto dto)
 {
     _permissionService.AddPermission(dto);
     return(ResultSuccess <string>("添加成功"));
 }
Esempio n. 8
0
        public async Task <ActionResult <PermissionDto> > Post([FromBody] PermissionDto permissionDto)
        {
            var result = await _permissionService.AddPermission(permissionDto);

            return(StatusCode(result.StatusCode, result.HttpResponse));
        }
Esempio n. 9
0
        /// <summary>
        /// Add permission for role
        /// </summary>
        /// <param name="listPermissionVM"></param>
        /// <returns></returns>
        public IActionResult AddPermission(List <PermissionViewModel> listPermissionVM)
        {
            var rs = _permissionService.AddPermission(listPermissionVM);

            return(new OkObjectResult(rs));
        }
Esempio n. 10
0
 public async Task <Permission> PostPermission([FromBody] Permission permission)
 {
     _permissionService.AddPermission(permission);
     return(await Task.FromResult(permission));
 }