diff --git a/migrations/Version20230408170059.php b/migrations/Version20230408170059.php new file mode 100644 index 00000000..9f686c38 --- /dev/null +++ b/migrations/Version20230408170059.php @@ -0,0 +1,52 @@ +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)'); + } +} diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index a468d355..57ac1f43 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -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 diff --git a/src/Form/UserAdminForm.php b/src/Form/UserAdminForm.php index 9f97d8f3..ce9cab04 100644 --- a/src/Form/UserAdminForm.php +++ b/src/Form/UserAdminForm.php @@ -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', diff --git a/src/Form/UserSettingsType.php b/src/Form/UserSettingsType.php index c54e90e9..cf75b0f8 100644 --- a/src/Form/UserSettingsType.php +++ b/src/Form/UserSettingsType.php @@ -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, diff --git a/templates/admin/user_admin.html.twig b/templates/admin/user_admin.html.twig index e24ce36d..ccbd7b0a 100644 --- a/templates/admin/user_admin.html.twig +++ b/templates/admin/user_admin.html.twig @@ -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 %} diff --git a/templates/users/user_info.html.twig b/templates/users/user_info.html.twig index 28d720b6..42c399c2 100644 --- a/templates/users/user_info.html.twig +++ b/templates/users/user_info.html.twig @@ -29,8 +29,11 @@
{{ user.email }}
#} - {{ user.email }} + {% if user.showEmailOnProfile %} + {{ user.email }} + {% else %} + - + {% endif %}