Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(admin-delegation): extract data collection logic to separate…
… methods

- Extract collectDelegationData() method to eliminate code duplication
- Add formatSettingsData() method for consistent data formatting
- Add outputPlainFormat() method to separate concerns
- Add proper empty state handling with user-friendly message

Signed-off-by: Misha M.-Kupriyanov <[email protected]>
  • Loading branch information
printminion-co authored and backportbot[bot] committed Sep 30, 2025
commit d78e2887d16e25ed916882db8845f76ffbacb079
88 changes: 66 additions & 22 deletions apps/settings/lib/Command/AdminDelegation/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,87 @@ protected function configure(): void {
protected function execute(InputInterface $input, OutputInterface $output): int {
$io = new SymfonyStyle($input, $output);

$this->outputPlainFormat($io);
// Collect delegation data
$delegationData = $this->collectDelegationData();

// Handle empty results
if (empty($delegationData)) {
$io->info('No delegated settings found.');
return 0;
}

$this->outputPlainFormat($io, $delegationData);

return 0;
}

/**
* Output data in plain table format
* Collect all delegation data in a structured format
*/
private function outputPlainFormat(SymfonyStyle $io): void {
$io->title('Current delegations');

private function collectDelegationData(): array {
$result = [];
$sections = $this->settingManager->getAdminSections();
$headers = ['Name', 'SettingId', 'Delegated to groups'];

foreach ($sections as $sectionPriority) {
foreach ($sectionPriority as $section) {
$sectionSettings = $this->settingManager->getAdminSettings($section->getId());
$sectionSettings = array_reduce($sectionSettings, [$this, 'getDelegatedSettings'], []);
if (empty($sectionSettings)) {
$delegatedSettings = array_reduce($sectionSettings, [$this, 'getDelegatedSettings'], []);

if (empty($delegatedSettings)) {
continue;
}

$io->section('Section: ' . $section->getID());
$io->table($headers, array_map(function (IDelegatedSettings $setting) use ($section) {
$className = get_class($setting);
$groups = array_map(
static fn (AuthorizedGroup $group) => $group->getGroupId(),
$this->authorizedGroupService->findExistingGroupsForClass($className)
);
natsort($groups);
return [
$setting->getName() ?: 'Global',
$className,
implode(', ', $groups),
];
}, $sectionSettings));
$result[] = [
'id' => $section->getID(),
'name' => $section->getName() ?: $section->getID(),
'settings' => $this->formatSettingsData($delegatedSettings)
];
}
}

return $result;
}

/**
* Format settings data for consistent output
*/
private function formatSettingsData(array $settings): array {
return array_map(function (IDelegatedSettings $setting) {
$className = get_class($setting);
$groups = array_map(
static fn (AuthorizedGroup $group) => $group->getGroupId(),
$this->authorizedGroupService->findExistingGroupsForClass($className)
);
natsort($groups);

return [
'name' => $setting->getName() ?: 'Global',
'className' => $className,
'delegatedGroups' => $groups,
];
}, $settings);
}

/**
* Output data in plain table format
*/
private function outputPlainFormat(SymfonyStyle $io, array $data): void {
$io->title('Current delegations');
$headers = ['Name', 'SettingId', 'Delegated to groups'];

foreach ($data as $section) {
$io->section('Section: ' . $section['id']);

$tableData = array_map(static function (array $setting) {
return [
$setting['name'],
$setting['className'],
implode(', ', $setting['delegatedGroups']),
];
}, $section['settings']);

$io->table($headers, $tableData);
}
}

/**
Expand Down