<commit_before><?php

namespace Wislem\Berrier\Http\Middleware;

use Closure;
use Menu;

class MenuMiddleware
{
    /**
     * Run the request filter.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure                  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $access = \Session::get('access');

        Menu::make('main', function($menu) use ($access) {
            $menu->add('Dashboard', 'admin')->prepend('<i class="fa fa-sitemap"></i> <span>')->append('</span>');
            $cms = $menu->add('CMS', ['class' => 'treeview'])->prepend('<i class="fa fa-edit"></i> <span>')->append('</span><i class="fa fa-angle-left pull-right"></i>');
                if($access === 2 or ($access == 1 and config('berrier.permissions.modules.pages') == 'mod:1')) {
                    $cms->add('Pages', 'admin/pages')->active('/admin/pages/*');
                }
                if($access === 2 or ($access == 1 and config('berrier.permissions.modules.posts') == 'mod:1')) {
                    $cms->add('Posts', 'admin/posts')->active('/admin/posts/*');
                }
                if($access === 2 or ($access == 1 and config('berrier.permissions.modules.categories') == 'mod:1')) {
                    $cms->add('Categories', 'admin/categories')->active('admin/categories/*');
                }

            if($access === 2 or ($access == 1 and config('berrier.permissions.modules.widgets') == 'mod:1')) {
                $blocks = $menu->add('Blocks', ['class' => 'treeview'])->prepend('<i class="fa fa-cubes"></i> <span>')->append('</span><i class="fa fa-angle-left pull-right"></i>');
                    $blocks->add('Menus', 'admin/menus')->active('/admin/menus/*');
                    $blocks->add('Widgets', 'admin/widgets')->active('/admin/widgets/*');
                $blocks->divide();
            }else {
                $cms->divide();
            }

            if($access === 2 or ($access == 1 and config('berrier.permissions.modules.users') == 'mod:1')) {
                $menu->add('Users', ['class' => 'treeview'])->prepend('<i class="fa fa-users"></i> <span>')->append('</span><i class="fa fa-angle-left pull-right"></i>');
                    $menu->users->add('Manage Users', 'admin/users')->active('admin/users/*');
                    $menu->users->add('Global user settings', 'admin/usettings')->active('admin/usettings/*');
            }

            if($access === 2 or ($access == 1 and config('berrier.permissions.modules.settings') == 'mod:1')) {
                $menu->add('Settings', 'admin/settings')->active('admin/settings/*')->prepend('<i class="fa fa-gears"></i> <span>')->append('</span>')->divide();
            }
        });

        return $next($request);
    }
}<commit_msg>Handling permissions the array way<commit_after><?php

namespace Wislem\Berrier\Http\Middleware;

use Closure;
use Menu;

class MenuMiddleware
{
    /**
     * Run the request filter.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure                  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $access = \Session::get('access');

        Menu::make('main', function($menu) use ($access) {
            $menu->add('Dashboard', 'admin')->prepend('<i class="fa fa-sitemap"></i> <span>')->append('</span>');
            $cms = $menu->add('CMS', ['class' => 'treeview'])->prepend('<i class="fa fa-edit"></i> <span>')->append('</span><i class="fa fa-angle-left pull-right"></i>');
            if(in_array($access, config('berrier.permissions.modules.pages'))) {
                $cms->add('Pages', 'admin/pages')->active('/admin/pages/*');
            }
            if(in_array($access, config('berrier.permissions.modules.posts'))) {
                $cms->add('Posts', 'admin/posts')->active('/admin/posts/*');
            }
            if(in_array($access, config('berrier.permissions.modules.categories'))) {
                $cms->add('Categories', 'admin/categories')->active('admin/categories/*');
            }

            if(in_array($access, config('berrier.permissions.modules.blocks'))) {
                $blocks = $menu->add('Blocks', ['class' => 'treeview'])->prepend('<i class="fa fa-cubes"></i> <span>')->append('</span><i class="fa fa-angle-left pull-right"></i>');
                $blocks->add('Menus', 'admin/menus')->active('/admin/menus/*');
                $blocks->add('Widgets', 'admin/widgets')->active('/admin/widgets/*');
                $blocks->divide();
            }else {
                $cms->divide();
            }

            if(in_array($access, config('berrier.permissions.modules.users'))) {
                $menu->add('Users', ['class' => 'treeview'])->prepend('<i class="fa fa-users"></i> <span>')->append('</span><i class="fa fa-angle-left pull-right"></i>');
                $menu->users->add('Manage Users', 'admin/users')->active('admin/users/*');
                $menu->users->add('Global user settings', 'admin/usettings')->active('admin/usettings/*');
            }

            if(in_array($access, config('berrier.permissions.modules.settings'))) {
                $menu->add('Settings', 'admin/settings')->active('admin/settings/*')->prepend('<i class="fa fa-gears"></i> <span>')->append('</span>')->divide();
            }
        });

        return $next($request);
    }
}
{'fraction_non_alphanumeric': 0.22673559822747416, 'fraction_numerical': 0.0033234859675036928, 'mean_word_length': 2.435003170577045, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7305621', 'n_tokens_mistral': 1647, 'n_tokens_neox': 1574, 'n_words': 250}