Skip to content

feat(governance): add API to read and change the labels of resources - #66615

Draft
susnux wants to merge 2 commits into
feat/files-node-resource-typefrom
feat/ncu-governance-labels
Draft

susnux wants to merge 2 commits into
feat/files-node-resource-typefrom
feat/ncu-governance-labels

Conversation

@susnux

@susnux susnux commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

NCU\Governance\ILabelManager reads the labels assigned to resources and assigns or removes them. The labels are managed by the governance app, core checks the access of the actor to the resource before delegating to it and dispatches an event for every label that was assigned or removed.

The access of an actor to resources is available to apps through NCU\Resource\Permission\IAccessManager.

Entities of this API

Apps only see ILabelManager. The core manager is the one bound in the container.
It checks access and dispatches events, and hands everything about labels to the governance app.
There is no registration: core looks up one known class when the app is enabled.

Details
flowchart LR
    A["Any app<br/>e.g. Tables, Mail, Files"] -->|"ILabelManager"| C["Core label manager<br/>OC\Governance\LabelManager"]
    C -->|"getAccess()"| AM["IAccessManager<br/>from #66612"]
    AM --> RT["Resource type of the owning app"]
    C -->|"same ILabelManager interface"| G["Governance app<br/>OCA\Governance\Service\LabelManager"]
    C -->|"LabelAssignedEvent<br/>LabelRemovedEvent"| L["Listeners in any app"]
    G --> S[("Labels, rules and<br/>assignments")]
Loading

Reading labels

One call for the whole list. Resources the actor cannot access never reach the governance app, and they come back with
an empty list, so "no labels" and "no access" look the same to the caller.

Details
sequenceDiagram
    autonumber
    participant T as Tables
    participant C as Core label manager
    participant AM as IAccessManager
    participant G as Governance app

    T->>C: getAssignedLabelsForResources(Alice, [table 1, table 2, table 3])
    C->>AM: getAccess(Alice, [table 1, table 2, table 3])
    AM-->>C: table 1 and table 3, table 2 left out
    C->>G: getAssignedLabelsForResources(Alice, [table 1, table 3])
    G-->>C: table 1: Internal, Audit hold · table 3: none
    C-->>T: table 1: 2 labels · table 2: [] · table 3: []
    Note over T: every requested key is present
Loading

Assigning a label

Core reads the assigned labels before and after the change and dispatches one event per difference.
That is how placed sensitivity label produces a removed event without core knowing the rule "one sensitivity label per resource".

Details
sequenceDiagram
    autonumber
    participant T as Tables
    participant C as Core label manager
    participant AM as IAccessManager
    participant G as Governance app
    participant E as Event dispatcher

    T->>C: assignLabel(Alice, table 1, "Confidential", reason)
    C->>AM: getAccess(Alice, [table 1])
    AM-->>C: entries for table 1
    C->>G: getAssignedLabels(Alice, table 1)
    G-->>C: before: Internal
    C->>G: assignLabel(Alice, table 1, "Confidential", reason)
    Note over G: checks its own rules, replaces Internal,<br/>writes the audit entry
    C->>G: getAssignedLabels(Alice, table 1)
    G-->>C: after: Confidential
    C->>E: LabelRemovedEvent(Alice, table 1, Internal, sensitivity)
    C->>E: LabelAssignedEvent(Alice, table 1, Confidential, sensitivity)
    C-->>T: done
Loading

Potential outcomes

Details
flowchart TD
    W["assignLabel() or removeLabel()"] --> R{"Resource type registered?"}
    R -->|no| X1["InvalidArgumentException"]
    R -->|yes| B{"Governance app enabled?"}
    B -->|no| X2["GovernanceUnavailableException"]
    B -->|yes| AC{"Actor has access to the resource?"}
    AC -->|no| X3["ResourceNotFoundException"]
    AC -->|yes| G["Governance app decides"]
    G -->|"label unknown or does not apply<br/>to this resource"| X4["LabelNotFoundException"]
    G -->|"actor may not change it,<br/>or reason missing"| X5["LabelPermissionException"]
    G -->|ok| D{"Assigned labels changed?"}
    D -->|yes| EV["Events dispatched"]
    D -->|no| NE["No event"]
Loading

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@susnux susnux added this to the Nextcloud 36 milestone Nov 14, 2026
@susnux
susnux requested a review from salmart-dev November 14, 2026 08:38
@susnux
susnux added this pull request to stack #66613 November 14, 2026 08:38
@susnux susnux added enhancement 3. to review Waiting for reviews labels Nov 14, 2026
`NCU\Governance\ILabelManager` reads the labels assigned to resources and
assigns or removes them. The labels are managed by the governance app, core
checks the access of the actor to the resource before delegating to it and
dispatches an event for every label that was assigned or removed.

Assisted-by: ClaudeCode:claude-fable-5-2
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux
susnux force-pushed the feat/ncu-governance-labels branch from a0dcd06 to 5555bdb Compare November 14, 2026 08:39
Who may label a resource is not only a question of access: a legal hold is
placed by someone the resource is not shared with. The label manager no
longer checks the access of the actor before asking the governance app, it
only handles the app not being enabled and unknown resource types.

The governance app also dispatches the events for assigned and removed
labels itself, so that changes made through its own API are announced too.

Assisted-by: ClaudeCode:claude-fable-5-2
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>

This branch has not been deployed

No deployments
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.

2 participants