Kaynağa Gözat

Utilisateurs : possibilité d'ajouter automatiquement un utilisateur à un groupe au moment de son inscription #1370

feature/souke
Guillaume Bourgeois 1 yıl önce
ebeveyn
işleme
578c9fd809
8 değiştirilmiş dosya ile 123 ekleme ve 37 silme
  1. +38
    -30
      backend/views/producer/update.php
  2. +14
    -1
      common/logic/Producer/Producer/Model/Producer.php
  3. +9
    -0
      common/logic/User/User/Service/UserBuilder.php
  4. +1
    -1
      common/logic/User/UserGroup/Service/UserGroupBuilder.php
  5. +16
    -0
      common/logic/User/UserUserGroup/Model/UserUserGroup.php
  6. +8
    -4
      common/logic/User/UserUserGroup/Service/UserUserGroupBuilder.php
  7. +28
    -0
      console/migrations/m231109_090026_add_column_producer_id_user_group_default.php
  8. +9
    -1
      frontend/forms/SignupForm.php

+ 38
- 30
backend/views/producer/update.php Dosyayı Görüntüle

@@ -40,6 +40,7 @@ use common\helpers\Dropdown;
use common\helpers\GlobalParam;
use common\logic\Distribution\Distribution\Module\DistributionModule;
use common\logic\User\User\Module\UserModule;
use common\logic\User\UserGroup\Module\UserGroupModule;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\logic\Producer\Producer\Model\Producer;
@@ -50,8 +51,11 @@ use yii\helpers\ArrayHelper;
\backend\assets\VuejsProducerUpdateAsset::register($this);

$userModule = UserModule::getInstance();
$userCurrent = GlobalParam::getCurrentUser();
$userGroupModule = UserGroupModule::getInstance();
$distributionExportManager = DistributionModule::getInstance()->getExportManager();

$userCurrent = GlobalParam::getCurrentUser();

$this->setTitle('Paramètres');
$this->addBreadcrumb($this->getTitle());

@@ -59,7 +63,7 @@ $this->addBreadcrumb($this->getTitle());

<script>
var appInitValues = {
isAdmin: <?= (int) $userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent) ?>
isAdmin: <?= (int)$userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent) ?>
};
</script>

@@ -67,8 +71,8 @@ $this->addBreadcrumb($this->getTitle());

<div id="nav-params">
<a v-for="section in sectionsArray" v-if="!section.isAdminSection || (section.isAdminSection && isAdmin)"
:class="'btn '+((currentSection == section.name) ? 'btn-primary' : 'btn-default')"
@click="changeSection(section)" :href="'#'+section.name">
:class="'btn '+((currentSection == section.name) ? 'btn-primary' : 'btn-default')"
@click="changeSection(section)" :href="'#'+section.name">
{{ section.nameDisplay }}
</a>
</div>
@@ -122,6 +126,10 @@ $this->addBreadcrumb($this->getTitle());
Producer::BEHAVIOR_HOME_POINT_SALE_DAY_LIST_INCOMING_DISTRIBUTIONS => 'Distributions à venir',
]); ?>
<?= $form->field($model, 'option_point_sale_wording') ?>

<h4>Groupes utilisateurs</h4>
<?= $form->field($model, 'id_user_group_default')
->dropDownList($userGroupModule->getRepository()->populateUserGroupDropdownList()); ?>
</div>
</div>

@@ -256,10 +264,10 @@ $this->addBreadcrumb($this->getTitle());

