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:
Tobias Wiese 2021-12-30 19:18:54 +01:00 committed by Igor Scheller
parent 9db8773150
commit e361400f68
7 changed files with 51 additions and 76 deletions

View File

@ -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\')
');
}
}

View File

@ -86,11 +86,6 @@ msgstr "News erfolgreich aktualisiert."
msgid "news.delete.success"
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"
msgstr "Ungültiger OAuth-Status"

View File

@ -84,9 +84,6 @@ msgstr "News successfully updated."
msgid "news.delete.success"
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"
msgstr "Invalid OAuth state"

View File

@ -73,7 +73,7 @@
{{ news.title }}
</div>
<div class="card-body bg-body">
{{ news.text|raw|markdown(false) }}
{{ news.text|markdown }}
</div>
</div>
</div>

View File

@ -60,7 +60,7 @@
{% endif %}
<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) %}
{{ m.button(__('news.read_more'), url('news/' ~ news.id), null, 'sm', null, null, 'chevron-double-right') }}
{% endif %}

View File

@ -80,14 +80,6 @@ class NewsController extends BaseController
*/
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) {
$this->cleanupModelNullValues($news);
}
@ -138,10 +130,6 @@ class NewsController extends BaseController
return $this->redirect->to('/news');
}
if (!$this->auth->can('admin_news_html')) {
$data['text'] = strip_tags($data['text']);
}
if (!$news->user) {
$news->user()->associate($this->auth->user());
}

View File

@ -23,40 +23,11 @@ class NewsControllerTest extends ControllerTest
protected $data = [
[
'title' => 'Foo',
'text' => '<b>foo</b>',
'is_meeting' => false,
'text' => '**foo**',
'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::edit
@ -76,10 +47,6 @@ class NewsControllerTest extends ControllerTest
return $this->response;
});
$this->auth->expects($this->once())
->method('can')
->with('admin_news_html')
->willReturn(true);
/** @var NewsController $controller */
$controller = $this->app->make(NewsController::class);
@ -103,10 +70,6 @@ class NewsControllerTest extends ControllerTest
return $this->response;
}
);
$this->auth->expects($this->once())
->method('can')
->with('admin_news_html')
->willReturn(true);
/** @var NewsController $controller */
$controller = $this->app->make(NewsController::class);
@ -142,10 +105,10 @@ class NewsControllerTest extends ControllerTest
public function saveCreateEditProvider(): array
{
return [
['Some <b>test</b>', true, true, 'Some <b>test</b>'],
['Some <b>test</b>', false, false, 'Some test'],
['Some <b>test</b>', false, true, 'Some <b>test</b>', 1],
['Some <b>test</b>', true, false, 'Some test', 1],
['Some test', true],
['Some test', false],
['Some test', false, 1],
['Some test', true, 1],
];
}
@ -155,15 +118,11 @@ class NewsControllerTest extends ControllerTest
*
* @param string $text
* @param bool $isMeeting
* @param bool $canEditHtml
* @param string $result
* @param int|null $id
*/
public function testSaveCreateEdit(
string $text,
bool $isMeeting,
bool $canEditHtml,
string $result,
int $id = null
) {
$this->request->attributes->set('id', $id);
@ -178,10 +137,6 @@ class NewsControllerTest extends ControllerTest
$this->request = $this->request->withParsedBody($body);
$this->addUser();
$this->auth->expects($this->once())
->method('can')
->with('admin_news_html')
->willReturn($canEditHtml);
$this->response->expects($this->once())
->method('redirectTo')
->with('http://localhost/news')
@ -201,7 +156,7 @@ class NewsControllerTest extends ControllerTest
$this->assertEquals('news.edit.success', $messages[0]);
$news = (new News())->find($id);
$this->assertEquals($result, $news->text);
$this->assertEquals($text, $news->text);
$this->assertEquals($isMeeting, (bool)$news->is_meeting);
}
@ -243,7 +198,7 @@ class NewsControllerTest extends ControllerTest
// Assert no changes
$news = News::find(1);
$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_pinned);
}
@ -305,8 +260,7 @@ class NewsControllerTest extends ControllerTest
(new News([
'title' => 'Foo',
'text' => '<b>foo</b>',
'is_meeting' => false,
'text' => '**foo**',
'user_id' => 1,
]))->save();
}