summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-01-11 17:15:14 +0100
committerGitHub <noreply@github.com>2024-01-11 17:15:14 +0100
commitd8e625f2081b4af9ffe535734af689e7b45cd794 (patch)
tree0df01ec07df3067d361e7f8b16262e433ee723d3 /core
parent10b9b20da50f74e3f3f04ce920aed0240e092cf2 (diff)
parente884ffd4c8046c3fd991ce56eee76b369aabc338 (diff)
downloadnextcloud-server-d8e625f2081b4af9ffe535734af689e7b45cd794.tar.gz
nextcloud-server-d8e625f2081b4af9ffe535734af689e7b45cd794.zip
Merge pull request #42585 from nextcloud/enh/add-rich-object-support-to-setupchecks
Add RichObject support for SetupCheck descriptions
Diffstat (limited to 'core')
-rw-r--r--core/Command/SetupChecks.php27
-rw-r--r--core/js/setupchecks.js25
2 files changed, 52 insertions, 0 deletions
diff --git a/core/Command/SetupChecks.php b/core/Command/SetupChecks.php
index bd76a9d1e65..e6e54fbcf22 100644
--- a/core/Command/SetupChecks.php
+++ b/core/Command/SetupChecks.php
@@ -45,6 +45,29 @@ class SetupChecks extends Base {
;
}
+ /**
+ * @TODO move this method to a common service used by notifications, activity and this command
+ * @throws \InvalidArgumentException if a parameter has no name or no type
+ */
+ private function richToParsed(string $message, array $parameters): string {
+ $placeholders = [];
+ $replacements = [];
+ foreach ($parameters as $placeholder => $parameter) {
+ $placeholders[] = '{' . $placeholder . '}';
+ foreach (['name','type'] as $requiredField) {
+ if (!isset($parameter[$requiredField]) || !is_string($parameter[$requiredField])) {
+ throw new \InvalidArgumentException("Invalid rich object, {$requiredField} field is missing");
+ }
+ }
+ $replacements[] = match($parameter['type']) {
+ 'user' => '@' . $parameter['name'],
+ 'file' => $parameter['path'] ?? $parameter['name'],
+ default => $parameter['name'],
+ };
+ }
+ return str_replace($placeholders, $replacements, $message);
+ }
+
protected function execute(InputInterface $input, OutputInterface $output): int {
$results = $this->setupCheckManager->runAll();
switch ($input->getOption('output')) {
@@ -70,6 +93,10 @@ class SetupChecks extends Base {
};
$verbosity = ($check->getSeverity() === 'error' ? OutputInterface::VERBOSITY_QUIET : OutputInterface::VERBOSITY_NORMAL);
$description = $check->getDescription();
+ $descriptionParameters = $check->getDescriptionParameters();
+ if ($description !== null && $descriptionParameters !== null) {
+ $description = $this->richToParsed($description, $descriptionParameters);
+ }
$output->writeln(
"\t\t".
($styleTag !== null ? "<{$styleTag}>" : '').
diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js
index 837482090b9..9eacb1b137a 100644
--- a/core/js/setupchecks.js
+++ b/core/js/setupchecks.js
@@ -317,6 +317,28 @@
return deferred.promise();
},
+ /**
+ * @param message The message string containing placeholders.
+ * @param parameters An object with keys as placeholders and values as their replacements.
+ *
+ * @return The message with placeholders replaced by values.
+ */
+ richToParsed: function (message, parameters) {
+ for (var [placeholder, parameter] of Object.entries(parameters)) {
+ var replacement;
+ if (parameter.type === 'user') {
+ replacement = '@' + parameter.name;
+ } else if (parameter.type === 'file') {
+ replacement = parameter.path || parameter.name;
+ } else {
+ replacement = parameter.name;
+ }
+ message = message.replace('{' + placeholder + '}', replacement);
+ }
+
+ return message;
+ },
+
addGenericSetupCheck: function(data, check, messages) {
var setupCheck = data[check] || { pass: true, description: '', severity: 'info', linkToDoc: null}
@@ -328,6 +350,9 @@
}
var message = setupCheck.description;
+ if (setupCheck.descriptionParameters) {
+ message = this.richToParsed(message, setupCheck.descriptionParameters);
+ }
if (setupCheck.linkToDoc) {
message += ' ' + t('core', 'For more details see the {linkstart}documentation ↗{linkend}.')
.replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + setupCheck.linkToDoc + '">')