public static bool TryRemoveMenuItem(
            [NotNull] this IHasMenuItems menuWithItems,
            string menuItemName)
        {
            Check.NotNull(menuWithItems, nameof(menuWithItems));

            return(menuWithItems.Items.RemoveAll(item => item.Name == menuItemName) > 0);
        }
Esempio n. 2
0
 protected virtual void GetAllMenuItems(IHasMenuItems menuWithItems, List <ApplicationMenuItem> output)
 {
     foreach (var item in menuWithItems.Items)
     {
         output.Add(item);
         GetAllMenuItems(item, output);
     }
 }
        public static ApplicationMenuItem GetMenuItemOrNull(
            [NotNull] this IHasMenuItems menuWithItems,
            string menuItemName)
        {
            Check.NotNull(menuWithItems, nameof(menuWithItems));

            return(menuWithItems.Items.FirstOrDefault(mi => mi.Name == menuItemName));
        }
Esempio n. 4
0
        protected virtual void NormalizeMenu(IHasMenuItems menuWithItems)
        {
            foreach (var menuItem in menuWithItems.Items)
            {
                NormalizeMenu(menuItem);
            }

            menuWithItems.Items.Normalize();
        }
Esempio n. 5
0
        protected virtual void RemoveMenus(IHasMenuItems menuWithItems, HashSet <ApplicationMenuItem> toBeDeleted)
        {
            menuWithItems.Items.RemoveAll(toBeDeleted.Contains);

            foreach (var item in menuWithItems.Items)
            {
                RemoveMenus(item, toBeDeleted);
            }
        }
Esempio n. 6
0
    private void AddChildItems(MenuItemDto menuItem, List <MenuItemDto> source, IHasMenuItems parent = null)
    {
        var applicationMenuItem = CreateApplicationMenuItem(menuItem);

        foreach (var item in source.Where(x => x.ParentId == menuItem.Id && x.IsActive))
        {
            AddChildItems(item, source, applicationMenuItem);
        }

        parent?.Items.Add(applicationMenuItem);
    }
Esempio n. 7
0
        public static ApplicationMenuItem GetMenuItem(this IHasMenuItems menuWithItems, string menuItemName)
        {
            var menuItem = menuWithItems.GetMenuItemOrNull(menuItemName);

            if (menuItem == null)
            {
                throw new AbpException($"Could not find a menu item with given name: {menuItemName}");
            }

            return(menuItem);
        }
        public static IHasMenuItems SetSubItemOrder(
            [NotNull] this IHasMenuItems menuWithItems,
            string menuItemName,
            int order)
        {
            Check.NotNull(menuWithItems, nameof(menuWithItems));

            var menuItem = menuWithItems.GetMenuItemOrNull(menuItemName);

            if (menuItem != null)
            {
                menuItem.Order = order;
            }

            return(menuWithItems);
        }
        public static ApplicationMenuItem FindMenuItem(this IHasMenuItems container, string menuItemName)
        {
            foreach (var menuItem in container.Items)
            {
                if (menuItem.Name == menuItemName)
                {
                    return(menuItem);
                }

                var subItem = FindMenuItem(menuItem, menuItemName);
                if (subItem != null)
                {
                    return(subItem);
                }
            }

            return(null);
        }
Esempio n. 10
0
        protected virtual async Task CheckPermissionsAsync(IServiceProvider serviceProvider, IHasMenuItems menuWithItems)
        {
            var allMenuItems = new List <ApplicationMenuItem>();

            GetAllMenuItems(menuWithItems, allMenuItems);

            foreach (var item in allMenuItems)
            {
                if (!item.RequiredPermissionName.IsNullOrWhiteSpace())
                {
                    item.RequirePermissions(item.RequiredPermissionName);
                }
            }

            var checkPermissionsMenuItems = allMenuItems.Where(x => x.StateCheckers.Any()).ToArray();

            if (checkPermissionsMenuItems.Any())
            {
                var toBeDeleted = new HashSet <ApplicationMenuItem>();
                var result      = await SimpleStateCheckerManager.IsEnabledAsync(checkPermissionsMenuItems);

                foreach (var menu in checkPermissionsMenuItems)
                {
                    if (!result[menu])
                    {
                        toBeDeleted.Add(menu);
                    }
                }

                RemoveMenus(menuWithItems, toBeDeleted);
            }
        }
Esempio n. 11
0
        protected virtual async Task CheckPermissionsAsync(IServiceProvider serviceProvider, IHasMenuItems menuWithItems)
        {
            var requiredPermissionItems = new List <ApplicationMenuItem>();

            GetRequiredPermissionNameMenus(menuWithItems, requiredPermissionItems);

            if (requiredPermissionItems.Any())
            {
                var permissionChecker = serviceProvider.GetRequiredService <IPermissionChecker>();
                var grantResult       = await permissionChecker.IsGrantedAsync(requiredPermissionItems.Select(x => x.RequiredPermissionName).Distinct().ToArray());

                var toBeDeleted = new HashSet <ApplicationMenuItem>();
                foreach (var menu in requiredPermissionItems)
                {
                    if (grantResult.Result[menu.RequiredPermissionName !] != PermissionGrantResult.Granted)
Esempio n. 12
0
 public static ApplicationMenuItem GetMenuItemOrNull(
     this IHasMenuItems menuWithItems,
     string menuItemName)
 {
     return(menuWithItems.Items.FirstOrDefault(mi => mi.Name == menuItemName));
 }