diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..96097ff --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - '3*' + +name: create_release + +jobs: + build: + name: create_release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Slack Notification on Start + uses: rtCamp/action-slack-notify@v2.2.0 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-release + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: "#f0ad4e" + SLACK_MESSAGE: "Start Job" + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: | + ${{ github.repository }}@${{ github.ref }} released. + draft: false + prerelease: false + + # テスト成功時はこちらのステップが実行される + - name: Slack Notification on Finish + uses: rtCamp/action-slack-notify@v2.2.0 + if: success() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-release + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: good + SLACK_MESSAGE: "Job Success" + + # テスト失敗時はこちらのステップが実行される + - name: Slack Notification on Failure + uses: rtCamp/action-slack-notify@v2.2.0 + if: failure() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_RELEASE }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: danger + SLACK_MESSAGE: "Job Failure" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..eb2068b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,170 @@ +on: + push: + branches: + - main + - master + - availability + pull_request: + branches: + - main + - master + - availability + +name: tests + +jobs: + setup: + name: setup + runs-on: ubuntu-latest + steps: + - name: Slack Notification on Start + uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: "#f0ad4e" + + tests: + name: tests + needs: setup + runs-on: ubuntu-latest + strategy: + matrix: + php: [ '7.1', '7.2', '7.3', '7.4' ] + mysql: [ '5.7', '8.0' ] + + env: + NC3_BUILD_DIR: "/opt/nc3" + NC3_DOCKER_DIR: "/opt/docker" + NC3_GIT_URL: "git://github.com/NetCommons3/NetCommons3.git" + NC3_GIT_BRANCH: "master" + PLUGIN_BUILD_DIR: ${{ github.workspace }} + PHP_VERSION: ${{ matrix.php }} + MYSQL_VERSION: ${{ matrix.mysql }} + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: cakephp_test + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v2 + + - name: Fix up git URLs + run: echo -e '[url "https://github.com/"]\n insteadOf = "git://github.com/"' >> ~/.gitconfig + + - name: environment + run: | + echo "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}" + echo "PLUGIN_BUILD_DIR=${PLUGIN_BUILD_DIR}" + echo "PHP_VERSION=${PHP_VERSION}" + echo "MYSQL_VERSION=${MYSQL_VERSION}" + ls -al ${PLUGIN_BUILD_DIR} + + - name: docker-compose install + run: | + curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > ~/docker-compose + chmod +x ~/docker-compose + sudo mv ~/docker-compose /usr/local/bin/docker-compose + docker-compose --version + + - name: git clone nc3 + run: git clone -b ${NC3_GIT_BRANCH} ${NC3_GIT_URL} ${NC3_BUILD_DIR} + + - name: git clone nc3_docker + run: git clone https://github.com/NetCommons3/nc3app-docker.git ${NC3_DOCKER_DIR} + + - name: docker-compose start + run: | + cd ${NC3_DOCKER_DIR} + docker-compose up -d + docker-compose start + + - run: docker ps + + - name: check libraries + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/start-on-docker.sh + + - name: nc3 build + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/app-build.sh + + - name: phpcs (PHP CodeSniffer) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpcs.sh + + - name: phpmd (PHP Mess Detector) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpmd.sh + + - name: phpcpd (PHP Copy/Paste Detector) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpcpd.sh + + - name: gjslint (JavaScript Style Check) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/gjslint.sh + + - name: phpdoc (PHP Documentor) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpdoc.sh + + - name: phpunit (PHP UnitTest) + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose exec -T nc3app bash /opt/scripts/phpunit.sh + sudo -s chmod a+w -R ${NC3_BUILD_DIR}/build + +# - name: push coveralls +# env: +# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# COVERALLS_FLAG_NAME: ${{ matrix.php }} +# run: | +# cd ${NC3_BUILD_DIR} +# ls -la ${NC3_BUILD_DIR} +# vendors/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v + + - name: docker-compose remove + if: always() + run: | + cd ${NC3_DOCKER_DIR} + docker-compose rm -f + + # テスト失敗時はこちらのステップが実行される + - name: Slack Notification on Failure + uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' && failure() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}(php${{ matrix.php }}, mysql${{ matrix.mysql }})" + SLACK_COLOR: danger + + teardown: + name: teardown + runs-on: ubuntu-latest + needs: tests + steps: + # テスト成功時はこちらのステップが実行される + - name: Slack Notification on Success + uses: rtCamp/action-slack-notify@v2.2.0 + if: env.SLACK_WEBHOOK != '' && success() + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TESTS }} + SLACK_CHANNEL: notify-nc3-tests + SLACK_TITLE: "${{ github.repository }}" + SLACK_COLOR: good diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index be7cc85..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: php - -php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - 7.1 - -sudo: false - -env: - matrix: - - NETCOMMONS_VERSION=master DB=mysql - global: - - secure: "hjkDbuIn2kJSKlMFFxzS7FuwGDqgVTPNoqjyN8WH0IiDi+CLMEqzQQ+gLvGEBvjcmjmD+Zv1G/bjmL+CE2G/UaDf6iH0sGBZEo9yWB5eyAnsTjeZ39lEz/I3pllUhmhMC2y9ykkhPhlTiHSeBFrzWXAm7TTUi5VCgMthaHbjnvs=" - - GIT_COMMITTER_NAME=s-nakajima - - GIT_COMMITTER_EMAIL=nakajimashouhei@gmail.com - - GIT_AUTHOR_NAME=s-nakajima - - GIT_AUTHOR_EMAIL=nakajimashouhei@gmail.com - -before_script: - - export NETCOMMONS_BUILD_DIR=`dirname $TRAVIS_BUILD_DIR`/NetCommons3 - - git clone git://github.com/NetCommons3/NetCommons3 $NETCOMMONS_BUILD_DIR - - cd $NETCOMMONS_BUILD_DIR - - git checkout $NETCOMMONS_VERSION - - travis_wait . tools/build/plugins/cakephp/travis/pre.sh - - . tools/build/plugins/cakephp/travis/environment.sh - -script: - - . tools/build/plugins/cakephp/travis/main.sh - -after_script: - - . tools/build/plugins/cakephp/travis/post.sh - -notifications: - email: - recipients: - - netcommons3@googlegroups.com - on_success: never # default: change - on_failure: always # default: always diff --git a/Config/Migration/1551245049_improve_performance_current.php b/Config/Migration/1551245049_improve_performance_current.php new file mode 100644 index 0000000..b00501f --- /dev/null +++ b/Config/Migration/1551245049_improve_performance_current.php @@ -0,0 +1,79 @@ + + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('NetCommonsMigration', 'NetCommons.Config/Migration'); + +/** + * Currentライブラリの速度改善 + * + * @author Shohei Nakajima + * @package NetCommons\Blocks\Config\Migration + */ +class ImprovePerformanceCurrent extends NetCommonsMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'improve_performance_current'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + 'alter_field' => array( + 'block_settings' => array( + 'block_key' => array('type' => 'string', 'null' => true, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + ), + ), + 'create_field' => array( + 'block_settings' => array( + 'indexes' => array( + 'block_key' => array('column' => array('`block_key`(191)', '`field_name`(191)', 'room_id', '`plugin_key`(191)', '`value`(191)'), 'unique' => 0), + ), + ), + ), + ), + 'down' => array( + 'alter_field' => array( + 'block_settings' => array( + 'block_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + ), + ), + 'drop_field' => array( + 'block_settings' => array('indexes' => array('block_key')), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Migration/1551251647_improve_performance_current_2.php b/Config/Migration/1551251647_improve_performance_current_2.php new file mode 100644 index 0000000..b5bac19 --- /dev/null +++ b/Config/Migration/1551251647_improve_performance_current_2.php @@ -0,0 +1,79 @@ + + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('NetCommonsMigration', 'NetCommons.Config/Migration'); + +/** + * Currentライブラリの速度改善 + * + * @author Shohei Nakajima + * @package NetCommons\Blocks\Config\Migration + */ +class ImprovePerformanceCurrent2 extends NetCommonsMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'improve_performance_current_2'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + 'alter_field' => array( + 'block_role_permissions' => array( + 'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + ), + ), + 'create_field' => array( + 'block_role_permissions' => array( + 'indexes' => array( + 'block_key' => array('column' => array('block_key', 'permission', 'roles_room_id', 'value', 'id'), 'unique' => 0), + ), + ), + ), + ), + 'down' => array( + 'alter_field' => array( + 'block_role_permissions' => array( + 'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + ), + ), + 'drop_field' => array( + 'block_role_permissions' => array('indexes' => array('block_key')), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Migration/1557795495_add_index_for_block_setting.php b/Config/Migration/1557795495_add_index_for_block_setting.php new file mode 100644 index 0000000..b966579 --- /dev/null +++ b/Config/Migration/1557795495_add_index_for_block_setting.php @@ -0,0 +1,70 @@ + array( + 'alter_field' => array( + 'block_settings' => array( + 'room_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'), + ), + ), + 'create_field' => array( + 'block_settings' => array( + 'indexes' => array( + 'room_id' => array('column' => 'room_id', 'unique' => 0), + ), + ), + ), + ), + 'down' => array( + 'alter_field' => array( + 'block_settings' => array( + 'room_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), + ), + ), + 'drop_field' => array( + 'block_settings' => array('indexes' => array('room_id')), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index e8fc2ac..8a7bd1c 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -53,7 +53,7 @@ public function after($event = array()) { public $block_role_permissions = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'roles_room_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'index'), - 'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'block_key' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'permission' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'パーミッション e.g.) content_creatable, post_top_article', 'charset' => 'utf8'), 'value' => array('type' => 'boolean', 'null' => false, 'default' => null), 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), @@ -62,7 +62,8 @@ public function after($event = array()) { 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'roles_room_id' => array('column' => array('roles_room_id', 'block_key'), 'unique' => 0) + 'roles_room_id' => array('column' => array('roles_room_id', 'block_key'), 'unique' => 0), + 'block_key' => array('column' => array('block_key', 'permission', 'roles_room_id', 'value', 'id'), 'unique' => 0) ), 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); @@ -75,8 +76,8 @@ public function after($event = array()) { public $block_settings = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'plugin_key' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), - 'room_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), - 'block_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'room_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'index'), + 'block_key' => array('type' => 'string', 'null' => true, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'field_name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'value' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'type' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), @@ -86,7 +87,9 @@ public function after($event = array()) { 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'plugin_key' => array('column' => array('plugin_key', 'room_id', 'block_key', 'field_name'), 'unique' => 0) + 'plugin_key' => array('column' => array('plugin_key', 'room_id', 'block_key', 'field_name'), 'unique' => 0), + 'block_key' => array('column' => array('block_key', 'field_name', 'room_id', 'plugin_key', 'value'), 'unique' => 0), + 'room_id' => array('column' => 'room_id', 'unique' => 0) ), 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') ); diff --git a/Model/Behavior/BlockBehavior.php b/Model/Behavior/BlockBehavior.php index f765ab8..e949630 100644 --- a/Model/Behavior/BlockBehavior.php +++ b/Model/Behavior/BlockBehavior.php @@ -267,13 +267,14 @@ private function __saveBlock(Model $model, $frame) { $model->data['Block']['plugin_key'] = Inflector::underscore($model->plugin); //blocksの登録 + $model->Block->create(null); $block = $model->Block->save($model->data['Block'], false); if (! $block) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } $model->data['BlocksLanguage']['block_id'] = $block['Block']['id']; $model->data['Block'] = $block['Block']; - Current::$current['Block'] = $block['Block']; + Current::write('Block', $block['Block']); //blocks_languagesの登録 if ($model->BlocksLanguage->isM17nGeneralPlugin()) { @@ -302,12 +303,13 @@ private function __saveBlock(Model $model, $frame) { ); $model->data['BlocksLanguage'] = Hash::insert($model->data['BlocksLanguage'], 'modified', null); + $model->BlocksLanguage->create(null); $blockLanguage = $model->BlocksLanguage->save($model->data['BlocksLanguage'], false); if (! $blockLanguage) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } $model->data['BlocksLanguage'] = $blockLanguage['BlocksLanguage']; - Current::$current['BlocksLanguage'] = $blockLanguage['BlocksLanguage']; + Current::write('BlocksLanguage', $blockLanguage['BlocksLanguage']); //Behaviorをセットしているモデルに対してblock_idとblock_keyをセットする if ($model->hasField('block_id') && ! Hash::check($model->data, $model->alias . '.block_id')) { diff --git a/Model/Behavior/BlockSettingBehavior.php b/Model/Behavior/BlockSettingBehavior.php index d4248e4..9534a8b 100644 --- a/Model/Behavior/BlockSettingBehavior.php +++ b/Model/Behavior/BlockSettingBehavior.php @@ -505,7 +505,7 @@ public function validateBlockSetting(Model $model, $blockKey = null) { if (array_key_exists($field, $inputData)) { // validate追加 $rule = $blockSetting['BlockSetting'][$field]['type']; - $model->validate = Hash::merge($model->validate, array( + $model->validate = ValidateMerge::merge($model->validate, array( $field => array( $rule => array( 'rule' => $rule, diff --git a/Model/Block.php b/Model/Block.php index 3105629..4fca8c8 100644 --- a/Model/Block.php +++ b/Model/Block.php @@ -211,7 +211,7 @@ public function bindModelBlockLang($joinKey = 'Block.id') { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge(array( + $this->validate = ValidateMerge::merge(array( 'room_id' => array( 'numeric' => array( 'rule' => array('numeric'), diff --git a/Model/BlockRolePermission.php b/Model/BlockRolePermission.php index 59c107c..fe22555 100644 --- a/Model/BlockRolePermission.php +++ b/Model/BlockRolePermission.php @@ -67,7 +67,7 @@ class BlockRolePermission extends BlocksAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = ValidateMerge::merge($this->validate, array( 'roles_room_id' => array( 'numeric' => array( 'rule' => array('numeric'), diff --git a/Model/BlockSetting.php b/Model/BlockSetting.php index b4a9238..6286552 100644 --- a/Model/BlockSetting.php +++ b/Model/BlockSetting.php @@ -34,7 +34,7 @@ class BlockSetting extends BlocksAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = ValidateMerge::merge($this->validate, array( 'plugin_key' => array( 'notBlank' => array( 'rule' => array('notBlank'), diff --git a/Model/BlocksLanguage.php b/Model/BlocksLanguage.php index e4be711..429b5e5 100644 --- a/Model/BlocksLanguage.php +++ b/Model/BlocksLanguage.php @@ -75,7 +75,7 @@ class BlocksLanguage extends BlocksAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge(array( + $this->validate = ValidateMerge::merge(array( 'language_id' => array( 'numeric' => array( 'rule' => array('numeric'), diff --git a/README.md b/README.md index c026250..d1ebad8 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,15 @@ Blocks ============== + +[![Tests Status](https://github.com/NetCommons3/Blocks/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/NetCommons3/Blocks/actions/workflows/tests.yml) +[![Coverage Status](https://coveralls.io/repos/NetCommons3/Blocks/badge.svg?branch=master)](https://coveralls.io/r/NetCommons3/Blocks?branch=master) +[![Stable Version](https://img.shields.io/packagist/v/netcommons/blocks.svg?label=stable)](https://packagist.org/packages/netcommons/blocks) + NetCommonsのブロックとは、フレームに割り当てるデータ概念です。
フレームに配置されるプラグインは、1つ以上のブロックを持ち1ブロックにたいして、複数のコンテンツが関連付けられます。
フレームの右上部Glyphicon(歯車)をクリックすると表示されるブロック設定画面の共通処理をまとめています。 -[![Build Status](https://api.travis-ci.org/NetCommons3/Blocks.png?branch=master)](https://travis-ci.org/NetCommons3/Blocks) -[![Coverage Status](https://coveralls.io/repos/NetCommons3/Blocks/badge.png?branch=master)](https://coveralls.io/r/NetCommons3/Blocks?branch=master) - -| dependencies | status | -| ------------- | ------ | -| composer.json | [![Dependency Status](https://www.versioneye.com/user/projects/543b99c1b2a9c5db88000385/badge.png)](https://www.versioneye.com/user/projects/543b99c1b2a9c5db88000385) | - ### BlockTabsComponent なくなる予定
diff --git a/Test/Case/TestSuite/BlockRolePermissionsControllerEditTest/TestEditGetTest.php b/Test/Case/TestSuite/BlockRolePermissionsControllerEditTest/TestEditGetTest.php index da29d85..e85eb7d 100644 --- a/Test/Case/TestSuite/BlockRolePermissionsControllerEditTest/TestEditGetTest.php +++ b/Test/Case/TestSuite/BlockRolePermissionsControllerEditTest/TestEditGetTest.php @@ -71,10 +71,10 @@ public function testTestEditGet() { $expected = array( 0 => array(array( 'method' => 'assertInput', 'type' => 'form', 'name' => null, - 'value' => '/test_blocks/TestSuiteBlockRolePermissionsControllerEditTest/edit/4?frame_id=6' + 'value' => '/test_blocks/TestSuiteBlockRolePermissionsControllerEditTest/edit/2?frame_id=6' )), 1 => array(array( - 'method' => 'assertInput', 'type' => 'input', 'name' => 'data[Block][id]', 'value' => '4' + 'method' => 'assertInput', 'type' => 'input', 'name' => 'data[Block][id]', 'value' => '2' )), 2 => array(array( 'name' => 'data[BlockRolePermission][content_creatable][room_administrator][value]', @@ -163,10 +163,10 @@ public function testTestEditGetWOUseCommentApproval() { $expected = array( 0 => array(array( 'method' => 'assertInput', 'type' => 'form', 'name' => null, - 'value' => '/test_blocks/TestSuiteBlockRolePermissionsControllerEditTest/edit/4?frame_id=6' + 'value' => '/test_blocks/TestSuiteBlockRolePermissionsControllerEditTest/edit/2?frame_id=6' )), 1 => array(array( - 'method' => 'assertInput', 'type' => 'input', 'name' => 'data[Block][id]', 'value' => '4' + 'method' => 'assertInput', 'type' => 'input', 'name' => 'data[Block][id]', 'value' => '2' )), 2 => array(array( 'name' => 'data[BlockRolePermission][content_creatable][room_administrator][value]', diff --git a/Test/Case/TestSuite/BlockRolePermissionsControllerEditTest/TestEditPostTest.php b/Test/Case/TestSuite/BlockRolePermissionsControllerEditTest/TestEditPostTest.php index 40ac818..2616574 100644 --- a/Test/Case/TestSuite/BlockRolePermissionsControllerEditTest/TestEditPostTest.php +++ b/Test/Case/TestSuite/BlockRolePermissionsControllerEditTest/TestEditPostTest.php @@ -69,31 +69,31 @@ public function testTestEditPost() { //チェック $expected = array( - 'Block' => array('id' => '4', 'key' => 'block_2'), + 'Block' => array('id' => '2', 'key' => 'block_1'), 'BlockRolePermission' => array( 'content_creatable' => array( 'general_user' => array( - 'roles_room_id' => '4', 'block_key' => 'block_2', + 'roles_room_id' => '4', 'block_key' => 'block_1', 'permission' => 'content_creatable', 'value' => '1' ) ), 'content_comment_creatable' => array( 'editor' => array( - 'roles_room_id' => '3', 'block_key' => 'block_2', + 'roles_room_id' => '3', 'block_key' => 'block_1', 'permission' => 'content_comment_creatable', 'value' => '1' ), 'general_user' => array( - 'roles_room_id' => '4', 'block_key' => 'block_2', + 'roles_room_id' => '4', 'block_key' => 'block_1', 'permission' => 'content_comment_creatable', 'value' => '1' ), 'visitor' => array( - 'roles_room_id' => '5', 'block_key' => 'block_2', + 'roles_room_id' => '5', 'block_key' => 'block_1', 'permission' => 'content_comment_creatable', 'value' => '1' ) ), 'content_comment_publishable' => array( 'editor' => array( - 'roles_room_id' => '3', 'block_key' => 'block_2', + 'roles_room_id' => '3', 'block_key' => 'block_1', 'permission' => 'content_comment_publishable', 'value' => '1' ) ) @@ -126,11 +126,11 @@ public function testTestEditPostWOUseCommentApproval() { //チェック $expected = array( - 'Block' => array('id' => '4', 'key' => 'block_2'), + 'Block' => array('id' => '2', 'key' => 'block_1'), 'BlockRolePermission' => array( 'content_creatable' => array( 'general_user' => array( - 'roles_room_id' => '4', 'block_key' => 'block_2', + 'roles_room_id' => '4', 'block_key' => 'block_1', 'permission' => 'content_creatable', 'value' => '1' ) ), diff --git a/Test/Case/TestSuite/BlocksControllerEditTest/DataProviderRoleAccessTest.php b/Test/Case/TestSuite/BlocksControllerEditTest/DataProviderRoleAccessTest.php index 43bbda9..ff086ae 100644 --- a/Test/Case/TestSuite/BlocksControllerEditTest/DataProviderRoleAccessTest.php +++ b/Test/Case/TestSuite/BlocksControllerEditTest/DataProviderRoleAccessTest.php @@ -58,22 +58,22 @@ public function testDataProviderRoleAccess() { //チェック $expected = array( - array( 'add', 'get', 'edit', 'chief_editor', false), - array( 'add', 'get', 'edit', 'editor', 'ForbiddenException'), - array( 'add', 'get', 'edit', 'general_user', 'ForbiddenException'), - array( 'add', 'get', 'edit', 'visitor', 'ForbiddenException'), - array( 'add', 'get', 'edit', null, 'ForbiddenException'), - array( 'edit', 'get', 'edit', 'chief_editor', false), - array( 'edit', 'get', 'edit', 'editor', 'ForbiddenException'), - array( 'edit', 'get', 'edit', 'general_user', 'ForbiddenException'), - array( 'edit', 'get', 'edit', 'visitor', 'ForbiddenException'), - array( 'edit', 'get', 'edit', null, 'ForbiddenException'), - array( 'delete', 'get', 'delete', 'room_administrator', 'BadRequestException'), - array( 'delete', 'get', 'delete', 'chief_editor', 'BadRequestException'), - array( 'delete', 'get', 'delete', 'editor', 'ForbiddenException'), - array( 'delete', 'get', 'delete', 'general_user', 'ForbiddenException'), - array( 'delete', 'get', 'delete', 'visitor', 'ForbiddenException'), - array( 'delete', 'get', 'delete', null, 'ForbiddenException') + array('add', 'get', 'edit', 'chief_editor', false), + array('add', 'get', 'edit', 'editor', 'ForbiddenException'), + array('add', 'get', 'edit', 'general_user', 'ForbiddenException'), + array('add', 'get', 'edit', 'visitor', 'ForbiddenException'), + array('add', 'get', 'edit', null, 'ForbiddenException'), + array('edit', 'get', 'edit', 'chief_editor', false), + array('edit', 'get', 'edit', 'editor', 'ForbiddenException'), + array('edit', 'get', 'edit', 'general_user', 'ForbiddenException'), + array('edit', 'get', 'edit', 'visitor', 'ForbiddenException'), + array('edit', 'get', 'edit', null, 'ForbiddenException'), + array('delete', 'get', 'delete', 'room_administrator', 'BadRequestException'), + array('delete', 'get', 'delete', 'chief_editor', 'BadRequestException'), + array('delete', 'get', 'delete', 'editor', 'ForbiddenException'), + array('delete', 'get', 'delete', 'general_user', 'ForbiddenException'), + array('delete', 'get', 'delete', 'visitor', 'ForbiddenException'), + array('delete', 'get', 'delete', null, 'ForbiddenException') ); $this->assertEquals($expected, $result); } diff --git a/Test/Case/TestSuite/BlocksControllerEditTest/TestEditTest.php b/Test/Case/TestSuite/BlocksControllerEditTest/TestEditTest.php index 9fd8135..36a4897 100644 --- a/Test/Case/TestSuite/BlocksControllerEditTest/TestEditTest.php +++ b/Test/Case/TestSuite/BlocksControllerEditTest/TestEditTest.php @@ -78,7 +78,7 @@ private function __expectedByGet() { 'method' => 'assertInput', 'type' => 'form', 'name' => null, - 'value' => '/test_blocks/TestSuiteBlocksControllerEditTest/edit/4?frame_id=6' + 'value' => '/test_blocks/TestSuiteBlocksControllerEditTest/edit/2?frame_id=6' ), 1 => array( 'method' => 'assertInput', @@ -90,7 +90,7 @@ private function __expectedByGet() { 'method' => 'assertInput', 'type' => 'input', 'name' => 'data[Block][id]', - 'value' => '4' + 'value' => '2' ), 3 => array( 'method' => 'assertInput', @@ -102,7 +102,7 @@ private function __expectedByGet() { 'method' => 'assertInput', 'type' => 'form', 'name' => null, - 'value' => '/test_blocks/TestSuiteBlocksControllerEditTest/delete/4?frame_id=6' + 'value' => '/test_blocks/TestSuiteBlocksControllerEditTest/delete/2' ), 5 => array( 'method' => 'assertInput', diff --git a/Test/Case/View/Helper/BlockTabsHelper/BlockTest.php b/Test/Case/View/Helper/BlockTabsHelper/BlockTest.php index e442cfa..573c008 100644 --- a/Test/Case/View/Helper/BlockTabsHelper/BlockTest.php +++ b/Test/Case/View/Helper/BlockTabsHelper/BlockTest.php @@ -136,8 +136,11 @@ public function testBlock($activeTab, $blockPermission) { $this->loadHelper('Blocks.BlockTabs', $viewVars, $requestData, $params); //データ生成 - Current::$current['Permission']['block_editable']['value'] = true; - Current::$current['Permission']['block_permission_editable']['value'] = $blockPermission; + Current::write('Frame.id', '6'); + Current::write('Room.id', '2'); + //Current::write('Block.id', '2'); + Current::writePermission('2', 'block_editable', true); + Current::writePermission('2', 'block_permission_editable', $blockPermission); //テスト実施 $result = $this->BlockTabs->block($activeTab); @@ -174,8 +177,10 @@ public function testBlockAdd() { //データ生成 $activeTab = 'block_settings'; - Current::$current['Permission']['block_editable']['value'] = true; - Current::$current['Permission']['block_permission_editable']['value'] = true; + Current::write('Frame.id', '6'); + Current::write('Room.id', '2'); + Current::writePermission('2', 'block_editable', true); + Current::writePermission('2', 'block_permission_editable', true); //テスト実施 $result = $this->BlockTabs->block($activeTab); diff --git a/Test/Case/View/Helper/BlockTabsHelper/MainTest.php b/Test/Case/View/Helper/BlockTabsHelper/MainTest.php index 6935606..723cbea 100644 --- a/Test/Case/View/Helper/BlockTabsHelper/MainTest.php +++ b/Test/Case/View/Helper/BlockTabsHelper/MainTest.php @@ -145,8 +145,11 @@ public function testMain($activeTab, $blockPermission) { $this->loadHelper('Blocks.BlockTabs', $viewVars, $requestData, $params); //データ生成 - Current::$current['Permission']['block_editable']['value'] = true; - Current::$current['Permission']['block_permission_editable']['value'] = $blockPermission; + Current::write('Frame.id', '6'); + Current::write('Room.id', '2'); + //Current::write('Block.id', '2'); + Current::writePermission('2', 'block_editable', true); + Current::writePermission('2', 'block_permission_editable', $blockPermission); //テスト実施 $result = $this->BlockTabs->main($activeTab); diff --git a/Test/Fixture/BlockSettingFixture.php b/Test/Fixture/BlockSettingFixture.php index ef3f752..6463f68 100644 --- a/Test/Fixture/BlockSettingFixture.php +++ b/Test/Fixture/BlockSettingFixture.php @@ -23,29 +23,6 @@ class BlockSettingFixture extends CakeTestFixture { */ public $pluginKey = 'dummy'; -/** - * Fields - * - * @var array - */ - public $fields = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), - 'plugin_key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'charset' => 'utf8mb4'), - 'room_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), - 'block_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'charset' => 'utf8mb4'), - 'field_name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'charset' => 'utf8mb4'), - 'value' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'charset' => 'utf8mb4'), - 'type' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'charset' => 'utf8mb4'), - 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), - 'created' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), - 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), - 'indexes' => array( - 'PRIMARY' => array('column' => 'id', 'unique' => 1) - ), - 'tableParameters' => array('charset' => 'utf8mb4', 'collate' => 'utf8mb4_general_ci', 'engine' => 'InnoDB') - ); - /** * Records * @@ -232,6 +209,8 @@ class BlockSettingFixture extends CakeTestFixture { * @return void */ public function init() { + require_once App::pluginPath('Blocks') . 'Config' . DS . 'Schema' . DS . 'schema.php'; + $this->fields = (new BlocksSchema())->tables['block_settings']; parent::init(); // 継承先で $this->pluginKey を上書きすれば、そのプラグインに対応したデータになるので diff --git a/Test/test_app/Plugin/TestBlocks/Controller/TestSuiteBlocksControllerTestErrorController.php b/Test/test_app/Plugin/TestBlocks/Controller/TestSuiteBlocksControllerTestErrorController.php index d536c80..7404a2a 100644 --- a/Test/test_app/Plugin/TestBlocks/Controller/TestSuiteBlocksControllerTestErrorController.php +++ b/Test/test_app/Plugin/TestBlocks/Controller/TestSuiteBlocksControllerTestErrorController.php @@ -27,7 +27,7 @@ class TestSuiteBlocksControllerTestErrorController extends AppController { */ public function index() { $this->autoRender = true; - throw new ForbiddenException(__d('net_commons', 'Permission denied')); + throw new ForbiddenException(); } } diff --git a/TestSuite/BlockRolePermissionsControllerEditTest.php b/TestSuite/BlockRolePermissionsControllerEditTest.php index 097ed66..16d12f3 100644 --- a/TestSuite/BlockRolePermissionsControllerEditTest.php +++ b/TestSuite/BlockRolePermissionsControllerEditTest.php @@ -207,7 +207,7 @@ public function testEditGet($approvalFields, $exception = null, $return = 'view' TestAuthGeneral::login($this); $frameId = '6'; - $blockId = '4'; + $blockId = '2'; //テスト実施 $url = array( @@ -260,8 +260,8 @@ public function testEditPost($data, $exception = null, $return = 'view') { TestAuthGeneral::login($this); $frameId = '6'; - $blockId = '4'; - $blockKey = 'block_2'; + $blockId = '2'; + $blockKey = 'block_1'; $roomId = '2'; $permissions = $this->_getPermissionData(true, Hash::check($data, '{s}.use_comment_approval')); diff --git a/TestSuite/BlocksControllerEditTest.php b/TestSuite/BlocksControllerEditTest.php index 0086ac6..019a8b4 100644 --- a/TestSuite/BlocksControllerEditTest.php +++ b/TestSuite/BlocksControllerEditTest.php @@ -209,7 +209,7 @@ public function testEdit($method, $data = null, $validationError = false) { TestAuthGeneral::login($this); $frameId = '6'; - $blockId = '4'; + $blockId = '2'; $roomId = '2'; if ($validationError) { $data = Hash::remove($data, $validationError['field']); @@ -224,11 +224,20 @@ public function testEdit($method, $data = null, $validationError = false) { 'frame_id' => $frameId, 'block_id' => $blockId )); + $deleteUrl = NetCommonsUrl::actionUrl(array( + 'plugin' => $this->plugin, + 'controller' => $this->_controller, + 'action' => 'delete', + //'frame_id' => $frameId, + 'block_id' => $blockId + )); + $params = array( 'method' => $method, 'return' => 'view', 'data' => $data ); + $this->testAction($url, $params); //チェック @@ -239,14 +248,6 @@ public function testEdit($method, $data = null, $validationError = false) { ); } else { //削除フォームの確認 - $deleteUrl = NetCommonsUrl::actionUrl(array( - 'plugin' => $this->plugin, - 'controller' => $this->_controller, - 'action' => 'delete', - 'frame_id' => $frameId, - 'block_id' => $blockId - )); - $asserts = array( array( 'method' => 'assertInput', 'type' => 'form', @@ -304,7 +305,7 @@ public function testDelete($data) { TestAuthGeneral::login($this); $frameId = '6'; - $blockId = '4'; + $blockId = '2'; //アクション実行 $url = NetCommonsUrl::actionUrl(array( diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..86fb650 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +3.3.7 diff --git a/View/Elements/public_type.ctp b/View/Elements/public_type.ctp old mode 100755 new mode 100644 diff --git a/View/Helper/BlockTabsHelper.php b/View/Helper/BlockTabsHelper.php index 8a23539..29d008f 100644 --- a/View/Helper/BlockTabsHelper.php +++ b/View/Helper/BlockTabsHelper.php @@ -394,7 +394,13 @@ private function __listTag($activeTab, $key, $tab) { $activeTabCss = ''; } - if (Current::permission(Hash::get($tab, 'permission', 'block_editable'))) { + if (isset($tab['permission'])) { + if (Current::permission($tab['permission'])) { + $html .= '
  • '; + $html .= $this->NetCommonsHtml->link(__d($tab['label'][0], $tab['label'][1]), $tab['url']); + $html .= '
  • '; + } + } elseif (Current::permission('block_editable')) { $html .= '
  • '; $html .= $this->NetCommonsHtml->link(__d($tab['label'][0], $tab['label'][1]), $tab['url']); $html .= '
  • '; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 09f2627..804c874 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,8 @@ + + + app/Plugin/Blocks @@ -14,6 +17,6 @@ - + diff --git a/webroot/js/block_role_permissions.js b/webroot/js/block_role_permissions.js index 38f3af8..5fe443a 100644 --- a/webroot/js/block_role_permissions.js +++ b/webroot/js/block_role_permissions.js @@ -88,13 +88,13 @@ NetCommonsApp.controller('BlockRolePermissions', ['$scope', function($scope) { '[value]"]'); if (! $event.currentTarget.checked) { - if (baseRole['level'] > role['level']) { + if (Number(baseRole['level']) > Number(role['level'])) { if (! angular.isUndefined(element[0]) && ! element[0].disabled) { element[0].checked = false; } } } else { - if (baseRole['level'] < role['level']) { + if (Number(baseRole['level']) < Number(role['level'])) { if (! angular.isUndefined(element[0]) && ! element[0].disabled) { element[0].checked = true; }