silverstripe / silverstripe-dms

Adds a Document Management System to Silverstripe
BSD 3-Clause "New" or "Revised" License
40 stars 52 forks source link

Add CSS class to document container for whether the document is accessible or not #193

Closed robbieaverill closed 5 years ago

robbieaverill commented 7 years ago

If a document cannot be viewed by the current user we should add a CSS class to the document container, e.g. dmsdocument-locked or similar. User code could the use this to add some custom styles to indicate that it may be accessible if the user logged in, but currently isn't.


Perhaps we could add something similar to what userforms does with an "extra class" field that the user can add custom CSS classes to, and we could add a check like this into the DMSDocument model - example:

diff --git a/code/model/DMSDocument.php b/code/model/DMSDocument.php
index a4ba0ca..2b31189 100644
--- a/code/model/DMSDocument.php
+++ b/code/model/DMSDocument.php
@@ -41,6 +41,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface
         "DownloadBehavior" => 'Enum(array("open","download"), "download")',
         "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')",
         "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
+        'ExtraClass' => 'Varchar(255)',
     );

     private static $belongs_many_many = array(
@@ -240,6 +241,17 @@ class DMSDocument extends DataObject implements DMSDocumentInterface
         return $this;
     }

+    public function getExtraClass()
+    {
+        $extraClass = $this->ExtraClass . ' ' . $this->getExtension();
+
+        if (!$this->canView()) {
+            $extraClass .= ' dmsdocument-private';
+        }
+
+        return $extraClass;
+    }
+
     /**
      * Returns a link to download this document from the DMS store.
      * Alternatively a basic javascript alert will be shown should the user not have view permissions. An extension
@@ -906,6 +918,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface
         $actionsPanel->addExtraClass('dmsdocument-actionspanel');
         $fields->push($actionsPanel);

+        $fields->push(TextField::create('ExtraClass'));
+
         $this->extend('updateCMSFields', $fields);

         return $fields;
diff --git a/templates/Includes/Document.ss b/templates/Includes/Document.ss
index a3fe7cf..a1c9a98 100644
--- a/templates/Includes/Document.ss
+++ b/templates/Includes/Document.ss
@@ -1,5 +1,5 @@
 <% if not $isHidden %>
-    <div class="document $Extension">
+    <div class="document $ExtraClass">
         <h4><a href="$Link" title="<%t DMSDocument.DOWNLOAD "Download {title}" title=$getTitle %>">$getTitle</a></h4>

         <% if $CoverImage %>
robbieaverill commented 5 years ago

Unfortunately, SilverStripe 3 has entered limited support in June 2018. This means we'll only be fixing critical bugs and security issues for SilverStripe 3 going forward.

You can read the SilverStripe Roadmap for more information on our support commitments.