Exemple #1
0
        public async Task DeleteAsync(Guid functionId)
        {
            var function = await functionRepository.GetByIdAsync(functionId);

            if (function == null)
            {
                throw new ItemNotFoundException($"Function with UUID '{functionId}' not found.");
            }

            await functionRepository.DeleteAsync(function);
        }
        /// <summary>
        /// Detects functions that are currently assigned to an application, but do not appear within the security contract definition and removes them.
        /// </summary>
        /// <param name="application"></param>
        /// <param name="securityContractDefaultConfigurationFunctions"></param>
        /// <returns></returns>
        private async Task <ApplicationModel> DetectFunctionsRemovedFromSecurityContractDefaultsAndRemoveFromApplication(ApplicationModel application, List <SecurityContractDefaultConfigurationFunction> securityContractDefaultConfigurationFunctions)
        {
            if (application.Functions.Count > 0)
            {
                logger.Debug($"Application Functions Count: {application.Functions.Count}");
                for (int i = application.Functions.Count - 1; i >= 0; i--)
                {
                    logger.Debug($"Checking whether function: '{application.Functions[i].Name}' should be removed from application '{application.Name}'.");
                    if (!securityContractDefaultConfigurationFunctions.Exists(f => f.Name == application.Functions[i].Name))
                    {
                        logger.Debug($"Function: '{application.Functions[i].Name}' is being removed from '{application.Name}' as it is no longer defined withn the defaults YAML!");
                        // Note: This only removes the function permissions association. The permission will still exist. We cannot remove the permission here, as it may be assigned to other functions.
                        await functionRepository.DeleteAsync(application.Functions[i]);
                    }
                }
            }

            return(application);
        }