Commit 73a105bd authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1740208: Fetch related view for artefacts we can see



Fix the way we find the related views now that we don't have a 'view'
type to restrict to. We can achieve this via the internal '_id' value
as that is a combination of old type and id values.

Also strip tags except the <span> one from highlighted description code
in case there is bad html/js in there.

behatnotneeded

Change-Id: I962accadb352b52dd72b61844f7fe0bd0d586ce2
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent 6657c4fa
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -1914,6 +1914,15 @@ class ElasticsearchPseudotype_all
            return mb_strtolower($chr, "UTF-8") != $chr;
        }

        $cleanuphighlight = function($str) {
            $str = strip_tags($str, '<span>');
            if (strpos($str, '<') > strpos($str, '>')) {
                // we probably have a broken close tag so will strip it out
                $str = substr($str, strpos($str, '>') + 1);
            }
            return $str;
        };

        foreach ($results['hits']['hits'] as $hit) {
            $tmp = array();
            $tmp['type'] = $hit['_source']['type'];
@@ -1933,7 +1942,8 @@ class ElasticsearchPseudotype_all
                $tmp['db']->deleted = false;
                $highlight = false;
                if (!empty($tmp['highlight'])) {
                    $highlight = implode(' ... ', $tmp['highlight']);
                    $highlights = array_map($cleanuphighlight, $tmp['highlight']);
                    $highlight = implode(' ... ', $highlights);
                    if (substr($highlight, 0, 1) !== '<' && !starts_with_upper(strip_tags($highlight))) {
                        $highlight = '... ' . $highlight;
                    }
+34 −31
Original line number Diff line number Diff line
@@ -364,6 +364,7 @@ class ElasticsearchType_artefact extends ElasticsearchType {
        $views = get_records_sql_array ( $sql, array (
                $id
        ) );

        if ($views) {
            $record_views = array ();
            foreach ( $views as $view ) {
@@ -463,33 +464,35 @@ class ElasticsearchType_artefact extends ElasticsearchType {
        global $USER;

        $acl = new ElasticsearchFilterAcl($USER);
        $viewmap = function($value) {
            return 'view' . $value;
        };

        $filter = [
                "bool" => [
                        "must" => [
        $filter = array(
            "bool" => array(
                "must" => array(
                    array (
                        array (
                                                'term' => [
                                                        '_type' => 'view'
                                                ]
                            'term' => array(
                                '_type' => 'doc'
                            )
                        ),
                        array (
                                                'terms' => [
                                                        'id' => array_keys ( $views )
                                                ]
                            'terms' => array(
                                '_id' => array_map($viewmap, array_keys($views))
                            )
                        )
                    )
                        ],
                ),
                "should" => $acl->get_params() ['should']
                ]
        ]
        ;
            )
        );

        $client = PluginSearchElasticsearch::make_client();
        $params = array (
            'index' => PluginSearchElasticsearch::get_write_indexname(),
            'body' => array (
                        'size' => 10, //
                'size' => 10,
                'query' => array (
                    'bool' => array (
                        'filter' => $filter