Allow users (and admins) to decide whether their email should be shown on their public profile

This commit is contained in:
Jan Böhmer 2023-04-08 19:53:05 +02:00
parent 71b0c2d83e
commit 5b5e8a4fd5
8 changed files with 104 additions and 3 deletions

View file

@ -168,6 +168,12 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/
protected ?string $email = '';
/**
* @var bool True if the user wants to show his email address on his (public) profile
* @ORM\Column(type="boolean", options={"default": false})
*/
protected bool $show_email_on_profile = false;
/**
* @var string|null The department the user is working
* @ORM\Column(type="string", length=255, nullable=true)
@ -632,6 +638,28 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
return $this;
}
/**
* Gets whether the email address of the user is shown on the public profile page.
* @return bool
*/
public function isShowEmailOnProfile(): bool
{
return $this->show_email_on_profile;
}
/**
* Sets whether the email address of the user is shown on the public profile page.
* @param bool $show_email_on_profile
* @return User
*/
public function setShowEmailOnProfile(bool $show_email_on_profile): User
{
$this->show_email_on_profile = $show_email_on_profile;
return $this;
}
/**
* Returns the about me text of the user.
* @return string

View file

@ -117,7 +117,11 @@ class UserAdminForm extends AbstractType
'required' => false,
'disabled' => !$this->security->isGranted('edit_infos', $entity),
])
->add('showEmailOnProfile', CheckboxType::class, [
'required' => false,
'label' => 'user.show_email_on_profile.label',
'disabled' => !$this->security->isGranted('edit_infos', $entity),
])
->add('department', TextType::class, [
'empty_data' => '',
'label' => 'user.department.label',

View file

@ -28,6 +28,7 @@ use App\Form\Type\RichTextEditorType;
use App\Form\Type\ThemeChoiceType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Event\PreSetDataEvent;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
@ -80,6 +81,11 @@ class UserSettingsType extends AbstractType
'label' => 'user.email.label',
'disabled' => !$this->security->isGranted('edit_infos', $options['data']) || $this->demo_mode,
])
->add('showEmailOnProfile', CheckboxType::class, [
'required' => false,
'label' => 'user.show_email_on_profile.label',
'disabled' => !$this->security->isGranted('edit_infos', $options['data']) || $this->demo_mode,
])
->add('avatar_file', FileType::class, [
'label' => 'user_settings.change_avatar.label',
'mapped' => false,