add sensitive filter settings #17

This commit is contained in:
ghost 2023-10-09 16:53:08 +03:00
parent 6effb4cad2
commit b1679f3f65
7 changed files with 88 additions and 8 deletions

2
.env
View File

@ -55,6 +55,8 @@ APP_LOCALES=en|cs|eo|fr|ka|de|he|it|lv|pl|pt|ru|es|uk
APP_THEME=default
APP_THEMES=default
APP_SENSITIVE=0
APP_TRACKERS=http://[201:23b4:991a:634d:8359:4521:5576:15b7]:2023/announce|http://[200:1e2f:e608:eb3a:2bf:1e62:87ba:e2f7]/announce|http://[316:c51a:62a3:8b9::5]/announce
APP_PAGE_TITLE_LENGTH_MIN=10

View File

@ -10,6 +10,7 @@ parameters:
app.locales: '%env(APP_LOCALES)%'
app.theme: '%env(APP_THEME)%'
app.themes: '%env(APP_THEMES)%'
app.sensitive: '%env(APP_SENSITIVE)%'
app.trackers: '%env(APP_TRACKERS)%'
app.page.title.length.min: '%env(APP_PAGE_TITLE_LENGTH_MIN)%'
app.page.title.length.max: '%env(APP_PAGE_TITLE_LENGTH_MAX)%'

View File

@ -142,6 +142,11 @@ class UserController extends AbstractController
);
}
// Update sensitive
$user->setSensitive(
$request->get('sensitive') === 'true'
);
// Save changes to DB
$userService->save($user);
@ -164,6 +169,7 @@ class UserController extends AbstractController
'moderator' => $user->isModerator(),
'approved' => $user->isApproved(),
'status' => $user->isStatus(),
'sensitive' => $user->isSensitive(),
'locale' => $user->getLocale(),
'locales' => $user->getLocales(),
'theme' => $user->getTheme(),
@ -223,8 +229,10 @@ class UserController extends AbstractController
'moderator' => $userTarget->isModerator(),
'approved' => $userTarget->isApproved(),
'status' => $userTarget->isStatus(),
'sensitive' => $userTarget->isSensitive(),
'locale' => $userTarget->getLocale(),
'locales' => $userTarget->getLocales(),
'theme' => $userTarget->getTheme(),
'added' => $userTarget->getAdded(),
'identicon' => $userService->identicon(
$userTarget->getAddress(),

View File

@ -38,6 +38,9 @@ class User
#[ORM\Column(length: 255)]
private ?string $theme = null;
#[ORM\Column]
private ?bool $sensitive = null;
public function getId(): ?int
{
return $this->id;
@ -145,4 +148,16 @@ class User
return $this;
}
public function isSensitive(): ?bool
{
return $this->sensitive;
}
public function setSensitive(bool $sensitive): static
{
$this->sensitive = $sensitive;
return $this;
}
}

View File

@ -36,21 +36,42 @@ class UserService
// Create new user
$user = new User();
$user->setAddress($address);
$user->setAdded(time());
$user->setApproved(false);
$user->setModerator(false);
$user->setStatus(true);
$user->setAddress(
$address
);
$user->setAdded(
time()
);
$user->setApproved(
false
);
$user->setModerator(
false
);
$user->setStatus(
true
);
$user->setLocale(
$this->parameterBagInterface->get('app.locale')
);
$user->setLocales(
explode('|', $this->parameterBagInterface->get('app.locales'))
);
$user->setTheme(
$this->parameterBagInterface->get('app.theme')
);
$user->setSensitive(
$this->parameterBagInterface->get('app.sensitive')
);
$this->save($user);
// Set initial user as approved & moderator
@ -58,6 +79,7 @@ class UserService
{
$user->setApproved(true);
$user->setModerator(true);
$user->setSensitive(false);
$this->save($user);
}

View File

@ -85,6 +85,20 @@
{% for i, locale in user.locales %}{% if i > 0 %},{% endif %} {{ locale|locale_name(locale)|u.title }}{% endfor %}
</td>
</tr>
<tr>
<td>{{ 'Theme'|trans }}</td>
<td>{{ user.theme }}</td>
</tr>
<tr>
<td>{{ 'Sensitive filter'|trans }}</td>
<td>
{% if user.sensitive %}
{{ 'yes'|trans }}
{% else %}
{{ 'no'|trans }}
{% endif %}
</td>
</tr>
</tbody>
</table>
</div>

View File

@ -85,7 +85,9 @@
</td>
</tr>
<tr>
<td>{{ 'Content filter'|trans }}</td>
<td>
{{ 'Content language' | trans }}
</td>
<td>
{% for locale in locales %}
<div class="padding-y-4-px">
@ -102,7 +104,9 @@
</td>
</tr>
<tr>
<td class="padding-t-16-px">{{ 'Theme'|trans }}</td>
<td class="padding-t-16-px">
{{ 'Theme' | trans }}
</td>
<td class="padding-t-16-px">
<select name="theme">
{% for theme in themes %}
@ -119,10 +123,24 @@
</select>
</td>
</tr>
<tr>
<td class="padding-y-8-px">
{{ 'Sensitive filter'|trans }}
</td>
<td>
<div class="padding-y-8-px">
{% if user.sensitive %}
<input name="sensitive" type="checkbox" value="true" checked="checked" />
{% else %}
<input name="sensitive" type="checkbox" value="true" />
{% endif %}
</div>
</td>
</tr>
</tbody>
</table>
<div class="text-right">
<input class="button-green" type="submit" value="{{'Save'|trans }}" />
<input class="button-green" type="submit" value="{{ 'Save' | trans }}" />
</div>
</form>
</div>