1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 17:54:44 +02:00

Various minor module updates

This commit is contained in:
Ryan Cramer
2018-08-02 12:31:41 -04:00
parent fb9d1458a8
commit 730b61a3c3
6 changed files with 87 additions and 5 deletions

View File

@@ -46,6 +46,25 @@ class Permissions extends PagesType {
'user-admin-all' => 'user-admin', '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? * Does the system have a permission with the given name?
* *
@@ -158,7 +177,9 @@ class Permissions extends PagesType {
$languages = $this->wire('languages'); $languages = $this->wire('languages');
if($languages) { if($languages) {
$label = $this->_('Edit fields on a page in language: %s'); $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) { foreach($languages as $language) {
if($language->isDefault()) continue; if($language->isDefault()) continue;
$a["page-edit-lang-$language->name"] = sprintf($label, $language->name); $a["page-edit-lang-$language->name"] = sprintf($label, $language->name);
@@ -180,6 +201,32 @@ class Permissions extends PagesType {
return $a; 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 * Return array of permission names that are delegated to another when not installed
* *

View File

@@ -35,8 +35,13 @@ class FieldtypePassword extends Fieldtype {
/** /**
* Return the associated Inputfield * Return the associated Inputfield
* *
* @param Page $page
* @param Field $field
* @return InputfieldPassword
*
*/ */
public function getInputfield(Page $page, Field $field) { public function getInputfield(Page $page, Field $field) {
/** @var InputfieldPassword $inputfield */
$inputfield = $this->modules->get('InputfieldPassword'); $inputfield = $this->modules->get('InputfieldPassword');
$inputfield->class = $this->className(); $inputfield->class = $this->className();
$inputfield->setPage($page); $inputfield->setPage($page);
@@ -46,6 +51,9 @@ class FieldtypePassword extends Fieldtype {
/** /**
* Return all Fieldtypes derived from FieldtypeText, which we will consider compatible * Return all Fieldtypes derived from FieldtypeText, which we will consider compatible
* *
* @param Field $field
* @return null|array
*
*/ */
public function ___getCompatibleFieldtypes(Field $field) { public function ___getCompatibleFieldtypes(Field $field) {
return null; return null;
@@ -54,6 +62,11 @@ class FieldtypePassword extends Fieldtype {
/** /**
* Sanitize value for runtime * Sanitize value for runtime
* *
* @param Page $page
* @param Field $field
* @param Password|string $value
* @return Password
*
*/ */
public function sanitizeValue(Page $page, Field $field, $value) { public function sanitizeValue(Page $page, Field $field, $value) {
@@ -73,6 +86,10 @@ class FieldtypePassword extends Fieldtype {
/** /**
* Get a blank password item object * Get a blank password item object
* *
* @param Page $page
* @param Field $field
* @return Password
*
*/ */
public function getBlankValue(Page $page, Field $field) { public function getBlankValue(Page $page, Field $field) {
$item = $this->wire(new Password()); $item = $this->wire(new Password());
@@ -125,6 +142,9 @@ class FieldtypePassword extends Fieldtype {
/** /**
* Return the database schema in specified format * Return the database schema in specified format
* *
* @param Field $field
* @return array
*
*/ */
public function getDatabaseSchema(Field $field) { public function getDatabaseSchema(Field $field) {
$schema = parent::getDatabaseSchema($field); $schema = parent::getDatabaseSchema($field);
@@ -139,6 +159,9 @@ class FieldtypePassword extends Fieldtype {
/** /**
* Return the fields required to configure an instance of FieldtypePassword * Return the fields required to configure an instance of FieldtypePassword
* *
* @param Field $field
* @return InputfieldWrapper
*
*/ */
public function ___getConfigInputfields(Field $field) { public function ___getConfigInputfields(Field $field) {
$inputfields = parent::___getConfigInputfields($field); $inputfields = parent::___getConfigInputfields($field);

View File

@@ -167,7 +167,7 @@ class ProcessPageType extends Process implements ConfigurableModule, WirePageEdi
$templateID = (int) $this->wire('input')->get('templates_id'); $templateID = (int) $this->wire('input')->get('templates_id');
if(!$templateID) $templateID = (int) $this->wire('session')->get($this->className() . 'TemplatesID'); if(!$templateID) $templateID = (int) $this->wire('session')->get($this->className() . 'TemplatesID');
$selector = $templateID ? "templates_id=$templateID, " : ""; $selector = $templateID ? "templates_id=$templateID, " : "";
return $this->renderList($selector . "limit=25, status<" . Page::statusMax); return $this->renderList($selector . "limit=100, status<" . Page::statusMax);
} }
/** /**

View File

@@ -48,16 +48,25 @@ class ProcessPermission extends ProcessPageType {
$optionalPermissions = $this->wire('permissions')->getOptionalPermissions(); $optionalPermissions = $this->wire('permissions')->getOptionalPermissions();
if(count($optionalPermissions)) { if(count($optionalPermissions)) {
$reducerPermissions = $this->wire('permissions')->getReducerPermissions();
$f = $this->wire('modules')->get('InputfieldCheckboxes'); $f = $this->wire('modules')->get('InputfieldCheckboxes');
$f->name = 'install_permissions'; $f->name = 'install_permissions';
$f->label = $this->_('Check the box next to each optional permission you would like to install.'); $f->label = $this->_('Check the box next to each optional permission you would like to install.');
$f->table = true; $f->table = true;
foreach($optionalPermissions as $name => $label) { 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); $fieldset->add($f);
$button = $this->wire('modules')->get('InputfieldSubmit'); $button = $this->wire('modules')->get('InputfieldSubmit');

View File

@@ -168,6 +168,8 @@ class ProcessProfile extends Process implements ConfigurableModule, WirePageEdit
if(strlen($inputfield->value)) { if(strlen($inputfield->value)) {
$passRequiredInputfields[] = $inputfield; $passRequiredInputfields[] = $inputfield;
} }
} else if($field->name === 'tfa_type') {
$passRequiredInputfields[] = $inputfield;
} }
$fieldset->add($inputfield); $fieldset->add($inputfield);
@@ -264,6 +266,7 @@ class ProcessProfile extends Process implements ConfigurableModule, WirePageEdit
} }
$v = $user->get($field->name); $v = $user->get($field->name);
if($field->type instanceof FieldtypeModule) $v = "$v";
if($inputfield->isChanged() || $v !== $value) { if($inputfield->isChanged() || $v !== $value) {