<h4>Divers</h4>
<?php
$choicesWeeksDistributionsActivatedInAdvanceArray = [null => '--'];
for($i = 1; $i < 13; $i++) {
$choicesWeeksDistributionsActivatedInAdvanceArray[$i] = $i.' semaine'.(($i > 1) ? 's' : '');
}
$choicesWeeksDistributionsActivatedInAdvanceArray = [null => '--'];
for ($i = 1; $i < 13; $i++) {
$choicesWeeksDistributionsActivatedInAdvanceArray[$i] = $i . ' semaine' . (($i > 1) ? 's' : '');
}
?>
<?= $form->field($model, 'option_weeks_distributions_activated_in_advance')
->dropDownList($choicesWeeksDistributionsActivatedInAdvanceArray)
@@ -279,25 +287,25 @@ $this->addBreadcrumb($this->getTitle());

<div v-show="currentSection == 'exports'" class="panel panel-default">
<div class="panel-body">
<h4>Exports affichés dans les distributions</h4>
<?= $distributionExportManager->getProducerFormCheckboxes($form, $model) ?>
<h4>Options exports</h4>
<?= $form->field($model, 'option_csv_separator')
->dropDownList([
';' => 'Point-virgule (;)',
',' => 'Virgule (,)'
], []); ?>
<?= $form->field($model, 'option_export_display_product_reference')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_export_display_column_delivery_note')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_csv_export_all_products')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_csv_export_by_piece')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'export_shopping_cart_labels_number_per_column')
->dropDownList(Dropdown::numberChoices(1, 20)); ?>
<h4>Exports affichés dans les distributions</h4>
<?= $distributionExportManager->getProducerFormCheckboxes($form, $model) ?>
<h4>Options exports</h4>
<?= $form->field($model, 'option_csv_separator')
->dropDownList([
';' => 'Point-virgule (;)',
',' => 'Virgule (,)'
], []); ?>
<?= $form->field($model, 'option_export_display_product_reference')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_export_display_column_delivery_note')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_csv_export_all_products')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_csv_export_by_piece')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'export_shopping_cart_labels_number_per_column')
->dropDownList(Dropdown::numberChoices(1, 20)); ?>
</div>
</div>

@@ -343,7 +351,7 @@ $this->addBreadcrumb($this->getTitle());
<?= $form->field($model, 'online_payment')
->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_online_payment_minimum_amount')
->hint('Valeur par défaut si non défini : '.Producer::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT.' €')
->hint('Valeur par défaut si non défini : ' . Producer::ONLINE_PAYMENT_MINIMUM_AMOUNT_DEFAULT . ' €')
->textInput(); ?>
<?= $form->field($model, 'option_stripe_mode_test')->dropDownList(Dropdown::noYesChoices()); ?>
<?= $form->field($model, 'option_online_payment_type')
@@ -435,7 +443,7 @@ $this->addBreadcrumb($this->getTitle());
<?php $urlAboutPage = Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/about']); ?>
<?= $form->field($model, 'option_testimony')
->textarea(['rows' => 7])
->hint("Écrivez ici votre témoignage concernant l'utilisation du logiciel. Il sera publié sur la page <a href=\"".$urlAboutPage."\" target=\"_blanck\">À propos</a> du site.") ; ?>
->hint("Écrivez ici votre témoignage concernant l'utilisation du logiciel. Il sera publié sur la page <a href=\"" . $urlAboutPage . "\" target=\"_blanck\">À propos</a> du site."); ?>
<?= $form->field($model, 'option_time_saved')
->dropDownList([
null => '--',
@@ -449,7 +457,7 @@ $this->addBreadcrumb($this->getTitle());
7 => '7 heures',
8 => '8 heures',
])
->hint("Sélectionnez le temps que vous estimez gagner chaque semaine en utilisant ce logiciel. Cette donnée sera utilisée sur la page <a href=\"".$urlAboutPage."\" target=\"_blanck\">À propos</a> du site.") ; ?>
->hint("Sélectionnez le temps que vous estimez gagner chaque semaine en utilisant ce logiciel. Cette donnée sera utilisée sur la page <a href=\"" . $urlAboutPage . "\" target=\"_blanck\">À propos</a> du site."); ?>
<?= $form->field($model, 'option_display_message_new_opendistrib_version')
->dropDownList(Dropdown::noYesChoices()); ?>
</div>

