]> _ Git - fluidbook-toolbox.git/commitdiff
fix #5397 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 24 Mar 2023 17:26:47 +0000 (18:26 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 24 Mar 2023 17:26:47 +0000 (18:26 +0100)
app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php
app/Models/FluidbookPublication.php
resources/views/vendor/backpack/crud/buttons/fluidbook_publication/clone.blade.php
resources/views/vendor/backpack/crud/buttons/fluidbook_publication/download.blade.php
resources/views/vendor/backpack/crud/buttons/fluidbook_publication/edit.blade.php
resources/views/vendor/backpack/crud/buttons/fluidbook_publication/preview.blade.php

index fb44df5fef138c24bfee08225991a12eb36aa9bc..6434090b2f90fde31b135509bf02bb5a37ad7d55 100644 (file)
@@ -241,6 +241,8 @@ trait LinksOperation
 
     protected function setupLinksDefaults()
     {
+        $this->crud->allowAccess('update');
+
         $this->crud->addButton('line', 'edit', 'view', 'crud::buttons.fluidbook_publication.edit', 'end');
         $this->crud->operation(['list', 'show'], function () {
             $this->crud->removeButton('update');
index cd643b6a80e52bbcb0e099bd773fd5bb8d544404..6f426e49507d7b55edf333d2a8420b6261d9456b 100644 (file)
@@ -210,7 +210,7 @@ html,body{height:100%;cursor: wait;font-family: "Open Sans", Arial;background-co
         if ($forceThemeData) {
             $theme = FluidbookTheme::fromArray(json_decode($forceThemeData, true), (count($ee) == 2 ? $ee[1] : null));
         } else if (count($ee) == 2) {
-            $theme = FluidbookTheme::find($ee[1]);
+            $theme = FluidbookTheme::withoutGlobalScopes()->find($ee[1]);
             $id = $ee[0];
         }
 
index 8f68c0a1be79b4543940079bcb99c94dd63e4195..688c7f91cf59903eb65d3730ee7d754a7c3553e0 100644 (file)
@@ -56,7 +56,7 @@ class FluidbookPublication extends ToolboxSettingsModel
 
     protected static $_docs = [];
 
-    protected $_operations = [CreateOperation::class, PreviewOperation::class, LinksOperation::class, CompositionOperation::class, StatsOperation::class, DownloadOperation::class, CloneOperation::class, DeletefbOperation::class, EditOperation::class,ChangeownerOperation::class];
+    protected $_operations = [CreateOperation::class, PreviewOperation::class, LinksOperation::class, CompositionOperation::class, StatsOperation::class, DownloadOperation::class, CloneOperation::class, DeletefbOperation::class, EditOperation::class, ChangeownerOperation::class];
 
     protected $casts = ['composition' => 'array'];
 
@@ -267,7 +267,7 @@ class FluidbookPublication extends ToolboxSettingsModel
      */
     public function getTheme()
     {
-        return FluidbookTheme::find($this->theme);
+        return FluidbookTheme::withoutGlobalScopes()->find($this->theme);
     }
 
     /**
@@ -285,7 +285,7 @@ class FluidbookPublication extends ToolboxSettingsModel
     protected static function _getDocument($documentID)
     {
         if (!isset(self::$_docs[$documentID])) {
-            self::$_docs[$documentID] = FluidbookDocument::find($documentID);
+            self::$_docs[$documentID] = FluidbookDocument::withoutGlobalScopes()->find($documentID);
         }
         return self::$_docs[$documentID];
     }
@@ -343,13 +343,13 @@ class FluidbookPublication extends ToolboxSettingsModel
 
     public function addWidgets()
     {
-        Widget::add([
-            'type' => 'alert',
-            'class' => 'alert alert-danger mb-2',
-            'heading' => __('En cours de développement'),
-            'content' => __('Les données et interfaces présentées dans cette section ne sont pas synchronisées avec les données en production. Toutes les modifications effectuées ici peuvent dont disparaître à tout moment.') . ' <p><a class="btn btn-warning" href="https://workshop.fluidbook.com/publications">' . __('Retour en production') . '</a></p>',
-            'close_button' => false, // show close button or not
-        ]);
+//        Widget::add([
+//            'type' => 'alert',
+//            'class' => 'alert alert-danger mb-2',
+//            'heading' => __('En cours de développement'),
+//            'content' => __('Les données et interfaces présentées dans cette section ne sont pas synchronisées avec les données en production. Toutes les modifications effectuées ici peuvent dont disparaître à tout moment.') . ' <p><a class="btn btn-warning" href="https://workshop.fluidbook.com/publications">' . __('Retour en production') . '</a></p>',
+//            'close_button' => false, // show close button or not
+//        ]);
 
     }
 
@@ -539,6 +539,67 @@ class FluidbookPublication extends ToolboxSettingsModel
         return true;
     }
 
+    public function allowsUpdate()
+    {
+        if (!can('fluidbook-publication:write')) {
+            return false;
+        }
+        if ($this->id < WorkshopMigration::WS3_BOOK_ID) {
+            return false;
+        }
+        return true;
+    }
+
+    public function allowsEdit()
+    {
+        return $this->allowsUpdate();
+    }
+
+
+    public function allowsClone()
+    {
+        return $this->allowsCreate();
+    }
+
+    public function allowsPreview()
+    {
+        if (can('fluidbook-publication:write')) {
+            return true;
+        }
+        if (!can('fluidbook-publication:read')) {
+            return false;
+        }
+        if ($this->status == 0) {
+            return false;
+        }
+        return true;
+    }
+
+    public function allowsDownload()
+    {
+        if ($this->id < WorkshopMigration::WS3_BOOK_ID) {
+            return false;
+        }
+        if (can('fluidbook-publication:write')) {
+            return true;
+        }
+        if (!can('fluidbook-publication:read')) {
+            return false;
+        }
+        if ($this->status == 0) {
+            return false;
+        }
+        return true;
+    }
+
+    public function allowsCreate()
+    {
+        if (!can('fluidbook-publication:write')) {
+            return false;
+        }
+        return true;
+    }
+
     protected function _baseReplicate(array $except = null)
     {
         $current = $this;
index f80cff4484e4b5c44fe246b01f2efd71381d2e92..3c1336ebab04a20904e8f382793e45000fe5ef45 100644 (file)
         ];
 
 @endphp
-
-<a class="btn btn-sm btn-link" href="#"
-   data-toggle="tooltip"
-   title="{{__('Cloner la publication')}}"
-   data-context-actions="{{json_encode($actions)}}"
-   data-context-route="{{$crud->route}}/$id/clone/$action"
-   data-context-id="{{$entry->getKey()}}"
-><i class="la la-copy"></i> {{__('Cloner')}}</a>
+@if($entry->allowsClone())
+    <a class="btn btn-sm btn-link" href="#"
+       data-toggle="tooltip"
+       title="{{__('Cloner la publication')}}"
+       data-context-actions="{{json_encode($actions)}}"
+       data-context-route="{{$crud->route}}/$id/clone/$action"
+       data-context-id="{{$entry->getKey()}}"
+    ><i class="la la-copy"></i> {{__('Cloner')}}</a>
+@endif
index c7f37fbebe76ee5ad23f450ce1e0aa40d8600adc..02da15523787f1124ec1cb624401466d27d389a3 100644 (file)
@@ -5,14 +5,17 @@
     $servers=\App\Models\FluidbookExternalInstallServer::getAllServers();
     $base=$crud->route.'/'.$entry->id;
     $basePackage=$base.'/package';
-    $actions=[
-        'delivery'=>
-            [
-                'label'=>__('Page de téléchargement'),
-                'url'=>$base.'/delivery',
-                ],
-        ];
-    $actions['sep_download']='---------';
+
+    $actions=[];
+
+
+
+//    $actions['delivery']=[
+//                'label'=>__('Page de téléchargement'),
+//                'url'=>$base.'/delivery',
+//                ];
+//
+//    $actions['sep_download']='---------';
     foreach (\App\Models\FluidbookPublication::getDownloadVersions() as $k=>$v) {
         if($k==='scorm'){
             continue;
 
 @endphp
 
-<a class="btn btn-sm btn-link" href="#"
-   data-toggle="tooltip"
-   title="{{__('Télécharger la publication')}}"
-   data-context-actions="{{json_encode($actions)}}"
-   data-context-route="{{$crud->route}}/$id/download/$action"
-   data-context-id="{{$entry->getKey()}}"
-><i class="la la-arrow-circle-down"></i> {{__('Télécharger')}}</a>
+@if($entry->allowsDownload())
+    <a class="btn btn-sm btn-link" href="#"
+       data-toggle="tooltip"
+       title="{{__('Télécharger la publication')}}"
+       data-context-actions="{{json_encode($actions)}}"
+       data-context-route="{{$crud->route}}/$id/download/$action"
+       data-context-id="{{$entry->getKey()}}"
+    ><i class="la la-arrow-circle-down"></i> {{__('Télécharger')}}</a>
+@endif
index 107242898ff7f7fcfbd0a478e02662d08a64f97e..6ca76a279d8fa0b20abfad2052a1ee63a28baa87 100644 (file)
@@ -14,7 +14,7 @@
                 ]
         ];
 @endphp
-@if($entry->getKey()>=\App\Console\Commands\WorkshopMigration::WS3_BOOK_ID)
+@if($entry->allowsEdit() && $entry->getKey()>=\App\Console\Commands\WorkshopMigration::WS3_BOOK_ID)
     <a class="btn btn-sm btn-link" href="#"
        data-toggle="tooltip"
        title="{{__('Éditer la publication')}}"
index 6545b24ebdf7cc276a796cbd3d5f576ce51b6917..81204882cd70b720f0f8cffb9be5b5fe74466b39 100644 (file)
@@ -6,12 +6,15 @@
     }
 @endphp
 
-<a class="btn btn-sm btn-link" target="{!! $actions['preview']['target'] !!}" href="{!! $actions['preview']['url'] !!}"
-   @if(count($actions)>1)
-       data-context-actions="{{json_encode($actions)}}"
+@if($entry->allowsPreview())
+    <a class="btn btn-sm btn-link" target="{!! $actions['preview']['target'] !!}"
+       href="{!! $actions['preview']['url'] !!}"
+       @if(count($actions)>1)
+           data-context-actions="{{json_encode($actions)}}"
        data-context-route="{{$crud->route}}/$id/edit/$action"
        data-context-id="{{$entry->getKey()}}"
-   @endif
-   data-toggle="tooltip"
-   title="{{__('Voir le fluidbook')}}"><i class="las la-eye"></i> {{__('Voir')}}
-</a>
+       @endif
+       data-toggle="tooltip"
+       title="{{__('Voir le fluidbook')}}"><i class="las la-eye"></i> {{__('Voir')}}
+    </a>
+@endif