news: remove html support
Since the support for markdown in news the html feature isn't really necessary any more.
This commit is contained in:
parent
9db8773150
commit
e361400f68
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Engelsystem\Migrations;
|
||||||
|
|
||||||
|
use Engelsystem\Database\Migration\Migration;
|
||||||
|
|
||||||
|
class RemoveAdminNewsHtmlPrivilege extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migration
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!$this->schema->hasTable('GroupPrivileges')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$connection = $this->schema->getConnection();
|
||||||
|
|
||||||
|
// Delete unused privileges
|
||||||
|
$connection->delete('
|
||||||
|
DELETE FROM `Privileges`
|
||||||
|
WHERE `name` = \'admin_news_html\'
|
||||||
|
');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migration
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
if (!$this->schema->hasTable('GroupPrivileges')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$connection->insert('
|
||||||
|
INSERT INTO `Privileges` (`name`, `desc`)
|
||||||
|
VALUES (\'admin_news_html\', \'Use HTML in news\')
|
||||||
|
');
|
||||||
|
}
|
||||||
|
}
|
|
@ -86,11 +86,6 @@ msgstr "News erfolgreich aktualisiert."
|
||||||
msgid "news.delete.success"
|
msgid "news.delete.success"
|
||||||
msgstr "News erfolgreich gelöscht."
|
msgstr "News erfolgreich gelöscht."
|
||||||
|
|
||||||
msgid "news.edit.contains-html"
|
|
||||||
msgstr ""
|
|
||||||
"Diese Nachricht beinhaltet HTML. Wenn du sie speicherst gehen diese "
|
|
||||||
"Formatierungen verloren!"
|
|
||||||
|
|
||||||
msgid "oauth.invalid-state"
|
msgid "oauth.invalid-state"
|
||||||
msgstr "Ungültiger OAuth-Status"
|
msgstr "Ungültiger OAuth-Status"
|
||||||
|
|
||||||
|
|
|
@ -84,9 +84,6 @@ msgstr "News successfully updated."
|
||||||
msgid "news.delete.success"
|
msgid "news.delete.success"
|
||||||
msgstr "News successfully deleted."
|
msgstr "News successfully deleted."
|
||||||
|
|
||||||
msgid "news.edit.contains-html"
|
|
||||||
msgstr "This message contains HTML. After saving the post some formatting will be lost!"
|
|
||||||
|
|
||||||
msgid "oauth.invalid-state"
|
msgid "oauth.invalid-state"
|
||||||
msgstr "Invalid OAuth state"
|
msgstr "Invalid OAuth state"
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
{{ news.title }}
|
{{ news.title }}
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body bg-body">
|
<div class="card-body bg-body">
|
||||||
{{ news.text|raw|markdown(false) }}
|
{{ news.text|markdown }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="card-body bg-body">
|
<div class="card-body bg-body">
|
||||||
{{ news.text(not is_overview)|raw|markdown(false) }}
|
{{ news.text(not is_overview)|markdown }}
|
||||||
{% if is_overview and news.text != news.text(false) %}
|
{% if is_overview and news.text != news.text(false) %}
|
||||||
{{ m.button(__('news.read_more'), url('news/' ~ news.id), null, 'sm', null, null, 'chevron-double-right') }}
|
{{ m.button(__('news.read_more'), url('news/' ~ news.id), null, 'sm', null, null, 'chevron-double-right') }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -80,14 +80,6 @@ class NewsController extends BaseController
|
||||||
*/
|
*/
|
||||||
protected function showEdit(?News $news, bool $isMeetingDefault = false): Response
|
protected function showEdit(?News $news, bool $isMeetingDefault = false): Response
|
||||||
{
|
{
|
||||||
if (
|
|
||||||
$news
|
|
||||||
&& !$this->auth->can('admin_news_html')
|
|
||||||
&& strip_tags($news->text) != $news->text
|
|
||||||
) {
|
|
||||||
$this->addNotification('news.edit.contains-html', 'warnings');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($news) {
|
if ($news) {
|
||||||
$this->cleanupModelNullValues($news);
|
$this->cleanupModelNullValues($news);
|
||||||
}
|
}
|
||||||
|
@ -138,10 +130,6 @@ class NewsController extends BaseController
|
||||||
return $this->redirect->to('/news');
|
return $this->redirect->to('/news');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->auth->can('admin_news_html')) {
|
|
||||||
$data['text'] = strip_tags($data['text']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$news->user) {
|
if (!$news->user) {
|
||||||
$news->user()->associate($this->auth->user());
|
$news->user()->associate($this->auth->user());
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,40 +23,11 @@ class NewsControllerTest extends ControllerTest
|
||||||
protected $data = [
|
protected $data = [
|
||||||
[
|
[
|
||||||
'title' => 'Foo',
|
'title' => 'Foo',
|
||||||
'text' => '<b>foo</b>',
|
'text' => '**foo**',
|
||||||
'is_meeting' => false,
|
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \Engelsystem\Controllers\Admin\NewsController::edit
|
|
||||||
* @covers \Engelsystem\Controllers\Admin\NewsController::showEdit
|
|
||||||
*/
|
|
||||||
public function testEditHtmlWarning()
|
|
||||||
{
|
|
||||||
$this->request->attributes->set('id', 1);
|
|
||||||
$this->response->expects($this->once())
|
|
||||||
->method('withView')
|
|
||||||
->willReturnCallback(function ($view, $data) {
|
|
||||||
$this->assertEquals('pages/news/edit.twig', $view);
|
|
||||||
|
|
||||||
/** @var Collection $warnings */
|
|
||||||
$warnings = $data['warnings'];
|
|
||||||
$this->assertNotEmpty($data['news']);
|
|
||||||
$this->assertTrue($warnings->isNotEmpty());
|
|
||||||
$this->assertEquals('news.edit.contains-html', $warnings->first());
|
|
||||||
|
|
||||||
return $this->response;
|
|
||||||
});
|
|
||||||
$this->addUser();
|
|
||||||
|
|
||||||
/** @var NewsController $controller */
|
|
||||||
$controller = $this->app->make(NewsController::class);
|
|
||||||
|
|
||||||
$controller->edit($this->request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Engelsystem\Controllers\Admin\NewsController::__construct
|
* @covers \Engelsystem\Controllers\Admin\NewsController::__construct
|
||||||
* @covers \Engelsystem\Controllers\Admin\NewsController::edit
|
* @covers \Engelsystem\Controllers\Admin\NewsController::edit
|
||||||
|
@ -76,10 +47,6 @@ class NewsControllerTest extends ControllerTest
|
||||||
|
|
||||||
return $this->response;
|
return $this->response;
|
||||||
});
|
});
|
||||||
$this->auth->expects($this->once())
|
|
||||||
->method('can')
|
|
||||||
->with('admin_news_html')
|
|
||||||
->willReturn(true);
|
|
||||||
|
|
||||||
/** @var NewsController $controller */
|
/** @var NewsController $controller */
|
||||||
$controller = $this->app->make(NewsController::class);
|
$controller = $this->app->make(NewsController::class);
|
||||||
|
@ -103,10 +70,6 @@ class NewsControllerTest extends ControllerTest
|
||||||
return $this->response;
|
return $this->response;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$this->auth->expects($this->once())
|
|
||||||
->method('can')
|
|
||||||
->with('admin_news_html')
|
|
||||||
->willReturn(true);
|
|
||||||
|
|
||||||
/** @var NewsController $controller */
|
/** @var NewsController $controller */
|
||||||
$controller = $this->app->make(NewsController::class);
|
$controller = $this->app->make(NewsController::class);
|
||||||
|
@ -142,10 +105,10 @@ class NewsControllerTest extends ControllerTest
|
||||||
public function saveCreateEditProvider(): array
|
public function saveCreateEditProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['Some <b>test</b>', true, true, 'Some <b>test</b>'],
|
['Some test', true],
|
||||||
['Some <b>test</b>', false, false, 'Some test'],
|
['Some test', false],
|
||||||
['Some <b>test</b>', false, true, 'Some <b>test</b>', 1],
|
['Some test', false, 1],
|
||||||
['Some <b>test</b>', true, false, 'Some test', 1],
|
['Some test', true, 1],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,15 +118,11 @@ class NewsControllerTest extends ControllerTest
|
||||||
*
|
*
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param bool $isMeeting
|
* @param bool $isMeeting
|
||||||
* @param bool $canEditHtml
|
|
||||||
* @param string $result
|
|
||||||
* @param int|null $id
|
* @param int|null $id
|
||||||
*/
|
*/
|
||||||
public function testSaveCreateEdit(
|
public function testSaveCreateEdit(
|
||||||
string $text,
|
string $text,
|
||||||
bool $isMeeting,
|
bool $isMeeting,
|
||||||
bool $canEditHtml,
|
|
||||||
string $result,
|
|
||||||
int $id = null
|
int $id = null
|
||||||
) {
|
) {
|
||||||
$this->request->attributes->set('id', $id);
|
$this->request->attributes->set('id', $id);
|
||||||
|
@ -178,10 +137,6 @@ class NewsControllerTest extends ControllerTest
|
||||||
|
|
||||||
$this->request = $this->request->withParsedBody($body);
|
$this->request = $this->request->withParsedBody($body);
|
||||||
$this->addUser();
|
$this->addUser();
|
||||||
$this->auth->expects($this->once())
|
|
||||||
->method('can')
|
|
||||||
->with('admin_news_html')
|
|
||||||
->willReturn($canEditHtml);
|
|
||||||
$this->response->expects($this->once())
|
$this->response->expects($this->once())
|
||||||
->method('redirectTo')
|
->method('redirectTo')
|
||||||
->with('http://localhost/news')
|
->with('http://localhost/news')
|
||||||
|
@ -201,7 +156,7 @@ class NewsControllerTest extends ControllerTest
|
||||||
$this->assertEquals('news.edit.success', $messages[0]);
|
$this->assertEquals('news.edit.success', $messages[0]);
|
||||||
|
|
||||||
$news = (new News())->find($id);
|
$news = (new News())->find($id);
|
||||||
$this->assertEquals($result, $news->text);
|
$this->assertEquals($text, $news->text);
|
||||||
$this->assertEquals($isMeeting, (bool)$news->is_meeting);
|
$this->assertEquals($isMeeting, (bool)$news->is_meeting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +198,7 @@ class NewsControllerTest extends ControllerTest
|
||||||
// Assert no changes
|
// Assert no changes
|
||||||
$news = News::find(1);
|
$news = News::find(1);
|
||||||
$this->assertEquals('Foo', $news->title);
|
$this->assertEquals('Foo', $news->title);
|
||||||
$this->assertEquals('<b>foo</b>', $news->text);
|
$this->assertEquals('**foo**', $news->text);
|
||||||
$this->assertFalse($news->is_meeting);
|
$this->assertFalse($news->is_meeting);
|
||||||
$this->assertFalse($news->is_pinned);
|
$this->assertFalse($news->is_pinned);
|
||||||
}
|
}
|
||||||
|
@ -305,8 +260,7 @@ class NewsControllerTest extends ControllerTest
|
||||||
|
|
||||||
(new News([
|
(new News([
|
||||||
'title' => 'Foo',
|
'title' => 'Foo',
|
||||||
'text' => '<b>foo</b>',
|
'text' => '**foo**',
|
||||||
'is_meeting' => false,
|
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
]))->save();
|
]))->save();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue