コード例 #1
0
        public virtual async Task <PermissionedObjectDto> SetAsync(PermissionedObjectDto permissionedObject)
        {
            // ToDo: AS - check if permission names exist
            var obj = await _permissionedObjectRepository.GetAll().FirstOrDefaultAsync(x =>
                                                                                       x.Object == permissionedObject.Object &&
                                                                                       x.Type == permissionedObject.Type &&
                                                                                       x.Module == permissionedObject.Module)
                      ??
                      new PermissionedObject()
            {
                Object = permissionedObject.Object,
                Type   = permissionedObject.Type,
                Module = permissionedObject.Module,
                Parent = permissionedObject.Parent,
                Name   = permissionedObject.Name,
            };

            obj.Category    = permissionedObject.Category;
            obj.Description = permissionedObject.Description;
            obj.Permissions = string.Join(",", permissionedObject.Permissions ?? new ConcurrentHashSet <string>());
            //obj.Inherited = permissionedObject.Inherited;
            obj.Hidden = permissionedObject.Hidden;
            obj.Access = (RefListPermissionedAccess?)permissionedObject.Access ?? RefListPermissionedAccess.Inherited;

            await _permissionedObjectRepository.InsertOrUpdateAsync(obj);

            await _cacheManager.GetPermissionedObjectCache().SetAsync(permissionedObject.Object, permissionedObject);

            return(permissionedObject);
        }
コード例 #2
0
        public List <PermissionedObjectDto> GetAll(string objectType = null)
        {
            if (objectType != null && !GetObjectTypes().Contains(objectType))
            {
                return(new List <PermissionedObjectDto>());
            }

            var api = _apiDescriptionsProvider.ApiDescriptionGroups.Items.SelectMany(g => g.Items.Select(a =>
            {
                var descriptor = a.ActionDescriptor.AsControllerActionDescriptor();
                var module     = GetModuleOfType(descriptor.ControllerTypeInfo.AsType());
                return(new ApiDescriptor()
                {
                    Description = a,
                    Module = module,
                    Service = descriptor.ControllerTypeInfo.AsType(),
                    HttpMethod = a.HttpMethod,
                    Endpoint = a.RelativePath,
                    Action = descriptor.MethodInfo
                });
            })).ToList();

            var allApiPermissions = new List <PermissionedObjectDto>();

            var modules = api.Select(x => x.Module).Distinct().ToList();

            foreach (var module in modules)
            {
                var services = api.Where(a => a.Module == module).Select(x => x.Service).Distinct().ToList();

                foreach (var service in services)
                {
                    var isDynamic = service.GetInterfaces().Any(x =>
                                                                x.IsGenericType &&
                                                                x.GetGenericTypeDefinition() == typeof(IDynamicCrudAppService <, ,>));

                    var objType = isDynamic
                        ? PermissionedObjectsSheshaTypes.WebCrudApi
                        : GetObjectType(service);

                    if (objectType != null && objType != objectType)
                    {
                        continue;
                    }

                    string name        = null;
                    string fullName    = null;
                    string description = null;
                    Type   eModule     = null;

                    Type entityType = null;
                    if (objType == PermissionedObjectsSheshaTypes.WebCrudApi)
                    {
                        entityType = service.FindBaseGenericType(typeof(AbpAsyncCrudAppService <, , , , , , ,>))?.GetGenericArguments()[0];
                        if (isDynamic && entityType != null)
                        {
                            name        = $"{entityType.Name}DynamicCrudAppService";
                            fullName    = $"{entityType.Namespace}.Dynamic{entityType.Name}CrudAppService";
                            description = $"CRUD API service for {entityType.Name} entity";
                            eModule     = GetModuleOfType(entityType);
                        }
                    }


                    var parent = new PermissionedObjectDto()
                    {
                        Object      = fullName ?? service.FullName,
                        Module      = (eModule ?? module)?.FullName ?? "",
                        Name        = name ?? GetName(service),
                        Type        = objType,
                        Description = description ?? GetDescription(service),
                        Dependency  = entityType != null
                    ? entityType.FullName
                    : null
                    };
                    allApiPermissions.Add(parent);

                    var methods = api.Where(a => a.Module == module && a.Service == service).ToList();

                    foreach (var methodInfo in methods)
                    {
                        var methodName = methodInfo.Action.Name.RemovePostfix("Async");

                        var child = new PermissionedObjectDto()
                        {
                            Object      = parent.Object + "@" + methodInfo.Action.Name,
                            Module      = parent.Module,
                            Name        = GetName(methodInfo.Action),
                            Type        = GetMethodType(objType),
                            Parent      = parent.Object,
                            Description = GetDescription(methodInfo.Action),
                            Dependency  = entityType != null && CrudMethods.ContainsKey(methodName)
                                ? entityType.FullName + "@" + CrudMethods.GetValueOrDefault(methodName)
                                : null,
                        };

                        child.AdditionalParameters.Add("HttpMethod", methodInfo.HttpMethod);
                        child.AdditionalParameters.Add("Endpoint", methodInfo.Endpoint);
                        //parent.Child.Add(child);
                        allApiPermissions.Add(child);
                    }
                }
            }

            return(allApiPermissions);
        }