Skip to content

Commit

Permalink
Merge pull request #2721 from LibreSign/backport/2720/stable28
Browse files Browse the repository at this point in the history
[stable28] chore: Set default signature method
  • Loading branch information
vitormattos authored Apr 12, 2024
2 parents 2d4942f + 74a2ed2 commit 7491e8e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
21 changes: 8 additions & 13 deletions lib/Service/IdentifyMethod/AbstractIdentifyMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ abstract class AbstractIdentifyMethod implements IIdentifyMethod {
* @var string[]
*/
public array $availableSignatureMethods = [];
protected string $defaultSignatureMethod = '';
/**
* @var AbstractSignatureMethod[]
*/
Expand Down Expand Up @@ -315,23 +316,17 @@ private function loadSavedSettings(): void {
}
return $carry;
}, []);
$enabled = false;
foreach ($this->availableSignatureMethods as $signatureMethodName) {
$this->signatureMethods[$signatureMethodName] =
$this->getEmptyInstanceOfSignatureMethodByName($signatureMethodName);
}
if (!isset($this->settings['signatureMethods']) || !is_array($this->settings['signatureMethods'])) {
return;
}
foreach ($this->settings['signatureMethods'] as $signatureMethodName => $settings) {
if (!in_array($signatureMethodName, $this->availableSignatureMethods)) {
unset($this->settings['signatureMethods'][$signatureMethodName]);
continue;
if (isset($this->settings[$signatureMethodName]['enabled']) && $this->settings[$signatureMethodName]['enabled']) {
$this->signatureMethods[$signatureMethodName]->enable();
$enabled = true;
}
$signatureMethod = $this->getEmptyInstanceOfSignatureMethodByName($signatureMethodName);
if (isset($settings['enabled']) && $settings['enabled']) {
$signatureMethod->enable();
}
$this->signatureMethods[$signatureMethodName] = $signatureMethod;
}
if (!$enabled && $this->defaultSignatureMethod) {
$this->signatureMethods[$this->defaultSignatureMethod]->enable();
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/Service/IdentifyMethod/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Account extends AbstractIdentifyMethod {
ISignatureMethod::SIGNATURE_METHOD_EMAIL_TOKEN,
ISignatureMethod::SIGNATURE_METHOD_PASSWORD,
];
public string $defaultSignatureMethod = ISignatureMethod::SIGNATURE_METHOD_PASSWORD;
public function __construct(
protected IdentifyService $identifyService,
private IUserManager $userManager,
Expand Down
1 change: 1 addition & 0 deletions lib/Service/IdentifyMethod/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Email extends AbstractIdentifyMethod {
ISignatureMethod::SIGNATURE_METHOD_CLICK_TO_SIGN,
ISignatureMethod::SIGNATURE_METHOD_EMAIL_TOKEN,
];
public string $defaultSignatureMethod = ISignatureMethod::SIGNATURE_METHOD_EMAIL_TOKEN;
public function __construct(
protected IdentifyService $identifyService,
private IdentifyMethodMapper $identifyMethodMapper,
Expand Down
24 changes: 12 additions & 12 deletions tests/integration/features/admin/initial_state.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Feature: admin/initial_state
Then the response should contain the initial state "libresign-identify_methods" with the following values:
"""
[
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":false,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"}}}
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":true,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":true,"label":"Email token","name":"emailToken"}}}
]
"""

Expand All @@ -20,8 +20,8 @@ Feature: admin/initial_state
And the response should contain the initial state "libresign-identify_methods" with the following values:
"""
[
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":false,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"}}}
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":true,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":true,"label":"Email token","name":"emailToken"}}}
]
"""

Expand All @@ -34,8 +34,8 @@ Feature: admin/initial_state
And the response should contain the initial state "libresign-identify_methods" with the following values:
"""
[
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":false,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"}}}
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":true,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":true,"label":"Email token","name":"emailToken"}}}
]
"""

Expand All @@ -48,8 +48,8 @@ Feature: admin/initial_state
And the response should contain the initial state "libresign-identify_methods" with the following values:
"""
[
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":false,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"}}}
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":true,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":true,"label":"Email token","name":"emailToken"}}}
]
"""

Expand All @@ -62,8 +62,8 @@ Feature: admin/initial_state
And the response should contain the initial state "libresign-identify_methods" with the following values:
"""
[
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":false,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"}}}
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":true,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":true,"label":"Email token","name":"emailToken"}}}
]
"""

Expand All @@ -75,7 +75,7 @@ Feature: admin/initial_state
And the response should contain the initial state "libresign-identify_methods" with the following values:
"""
[
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":false,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":false,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"}}}
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":true,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":false,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":true,"label":"Email token","name":"emailToken"}}}
]
"""
4 changes: 2 additions & 2 deletions tests/integration/features/page/index.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: page/sign_identify_default
And the response should contain the initial state "libresign-identify_methods" with the following values:
"""
[
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":false,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"}}}
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":true,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":true,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":true,"label":"Email token","name":"emailToken"}}}
]
"""

0 comments on commit 7491e8e

Please sign in to comment.