Skip to content

Commit

Permalink
plugin: Disable Multi-intance Support for 2FA plugin
Browse files Browse the repository at this point in the history
Official 2FA Plugin  doesn't support multiple instances at the moment due to how the
plugin loads config info for versions <= 0.3
  • Loading branch information
protich committed Sep 12, 2022
1 parent f8f5d3d commit 2318714
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
37 changes: 37 additions & 0 deletions include/class.plugin.php
Expand Up @@ -592,6 +592,43 @@ function useModalConfig() {
}


/*
* canAddInstance
*
* Multi-instance plugins can add unlimited instances, otherwise only
* one plugin is allowed.
*
*/
function canAddInstance() {

if (!$this->isMultiInstance()
&& $this->getNumInstances())
return false;

// TODO: To be removed down the road. 2FA Plugi doesn't support
// multiple instances at the moment due to how the plugin loads
// config info for versions <= 0.3
if (is_a($this, 'Auth2FAPlugin')
&& $this->getVersion() <= 0.3)
return false;

return true;
}


/*
*
* isMultiInstance
*
* Indicates if the plugin supports multiple instances
* Default is true unless overwritten downstream.
*
*/

function isMultiInstance() {
return true;
}

/*
* getNewInstanceOptions
*
Expand Down
2 changes: 1 addition & 1 deletion include/staff/templates/plugin-instances.tmpl.php
Expand Up @@ -51,7 +51,7 @@
</ul>
</div>
<?php
} else {
} elseif ($plugin->canAddInstance()) {
$href = sprintf($modal
? '#plugins/%d/instances/add'
: 'plugins.php?id=%d&a=add-instance#instances',
Expand Down
8 changes: 0 additions & 8 deletions include/upgrader/streams/core/c37e1656-e2b4e5cb.task.php
Expand Up @@ -47,14 +47,6 @@ function run($time) {
->filter(['backend' => $p::$id])
->update(['backend' => $p->getBkId()]);
}
// 2fa backends
foreach (Staff2FABackend::allRegistered() as $p) {
if ($p::$id && $p->getBkId() == $p::$id)
continue;
ConfigItems::objects()
->filter(['default_2fa' => $p::$id])
->update(['default_2fa' => $p->getBkId()]);
}
// Password Policies
$config = $ost->getConfig();
foreach (PasswordPolicy::allActivePolicies() as $p) {
Expand Down

0 comments on commit 2318714

Please sign in to comment.