diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..592d72f --- /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: | + NetCommons ${{ 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..6da4321 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,168 @@ +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +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 19508b2..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: "Zne29ern9LsmaFB4IXG/Qu794ansG0duVm020H4SwOeHF6+wvgOqvfW2HCvuyPD5ZBNvwvy7Zx6euIP0nrlv8HJCpJLGqgcIH6DiC978Nu+cELS05AzbHGYkMKakjXX1LJIybmoQWBMfIWGQgGpyXB31Nmzr+BbZpQGdFREs1U0MF2S300XO6UrIKfBnJQINdg/YzDW5jAjtFPh79vMO2zdTVrkBLuDYuj4GhmOwwa9RBvU8nBvsPGvlmCqnY/+Od22OWir3qQ2xIJGVO33fDQROiSYu42py+RoWTzFsi/MTU4vSYDhTLNRj8Fnq4xQ/KZRUcJp+cNxQ8+mcTlyH27U5Hx8DJx7bPqgB4zP7z7mnCqML0WwkZ8Vr3oohQ19RWWwoeevp2fL+2Ltcg4aKeVRsdm3GRF87AucSZEeOKkk9Ah4UQMFYeReazeltMRnzW1U4LqIkyU9+fxEcmZdk6PGpyllyTjP0DFg1JXLwNYkow5OuWeZSm+VMYxI4AH/Jfq3G2xIBpr42rxjGAe7lNReSUbcxclG/NhMCCXD4Dgd2p1r46Jh8bE9JOaK7t+WYsRj98Ah/ijBtpHzyEZ54SE67z3yiG1DnnhUQmkGuxSoz/hvk27uHvtUMPbWXdr6Rgu9T6L02hWZPm+XVzp4Iu4jyg4UliJEdCHuyThdIlwU=" - - 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/Model/Behavior/WorkflowBehavior.php b/Model/Behavior/WorkflowBehavior.php index 151c7e3..5d55d44 100644 --- a/Model/Behavior/WorkflowBehavior.php +++ b/Model/Behavior/WorkflowBehavior.php @@ -18,6 +18,7 @@ * * @author Shohei Nakajima * @package NetCommons\Workflow\Model\Befavior + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class WorkflowBehavior extends ModelBehavior { @@ -175,7 +176,7 @@ public function beforeValidate(Model $model, $options = array()) { $statuses = self::$statusesForEditor; } - $model->validate = Hash::merge($model->validate, array( + $model->validate = ValidateMerge::merge($model->validate, array( 'status' => array( 'numeric' => array( 'rule' => array('numeric'), @@ -227,16 +228,23 @@ private function __hasSaveField(Model $model, $needle) { * * @param Model $model Model using this behavior * @param array $conditions Model::find conditions default value + * @param bool $useCommentCreatable コメントの作成権限でもチェックするかどうか * @return array Conditions data * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ - public function getWorkflowConditions(Model $model, $conditions = array()) { + public function getWorkflowConditions( + Model $model, + $conditions = array(), + $useCommentCreatable = false + ) { if (Current::permission('content_editable')) { $activeConditions = array(); $latestConditons = array( $model->alias . '.is_latest' => true, ); - } elseif (Current::permission('content_creatable')) { + } elseif (Current::permission('content_creatable') || + $useCommentCreatable && Current::permission('content_comment_creatable')) { $activeConditions = array( $model->alias . '.is_active' => true, $model->alias . '.created_user !=' => Current::read('User.id'), @@ -292,7 +300,16 @@ public function getWorkflowConditions(Model $model, $conditions = array()) { $langConditions = array(); } + $currentBlockId = Current::read('Block.id'); + $blockConditions = []; + if ($currentBlockId && $model->hasField('block_id')) { + $blockConditions = [ + $model->alias . '.block_id' => $currentBlockId, + ]; + } + $conditions = Hash::merge( + $blockConditions, array( $langConditions, array('OR' => array($activeConditions, $latestConditons)) @@ -309,12 +326,19 @@ public function getWorkflowConditions(Model $model, $conditions = array()) { * @param Model $model Model using this behavior * @param string $type Type of find operation (all / first / count / neighbors / list / threaded) * @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks) + * @param bool $useCommentCreatable コメントの作成権限でもチェックするかどうか * @return array Conditions data + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ - public function getWorkflowContents(Model $model, $type, $query = array()) { + public function getWorkflowContents( + Model $model, + $type, + $query = array(), + $useCommentCreatable = false + ) { $query = Hash::merge(array( 'recursive' => -1, - 'conditions' => $this->getWorkflowConditions($model) + 'conditions' => $this->getWorkflowConditions($model, [], $useCommentCreatable) ), $query); return $model->find($type, $query); @@ -361,7 +385,8 @@ public function canEditWorkflowContent(Model $model, $data) { if (! isset($data[$model->alias]['created_user'])) { return false; } - return ((int)$data[$model->alias]['created_user'] === (int)Current::read('User.id')); + return (Current::permission('content_creatable') && + ((int)$data[$model->alias]['created_user'] === (int)Current::read('User.id'))); } /** @@ -374,7 +399,8 @@ public function canEditWorkflowContent(Model $model, $data) { * @return bool true:削除可、false:削除不可 */ public function canDeleteWorkflowContent(Model $model, $data) { - if (! $this->canEditWorkflowContent($model, $data)) { + //Model側で継承している場合、そのcanEditWorkflowContentが実行されるように、$thisではなく、$modelで呼び出す。 + if (! $model->canEditWorkflowContent($data)) { return false; } if (Current::permission('content_publishable')) { diff --git a/README.md b/README.md index 32e118e..53be543 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,6 @@ Workflow ============== -Workflow for NetComomns3 - -[![Build Status](https://api.travis-ci.org/NetCommons3/Workflow.png?branch=master)](https://travis-ci.org/NetCommons3/Workflow) -[![Coverage Status](https://coveralls.io/repos/NetCommons3/Workflow/badge.png?branch=master)](https://coveralls.io/r/NetCommons3/Workflow?branch=master) - -| dependencies | status | -| ------------- | ------ | -| composer.json | [![Dependency Status](https://www.versioneye.com/user/projects/55e64f4fe7e33d000c0007e9/badge.png)](https://www.versioneye.com/user/projects/55e64f4fe7e33d000c0007e9) | +[![Tests Status](https://github.com/NetCommons3/Workflow/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/NetCommons3/Workflow/actions/workflows/tests.yml) +[![Coverage Status](https://coveralls.io/repos/NetCommons3/Workflow/badge.svg?branch=master)](https://coveralls.io/r/NetCommons3/Workflow?branch=master) +[![Stable Version](https://img.shields.io/packagist/v/netcommons/workflow.svg?label=stable)](https://packagist.org/packages/netcommons/workflow) diff --git a/Test/Case/Model/Behavior/WorkflowBehavior/CanEditWorkflowContentTest.php b/Test/Case/Model/Behavior/WorkflowBehavior/CanEditWorkflowContentTest.php index 710cbb7..9c11277 100644 --- a/Test/Case/Model/Behavior/WorkflowBehavior/CanEditWorkflowContentTest.php +++ b/Test/Case/Model/Behavior/WorkflowBehavior/CanEditWorkflowContentTest.php @@ -92,6 +92,7 @@ public function testCanEditWorkflowContent($permission, $assert, $userId, $data) Current::$current['User']['id'] = $userId; Current::write('Room.id', '2'); Current::writePermission('2', 'content_editable', $permission); + Current::writePermission('2', 'content_creatable', true); $result = $this->TestModel->canEditWorkflowContent($data); //チェック diff --git a/Test/Case/View/Elements/FormTest.php b/Test/Case/View/Elements/FormTest.php index db61a5f..56f3537 100644 --- a/Test/Case/View/Elements/FormTest.php +++ b/Test/Case/View/Elements/FormTest.php @@ -24,7 +24,9 @@ class WorkflowViewElementsFormTest extends NetCommonsControllerTestCase { * * @var array */ - public $fixtures = array(); + public $fixtures = array( + 'plugin.workflow.workflow_comment', + ); /** * Plugin name 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/index.ctp b/View/Elements/index.ctp index 1bcfc9c..95da861 100644 --- a/View/Elements/index.ctp +++ b/View/Elements/index.ctp @@ -17,7 +17,7 @@
DisplayUser->handleLink($comment, array('avatar' => true)); ?> - + Date->dateFormat($comment['WorkflowComment']['created']); ?>
diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b636b39..dffa9d0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,8 @@ + + + app/Plugin/Workflow @@ -14,6 +17,6 @@ - +