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

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use App\Migration\AbstractMultiPlatformMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230408170059 extends AbstractMultiPlatformMigration
{
public function getDescription(): string
{
return '';
}
public function mySQLUp(Schema $schema): void
{
$this->addSql('ALTER TABLE `users` ADD show_email_on_profile TINYINT(1) DEFAULT 0 NOT NULL');
}
public function mySQLDown(Schema $schema): void
{
$this->addSql('ALTER TABLE `users` DROP show_email_on_profile');
}
public function sqLiteUp(Schema $schema): void
{
$this->addSql('ALTER TABLE users ADD COLUMN show_email_on_profile BOOLEAN DEFAULT 0 NOT NULL');
}
public function sqLiteDown(Schema $schema): void
{
$this->addSql('CREATE TEMPORARY TABLE __temp__users AS SELECT id, group_id, currency_id, id_preview_attachment, disabled, config_theme, pw_reset_token, config_instock_comment_a, config_instock_comment_w, about_me, trusted_device_cookie_version, backup_codes, google_authenticator_secret, config_timezone, config_language, email, department, last_name, first_name, need_pw_change, password, name, settings, backup_codes_generation_date, pw_reset_expires, saml_user, last_modified, datetime_added, permissions_data FROM "users"');
$this->addSql('DROP TABLE "users"');
$this->addSql('CREATE TABLE "users" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, group_id INTEGER DEFAULT NULL, currency_id INTEGER DEFAULT NULL, id_preview_attachment INTEGER DEFAULT NULL, disabled BOOLEAN NOT NULL, config_theme VARCHAR(255) DEFAULT NULL, pw_reset_token VARCHAR(255) DEFAULT NULL, config_instock_comment_a CLOB NOT NULL, config_instock_comment_w CLOB NOT NULL, about_me CLOB DEFAULT \'\' NOT NULL, trusted_device_cookie_version INTEGER NOT NULL, backup_codes CLOB NOT NULL --(DC2Type:json)
, google_authenticator_secret VARCHAR(255) DEFAULT NULL, config_timezone VARCHAR(255) DEFAULT NULL, config_language VARCHAR(255) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, department VARCHAR(255) DEFAULT NULL, last_name VARCHAR(255) DEFAULT NULL, first_name VARCHAR(255) DEFAULT NULL, need_pw_change BOOLEAN NOT NULL, password VARCHAR(255) DEFAULT NULL, name VARCHAR(180) NOT NULL, settings CLOB NOT NULL --(DC2Type:json)
, backup_codes_generation_date DATETIME DEFAULT NULL, pw_reset_expires DATETIME DEFAULT NULL, saml_user BOOLEAN NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, permissions_data CLOB DEFAULT \'[]\' NOT NULL --(DC2Type:json)
, CONSTRAINT FK_1483A5E9FE54D947 FOREIGN KEY (group_id) REFERENCES "groups" (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1483A5E938248176 FOREIGN KEY (currency_id) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1483A5E9EA7100A1 FOREIGN KEY (id_preview_attachment) REFERENCES "attachments" (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO "users" (id, group_id, currency_id, id_preview_attachment, disabled, config_theme, pw_reset_token, config_instock_comment_a, config_instock_comment_w, about_me, trusted_device_cookie_version, backup_codes, google_authenticator_secret, config_timezone, config_language, email, department, last_name, first_name, need_pw_change, password, name, settings, backup_codes_generation_date, pw_reset_expires, saml_user, last_modified, datetime_added, permissions_data) SELECT id, group_id, currency_id, id_preview_attachment, disabled, config_theme, pw_reset_token, config_instock_comment_a, config_instock_comment_w, about_me, trusted_device_cookie_version, backup_codes, google_authenticator_secret, config_timezone, config_language, email, department, last_name, first_name, need_pw_change, password, name, settings, backup_codes_generation_date, pw_reset_expires, saml_user, last_modified, datetime_added, permissions_data FROM __temp__users');
$this->addSql('DROP TABLE __temp__users');
$this->addSql('CREATE UNIQUE INDEX UNIQ_1483A5E95E237E06 ON "users" (name)');
$this->addSql('CREATE INDEX IDX_1483A5E9FE54D947 ON "users" (group_id)');
$this->addSql('CREATE INDEX IDX_1483A5E938248176 ON "users" (currency_id)');
$this->addSql('CREATE INDEX IDX_1483A5E9EA7100A1 ON "users" (id_preview_attachment)');
$this->addSql('CREATE INDEX user_idx_username ON "users" (name)');
}
}

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,

View file

@ -21,6 +21,7 @@
{{ form_row(form.first_name) }}
{{ form_row(form.last_name) }}
{{ form_row(form.email) }}
{{ form_row(form.showEmailOnProfile) }}
{{ form_row(form.department) }}
{{ form_row(form.aboutMe) }}
{% endblock %}

View file

@ -29,8 +29,11 @@
<div class="form-group row">
<label class="col-form-label col-md-4">{% trans %}user.email.label{% endtrans %}</label>
<div class="col-md-8">
{# <p class="form-control-plaintext">{{ user.email }}</p>#}
<a class="form-control-plaintext" href="mailto:{{ user.email }}">{{ user.email }}</a>
{% if user.showEmailOnProfile %}
<a class="form-control-plaintext" href="mailto:{{ user.email }}">{{ user.email }}</a>
{% else %}
<span class="form-control-plaintext text-muted">-</span>
{% endif %}
</div>
</div>
<div class="form-group row">

View file

@ -25,6 +25,7 @@
{{ form_row(settings_form.last_name) }}
{{ form_row(settings_form.department) }}
{{ form_row(settings_form.email) }}
{{ form_row(settings_form.showEmailOnProfile) }}
{{ form_row(settings_form.avatar_file) }}
<div class="mb-3 row {% if user.masterPictureAttachment is null %}d-none{% endif %}">
<div class="offset-sm-3 col-sm-9">

View file

@ -11283,5 +11283,11 @@ Element 3</target>
<target>Lot owner</target>
</segment>
</unit>
<unit id="47OCK_W" name="user.show_email_on_profile.label">
<segment>
<source>user.show_email_on_profile.label</source>
<target>Show email on public profile page</target>
</segment>
</unit>
</file>
</xliff>