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
APP_THEME=default APP_THEME=default
APP_THEMES=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_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 APP_PAGE_TITLE_LENGTH_MIN=10

1
config/services.yaml

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

8
src/Controller/UserController.php

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

15
src/Entity/User.php

@ -38,6 +38,9 @@ class User
#[ORM\Column(length: 255)] #[ORM\Column(length: 255)]
private ?string $theme = null; private ?string $theme = null;
#[ORM\Column]
private ?bool $sensitive = null;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@ -145,4 +148,16 @@ class User
return $this; 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
// Create new user // Create new user
$user = new User(); $user = new User();
$user->setAddress($address); $user->setAddress(
$user->setAdded(time()); $address
$user->setApproved(false); );
$user->setModerator(false);
$user->setStatus(true); $user->setAdded(
time()
);
$user->setApproved(
false
);
$user->setModerator(
false
);
$user->setStatus(
true
);
$user->setLocale( $user->setLocale(
$this->parameterBagInterface->get('app.locale') $this->parameterBagInterface->get('app.locale')
); );
$user->setLocales( $user->setLocales(
explode('|', $this->parameterBagInterface->get('app.locales')) explode('|', $this->parameterBagInterface->get('app.locales'))
); );
$user->setTheme( $user->setTheme(
$this->parameterBagInterface->get('app.theme') $this->parameterBagInterface->get('app.theme')
); );
$user->setSensitive(
$this->parameterBagInterface->get('app.sensitive')
);
$this->save($user); $this->save($user);
// Set initial user as approved & moderator // Set initial user as approved & moderator
@ -58,6 +79,7 @@ class UserService
{ {
$user->setApproved(true); $user->setApproved(true);
$user->setModerator(true); $user->setModerator(true);
$user->setSensitive(false);
$this->save($user); $this->save($user);
} }

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

@ -85,6 +85,20 @@
{% for i, locale in user.locales %}{% if i > 0 %},{% endif %} {{ locale|locale_name(locale)|u.title }}{% endfor %} {% for i, locale in user.locales %}{% if i > 0 %},{% endif %} {{ locale|locale_name(locale)|u.title }}{% endfor %}
</td> </td>
</tr> </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> </tbody>
</table> </table>
</div> </div>

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

@ -85,7 +85,9 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td>{{ 'Content filter'|trans }}</td> <td>
{{ 'Content language' | trans }}
</td>
<td> <td>
{% for locale in locales %} {% for locale in locales %}
<div class="padding-y-4-px"> <div class="padding-y-4-px">
@ -102,7 +104,9 @@
</td> </td>
</tr> </tr>
<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"> <td class="padding-t-16-px">
<select name="theme"> <select name="theme">
{% for theme in themes %} {% for theme in themes %}
@ -119,6 +123,20 @@
</select> </select>
</td> </td>
</tr> </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> </tbody>
</table> </table>
<div class="text-right"> <div class="text-right">

Loading…
Cancel
Save