Skip to content

Conversation

@printminion-co
Copy link
Contributor

@printminion-co printminion-co commented Sep 22, 2025

Overview

This PR enhances the occ admin-delegation:show command by adding support for JSON output formats, providing a more programmatic way to access delegation information.

Changes Made

  • Enhanced Command Options: Added --output option to the admin-delegation:show command with support for:

    • plain (default) - existing table format
    • json - compact JSON output
    • json_pretty - formatted JSON output
  • New Import: Added Symfony\Component\Console\Input\InputOption import to support the new option parameter

  • Improved Data Structure: Implemented structured JSON output that includes:

    • Section ID and metadata
    • Setting names and class names
    • Authorized groups for each delegated setting
    • Proper nesting of sections and their associated settings

Usage

# Default table output (unchanged)
occ admin-delegation:show

# JSON output
occ admin-delegation:show --output=json

# Pretty-printed JSON output  
occ admin-delegation:show --output=json_pretty
JSON Output
[
    {
        "id": "overview",
        "name": "Overview",
        "settings": [
            {
                "name": "Security & setup checks",
                "className": "OCA\\Settings\\Settings\\Admin\\Overview",
                "delegatedGroups": []
            }
        ]
    },
    {
        "id": "server",
        "name": "Basic settings",
        "settings": [
            {
                "name": "Background jobs",
                "className": "OCA\\Settings\\Settings\\Admin\\Server",
                "delegatedGroups": []
            }
        ]
    },
    {
        "id": "sharing",
        "name": "Sharing",
        "settings": [
            {
                "name": "Global",
                "className": "OCA\\Settings\\Settings\\Admin\\Sharing",
                "delegatedGroups": []
            }
        ]
    },
    {
        "id": "theming",
        "name": "Theming",
        "settings": [
            {
                "name": "Global",
                "className": "OCA\\Theming\\Settings\\Admin",
                "delegatedGroups": []
            }
        ]
    },
    {
        "id": "ai",
        "name": "Assistant",
        "settings": [
            {
                "name": "Artificial Intelligence",
                "className": "OCA\\Settings\\Settings\\Admin\\ArtificialIntelligence",
                "delegatedGroups": []
            }
        ]
    },
    {
        "id": "admindelegation",
        "name": "Administration privileges",
        "settings": [
            {
                "name": "Users",
                "className": "OCA\\Settings\\Settings\\Admin\\Users",
                "delegatedGroups": []
            },
            {
                "name": "Webhooks",
                "className": "OCA\\WebhookListeners\\Settings\\Admin",
                "delegatedGroups": []
            }
        ]
    }
]

Benefits

  • API Integration: Enables easier integration with external tools and scripts
  • Automation: Facilitates automated processing of delegation configurations
  • Backward Compatibility: Maintains existing table output as the default behavior
  • Structured Data: Provides consistently formatted delegation data for programmatic consumption

Technical Details

  • Leverages the existing Base class output formatting methods
  • Maintains the same data collection logic for consistency
  • Proper error handling and fallback to default plain output

Files Changed

  • apps/settings/lib/Command/AdminDelegation/Show.php

This enhancement improves the usability of the admin delegation system for both interactive use and automation scenarios.

Checklist

@printminion-co printminion-co requested a review from a team as a code owner September 22, 2025 14:52
@printminion-co printminion-co requested review from ArtificialOwl, come-nc, Copilot and salmart-dev and removed request for a team September 22, 2025 14:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the occ admin-delegation:show command by adding JSON output format support, enabling programmatic access to delegation information while maintaining backward compatibility with the existing table format.

  • Added --output option with support for plain, json, and json_pretty formats
  • Refactored data collection and formatting logic to support structured JSON output
  • Implemented proper validation and error handling for output format options

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When extending OC\Core\Command\Base, there is already an output option, you do not need to add it.

@printminion-co printminion-co marked this pull request as draft September 23, 2025 11:18
@printminion-co printminion-co force-pushed the feature/add_json_output_to_occ_admin-delegation branch from a84d419 to eb9a960 Compare September 23, 2025 11:20
Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
prepare to add json output

Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
… 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 <kupriyanov@strato.de>
- Add --output option supporting plain, json, and json_pretty formats
- Add validateOutputFormat() method for input validation
- Implement proper error handling for invalid output formats
- Support empty state handling for both plain and JSON outputs
- Use Base class writeArrayInOutputFormat() for consistent JSON output
- Maintain backward compatibility with plain format as default

Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
@printminion-co printminion-co force-pushed the feature/add_json_output_to_occ_admin-delegation branch from eb9a960 to c04398c Compare September 23, 2025 11:30
@printminion-co printminion-co marked this pull request as ready for review September 23, 2025 11:37
@come-nc
Copy link
Contributor

come-nc commented Sep 30, 2025

Failures are not related

@sorbaugh sorbaugh merged commit f8fd111 into nextcloud:master Sep 30, 2025
380 of 391 checks passed
@printminion-co
Copy link
Contributor Author

/backport to stable31

@come-nc
Copy link
Contributor

come-nc commented Sep 30, 2025

/backport to stable32

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2025

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants