Skip to content
Snippets Groups Projects
Commit 9489c1a6 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

perform redirect after commenting on a news, fixes #907

Closes #907

Merge request studip/studip!515
parent 86a0f5fd
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ class Course_OverviewController extends AuthenticatedController
}
// Fetch news
$response = $this->relay('news/display/' . $this->course_id);
$response = $this->relayWithRedirect('news/display/' . $this->course_id);
$this->news = $response->body;
// Fetch votes
......
......@@ -132,7 +132,7 @@ class Institute_OverviewController extends AuthenticatedController
}
// Fetch news
$response = $this->relay('news/display/' . $this->institute_id);
$response = $this->relayWithRedirect('news/display/' . $this->institute_id);
$this->news = $response->body;
// Fetch votes
......
......@@ -59,7 +59,6 @@ class NewsController extends StudipController
* Widget controller to produce the formally known show_votes()
*
* @param String $range_id range id of the news to get displayed
* @return array() Array of votes
*/
public function display_action($range_id)
{
......@@ -81,11 +80,21 @@ class NewsController extends StudipController
// Check if user wrote a comment
if (Request::submitted('accept') && trim(Request::get('comment_content')) && Request::isPost()) {
CSRFProtection::verifySecurityToken();
StudipComment::create([
'object_id' => Request::get('comsubmit'),
$news_id = Request::get('comsubmit');
$comment = StudipComment::create([
'object_id' => $news_id,
'user_id' => $GLOBALS['user']->id,
'content' => trim(Request::get('comment_content'))
]);
$url = URLHelper::getURL(Request::url() . "#newscomment-{$comment->id}", [
'contentbox_open' => $news_id,
'comments' => true,
]);
$this->redirect($url);
return;
}
// Check if user wants to remove a announcement
......
......@@ -116,7 +116,7 @@ class ProfileController extends AuthenticatedController
$show_admin = ($this->perm->have_perm('autor') && $this->user->user_id == $this->current_user->user_id)
|| (Deputy::isEditActivated() && Deputy::isDeputy($this->user->user_id, $this->current_user->user_id, true));
if (Visibility::verify('news', $this->current_user->user_id) || $show_admin) {
$response = $this->relay('news/display/' . $this->current_user->user_id);
$response = $this->relayWithRedirect('news/display/' . $this->current_user->user_id);
$this->news = $response->body;
}
......
......@@ -534,6 +534,28 @@ abstract class StudipController extends Trails_Controller
return call_user_func_array([$controller, 'perform_relayed'], $args);
}
/**
* Relays current request and performs redirect if neccessary.
*
* @param string $to_uri a trails route
* @return Trails_Response
*
* @see StudipController::relay()
*/
public function relayWithRedirect(...$args): Trails_Response
{
$response = $this->relay(...$args);
// If the relayed action should perform a redirect, do so
if (isset($response->headers['Location'])) {
header("Location: {$response->headers['Location']}");
page_close();
die;
}
return $response;
}
/**
* perform a given action/parameter string from an relayed request
* before_filter and after_filter methods are not called
......
<article class="comment open">
<time><?= reltime($comment[3]) ?></time>
<article class="comment open" id="newscomment-<?= htmlReady($comment['comment_id']) ?>">
<time><?= reltime($comment['mkdate']) ?></time>
<h1>#<?= $index + 1 ?>
<a href="<?= URLHelper::getLink('dispatch.php/profile?username=' . $comment[2]) ?>">
<?= htmlReady($comment[1]) ?>
<a href="<?= URLHelper::getLink('dispatch.php/profile', ['username' => $comment['username']]) ?>">
<?= htmlReady($comment['fullname']) ?>
</a>
</h1>
<?= formatReady($comment[0]) ?>
</article>
\ No newline at end of file
<?= formatReady($comment['content']) ?>
</article>
......@@ -22,7 +22,7 @@ class NewsWidget extends StudIPPlugin implements PortalPlugin
{
$dispatcher = new StudipDispatcher();
$controller = new NewsController($dispatcher);
$response = $controller->relay('news/display/studip');
$response = $controller->relayWithRedirect('news/display/studip');
$template = $GLOBALS['template_factory']->open('shared/string');
$template->content = $response->body;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment