-
Notifications
You must be signed in to change notification settings - Fork 210
feat: exchange cloud ID #4417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
redblom
wants to merge
2
commits into
nextcloud:main
Choose a base branch
from
sara-nl:invite-for-cloudid-exchange
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: exchange cloud ID #4417
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Contacts\Command; | ||
|
|
||
| use OCA\Contacts\AppInfo\Application; | ||
| use OCA\Contacts\ConfigLexicon; | ||
| use OCA\Contacts\Service\FederatedInvitesService; | ||
| use OCP\IAppConfig; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Helper\Table; | ||
| use Symfony\Component\Console\Input\InputArgument; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| /** | ||
| * Manage OCM invite configuration. | ||
| * | ||
| * Usage: | ||
| * occ contacts:ocm-invites-config | ||
| * occ contacts:ocm-invites-config <key> | ||
| * occ contacts:ocm-invites-config <key> <value> | ||
| * | ||
| * Boolean values accept on/off, true/false, 1/0, and yes/no. | ||
| */ | ||
| class OcmInvitesConfig extends Command { | ||
| public function __construct( | ||
| private IAppConfig $appConfig, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| #[\Override] | ||
| protected function configure(): void { | ||
| $supportedOptions = implode(', ', $this->getSupportedOptions()); | ||
| $help = <<<HELP | ||
| The <info>%command.name%</info> command reads and writes Contacts OCM invite settings. | ||
|
|
||
| Supported keys: | ||
| {$supportedOptions} | ||
|
|
||
| Key info: | ||
| <info>ocm_invites_enabled</info> - If set to true then the capability to send and accept invitations to exchange contact info is enabled in the app - bool, default false | ||
| <info>ocm_invites_optional_mail</info> - If set to true then sending an invitation by email is optional - bool, default false | ||
| <info>ocm_invites_cc_sender</info> - If set to true then the option to send a copy of the invitation to the sender is displayed - bool, default true | ||
| <info>ocm_invites_encoded_copy_button</info> - If set to true then the button to copy the encoded invitation is displayed - bool, default false | ||
| <info>ocm_invites_disable_ssrf_guard</info> - If set to true SSRF guard will be turned off. Warning: This is for development/testing purposes only! | ||
| In production environments the value of this key should always be false - bool, default false | ||
| <info>mesh_providers_service</info> - The url that returns the list of mesh providers that will be displayed on the WAYF page - string, default empty | ||
|
|
||
| Boolean values accept: on/off, true/false, 1/0, yes/no. | ||
|
|
||
| Examples: | ||
| <info>occ %command.name%</info> | ||
| <info>occ %command.name% ocm_invites_enabled on</info> | ||
| <info>occ %command.name% mesh_providers_service "https://mesh.example"</info> | ||
|
|
||
| HELP; | ||
|
|
||
| $this | ||
| ->setName('contacts:ocm-invites-config') | ||
| ->setDescription('Manage OCM invite configuration.') | ||
| ->addArgument( | ||
| 'option', | ||
| InputArgument::OPTIONAL, | ||
| 'Config key to read or write. Omit to list supported keys.', | ||
| ) | ||
| ->addArgument( | ||
| 'value', | ||
| InputArgument::OPTIONAL, | ||
| 'Value to write. Omit to read the current value.', | ||
| ) | ||
| ->setHelp($help); | ||
| } | ||
|
|
||
| #[\Override] | ||
| protected function execute(InputInterface $input, OutputInterface $output): int { | ||
| $option = $input->getArgument('option'); | ||
| $value = $input->getArgument('value'); | ||
|
|
||
| if ($option === null) { | ||
| return $this->listAll($output); | ||
| } | ||
|
|
||
| if (!in_array($option, $this->getSupportedOptions(), true)) { | ||
| $output->writeln(sprintf( | ||
| '<error>Unknown OCM invite config key "%s". Allowed: %s.</error>', | ||
| $option, | ||
| implode(', ', $this->getSupportedOptions()), | ||
| )); | ||
| return self::FAILURE; | ||
| } | ||
|
|
||
| if ($value === null) { | ||
| $output->writeln($this->getCurrentValue($option)); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| if ($option === ConfigLexicon::MESH_PROVIDERS_SERVICE) { | ||
| $normalised = trim($value); | ||
| $current = $this->appConfig->getValueString(Application::APP_ID, $option); | ||
| if ($current === $normalised) { | ||
| $output->writeln(sprintf('%s is already "%s".', $option, $normalised)); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| $this->appConfig->setValueString(Application::APP_ID, $option, $normalised); | ||
| $output->writeln(sprintf('%s: "%s"', $option, $normalised)); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| $parsed = $this->parseBool($value); | ||
| if ($parsed === null) { | ||
| $output->writeln(sprintf( | ||
| '<error>Cannot parse "%s" as boolean. Use on/off, true/false, 1/0, or yes/no.</error>', | ||
| $value, | ||
| )); | ||
| return self::INVALID; | ||
| } | ||
|
|
||
| $current = $this->appConfig->getValueBool(Application::APP_ID, $option); | ||
| if ($current === $parsed) { | ||
| $output->writeln(sprintf('%s is already %s.', $option, $this->formatBool($parsed))); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| $this->appConfig->setValueBool(Application::APP_ID, $option, $parsed); | ||
| $output->writeln(sprintf('%s: %s', $option, $this->formatBool($parsed))); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| private function listAll(OutputInterface $output): int { | ||
| $table = new Table($output); | ||
| $table->setHeaders(['option', 'type', 'value']); | ||
| foreach ($this->getSupportedOptions() as $key) { | ||
| $table->addRow([ | ||
| $key, | ||
| $this->isBooleanOption($key) ? 'bool' : 'string', | ||
| $this->getCurrentValue($key), | ||
| ]); | ||
| } | ||
| $table->render(); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| private function getSupportedOptions(): array { | ||
| return [ | ||
| ConfigLexicon::OCM_INVITES_ENABLED, | ||
| ...FederatedInvitesService::OCM_INVITES_BOOL_KEYS, | ||
| ConfigLexicon::MESH_PROVIDERS_SERVICE, | ||
| ]; | ||
| } | ||
|
|
||
| private function isBooleanOption(string $option): bool { | ||
| return in_array($option, [ | ||
| ConfigLexicon::OCM_INVITES_ENABLED, | ||
| ...FederatedInvitesService::OCM_INVITES_BOOL_KEYS, | ||
| ], true); | ||
| } | ||
|
|
||
| private function getCurrentValue(string $option): string { | ||
| if ($this->isBooleanOption($option)) { | ||
| return $this->formatBool($this->appConfig->getValueBool(Application::APP_ID, $option)); | ||
| } | ||
|
|
||
| return $this->appConfig->getValueString(Application::APP_ID, $option); | ||
| } | ||
|
|
||
| private function formatBool(bool $value): string { | ||
| return $value ? 'on' : 'off'; | ||
| } | ||
|
|
||
| private function parseBool(string $raw): ?bool { | ||
| $normalised = strtolower(trim($raw)); | ||
| if (in_array($normalised, ['true', '1', 'on', 'yes'], true)) { | ||
| return true; | ||
| } | ||
| if (in_array($normalised, ['false', '0', 'off', 'no'], true)) { | ||
| return false; | ||
| } | ||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Contacts; | ||
|
|
||
| use OCP\Config\Lexicon\Entry; | ||
| use OCP\Config\Lexicon\ILexicon; | ||
| use OCP\Config\Lexicon\Strictness; | ||
| use OCP\Config\ValueType; | ||
| use OCP\IAppConfig; | ||
|
|
||
| /** | ||
| * Config Lexicon for contacts. | ||
| * | ||
| * Please add and manage your config keys in this file and keep the | ||
| * Lexicon up to date. | ||
| * | ||
| * {@see ILexicon} | ||
| */ | ||
| class ConfigLexicon implements ILexicon { | ||
| public const OCM_INVITES_ENABLED = 'ocm_invites_enabled'; | ||
| public const OCM_INVITES_OPTIONAL_MAIL = 'ocm_invites_optional_mail'; | ||
| public const OCM_INVITES_CC_SENDER = 'ocm_invites_cc_sender'; | ||
| public const OCM_INVITES_ENCODED_COPY_BUTTON = 'ocm_invites_encoded_copy_button'; | ||
| public const OCM_INVITES_DISABLE_SSRF_GUARD = 'ocm_invites_disable_ssrf_guard'; | ||
| public const MESH_PROVIDERS_SERVICE = 'mesh_providers_service'; | ||
| public const WAYF_ENDPOINT = 'wayf_endpoint'; | ||
| public const FEDERATIONS_CACHE = 'federations_cache'; | ||
|
|
||
| #[\Override] | ||
| public function getStrictness(): Strictness { | ||
| return Strictness::NOTICE; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getAppConfigs(): array { | ||
| return [ | ||
| new Entry( | ||
| self::OCM_INVITES_ENABLED, | ||
| ValueType::BOOL, | ||
| defaultRaw: false, | ||
| definition: 'Whether OCM invites for contacts are enabled.', | ||
| lazy: true, | ||
| ), | ||
| new Entry( | ||
| self::OCM_INVITES_OPTIONAL_MAIL, | ||
| ValueType::BOOL, | ||
| defaultRaw: false, | ||
| definition: 'Whether the recipient email field is optional when creating an OCM invite.', | ||
| lazy: true, | ||
| ), | ||
| new Entry( | ||
| self::OCM_INVITES_CC_SENDER, | ||
| ValueType::BOOL, | ||
| defaultRaw: true, | ||
| definition: 'Whether the sender is CC-ed on the OCM invite email.', | ||
| lazy: true, | ||
| ), | ||
| new Entry( | ||
| self::OCM_INVITES_ENCODED_COPY_BUTTON, | ||
| ValueType::BOOL, | ||
| defaultRaw: false, | ||
| definition: 'Whether the invite email "Open invite" button uses the encoded WAYF URL instead of the raw token.', | ||
| lazy: true, | ||
| ), | ||
| new Entry( | ||
| self::OCM_INVITES_DISABLE_SSRF_GUARD, | ||
| ValueType::BOOL, | ||
| defaultRaw: false, | ||
| definition: 'Unsafe development override that disables private-host and localhost checks for OCM invite discovery.', | ||
| lazy: true, | ||
| ), | ||
| new Entry( | ||
| self::MESH_PROVIDERS_SERVICE, | ||
| ValueType::STRING, | ||
| defaultRaw: '', | ||
| definition: 'Space-separated list of mesh provider service URLs used for WAYF discovery.', | ||
| lazy: true, | ||
| ), | ||
| new Entry( | ||
| self::WAYF_ENDPOINT, | ||
| ValueType::STRING, | ||
| defaultRaw: '', | ||
| definition: 'Optional override for the base WAYF endpoint used in invite links.', | ||
| note: 'If empty, the app route is used at runtime.', | ||
| lazy: true, | ||
| ), | ||
| new Entry( | ||
| self::FEDERATIONS_CACHE, | ||
| ValueType::ARRAY, | ||
| defaultRaw: [], | ||
| definition: 'Internal cron-maintained cache for discovered federations and expiry metadata.', | ||
| flags: IAppConfig::FLAG_SENSITIVE, | ||
| lazy: true, | ||
| ), | ||
| ]; | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function getUserConfigs(): array { | ||
| return []; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want a command for that? Why is the already existing command to set config values not enough?
If the reason is for documentation, then I think we should drop the custom command and simply extend the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm maybe we misunderstood your suggestion here. Anyway, a dedicated command (with documentation) seemed useful to us.
So is extending the docs the preferred way then?