From b757b787e25113d91955e125708313589eb91673 Mon Sep 17 00:00:00 2001 From: kteraguchi Date: Wed, 5 Jul 2017 19:19:47 +0900 Subject: [PATCH 1/2] Change publishable permission update --- .../Behavior/BlockRolePermissionBehavior.php | 62 ---------------- View/Helper/BlockRolePermissionFormHelper.php | 73 ------------------- 2 files changed, 135 deletions(-) diff --git a/Model/Behavior/BlockRolePermissionBehavior.php b/Model/Behavior/BlockRolePermissionBehavior.php index 904b607..98cc057 100644 --- a/Model/Behavior/BlockRolePermissionBehavior.php +++ b/Model/Behavior/BlockRolePermissionBehavior.php @@ -103,68 +103,6 @@ public function beforeValidate(Model $model, $options = array()) { return true; } -/** - * beforeSave is called before a model is saved. Returning false from a beforeSave callback - * will abort the save operation. - * - * @param Model $model Model using this behavior - * @param array $options Options passed from Model::save(). - * @return mixed False if the operation should abort. Any other result will continue. - * @see Model::save() - */ - public function beforeSave(Model $model, $options = array()) { - if (! isset($model->data['BlockRolePermission'])) { - return true; - } - - if (! isset($model->data[$model->alias]['approval_type'])) { - return true; - } - $approvalType = $model->data[$model->alias]['approval_type']; - - $approvalTypes = [Block::NOT_NEED_APPROVAL, Block::NEED_APPROVAL, Block::NEED_COMMENT_APPROVAL]; - if (! in_array($approvalType, $approvalTypes, true)) { - return true; - } - - $permission = Hash::get($model->data['BlockRolePermission'], 'content_publishable', array()); - foreach ($permission as $roleKey => $role) { - if (in_array($approvalType, [Block::NOT_NEED_APPROVAL, Block::NEED_COMMENT_APPROVAL])) { - $value = Hash::get( - $model->data['BlockRolePermission'], 'content_creatable.' . $roleKey . '.value', true - ); - } else { - $value = false; - } - $model->data['BlockRolePermission'] = Hash::insert( - $model->data['BlockRolePermission'], 'content_publishable.' . $roleKey . '.value', $value - ); - } - - $permission = Hash::get( - $model->data['BlockRolePermission'], 'content_comment_publishable', array() - ); - foreach ($permission as $roleKey => $role) { - if ($approvalType === Block::NOT_NEED_APPROVAL) { - $pathKey = 'content_comment_creatable.' . $roleKey . '.value'; - $value = Hash::get($model->data['BlockRolePermission'], $pathKey, true); - - } elseif ($approvalType === Block::NEED_COMMENT_APPROVAL) { - $pathKey = 'content_comment_publishable.' . $roleKey . '.value'; - $value = Hash::get($model->data['BlockRolePermission'], $pathKey, false); - - } else { - $value = false; - } - $pathKey = 'content_comment_publishable.' . $roleKey . '.value'; - $model->data['BlockRolePermission'] = Hash::insert( - $model->data['BlockRolePermission'], $pathKey, $value - ); - } - - return true; - } - /** * afterSave is called after a model is saved. * diff --git a/View/Helper/BlockRolePermissionFormHelper.php b/View/Helper/BlockRolePermissionFormHelper.php index e7057c5..2f6e2c0 100644 --- a/View/Helper/BlockRolePermissionFormHelper.php +++ b/View/Helper/BlockRolePermissionFormHelper.php @@ -55,49 +55,6 @@ public function checkboxBlockRolePermission($fieldName, $attributes = array()) { return $html; } -/** - * BlockRolePermissionのコンテンツ公開権限 - * - * @return string HTML - */ - public function contentPublishablePermission() { - $fieldName = 'BlockRolePermission.content_publishable'; - list($model, $permission) = explode('.', $fieldName); - $html = ''; - - if (! isset($this->_View->request->data[$model][$permission])) { - return $html; - } - - foreach ($this->_View->request->data[$model][$permission] as $roleKey => $role) { - if (! $role['default'] && $role['fixed']) { - continue; - } - - $pubFieldName = $fieldName . '.' . $roleKey; - if (Hash::get($this->_View->request->data, $pubFieldName . '.id')) { - $outputPublishable = true; - } elseif (! (bool)Hash::get($this->_View->request->data, $pubFieldName . '.roles_room_id')) { - $outputPublishable = false; - } elseif (! (bool)Hash::get($this->_View->request->data, $pubFieldName . '.fixed')) { - $outputPublishable = true; - } else { - //作成権限ON固定で、公開権限がOFFの場合、inputタグを表示する - $outputPublishable = ! Hash::get($this->_View->request->data, $pubFieldName . '.default'); - } - if (! $outputPublishable) { - continue; - } - - $html .= $this->NetCommonsForm->hidden($pubFieldName . '.id'); - $html .= $this->NetCommonsForm->hidden($pubFieldName . '.roles_room_id'); - $html .= $this->NetCommonsForm->hidden($pubFieldName . '.block_key'); - $html .= $this->NetCommonsForm->hidden($pubFieldName . '.permission'); - } - - return $html; - } - /** * BlockRolePermissionのチェックボックス表示 * @@ -112,13 +69,6 @@ private function __inputBlockRolePermission($model, $permission, $roleKey, $attr $html .= '
'; $fieldName = $model . '.' . $permission . '.' . $roleKey; - if ($permission === 'content_creatable') { - $pubFieldName = $model . '.' . 'content_publishable' . '.' . $roleKey; - } elseif ($permission === 'content_comment_creatable') { - $pubFieldName = $model . '.' . 'content_comment_publishable' . '.' . $roleKey; - } else { - $pubFieldName = ''; - } if (! Hash::get($this->_View->request->data, $fieldName . '.fixed')) { $html .= $this->NetCommonsForm->hidden($fieldName . '.id'); @@ -143,29 +93,6 @@ private function __inputBlockRolePermission($model, $permission, $roleKey, $attr $html .= $this->NetCommonsForm->checkbox($fieldName . '.value', $options); - if (! $pubFieldName) { - $html .= '
'; - return $html; - } - if (Hash::get($this->_View->request->data, $pubFieldName . '.id')) { - $outputPublishable = true; - } elseif (! (bool)Hash::get($this->_View->request->data, $pubFieldName . '.fixed')) { - $outputPublishable = true; - } else { - //作成権限ON固定で、公開権限がOFFの場合、inputタグを表示する - $outputPublishable = ! Hash::get($this->_View->request->data, $pubFieldName . '.default'); - } - if (! $outputPublishable) { - $html .= ''; - return $html; - } - - $html .= $this->NetCommonsForm->hidden($pubFieldName . '.id'); - $html .= $this->NetCommonsForm->hidden($pubFieldName . '.roles_room_id'); - $html .= $this->NetCommonsForm->hidden($pubFieldName . '.block_key'); - $html .= $this->NetCommonsForm->hidden($pubFieldName . '.permission'); - $html .= $this->NetCommonsForm->hidden($pubFieldName . '.value'); - $html .= ''; return $html; } From 88d72b6a02d59ca403e658dbbede8b1f6fd744cd Mon Sep 17 00:00:00 2001 From: kteraguchi Date: Thu, 6 Jul 2017 12:50:45 +0900 Subject: [PATCH 2/2] Add migration --- ...99309604_delete_publishable_permission.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Config/Migration/1499309604_delete_publishable_permission.php diff --git a/Config/Migration/1499309604_delete_publishable_permission.php b/Config/Migration/1499309604_delete_publishable_permission.php new file mode 100644 index 0000000..1b6e3af --- /dev/null +++ b/Config/Migration/1499309604_delete_publishable_permission.php @@ -0,0 +1,92 @@ + array(), + 'down' => array(), + ); + +/** + * 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) { + if ($direction === 'down') { + return true; + } + + /* @var $DefaultRolePermission AppModel */ + /* @var $RolesRoom AppModel */ + /* @var $Block AppModel */ + $DefaultRolePermission = $this->generateModel('DefaultRolePermission'); + $RolesRoom = $this->generateModel('RolesRoom'); + $Block = $this->generateModel('BlockRolePermission'); + + $query = [ + 'fields' => 'role_key', + 'conditions' => [ + 'permission' => 'content_comment_publishable', + 'fixed' => '1' + ], + 'recursive' => -1 + ]; + $roleKeyList = $DefaultRolePermission->find('list', $query); + + $query = [ + 'fields' => 'id', + 'conditions' => [ + 'role_key' => $roleKeyList, + ], + 'recursive' => -1 + ]; + $roleRoomIdList = $RolesRoom->find('list', $query); + + $conditions = [ + 'OR' => [ + 'permission' => 'content_publishable', + [ + 'permission' => 'content_comment_publishable', + 'roles_room_id' => $roleRoomIdList + ] + ] + ]; + if (!$Block->deleteAll($conditions, false)) { + return false; + } + + return true; + } +}