Exemplo n.º 1
0
        public async override Task <Guid> Execute(PermissionCreateCommand input, User?user)
        {
            var p = new Permission(input.Action, input.Scope);

            await spec.CheckAndThrow(p);

            await repo.Add(p);

            return(p.Id);
        }
Exemplo n.º 2
0
        public async Task <string> AddAsync(PermissionNewDto permission)
        {
            if (await _permissionRepo.IsExistedAsync(clientId: permission.ClientId, key: permission.Key))
            {
                throw new IamException(HttpStatusCode.BadRequest, "已经存在");
            }

            if (permission.Type == PermissionType.View)
            {
                if (String.IsNullOrWhiteSpace(permission.Url))
                {
                    throw new IamException(HttpStatusCode.BadRequest, "Url 不能为空");
                }
            }

            if (!String.IsNullOrWhiteSpace(permission.ParentId))
            {
                var parent = await _permissionRepo.GetAsync(permission.ParentId);

                if (parent == null)
                {
                    throw new IamException(HttpStatusCode.BadRequest, "父级不存在!");
                }

                if (parent.ClientId != permission.ClientId)
                {
                    throw new IamException(HttpStatusCode.BadRequest, $"父级并不属于客户端({permission.ClientId})!");
                }
            }

            string id = Guid.NewGuid().ToString();

            _permissionRepo.Add(new Permission(id, permission.ClientId, permission.Type, permission.Key, permission.Name, permission.Desc,
                                               permission.ParentId, permission.Url, permission.Icon, permission.Order, permission.Level));

            return(id);
        }