--- /datas2/moodles/moodle31+/moodle/blocks/moodleblock.class.php	2017-02-16 09:14:43.000000000 +0100
+++ /datas2/gitworkspace/moodle31/moodle2_version/blocks/moodleblock.class.php	2017-05-09 15:25:55.039444153 +0200
@@ -285,13 +285,19 @@
      * @since Moodle 2.0.
      */
     protected function formatted_contents($output) {
-        $this->get_content();
-        $this->get_required_javascript();
-        if (!empty($this->content->text)) {
-            return $this->content->text;
-        } else {
+        //UNISTRA DEV
+        if($this->can_view()){
+            $this->get_content();
+            $this->get_required_javascript();
+            if (!empty($this->content->text)) {
+                return $this->content->text;
+            } else {
+                return '';
+            }
+        }else{
             return '';
         }
+        //END UNISTRA DEV
     }
 
     /**
@@ -681,6 +687,40 @@
     public function get_aria_role() {
         return 'complementary';
     }
+    
+    //UNISTRA DEV
+    function can_view() {
+        global $DB, $CFG;
+        if($CFG->MDL_dashboard){
+            require_once ($CFG->dirroot.'/my/lib.php');
+            $context = $this->context;
+            //check if it is a dashboard user block instance
+            //in that case user corresponding system dashboard instance context
+            $birecord = $DB->get_record_sql( "SELECT bi.id, bi.blockname
+            FROM {my_pages} p
+            JOIN {context} ctx ON ctx.instanceid = p.userid AND ctx.contextlevel = :usercontextlevel
+            JOIN {block_instances} bi ON bi.parentcontextid = ctx.id AND
+                bi.pagetypepattern = :pagetypepattern AND
+                (bi.subpagepattern IS NULL OR bi.subpagepattern = " . $DB->sql_concat("''", 'p.id') . ")
+            WHERE p.private = :private and bi.id=:biid",
+                    array('private' => MY_PAGE_PRIVATE,
+                            'usercontextlevel' => CONTEXT_USER,
+                            'pagetypepattern' => 'my-index',
+                            'biid' => $this->instance->id)
+            );
+            if($birecord){
+                $sql = 'select bi.id,bi.blockname from {block_instances} bi inner join {my_pages} mp on \'\' || mp.id=bi.subpagepattern where bi.pagetypepattern=:pagetypepattern and bi.parentcontextid=:syscontextid and bi.blockname=:blockname';
+                $bisysrecord = $DB->get_record_sql($sql, array('syscontextid'=> context_system::instance()->id, 'pagetypepattern' => 'my-index','blockname'=> $birecord->blockname,'contextblock'=> CONTEXT_BLOCK));
+                if($bisysrecord){
+                    $context = context_block::instance($bisysrecord->id);
+                }
+            }
+            return has_capability('moodle/block:view', $context);
+        }else{
+            return true;
+        }
+    }
+    //END UNISTRA DEV
 }
 
 /**