+ 14
- 1
common/logic/Producer/Producer/Model/Producer.php Dosyayı Görüntüle

@@ -40,6 +40,7 @@ namespace common\logic\Producer\Producer\Model;

use common\logic\Config\TaxRate\Model\TaxRate;
use common\logic\User\User\Model\User;
use common\logic\User\UserGroup\Model\UserGroup;
use common\logic\User\UserProducer\Model\UserProducer;
use common\components\ActiveRecordCommon;
use yii\web\UploadedFile;
@@ -166,7 +167,8 @@ class Producer extends ActiveRecordCommon
'dolibarr_product_id',
'option_weeks_distributions_activated_in_advance',
'option_document_width_logo',
'export_shopping_cart_labels_number_per_column'
'export_shopping_cart_labels_number_per_column',
'id_user_group_default'
],
'integer'
],
@@ -453,6 +455,7 @@ class Producer extends ActiveRecordCommon
'option_document_width_logo' => 'Largeur du logo dans les documents',
'export_shopping_cart_labels_number_per_column' => "Étiquettes (PDF) : nombre d'étiquettes par colonne",
'option_document_display_price_unit_reference' => "Afficher les prix au kilogramme",
'id_user_group_default' => "Groupe utilisateur par défaut attribué à l'inscription",
];
}

@@ -486,6 +489,16 @@ class Producer extends ActiveRecordCommon
$this->populateFieldObject('id_tax_rate', 'taxRate', $taxRate);
}

public function getUserGroupDefault()
{
return $this->hasOne(UserGroup::class, ['id' => 'id_user_group_default']);
}

public function populateUserGroupDefault(UserGroup $userGroup)
{
$this->populateFieldObject('id_user_group_default', 'userGroupDefault', $userGroup);
}

// ---

public static function getBillingTypePopulateDropdown()

+ 9
- 0
common/logic/User/User/Service/UserBuilder.php Dosyayı Görüntüle

@@ -10,19 +10,23 @@ use common\logic\Producer\Producer\Model\Producer;
use common\logic\User\User\Event\UserCreateEvent;
use common\logic\User\User\Model\User;
use common\logic\User\User\Repository\UserRepository;
use common\logic\User\UserGroup\Model\UserGroup;
use common\logic\User\UserProducer\Service\UserProducerBuilder;
use common\logic\User\UserUserGroup\Service\UserUserGroupBuilder;

class UserBuilder extends AbstractBuilder
{
protected UserRepository $userRepository;
protected UserNotifier $userNotifier;
protected UserProducerBuilder $userProducerBuilder;
protected UserUserGroupBuilder $userUserGroupBuilder;

public function loadDependencies(): void
{
$this->userRepository = $this->loadService(UserRepository::class);
$this->userNotifier = $this->loadService(UserNotifier::class);
$this->userProducerBuilder = $this->loadService(UserProducerBuilder::class);
$this->userUserGroupBuilder = $this->loadService(UserUserGroupBuilder::class);
}

public function instanciateUser(
@@ -188,4 +192,9 @@ class UserBuilder extends AbstractBuilder
$user->id_producer = $producer->id;
$this->update($user);
}

public function addUserGroup(User $user, UserGroup $userGroup)
{
$this->userUserGroupBuilder->createUserUserGroup($user, $userGroup);
}
}

+ 1
- 1
common/logic/User/UserGroup/Service/UserGroupBuilder.php Dosyayı Görüntüle

@@ -17,7 +17,7 @@ class UserGroupBuilder extends AbstractBuilder
public function createUserGroup(): UserGroup
{
$userGroup = $this->instanciateUserGroup();
$this->saveCreate($userGroup);
$this->create($userGroup);

return $userGroup;
}

+ 16
- 0
common/logic/User/UserUserGroup/Model/UserUserGroup.php Dosyayı Görüntüle

