From 28b06d51ce4c2df20c2cabd03f852663e008875c Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 11 Dec 2016 14:37:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?API=20=D0=B4=D0=BB=D1=8F=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD?= =?UTF-8?q?=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/AccountsController.php | 30 +++++++ api/modules/internal/models/BlockForm.php | 80 +++++++++++++++++++ common/models/amqp/AccountBanned.php | 14 ++++ 3 files changed, 124 insertions(+) create mode 100644 api/modules/internal/controllers/AccountsController.php create mode 100644 api/modules/internal/models/BlockForm.php create mode 100644 common/models/amqp/AccountBanned.php 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 @@ +