Answers.Body: <p>Using a custom module it's easy to simply <em>hide</em> the <strong>Assets</strong> section of the CP.</p>
  <p>Users would still be able to access the assets library by entering manually the URL but this is good enough for my use case.</p>
  <p>Here's the (simplified) code:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace modules\appModule;
  
  use Craft;
  use craft\events\RegisterCpNavItemsEvent;
  use craft\web\twig\variables\Cp;
  use yii\base\Module;
  
  class AppModule extends Module
  {
      public function init()
      {
          $user = Craft::$app-&gt;getUser();
          if (
              Craft::$app-&gt;getRequest()-&gt;isCpRequest
              &amp;&amp; !$user-&gt;isGuest
              &amp;&amp; $user-&gt;getIdentity()-&gt;isInGroup('editors')
          ) {
              Event::on(Cp::class, Cp::EVENT_REGISTER_CP_NAV_ITEMS, function(RegisterCpNavItemsEvent $event) {
                  $event-&gt;navItems = array_filter($event-&gt;navItems, static fn ($item) =&gt; $item['url'] !== 'assets');
              });
          }
      }
  }
  
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-02T14:23:22.133Z
Answers.LastActivityDate: 2021-03-02T14:23:22.133Z
Answers.UserDisplayName: nstCactus
Body: <p>I need to hide the assets section of the control panel to a given user group.</p>
  <p>Changing the group permissions to prevent them from viewing all asset volumes also prevents them from uploading assets in entries, which is not what I want.</p>
  <p>I want them to be able to upload new assets but prevent them from snooping around in the asset library.</p>
  <p>Is there a way to achieve this?</p>
  
Tags: <assets><control-panel><permissions>
Title: How to hide the assets section of the control panel to specific user groups?
ThreadText: # How to hide the assets section of the control panel to specific user groups?
  
  (Asked by: username_0 on 2021-03-02)
  
  I need to hide the assets section of the control panel to a given user group.
  
  Changing the group permissions to prevent them from viewing all asset volumes also prevents them from uploading assets in entries, which is not what I want.
  
  I want them to be able to upload new assets but prevent them from snooping around in the asset library.
  
  Is there a way to achieve this?
  
  **Tags:** assets, control-panel, permissions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-03-02. Score: 2
  
  Using a custom module it's easy to simply *hide* the **Assets** section of the CP.
  
  Users would still be able to access the assets library by entering manually the URL but this is good enough for my use case.
  
  Here's the (simplified) code:
  
  ```php
  <?php
  
  namespace modules\appModule;
  
  use Craft;
  use craft\events\RegisterCpNavItemsEvent;
  use craft\web\twig\variables\Cp;
  use yii\base\Module;
  
  class AppModule extends Module
  {
      public function init()
      {
          $user = Craft::$app->getUser();
          if (
              Craft::$app->getRequest()->isCpRequest
              && !$user->isGuest
              && $user->getIdentity()->isInGroup('editors')
          ) {
              Event::on(Cp::class, Cp::EVENT_REGISTER_CP_NAV_ITEMS, function(RegisterCpNavItemsEvent $event) {
                  $event->navItems = array_filter($event->navItems, static fn ($item) => $item['url'] !== 'assets');
              });
          }
      }
  }
  
  ```
  
  
  ---
  
  