Can the user export (see portfolios) the post in this discussion?

@param stdClass $user The user to check
@param post_entity $post The post the user wants to export
@return bool
495181
public function can_export_post(stdClass $user, post_entity $post) : bool {
        global $CFG;
        $context = $this->get_context();
        return $CFG->enableportfolios  && (has_capability('mod/forum:exportpost', $context, $user) ||
            ($post->is_owned_by_user($user) && has_capability('mod/forum:exportownpost', $context, $user)));
    }
154966
public function savePost(DataObject $post, $data) {
		if ($post->checkPerm('Write') && isset($data['Content'])) {
			$post->Content = $data['Content'];
			if ($this->securityContext->getMember()->Balance >= MicroBlogMember::BALANCE_THRESHOLD) {
				$post->analyseContent();
				$post->write();
			} else {
				$this->queuedJobService->queueJob(new ProcessPostJob($post));
			}
			$html = $post->renderWith('PostContent');
			return $post;
		}
	}
543234
public function read(User $user, User $entity)
    {
        if ($entity->id === $user->id) {
            return true;
        }
        return $user->hasPermission('user-read');
    }
966617
public static function export_user_data(approved_contextlist $contextlist) {
        if (empty($contextlist->count())) {
            return;
        }

        $user = $contextlist->get_user();

        foreach ($contextlist->get_contexts() as $context) {
            if ($context->contextlevel != CONTEXT_MODULE) {
                continue;
            }

            // Cannot make use of helper::export_context_files(), need to manually export assignment details.
            $assignmentdata = self::get_assignment_by_context($context);

            // Get assignment details object for output.
            $assignment = self::get_assignment_output($assignmentdata);
            writer::with_context($context)->export_data([], $assignment);

            // Check if the user has marked any assignment's submissions to determine assignment submissions to export.
            $teacher = (self::has_marked_assignment_submissions($assignmentdata->id, $user->id) == true) ? true : false;

            // Get the assignment submissions submitted by & marked by the user for an assignment.
            $submissionsdata = self::get_assignment_submissions_by_assignment($assignmentdata->id, $user->id, $teacher);

            foreach ($submissionsdata as $submissiondata) {
                // Default subcontext path to export assignment submissions submitted by the user.
                $subcontexts = [
                    get_string('privacy:submissionpath', 'mod_assignment')
                ];

                if ($teacher == true) {
                    if ($submissiondata->teacher == $user->id) {
                        // Export assignment submissions that have been marked by the user.
                        $subcontexts = [
                            get_string('privacy:markedsubmissionspath', 'mod_assignment'),
                            transform::user($submissiondata->userid)
                        ];
                    }
                }

                // Get assignment submission details object for output.
                $submission = self::get_assignment_submission_output($submissiondata);
                $itemid = $submissiondata->id;

                writer::with_context($context)
                    ->export_data($subcontexts, $submission)
                    ->export_area_files($subcontexts, 'mod_assignment', 'submission', $itemid);
            }
        }
    }
361489
public function can_reply_privately_to_post(stdClass $user, post_entity $post) : bool {
        if ($post->is_private_reply()) {
            // You cannot reply privately to a post which is, itself, a private reply.
            return false;
        }

        return has_capability('mod/forum:postprivatereply', $this->get_context(), $user);
    }
666834
public function deletePost(Blog $blog, Post $post, User $user)
    {
        //remove tags beforehand
        $event = new GenericDataEvent([
            'tags' => [],
            'data' => [
                [
                    'class' => 'Icap\BlogBundle\Entity\Post',
                    'id' => $post->getUuid(),
                    'name' => $post->getTitle(),
                ],
            ],
            'replace' => true,
        ]);
        $this->eventDispatcher->dispatch('claroline_tag_multiple_data', $event);

        $this->om->remove($post);
        $this->om->flush();

        $this->trackingManager->dispatchPostDeleteEvent($post);
    }
463724
public static function create_from_user(\assign $assign, \stdClass $user) {
        $data = array(
            'context' => $assign->get_context(),
            'objectid' => $assign->get_instance()->id,
            'relateduserid' => $user->id,
        );
        self::$preventcreatecall = false;
        /** @var submission_unlocked $event */
        $event = self::create($data);
        self::$preventcreatecall = true;
        $event->set_assign($assign);
        $event->add_record_snapshot('user', $user);
        return $event;
    }
89508
protected static function export_data($context, $user) {
        if (!$context) {
            return;
        }
        $contextdata = helper::get_context_data($context, $user);
        helper::export_context_files($context, $user);
        writer::with_context($context)->export_data([], $contextdata);
    }
848139
public function edit($user, $comment)
    {
        return $this->postPolicy->show($user, $comment->post)
            || $user->owns($comment)
            || $user->can('blog.comment.edit');
    }
280467
public function can_view_discussion(stdClass $user, discussion_entity $discussion) : bool {
        $forumrecord = $this->get_forum_record();
        $discussionrecord = $this->get_discussion_record($discussion);
        $context = $this->get_context();

        return forum_user_can_see_discussion($forumrecord, $discussionrecord, $context, $user);
    }
880946
public function saveUser($user)
    {
        if (is_array($user)) {
            $user = new Entity\Users($user);
        }

        // Make sure the username is slug-like
        $user->setUsername($this->app['slugify']->slugify($user->getUsername()));

        // Save the entity
        return $this->getRepository()->save($user);
    }
