]> BookStack Code Mirror - bookstack/commitdiff
Prevented created/update_by filters be wiped in search
authorDan Brown <redacted>
Sun, 14 Nov 2021 15:07:13 +0000 (15:07 +0000)
committerDan Brown <redacted>
Sun, 14 Nov 2021 15:07:13 +0000 (15:07 +0000)
Updating filters via sidebar would wipe the created_by/update_by filters
since these were not part of the sidebar filter form.
This adds them, if existing, as hidden inputs.
Includes tests to cover.

Closes #2736

resources/views/search/all.blade.php
tests/Entity/EntitySearchTest.php

index b9adccca79b893d32abc6e6af090335a4681036f..85e6d1b7b525d6ba715030de7c583679f8ad8ea3 100644 (file)
                         @include('search.parts.date-filter', ['name' => 'created_after', 'filters' => $options->filters])
                         @include('search.parts.date-filter', ['name' => 'created_before', 'filters' => $options->filters])
 
+                        @if(isset($options->filters['created_by']))
+                            <input type="hidden" name="filters[created_by]" value="{{ $options->filters['created_by'] }}">
+                        @endif
+                        @if(isset($options->filters['updated_by']))
+                            <input type="hidden" name="filters[updated_by]" value="{{ $options->filters['updated_by'] }}">
+                        @endif
+
                         <button type="submit" class="button">{{ trans('entities.search_update') }}</button>
                     </form>
 
index 6929adc74bb60feb92293104094afa2f1f4dfa73..2b7bfd08dfd28897c06cf3e7ff250a4320ee5f9d 100644 (file)
@@ -411,4 +411,11 @@ class EntitySearchTest extends TestCase
         $search->assertSee('My &lt;cool&gt; <strong>TestPageContent</strong>', false);
         $search->assertSee('My supercool &lt;great&gt; <strong>TestPageContent</strong> page', false);
     }
+
+    public function test_searches_with_user_filters_adds_them_into_advanced_search_form()
+    {
+        $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:me} {created_by:dan}'));
+        $resp->assertElementExists('form input[type="hidden"][name="filters[updated_by]"][value="me"]');
+        $resp->assertElementExists('form input[type="hidden"][name="filters[created_by]"][value="dan"]');
+    }
 }