Browse Source

add sensitive filter settings #17

main
ghost 1 year ago
parent
commit
b1679f3f65
  1. 2
      .env
  2. 1
      config/services.yaml
  3. 8
      src/Controller/UserController.php
  4. 15
      src/Entity/User.php
  5. 32
      src/Service/UserService.php
  6. 14
      templates/default/user/info.html.twig
  7. 22
      templates/default/user/profile.html.twig

2
.env

@ -55,6 +55,8 @@ APP_LOCALES=en|cs|eo|fr|ka|de|he|it|lv|pl|pt|ru|es|uk @@ -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

1
config/services.yaml

@ -10,6 +10,7 @@ parameters: @@ -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)%'

8
src/Controller/UserController.php

@ -142,6 +142,11 @@ class UserController extends AbstractController @@ -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 @@ -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 @@ -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(),

15
src/Entity/User.php

@ -38,6 +38,9 @@ class User @@ -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 @@ -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;
}
}

32
src/Service/UserService.php

@ -36,21 +36,42 @@ class UserService @@ -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 @@ -58,6 +79,7 @@ class UserService
{
$user->setApproved(true);
$user->setModerator(true);
$user->setSensitive(false);
$this->save($user);
}

14
templates/default/user/info.html.twig

@ -85,6 +85,20 @@ @@ -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>

22
templates/default/user/profile.html.twig

@ -85,7 +85,9 @@ @@ -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 @@ @@ -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,6 +123,20 @@ @@ -119,6 +123,20 @@
</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">

Loading…
Cancel
Save