@@ -39,6 +39,7 @@ termes.
namespace common\logic\User\UserUserGroup\Model;

use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\User\User\Model\User;
use common\logic\User\UserGroup\Model\UserGroup;
use Yii;
use common\components\ActiveRecordCommon ;
@@ -93,4 +94,19 @@ class UserUserGroup extends ActiveRecordCommon
{
return $this->hasOne(UserGroup::class, ['id' => 'id_user_group']);
}

public function populateUserGroup(UserGroup $userGroup): void
{
$this->populateFieldObject('id_user_group', 'userGroup', $userGroup);
}

public function getUser()
{
return $this->hasOne(User::class, ['id' => 'id_user']);
}

public function populateUser(User $user): void
{
$this->populateFieldObject('id_user', 'user', $user);
}
}

+ 8
- 4
common/logic/User/UserUserGroup/Service/UserUserGroupBuilder.php Dosyayı Görüntüle

@@ -3,21 +3,25 @@
namespace common\logic\User\UserUserGroup\Service;

use common\logic\AbstractBuilder;
use common\logic\User\User\Model\User;
use common\logic\User\UserGroup\Model\UserGroup;
use common\logic\User\UserUserGroup\Model\UserUserGroup;

class UserUserGroupBuilder extends AbstractBuilder
{
public function instanciateUserUserGroup(): UserUserGroup
public function instanciateUserUserGroup(User $user, UserGroup $userGroup): UserUserGroup
{
$userUserGroup = new UserUserGroup();
$userUserGroup->populateUser($user);
$userUserGroup->populateUserGroup($userGroup);

return $userUserGroup;
}

public function createUserUserGroup(): UserUserGroup
public function createUserUserGroup(User $user, UserGroup $userGroup): UserUserGroup
{
$userUserGroup = $this->instanciateUserUserGroup();
$this->saveCreate($userUserGroup);
$userUserGroup = $this->instanciateUserUserGroup($user, $userGroup);
$this->create($userUserGroup);

return $userUserGroup;
}

+ 28
- 0
console/migrations/m231109_090026_add_column_producer_id_user_group_default.php Dosyayı Görüntüle

@@ -0,0 +1,28 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m231109_090026_add_column_producer_id_user_group_default
*/
class m231109_090026_add_column_producer_id_user_group_default extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('producer', 'id_user_group_default', Schema::TYPE_INTEGER);
$this->addForeignKey('user_group_default_fk', 'producer', 'id_user_group_default', 'user_group', 'id');
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('producer', 'id_user_group_default');
$this->dropForeignKey('user_group_default_fk', 'producer');
}
}

+ 9
- 1
frontend/forms/SignupForm.php Dosyayı Görüntüle

@@ -43,6 +43,7 @@ use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Module\ProducerModule;
use common\logic\User\User\Model\User;
use common\logic\User\User\Module\UserModule;
use common\logic\User\UserGroup\Module\UserGroupModule;
use yii\base\Model;

/**
@@ -234,7 +235,8 @@ class SignupForm extends Model
*/
public function signup()
{
$userModule = \Yii::$app->logic->getUserModule();
$userGroupModule = UserGroupModule::getInstance();
$userModule = UserModule::getInstance();
$producerModule = \Yii::$app->logic->getProducerModule();

if ($this->validate()) {
@@ -255,6 +257,12 @@ class SignupForm extends Model

\Yii::$app->logic->setProducerContext($producer);

if(!$this->isProducer()) {
if($producer->id_user_group_default) {
$userGroupDefault = $userGroupModule->getRepository()->findOneUserGroupById($producer->id_user_group_default);
$userModule->getBuilder()->addUserGroup($user, $userGroupDefault);
}
}
$producerModule->addUser($user, $producer, true, $this->newsletter);
$userModule->sendEmailSignup($user, $producer);


Yükleniyor…
İptal
Kaydet