From 730b61a3c3421be16c6a4acc5fd4ac30b44eac15 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 2 Aug 2018 12:31:41 -0400 Subject: [PATCH] Various minor module updates --- wire/core/Permissions.php | 49 ++++++++++++++++++- .../Fieldtype/FieldtypePassword.module | 23 +++++++++ .../ProcessPageType/ProcessPageType.module | 2 +- .../ProcessPermission.module | 11 ++++- .../ProcessProfile/ProcessProfile.module | 3 ++ .../ProcessTemplateExportImport.php | 4 +- 6 files changed, 87 insertions(+), 5 deletions(-) diff --git a/wire/core/Permissions.php b/wire/core/Permissions.php index 03ca0428..a29ebd6f 100644 --- a/wire/core/Permissions.php +++ b/wire/core/Permissions.php @@ -46,6 +46,25 @@ class Permissions extends PagesType { 'user-admin-all' => 'user-admin', ); + /** + * Permissions that can reduce existing access upon installation + * + * @var array + * + */ + protected $reducerPermissions = array( + 'page-hide', + 'page-publish', + 'page-edit-created', + 'page-edit-images', + 'page-rename', + 'page-edit-lang-', + 'page-edit-lang-none', + 'user-admin-', + 'user-admin-all', + 'page-lister-', + ); + /** * Does the system have a permission with the given name? * @@ -158,7 +177,9 @@ class Permissions extends PagesType { $languages = $this->wire('languages'); if($languages) { $label = $this->_('Edit fields on a page in language: %s'); - $a["page-edit-lang-default"] = sprintf($label, 'default') . ' ' . $this->_('(also required to create or delete pages)'); + $alsoLabel = $this->_('(also required to create or delete pages)'); + $a["page-edit-lang-default"] = sprintf($label, 'default') . ' ' . $alsoLabel; + $a["page-edit-lang-none"] = $this->_('Edit single-language fields on multi-language page'); foreach($languages as $language) { if($language->isDefault()) continue; $a["page-edit-lang-$language->name"] = sprintf($label, $language->name); @@ -180,6 +201,32 @@ class Permissions extends PagesType { return $a; } + /** + * Get permission names that can reduce existing access, when installed + * + * Returned permission names that end with a "-" indicate that given permission name is a prefix + * that applies for anything that appears after it. + * + * @return array Array of permission names where both index and value are permission name + * + */ + public function getReducerPermissions() { + $a = $this->reducerPermissions; + $languages = $this->wire('languages'); + if($languages && $this->wire('modules')->isInstalled('LanguageSupportFields')) { + foreach($languages as $language) { + $a[] = "page-edit-lang-$language->name"; + } + } + foreach($this->wire('roles') as $role) { + $a[] = "user-admin-$role->name"; + } + $a = array_flip($a); + foreach($a as $k => $v) $a[$k] = $k; + return $a; + } + + /** * Return array of permission names that are delegated to another when not installed * diff --git a/wire/modules/Fieldtype/FieldtypePassword.module b/wire/modules/Fieldtype/FieldtypePassword.module index ea4d078a..001b6b4b 100644 --- a/wire/modules/Fieldtype/FieldtypePassword.module +++ b/wire/modules/Fieldtype/FieldtypePassword.module @@ -34,9 +34,14 @@ class FieldtypePassword extends Fieldtype { /** * Return the associated Inputfield + * + * @param Page $page + * @param Field $field + * @return InputfieldPassword * */ public function getInputfield(Page $page, Field $field) { + /** @var InputfieldPassword $inputfield */ $inputfield = $this->modules->get('InputfieldPassword'); $inputfield->class = $this->className(); $inputfield->setPage($page); @@ -45,6 +50,9 @@ class FieldtypePassword extends Fieldtype { /** * Return all Fieldtypes derived from FieldtypeText, which we will consider compatible + * + * @param Field $field + * @return null|array * */ public function ___getCompatibleFieldtypes(Field $field) { @@ -53,6 +61,11 @@ class FieldtypePassword extends Fieldtype { /** * Sanitize value for runtime + * + * @param Page $page + * @param Field $field + * @param Password|string $value + * @return Password * */ public function sanitizeValue(Page $page, Field $field, $value) { @@ -72,6 +85,10 @@ class FieldtypePassword extends Fieldtype { /** * Get a blank password item object + * + * @param Page $page + * @param Field $field + * @return Password * */ public function getBlankValue(Page $page, Field $field) { @@ -124,6 +141,9 @@ class FieldtypePassword extends Fieldtype { /** * Return the database schema in specified format + * + * @param Field $field + * @return array * */ public function getDatabaseSchema(Field $field) { @@ -138,6 +158,9 @@ class FieldtypePassword extends Fieldtype { /** * Return the fields required to configure an instance of FieldtypePassword + * + * @param Field $field + * @return InputfieldWrapper * */ public function ___getConfigInputfields(Field $field) { diff --git a/wire/modules/Process/ProcessPageType/ProcessPageType.module b/wire/modules/Process/ProcessPageType/ProcessPageType.module index a7c0d640..f71673f3 100644 --- a/wire/modules/Process/ProcessPageType/ProcessPageType.module +++ b/wire/modules/Process/ProcessPageType/ProcessPageType.module @@ -167,7 +167,7 @@ class ProcessPageType extends Process implements ConfigurableModule, WirePageEdi $templateID = (int) $this->wire('input')->get('templates_id'); if(!$templateID) $templateID = (int) $this->wire('session')->get($this->className() . 'TemplatesID'); $selector = $templateID ? "templates_id=$templateID, " : ""; - return $this->renderList($selector . "limit=25, status<" . Page::statusMax); + return $this->renderList($selector . "limit=100, status<" . Page::statusMax); } /** diff --git a/wire/modules/Process/ProcessPermission/ProcessPermission.module b/wire/modules/Process/ProcessPermission/ProcessPermission.module index 153c83a3..6c4bf561 100644 --- a/wire/modules/Process/ProcessPermission/ProcessPermission.module +++ b/wire/modules/Process/ProcessPermission/ProcessPermission.module @@ -48,16 +48,25 @@ class ProcessPermission extends ProcessPageType { $optionalPermissions = $this->wire('permissions')->getOptionalPermissions(); if(count($optionalPermissions)) { + $reducerPermissions = $this->wire('permissions')->getReducerPermissions(); $f = $this->wire('modules')->get('InputfieldCheckboxes'); $f->name = 'install_permissions'; $f->label = $this->_('Check the box next to each optional permission you would like to install.'); $f->table = true; + foreach($optionalPermissions as $name => $label) { - $f->addOption($name, "$name|$label"); + $displayName = $name; + if(isset($reducerPermissions[$name])) $displayName .= '*'; + $f->addOption($name, "$displayName|$label"); } + $f->notes = '*' . + $this->_('When installed, user must have this permission to complete described task.') . ' ' . + $this->_('When NOT installed, permission is assumed if user already has edit access to described resource.') . ' ' . + $this->_('As a result, if installed, this permission may remove existing access until it is assigned to roles.'); + $fieldset->add($f); $button = $this->wire('modules')->get('InputfieldSubmit'); diff --git a/wire/modules/Process/ProcessProfile/ProcessProfile.module b/wire/modules/Process/ProcessProfile/ProcessProfile.module index ee032193..5b58bf22 100644 --- a/wire/modules/Process/ProcessProfile/ProcessProfile.module +++ b/wire/modules/Process/ProcessProfile/ProcessProfile.module @@ -168,6 +168,8 @@ class ProcessProfile extends Process implements ConfigurableModule, WirePageEdit if(strlen($inputfield->value)) { $passRequiredInputfields[] = $inputfield; } + } else if($field->name === 'tfa_type') { + $passRequiredInputfields[] = $inputfield; } $fieldset->add($inputfield); @@ -264,6 +266,7 @@ class ProcessProfile extends Process implements ConfigurableModule, WirePageEdit } $v = $user->get($field->name); + if($field->type instanceof FieldtypeModule) $v = "$v"; if($inputfield->isChanged() || $v !== $value) { diff --git a/wire/modules/Process/ProcessTemplate/ProcessTemplateExportImport.php b/wire/modules/Process/ProcessTemplate/ProcessTemplateExportImport.php index e05a78f6..e767b66d 100644 --- a/wire/modules/Process/ProcessTemplate/ProcessTemplateExportImport.php +++ b/wire/modules/Process/ProcessTemplate/ProcessTemplateExportImport.php @@ -259,8 +259,8 @@ class ProcessTemplateExportImport extends Wire { $attr = array('checked' => 'checked'); } - if($new) $optionValue = "$property|$newValue"; - else $optionValue = "$property|$oldValue|$newValue"; + if($new) $optionValue = " $property|$newValue"; + else $optionValue = " $property|$oldValue|$newValue"; $f->addOption($property, $optionValue, $attr); }