diff --git a/api/modules/internal/controllers/AccountsController.php b/api/modules/internal/controllers/AccountsController.php new file mode 100644 index 0000000..2c86fd3 --- /dev/null +++ b/api/modules/internal/controllers/AccountsController.php @@ -0,0 +1,30 @@ + [ + 'class' => AccessControl::class, + 'rules' => [ + [ + 'actions' => ['block'], + 'allow' => true, + 'roles' => [S::ACCOUNT_BLOCK], + ], + ], + ], + ]); + } + + public function actionBlock(int $accountId) { + + } + +} diff --git a/api/modules/internal/models/BlockForm.php b/api/modules/internal/models/BlockForm.php new file mode 100644 index 0000000..a60b757 --- /dev/null +++ b/api/modules/internal/models/BlockForm.php @@ -0,0 +1,80 @@ + self::DURATION_FOREVER], + [['message'], 'string'], + ]; + } + + public function getAccount(): Account { + return $this->account; + } + + public function ban(): bool { + $transaction = Yii::$app->db->beginTransaction(); + + $account = $this->account; + $account->status = Account::STATUS_BANNED; + $account->save(); + + $this->createTask(); + + $transaction->commit(); + + return true; + } + + public function createTask() { + $model = new AccountBanned(); + $model->accountId = $this->account->id; + $model->duration = $this->duration; + $model->message = $this->message; + + $message = Amqp::getInstance()->prepareMessage($model, [ + 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT, + ]); + + Amqp::sendToEventsExchange('accounts.account-banned', $message); + } + + public function __construct(Account $account, array $config = []) { + $this->account = $account; + parent::__construct($config); + } + +} diff --git a/common/models/amqp/AccountBanned.php b/common/models/amqp/AccountBanned.php new file mode 100644 index 0000000..1b1198e --- /dev/null +++ b/common/models/amqp/AccountBanned.php @@ -0,0 +1,14 @@ +