From b82db04a71afede9792efa103ee7452ecda2733c Mon Sep 17 00:00:00 2001 From: Yarik Date: Sun, 28 Feb 2016 17:58:05 +0200 Subject: [PATCH] test --- common/components/rules/CommentOwnRule.php | 17 +++++++++++++++++ common/config/main.php | 44 +++++++++++++++++++++++++++++++++++++++++++- common/modules/comment/Module.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/comment/Permissions.php | 12 ++++++++++++ common/modules/comment/commands/RbacController.php | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/comment/interfaces/CommentInterface.php | 11 +++++++++++ common/modules/comment/models/Comment.php | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/comment/rbac/ArtboxCommentCreateRule.php | 17 +++++++++++++++++ common/modules/comment/rbac/ArtboxCommentDeleteOwnRule.php | 17 +++++++++++++++++ common/modules/comment/rbac/ArtboxCommentDeleteRule.php | 17 +++++++++++++++++ common/modules/comment/rbac/ArtboxCommentUpdateOwnRule.php | 17 +++++++++++++++++ common/modules/comment/rbac/ArtboxCommentUpdateRule.php | 17 +++++++++++++++++ common/modules/comment/widgets/CommentWidget.php | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/comment/widgets/views/form-comment.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/comment/widgets/views/list-comment.php | 12 ++++++++++++ common/modules/comment/widgets/views/project_comment_view.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 3 ++- composer.lock | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- console/controllers/CommentRulesController.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m160225_143331_comment_test.php | 42 ++++++++++++++++++++++++++++++++++++++++++ frontend/views/performer/portfolio-view.php | 27 ++++++++++++++++++++++++++- 21 files changed, 948 insertions(+), 30 deletions(-) create mode 100644 common/components/rules/CommentOwnRule.php create mode 100644 common/modules/comment/Module.php create mode 100644 common/modules/comment/Permissions.php create mode 100644 common/modules/comment/commands/RbacController.php create mode 100644 common/modules/comment/interfaces/CommentInterface.php create mode 100644 common/modules/comment/models/Comment.php create mode 100644 common/modules/comment/rbac/ArtboxCommentCreateRule.php create mode 100644 common/modules/comment/rbac/ArtboxCommentDeleteOwnRule.php create mode 100644 common/modules/comment/rbac/ArtboxCommentDeleteRule.php create mode 100644 common/modules/comment/rbac/ArtboxCommentUpdateOwnRule.php create mode 100644 common/modules/comment/rbac/ArtboxCommentUpdateRule.php create mode 100644 common/modules/comment/widgets/CommentWidget.php create mode 100644 common/modules/comment/widgets/views/form-comment.php create mode 100644 common/modules/comment/widgets/views/list-comment.php create mode 100644 common/modules/comment/widgets/views/project_comment_view.php create mode 100644 console/controllers/CommentRulesController.php create mode 100644 console/migrations/m160225_143331_comment_test.php diff --git a/common/components/rules/CommentOwnRule.php b/common/components/rules/CommentOwnRule.php new file mode 100644 index 0000000..942e51f --- /dev/null +++ b/common/components/rules/CommentOwnRule.php @@ -0,0 +1,17 @@ +user_id == $user : false; + } + + } \ No newline at end of file diff --git a/common/config/main.php b/common/config/main.php index 45372c9..cb2878a 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -1,5 +1,6 @@ 'Europe/Kiev', 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'controllerMap' => [ @@ -38,6 +39,47 @@ return [ 'file' => [ 'class' => 'common\modules\file\Module', ], + 'comment' => [ + 'class' => 'common\modules\comment\Module', + 'useRbac' => true, + 'rbac' => [ + 'rules' => [ + \common\modules\comment\rbac\ArtboxCommentCreateRule::className(), + \common\modules\comment\rbac\ArtboxCommentDeleteRule::className(), + \common\modules\comment\rbac\ArtboxCommentUpdateRule::className(), + \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule::className(), + \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule::className(), + ], + 'permissions' => [ + [ + 'name' => common\modules\comment\Permissions::CREATE, + 'description' => 'Can create comments', + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentCreateRule())->name, + ], + [ + 'name' => common\modules\comment\Permissions::UPDATE, + 'description' => 'Can update comments', + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateRule())->name, + ], + [ + 'name' => common\modules\comment\Permissions::DELETE, + 'description' => 'Can delete comments', + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteRule())->name, + ], + [ + 'name' => common\modules\comment\Permissions::UPDATE_OWN, + 'description' => 'Can update own comments', + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentUpdateOwnRule())->name, + ], + [ + 'name' => common\modules\comment\Permissions::DELETE_OWN, + 'description' => 'Can delete own comments', + 'ruleName' =>(new \common\modules\comment\rbac\ArtboxCommentDeleteOwnRule())->name, + ], + ], + ], + + ], ], 'bootstrap' => [ diff --git a/common/modules/comment/Module.php b/common/modules/comment/Module.php new file mode 100644 index 0000000..6a18e72 --- /dev/null +++ b/common/modules/comment/Module.php @@ -0,0 +1,74 @@ + + * [ + * 'rules' => [ + * \full\namapaced\ClassName, + * \another\one\ClassName, + * ], + * 'permissions' => [ + * [ + * 'name' => stringName, + * 'description' => descriptionText, + * 'ruleName' => (new \full\namespaced\ClassName())->name (optional) + * ], + * [ + * 'name' => stringName2, + * 'description' => descriptionText2, + * 'ruleName' => (new \another\one\ClassName())->name (optional) + * ], + * ] + * ] + * + * + * @var array + * @see \common\modules\comment\commands\RbacController + */ + public $rbac = []; + + /** + * @var \yii\db\Connection Connection to the db + */ + public $db = null; + + /** + * @inheritdoc + */ + public function init() + { + parent::init(); + if(\Yii::$app instanceof \yii\console\Application) { + $this->controllerNamespace = 'common\modules\comment\commands'; + } + if($this->db === null) { + $this->db = \Yii::$app->db; + } elseif(!$this->db instanceof \yii\db\Connection) { + throw new \yii\base\InvalidConfigException('Конфиг db обязан наследоваться от'.\yii\db\Connection::className()); + } + } + } \ No newline at end of file diff --git a/common/modules/comment/Permissions.php b/common/modules/comment/Permissions.php new file mode 100644 index 0000000..49b5aec --- /dev/null +++ b/common/modules/comment/Permissions.php @@ -0,0 +1,12 @@ +controller->module; + if(!$module->useRbac) { + throw new \yii\base\InvalidConfigException('Please set useRbac config to TRUE in your module configs'); + } + $auth = \Yii::$app->getAuthManager(); + if(!$auth instanceof \yii\rbac\ManagerInterface) { + throw new \yii\base\InvalidConfigException('ManagerInterface is not configured'); + } + if(!empty($module->rbac['rules'])) { + foreach($module->rbac['rules'] as $rule) { + $rule_model = new $rule(); + echo "Creating rule: ".$rule_model->name."\n"; + if($auth->add($rule_model)) { + echo "Successful\n"; + } else { + echo "Failed\n"; + } + unset($rule_model); + } + } + if(!empty($module->rbac['permissions'])) { + foreach($module->rbac['permissions'] as $permission) { + echo "Creating permission: ".$permission['name']."\n"; + if($auth->add(new \yii\rbac\Permission($permission))) { + echo "Successful\n"; + } else { + echo "Failed\n"; + } + } + } + } + + public function actionUninstall() + { + /** + * @var \common\modules\comment\Module $module + */ + $module = \Yii::$app->controller->module; + if(!$module->useRbac) { + throw new \yii\base\InvalidConfigException('Please set useRbac config to TRUE in your module configs'); + } + $auth = \Yii::$app->getAuthManager(); + if(!$auth instanceof \yii\rbac\ManagerInterface) { + throw new \yii\base\InvalidConfigException('ManagerInterface is not configured'); + } + if(!empty($module->rbac['rules'])) { + foreach($module->rbac['rules'] as $rule) { + $rule_model = new $rule(); + echo "Removing rule: ".$rule_model->name."\n"; + if($auth->remove($rule_model)) { + echo "Successful\n"; + } else { + echo "Failed\n"; + } + unset($rule_model); + } + } + if(!empty($module->rbac['permissions'])) { + foreach($module->rbac['permissions'] as $permission) { + echo "Removing permission: ".$permission['name']."\n"; + if($auth->remove(new \yii\rbac\Permission($permission))) { + echo "Successful\n"; + } else { + echo "Failed\n"; + } + } + } + } + + } \ No newline at end of file diff --git a/common/modules/comment/interfaces/CommentInterface.php b/common/modules/comment/interfaces/CommentInterface.php new file mode 100644 index 0000000..7f91380 --- /dev/null +++ b/common/modules/comment/interfaces/CommentInterface.php @@ -0,0 +1,11 @@ + ['user_name', 'user_email', 'text'], + self::SCENARIO_USER => ['text'], + ]; + } + + public static function tableName() + { + return '{{%comment}}'; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'text' => \Yii::t('app', 'Комментарий'), + 'user_name' => \Yii::t('app', 'Имя'), + 'user_email' => \Yii::t('app', 'Email'), + ]; + } + + public function getGuestComment($entity) + { + return true; + } + + public function getComments($entity) + { + return $this->find()->where(['entity' => $this->entity]); + } + + public function postComment($data) + { + if($this->load($data) && $this->insert($data)) { + $this->clearSafe(); + return true; + } else { + return false; + } + } + + public function updateComment($comment_id) + { + // TODO: Implement updateComment() method. + } + + public function deleteComment($comment_id) + { + // TODO: Implement deleteComment() method. + } + + public function checkCreate($entity) + { + if($this->getGuestComment($entity)) { + return true; + } else { + return \Yii::$app->user->can(\common\modules\comment\Permissions::CREATE, ['entity' => $entity]); + } + } + + protected function clearSafe($setNew = true) { + $safe = $this->safeAttributes(); + $count = count($safe); + $values = array_fill(0, $count, NULL); + $result = array_combine($safe, $values); + $this->setAttributes($result); + $this->setIsNewRecord($setNew); + } + + } \ No newline at end of file diff --git a/common/modules/comment/rbac/ArtboxCommentCreateRule.php b/common/modules/comment/rbac/ArtboxCommentCreateRule.php new file mode 100644 index 0000000..6f481fc --- /dev/null +++ b/common/modules/comment/rbac/ArtboxCommentCreateRule.php @@ -0,0 +1,17 @@ + 'div', + 'view' => 'list-comment', + 'class' => 'test-class', + ]; + + public $success_options = [ + 'tag' => 'div', + 'content' => null, + 'class' => 'test-class-success', + ]; + + public $form_options = [ + 'tag' => 'div', + 'view' => 'form-comment', + 'class' => 'test-class-form', + ]; + + protected $isSuccess = false; + + public $entity; + + public $template = "{success}\n{form}\n{list}"; + + public $options = []; + + /** + * @var \yii\data\DataProviderInterface + */ + public $dataProvider; + + /** + * @inheritdoc + */ + public function init() + { + parent::init(); + if(is_string($this->comment_class)) { + $this->comment_class = new $this->comment_class($this->class_options); + } elseif(!is_object($this->comment_class)) { + throw new \yii\base\InvalidConfigException(__CLASS__.'->comment_class must be defined as string or object.'); + } + $this->comment_class->entity = $this->entity; + $this->createDataProvider(); + if($this->comment_class->checkCreate($this->entity)) { + $this->handleCreate(); + } + ob_start(); + } + + /** + * @inheritdoc + * @return string + */ + public function run() + { + $content = ob_get_clean(); + $this->createParts(); + return $this->renderWidget(); + } + + public function createParts() { + if($this->display_comment_success && $this->isSuccess) { + $tag = ArrayHelper::remove($this->success_options, 'tag', 'div'); + if(is_callable($this->success_options['content'])) { + $result = call_user_func(ArrayHelper::remove($this->success_options, 'content'), $this->success_text); + } elseif($this->success_options['content'] != NULL) { + $result = Html::encode(ArrayHelper::remove($this->success_options, 'content', $this->success_text)); + } else { + $result = Html::encode($this->success_text); + } + $this->parts['success'] = Html::tag($tag, $result, $this->success_options); + unset($tag, $result); + } + + if($this->display_comment_list) { + $tag = ArrayHelper::remove($this->list_options, 'tag', 'div'); + $view = ArrayHelper::remove($this->list_options, 'view'); + $this->parts['list'] = Html::tag($tag, $this->renderItems($view), $this->list_options); + } + + if($this->display_comment_form) { + $tag = ArrayHelper::remove($this->form_options, 'tag', 'div'); + $view = ArrayHelper::remove($this->form_options, 'view'); + $this->parts['form'] = Html::tag($tag, $this->renderForm($view), $this->list_options); + } + } + + public function createDataProvider() + { + $this->dataProvider = new \yii\data\ActiveDataProvider([ + 'query' => $this->comment_class->getComments($this->entity), + 'pagination' => [ + 'pageSize' => 10, + ], + ]); + } + + public function renderItems($view) { + if(empty($view)) { + throw new \yii\base\InvalidConfigException("list_options[view] must be set"); + } + return $this->render($view, ['dataProvider' => $this->dataProvider]); + } + + public function renderForm($view) { + if(empty($view)) { + throw new \yii\base\InvalidConfigException("form_options[view] must be set"); + } + return $this->render($view, [ + 'model' => $this->comment_class, + 'user' => \Yii::$app->user->identity, + 'dataProvider' => $this->dataProvider, + ]); + } + + public function renderWidget() { + $template = $this->template; + $parts = $this->parts; + $options = $this->options; + $template = preg_replace('/{success}/', ArrayHelper::remove($parts, 'success', ''), $template); + $template = preg_replace('/{list}/', ArrayHelper::remove($parts, 'list', ''), $template); + $template = preg_replace('/{form}/', ArrayHelper::remove($parts, 'form', ''), $template); + $tag = ArrayHelper::remove($options, 'tag', 'div'); + return Html::tag($tag, $template, $options); + } + + public function handleCreate() + { + $data = \Yii::$app->request->post(); + if($this->comment_class->postComment($data)) { + $this->isSuccess = true; + }; + } + } \ No newline at end of file diff --git a/common/modules/comment/widgets/views/form-comment.php b/common/modules/comment/widgets/views/form-comment.php new file mode 100644 index 0000000..1e3fe2b --- /dev/null +++ b/common/modules/comment/widgets/views/form-comment.php @@ -0,0 +1,52 @@ + +
Комментарии: totalCount ?>
+ +
+ + + scenario == $model::SCENARIO_GUEST) { + echo $form->field($model, 'user_name', [ + 'options' => [ + 'class' => 'input-blocks-comm', + ], + 'inputOptions' => [ + 'class' => 'custom-input-4', + ], + ])->textInput(); + echo $form->field($model, 'user_email', [ + 'options' => [ + 'class' => 'input-blocks-comm', + ], + 'inputOptions' => [ + 'class' => 'custom-input-4', + ], + ])->textInput(); + } + echo $form->field($model, 'text', [ + 'options' => [ + 'class' => 'input-blocks-comm area-comm', + ], + 'inputOptions' => [ + 'class' => 'custom-area-4', + ], + ])->textarea(); + ?> +
+ +
+ end(); + ?> +
\ No newline at end of file diff --git a/common/modules/comment/widgets/views/list-comment.php b/common/modules/comment/widgets/views/list-comment.php new file mode 100644 index 0000000..4f37738 --- /dev/null +++ b/common/modules/comment/widgets/views/list-comment.php @@ -0,0 +1,12 @@ + $dataProvider, + 'itemView' => 'project_comment_view', + 'itemOptions' => [ + 'tag' => false, + ], + 'summary' => '', +]); \ No newline at end of file diff --git a/common/modules/comment/widgets/views/project_comment_view.php b/common/modules/comment/widgets/views/project_comment_view.php new file mode 100644 index 0000000..8f169e9 --- /dev/null +++ b/common/modules/comment/widgets/views/project_comment_view.php @@ -0,0 +1,65 @@ +user_id )) { + $user = User::find() + ->where([ 'id' => $model->user_id ]) + ->with('userInfo') + ->one(); + } +?> +
+
+
+ userInfo->image )) { + echo ""; + } else { + echo ""; + } + ?> +
+
+
+ firstname . ' ' . $user->lastname, [ + 'performer/common', + 'performer_id' => $user->id, + ]); + } else { + echo $model->user_name . '(Гость)'; + } + ?> +
+
+
+ + + + +
+
+ +
+ +
+ text) ?> +
+ +
+
+
\ No newline at end of file diff --git a/composer.json b/composer.json index f30dab2..4cf1f53 100755 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "yiisoft/yii2-imagine": "^2.0", "mihaildev/yii2-elfinder": "^1.1", "kartik-v/yii2-widget-colorinput": "*", - "2amigos/yii2-transliterator-helper": "*" + "2amigos/yii2-transliterator-helper": "*", + "rmrevin/yii2-comments": "1.4.*" }, "require-dev": { "yiisoft/yii2-codeception": "*", diff --git a/composer.lock b/composer.lock index b736686..25edbf4 100755 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "dfde859453134d35dc61fc6825917302", - "content-hash": "ec129e7be083837c52b871f4c8ec7f56", + "hash": "67e32b98a5cc37bfa51bc84148316627", + "content-hash": "706cd7bd8f9339ce92d17c5871da8b8f", "packages": [ { "name": "2amigos/yii2-transliterator-helper", @@ -762,18 +762,23 @@ "source": { "type": "git", "url": "https://github.com/kartik-v/yii2-widget-select2.git", - "reference": "519241c7360a0470624f24d872741e1ea880de75" + "reference": "4d03239c1e28ef8d3b96ab7fe360f5cbda34fb69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/kartik-v/yii2-widget-select2/zipball/519241c7360a0470624f24d872741e1ea880de75", - "reference": "519241c7360a0470624f24d872741e1ea880de75", + "url": "https://api.github.com/repos/kartik-v/yii2-widget-select2/zipball/4d03239c1e28ef8d3b96ab7fe360f5cbda34fb69", + "reference": "4d03239c1e28ef8d3b96ab7fe360f5cbda34fb69", "shasum": "" }, "require": { "kartik-v/yii2-krajee-base": "~1.7" }, "type": "yii2-extension", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, "autoload": { "psr-4": { "kartik\\select2\\": "" @@ -802,7 +807,7 @@ "widget", "yii2" ], - "time": "2016-02-01 02:19:01" + "time": "2016-02-17 11:49:30" }, { "name": "lusitanian/oauth", @@ -1067,6 +1072,57 @@ "time": "2016-01-13 18:15:48" }, { + "name": "rmrevin/yii2-comments", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/rmrevin/yii2-comments.git", + "reference": "9aaf46b0a5c2c3d71b9dafd669ef78810729951f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rmrevin/yii2-comments/zipball/9aaf46b0a5c2c3d71b9dafd669ef78810729951f", + "reference": "9aaf46b0a5c2c3d71b9dafd669ef78810729951f", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "rmrevin/yii2-fontawesome": "~2.10", + "yiisoft/yii2": "2.0.*" + }, + "type": "yii2-extension", + "extra": { + "asset-installer-paths": { + "npm-asset-library": "vendor/npm", + "bower-asset-library": "vendor/bower" + } + }, + "autoload": { + "psr-4": { + "rmrevin\\yii\\module\\Comments\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Revin", + "email": "xgismox@gmail.com", + "homepage": "http://rmrevin.ru/" + } + ], + "description": "Comments module for Yii2", + "keywords": [ + "comment", + "module", + "widget", + "yii" + ], + "time": "2015-10-05 17:48:21" + }, + { "name": "rmrevin/yii2-fontawesome", "version": "2.13.0", "source": { @@ -1177,12 +1233,12 @@ "source": { "type": "git", "url": "https://github.com/yiisoft/yii2-framework.git", - "reference": "abb6d386b71fe4d30d028c293202223311162dd2" + "reference": "c47257db05de10b0924b1e47c855212b457c69a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/abb6d386b71fe4d30d028c293202223311162dd2", - "reference": "abb6d386b71fe4d30d028c293202223311162dd2", + "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/c47257db05de10b0924b1e47c855212b457c69a3", + "reference": "c47257db05de10b0924b1e47c855212b457c69a3", "shasum": "" }, "require": { @@ -1193,7 +1249,7 @@ "cebe/markdown": "~1.0.0 | ~1.1.0", "ext-ctype": "*", "ext-mbstring": "*", - "ezyang/htmlpurifier": "4.6.*", + "ezyang/htmlpurifier": "~4.6", "lib-pcre": "*", "php": ">=5.4.0", "yiisoft/yii2-composer": "~2.0.4" @@ -1263,7 +1319,7 @@ "framework", "yii2" ], - "time": "2016-02-11 15:39:25" + "time": "2016-02-21 17:08:31" }, { "name": "yiisoft/yii2-bootstrap", @@ -1368,12 +1424,12 @@ "source": { "type": "git", "url": "https://github.com/yiisoft/yii2-imagine.git", - "reference": "586c9c99cb541ec4d4d2ec2a206b08a6fd6de888" + "reference": "d87e6a0d1adfd6fa5ef49c18228b2fc9bca04299" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-imagine/zipball/586c9c99cb541ec4d4d2ec2a206b08a6fd6de888", - "reference": "586c9c99cb541ec4d4d2ec2a206b08a6fd6de888", + "url": "https://api.github.com/repos/yiisoft/yii2-imagine/zipball/d87e6a0d1adfd6fa5ef49c18228b2fc9bca04299", + "reference": "d87e6a0d1adfd6fa5ef49c18228b2fc9bca04299", "shasum": "" }, "require": { @@ -1408,7 +1464,7 @@ "imagine", "yii2" ], - "time": "2015-09-29 10:49:20" + "time": "2016-02-21 23:09:41" }, { "name": "yiisoft/yii2-jui", @@ -1545,12 +1601,12 @@ "source": { "type": "git", "url": "https://github.com/fzaninotto/Faker.git", - "reference": "772feacf6849bf0114873e2b869bb500fccfd438" + "reference": "2585edbef8b0e7a44c695217c35b16720203d8ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/772feacf6849bf0114873e2b869bb500fccfd438", - "reference": "772feacf6849bf0114873e2b869bb500fccfd438", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/2585edbef8b0e7a44c695217c35b16720203d8ee", + "reference": "2585edbef8b0e7a44c695217c35b16720203d8ee", "shasum": "" }, "require": { @@ -1587,7 +1643,7 @@ "faker", "fixtures" ], - "time": "2016-02-11 12:29:31" + "time": "2016-02-23 12:35:04" }, { "name": "phpspec/php-diff", @@ -1674,12 +1730,12 @@ "source": { "type": "git", "url": "https://github.com/yiisoft/yii2-debug.git", - "reference": "7a28977497e43bf7180a793389e6a5739ec52756" + "reference": "e30ded9067f595b5e6d3536ec1365353b826b300" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/7a28977497e43bf7180a793389e6a5739ec52756", - "reference": "7a28977497e43bf7180a793389e6a5739ec52756", + "url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/e30ded9067f595b5e6d3536ec1365353b826b300", + "reference": "e30ded9067f595b5e6d3536ec1365353b826b300", "shasum": "" }, "require": { @@ -1713,7 +1769,7 @@ "debugger", "yii2" ], - "time": "2015-12-31 16:25:50" + "time": "2016-02-16 08:23:57" }, { "name": "yiisoft/yii2-faker", @@ -1768,12 +1824,12 @@ "source": { "type": "git", "url": "https://github.com/yiisoft/yii2-gii.git", - "reference": "bb0eba84639a99bff6c8bc9e803bd8ac3ab66297" + "reference": "ce42838abcbef076ebaf46147671d518ae69d028" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/bb0eba84639a99bff6c8bc9e803bd8ac3ab66297", - "reference": "bb0eba84639a99bff6c8bc9e803bd8ac3ab66297", + "url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/ce42838abcbef076ebaf46147671d518ae69d028", + "reference": "ce42838abcbef076ebaf46147671d518ae69d028", "shasum": "" }, "require": { @@ -1813,7 +1869,7 @@ "gii", "yii2" ], - "time": "2016-02-02 07:11:51" + "time": "2016-02-21 20:39:29" } ], "aliases": [], diff --git a/console/controllers/CommentRulesController.php b/console/controllers/CommentRulesController.php new file mode 100644 index 0000000..57d3ef0 --- /dev/null +++ b/console/controllers/CommentRulesController.php @@ -0,0 +1,56 @@ +getAuthManager(); + $commentownrule = new CommentOwnRule(); + $auth->add($commentownrule); + $auth->add(new Permission([ + 'name' => 'Update own comment', + 'ruleName' => $commentownrule->name, + 'description' => 'Can update own comment', + ])); + $auth->add(new Permission([ + 'name' => 'Delete own comment', + 'ruleName' => $commentownrule->name, + 'description' => 'Can delete own comment', + ])); + return 'Success'; + } + + public function actionUpdate() + { + $auth = \Yii::$app->getAuthManager(); + $commentownrule = new CommentOwnRule(); + $auth->add(new Permission([ + 'name' => \rmrevin\yii\module\Comments\Permission::CREATE, + 'description' => 'Can create own comments', + ])); + $auth->add(new Permission([ + 'name' => \rmrevin\yii\module\Comments\Permission::UPDATE, + 'description' => 'Can update all comments', + ])); + $auth->add(new Permission([ + 'name' => \rmrevin\yii\module\Comments\Permission::UPDATE_OWN, + 'ruleName' => $commentownrule->name, + 'description' => 'Can update own comments', + ])); + $auth->add(new Permission([ + 'name' => \rmrevin\yii\module\Comments\Permission::DELETE, + 'description' => 'Can delete all comments', + ])); + $auth->add(new Permission([ + 'name' => \rmrevin\yii\module\Comments\Permission::DELETE_OWN, + 'ruleName' => $commentownrule->name, + 'description' => 'Can delete own comments', + ])); + echo 'ok'; + return 'ok'; + } + } \ No newline at end of file diff --git a/console/migrations/m160225_143331_comment_test.php b/console/migrations/m160225_143331_comment_test.php new file mode 100644 index 0000000..c186a1b --- /dev/null +++ b/console/migrations/m160225_143331_comment_test.php @@ -0,0 +1,42 @@ +createTable('{{%comment}}', [ + 'comment_id' => $this->primaryKey(), + 'entity' => $this->string()->notNull(), + 'text' => $this->text()->notNull(), + 'user_id' => $this->integer(), + 'user_name' => $this->string(), + 'user_email' => $this->string(), + 'comment_pid' => $this->integer(), + 'status' => $this->integer(), + 'date_add' => $this->timestamp()->notNull()->defaultExpression('NOW()'), + 'date_update' => $this->timestamp()->notNull()->defaultExpression('NOW()'), + 'date_delete' => $this->timestamp(), + ]); + + $this->addForeignKey('comment_user', '{{%comment}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'CASCADE'); + } + + public function down() + { + $this->dropForeignKey('comment_user', '{{%comment}}'); + $this->dropTable('{{%comment}}'); + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/views/performer/portfolio-view.php b/frontend/views/performer/portfolio-view.php index aeb2b29..5b1fc00 100644 --- a/frontend/views/performer/portfolio-view.php +++ b/frontend/views/performer/portfolio-view.php @@ -13,7 +13,6 @@ $this->title = 'My Yii Application'; ?> -
@@ -109,6 +108,30 @@ ?>
+ $portfolio::tableName().'-'.$portfolio->portfolio_id, + 'comment_class' => \common\modules\comment\models\Comment::className(), + 'class_options' => [ + 'scenario' => is_int(\Yii::$app->user->getId())?\common\modules\comment\models\Comment::SCENARIO_USER:\common\modules\comment\models\Comment::SCENARIO_GUEST, + 'user_id' => \Yii::$app->user->getId(), + ], + 'list_options' => [ + 'view' => 'list-comment', + ], + 'form_options' => [ + 'view' => 'form-comment', + 'tag' => false, + ], + 'options' => [ + 'class' => 'new-portf-comments-wr style', + ], + ]); + ?> + +
Комментарии: 3
@@ -286,6 +309,8 @@
+ */ + ?>