Add a user in Cockpit and change access rights with the Cockpit GROUPS plugin - Bugs with Assets / Finder modules

Re,

Here is what I have managed to do without use Cockpit GROUPS plugin. It’s a bit of a fiddle, but it works. I don’t know what you think…

// in : config/bootstrap.php

<?php
if (COCKPIT_ADMIN_CP) {
    $app->on('admin.init', function() use($app) {
        // CHECKS IF THE USER IS NOT AN ADMINISTRATOR
        if ($this->helper('admin')->user['group'] != 'admin') {

            // IF THE USER TRIES TO ACCESS THE ./ASSETSMANAGER PAGE, AN ERROR MESSAGE IS SHOWN
            $this->bind('/assetsmanager', function() {
                return $this->helper('admin')->denyRequest(); // or : $this->reroute('/');
            });

            // WE ALSO BLOCK ACCESS TO THE ASSETS MODULE WHEN WE ARE IN A COLLECTION / SINGLETON MODULES
            $app->on('cockpit.assets.list' , function () {
                return cockpit()->stop('{"error": "You can\'t use this module."}', 401);
            });

            $app->on('cockpit.assets.save' , function () {
                return cockpit()->stop('{"error": "You can\'t use this module."}', 401);
            });

            $app->on('cockpit.assets.remove' , function () {
                return cockpit()->stop('{"error": "You can\'t use this module."}', 401);
            });

            // FOR MORE SECURITY WE HIDE THE LINK TO THE ASSETS MODULE 
            // IN THE MENU OF COCKPIT AND IN THE COLLECTION / SINGLETON MODULES
            $app->on('app.layout.header', function() {
                echo "<style>
                    .app-menu-container .uk-grid-margin:nth-child(2),
                    cp-field[type='image'] .uk-margin-top a:nth-child(2) { 
                        display: none;
                        visibility: hidden; 
                    }
                </style>";
            });
        }
    });
}

Bye.

1 Like