1010074
public function getUserGuidedPortfoliosData(User $user)
    {
        /** @var \Icap\PortfolioBundle\Entity\Portfolio[] $portfolios */
        $portfolios = $this->entityManager->getRepository('IcapPortfolioBundle:Portfolio')->findAvailableToGuideByUser($user);

        $data = [];

        foreach ($portfolios as $portfolio) {
            $data[] = $this->getUserGuidedPortfolioData($portfolio, $user);
        }

        return $data;
    }
77175
protected static function export_user_data_user_evidence(context_user $context) {
        global $DB;

        $userid = $context->instanceid;
        $path = [get_string('competencies', 'core_competency'), get_string('privacy:path:userevidence', 'core_competency')];
        $uefields = user_evidence::get_sql_fields('ue', 'ue_');
        $cfields = competency::get_sql_fields('c', 'c_');

        $sql = "
            SELECT $uefields, $cfields
              FROM {" . user_evidence::TABLE . "} ue
         LEFT JOIN {" . user_evidence_competency::TABLE . "} uec
                ON uec.userevidenceid = ue.id
         LEFT JOIN {" . competency::TABLE . "} c
                ON c.id = uec.competencyid
             WHERE ue.userid = :userid
          ORDER BY ue.id";
        $params = ['userid' => $userid];

        $recordset = $DB->get_recordset_sql($sql, $params);
        static::recordset_loop_and_export($recordset, 'ue_id', null, function($carry, $record) use ($userid, $context){
            if ($carry === null) {
                $ue = new user_evidence(null, user_evidence::extract_record($record, 'ue_'));
                $carry = static::transform_user_evidence($userid, $ue);
            }

            if (!empty($record->c_id)) {
                $competency = new competency(null, competency::extract_record($record, 'c_'));
                $carry['competencies'][] = static::transform_competency_brief($competency);
            }

            return $carry;
        }, function($ueid, $data) use ($context, $path) {
            $finalpath = array_merge($path, [$data['name'] . ' (' . $ueid . ')']);
            writer::with_context($context)->export_area_files($finalpath, 'core_competency', 'userevidence', $ueid);
            writer::with_context($context)->export_data($finalpath, (object) $data);
        });
    }
891677
public function findGuidedPortfolios(User $user, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('p')
            ->join('p.portfolioGuides', 'guides')
            ->andWhere('guides.user = :guide')
            ->setParameter('guide', $user)
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getResult() : $queryBuilder->getQuery();
    }
290166
public static function export_customfield_data(data_controller $data, \stdClass $exportdata, array $subcontext) {
        $context = $data->get_context();
        // For text fields we want to apply format_string even to raw value to avoid CSS.
        $exportdata->{$data->datafield()} = $data->export_value();
        writer::with_context($context)
            ->export_data($subcontext, $exportdata);
    }
370592
private function prepare_post($post, $fileoutputextras=null) {
        global $DB;
        static $users;
        if (empty($users)) {
            $users = array($this->user->id => $this->user);
        }
        if (!array_key_exists($post->userid, $users)) {
            $users[$post->userid] = $DB->get_record('user', array('id' => $post->userid));
        }
        // add the user object on to the post so we can pass it to the leap writer if necessary
        $post->author = $users[$post->userid];
        $viewfullnames = true;
        // format the post body
        $options = portfolio_format_text_options();
        $format = $this->get('exporter')->get('format');
        $formattedtext = format_text($post->message, $post->messageformat, $options, $this->get('course')->id);
        $formattedtext = portfolio_rewrite_pluginfile_urls($formattedtext, $this->modcontext->id, 'mod_forum', 'post', $post->id, $format);

        $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';

        $output .= '<tr class="header"><td>';// can't print picture.
        $output .= '</td>';

        if ($post->parent) {
            $output .= '<td class="topic">';
        } else {
            $output .= '<td class="topic starter">';
        }
        $output .= '<div class="subject">'.format_string($post->subject).'</div>';

        $fullname = fullname($users[$post->userid], $viewfullnames);
        $by = new stdClass();
        $by->name = $fullname;
        $by->date = userdate($post->modified, '', core_date::get_user_timezone($this->user));
        $output .= '<div class="author">'.get_string('bynameondate', 'forum', $by).'</div>';

        $output .= '</td></tr>';

        $output .= '<tr><td class="left side" valign="top">';

        $output .= '</td><td class="content">';

        $output .= $formattedtext;

        if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id]) && count($this->keyedfiles[$post->id]) > 0) {
            $output .= '<div class="attachments">';
            $output .= '<br /><b>' .  get_string('attachments', 'forum') . '</b>:<br /><br />';
            foreach ($this->keyedfiles[$post->id] as $file) {
                $output .= $format->file_output($file)  . '<br/ >';
            }
            $output .= "</div>";
        }

        $output .= '</td></tr></table>'."\n\n";

        return $output;
    }
436880
private function serializePicture(User $user)
    {
        if (!empty($user->getPicture())) {
            /** @var PublicFile $file */
            $file = $this->om
                ->getRepository(PublicFile::class)
                ->findOneBy(['url' => $user->getPicture()]);

            if ($file) {
                return $this->fileSerializer->serialize($file);
            }
        }

        return null;
    }