Browse code

Allow non admin users to get access to memberfiles per user view

Benjamin Roth authored on12/10/2023 14:45:10
Showing1 changed files
... ...
@@ -42,7 +42,7 @@ class MemberListener {
42 42
      */
43 43
     public function onListSecureDownloadsOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
44 44
     {
45
-        if (!$this->User->isAdmin && !$this->User->hasAccess('edit','sec_dl_access'))
45
+        if (!$this->User->isAdmin && !$this->User->hasAccess('tl_member_secureDownloads::ctime','alexf'))
46 46
         {
47 47
             return '';
48 48
         }
Browse code

Fix truncate sql error by changing sec_dl_access flag

Benjamin Roth authored on11/09/2023 10:38:46
Showing1 changed files
... ...
@@ -42,7 +42,7 @@ class MemberListener {
42 42
      */
43 43
     public function onListSecureDownloadsOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
44 44
     {
45
-        if (!$this->User->isAdmin && !$this->User->hasAccess(1,'sec_dl_access'))
45
+        if (!$this->User->isAdmin && !$this->User->hasAccess('edit','sec_dl_access'))
46 46
         {
47 47
             return '';
48 48
         }
Browse code

Update

Benjamin Roth authored on26/07/2023 17:00:15
Showing1 changed files
... ...
@@ -42,23 +42,14 @@ class MemberListener {
42 42
      */
43 43
     public function onListSecureDownloadsOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
44 44
     {
45
-        if (Input::get('popup'))
45
+        if (!$this->User->isAdmin && !$this->User->hasAccess(1,'sec_dl_access'))
46 46
         {
47 47
             return '';
48
-        } else
49
-        {
50
-            $objSecFile = SecureDownloadsModel::findByPk($row['id']);
51
-            $objFile = $objSecFile->getRelated('uuid');
52
-            $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['show'][1], $objFile->name);
53
-
54
-            if ($objFile !== null)
55
-            {
56
-                return '<a href="contao/popup.php?src=' . base64_encode($objFile->path) . '" title="' . StringUtil::specialchars($title, false, true) . '"' . $attributes . ' onclick="Backend.openModalIframe({\'width\':600,\'title\':\'' . str_replace("'", "\\'", StringUtil::specialchars($objFile->name, false, true)) . '\',\'url\':this.href,\'height\':300});return false">' . Image::getHtml($icon, $label) . '</a> ';
57
-            } else
58
-            {
59
-                return '';
60
-            }
61 48
         }
49
+
50
+        $href .= '&amp;id='.$row['id'];
51
+
52
+        return '<a href="'.Backend::addToUrl($href).'" title="'.StringUtil::specialchars($title).'">'.Image::getHtml($icon, $label).'</a> ';
62 53
     }
63 54
 
64 55
 }
Browse code

Update

Benjamin Roth authored on26/07/2023 15:18:55
Showing1 changed files
... ...
@@ -38,7 +38,7 @@ class MemberListener {
38 38
     }
39 39
 
40 40
     /**
41
-     * @Callback(table="tl_member", target="list.operations.secureDownloads.button"
41
+     * @Callback(table="tl_member", target="list.operations.secureDownloads.button")
42 42
      */
43 43
     public function onListSecureDownloadsOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
44 44
     {
Browse code

Update

Benjamin Roth authored on26/07/2023 13:13:48
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,64 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of memberfiles bundle.
7
+ *
8
+ * (c) vonRotenberg
9
+ *
10
+ * @license commercial
11
+ */
12
+
13
+namespace vonRotenberg\MemberfilesBundle\EventListener\DataContainer;
14
+
15
+use Contao\Backend;
16
+use Contao\BackendUser;
17
+use Contao\CoreBundle\ServiceAnnotation\Callback;
18
+use Contao\DataContainer;
19
+use Contao\File;
20
+use Contao\Image;
21
+use Contao\Input;
22
+use Contao\StringUtil;
23
+use Contao\System;
24
+use Contao\Date;
25
+use Contao\Config;
26
+use vonRotenberg\MemberfilesBundle\Model\SecureDownloadsModel;
27
+
28
+class MemberListener {
29
+
30
+    /**
31
+     * @var BackendUser
32
+     */
33
+    protected $User;
34
+
35
+    public function __construct()
36
+    {
37
+        $this->User = BackendUser::getInstance();
38
+    }
39
+
40
+    /**
41
+     * @Callback(table="tl_member", target="list.operations.secureDownloads.button"
42
+     */
43
+    public function onListSecureDownloadsOperationCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes, string $table, array $rootRecordIds, ?array $childRecordIds, bool $circularReference, ?string $previous, ?string $next, DataContainer $dc)
44
+    {
45
+        if (Input::get('popup'))
46
+        {
47
+            return '';
48
+        } else
49
+        {
50
+            $objSecFile = SecureDownloadsModel::findByPk($row['id']);
51
+            $objFile = $objSecFile->getRelated('uuid');
52
+            $title = sprintf($GLOBALS['TL_LANG']['tl_member_secureDownloads']['show'][1], $objFile->name);
53
+
54
+            if ($objFile !== null)
55
+            {
56
+                return '<a href="contao/popup.php?src=' . base64_encode($objFile->path) . '" title="' . StringUtil::specialchars($title, false, true) . '"' . $attributes . ' onclick="Backend.openModalIframe({\'width\':600,\'title\':\'' . str_replace("'", "\\'", StringUtil::specialchars($objFile->name, false, true)) . '\',\'url\':this.href,\'height\':300});return false">' . Image::getHtml($icon, $label) . '</a> ';
57
+            } else
58
+            {
59
+                return '';
60
+            }
61
+        }
62
+    }
63
+
64
+}