Skip to content

fix: grant VIEW to all workspace users on created computed attributes - #27

Merged
xvalovic merged 2 commits into
gooddata:masterfrom
xvalovic:rva/ca-view-permissions
Nov 10, 2026
Merged

xvalovic merged 2 commits into
gooddata:masterfrom
xvalovic:rva/ca-view-permissions

Conversation

@xvalovic

@xvalovic xvalovic commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A computed attribute created via POST /entities/.../computedAttributes is private to its creator (only MANAGE users and the creator see it). Every report referencing a migrated CA then fails with 403 for regular users (Calcique: Caller lacks VIEW on objects referenced by request). Observed on RingCentral EV_Master for CAs created by the release tooling; CAs created by this toolkit end up in the same state.

Fix

CloudClient.create_computed_attribute calls POST .../computedAttributes/{id}/managePermissions with allWorkspaceUsers = VIEW after a successful create. Mirrors create_dashboard_permissions_for_public_dashboards: plain application/json, non-204 is logged as an error and does not fail the create.

Updates of existing CAs are untouched. CAs migrated before this fix stay private and need a one-off managePermissions call per workspace.

Tests

tests/test_cloud_client_computed_attributes.py: grant is sent after 201 with the right URL/payload/headers, not sent after a failed create, and a failed grant keeps the create response.

make check fails only on pre-existing lint errors in mps_scripting/orchestrator/failed_report.py; ruff, pytest and ty pass on the changed files.

🤖 Generated with Claude Code

A computed attribute created via the entity API is private to its
creator, so every report using a migrated CA fails with 403 for
non-admin users (Calcique: "Caller lacks VIEW on objects referenced by
request"). CloudClient.create_computed_attribute now calls
managePermissions with allWorkspaceUsers=VIEW after a successful POST,
same as public dashboards. A failed grant is logged and does not fail
the create.

risk: low

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ca21dc39-07df-4026-b028-30f107d0eb1a
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@JosefGruber JosefGruber left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved

@Martinlll

Martinlll commented Nov 10, 2026 •

Copy link
Copy Markdown

Tested before fix selected computed attributed had:

{
    "rules": [],
    "users": [
        {
            "id": "id of the user",
            "name": "name of the user",
            "email": "author migrating the CA only",
            "permissions": [
                {
                    "level": "EDIT",
                    "source": "direct"
                }
            ]
        }
    ],
    "userGroups": []
}

After fix there is also:

"rules": [
        {
            "type": "allWorkspaceUsers",
            "permissions": [
                {
                    "level": "VIEW",
                    "source": "direct"
                }
            ]
        }
    ]

@marmil-cz marmil-cz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this. Granting VIEW fixes the 403s for CAs created from now on, but doing the grant inside create_computed_attribute leaves some gaps:

  1. A failed grant is never retried. If the CA is created but the grant returns 500 or times out, the error is only logged and the CA isn't added to cloud_failed_computed_attributes.json. On the next run the CA is skipped because it already exists, so it stays private.
  2. A grant that throws makes a created CA look failed. If _post raises during the grant (a rate limit with no Retry-After, or a connection error after retries), the exception escapes create_computed_attribute. The CA exists in Cloud but is reported as failed, and the next run skips it.
  3. --overwrite-existing doesn't fix older CAs. update_computed_attribute doesn't grant, so CAs from earlier migrations need a manual call that the README doesn't document.
  4. Only 204 counts as success. Any other 2xx is logged as an error; response.ok is safer.
  5. Duplicated code. The grant request is a copy of create_dashboard_permissions_for_public_dashboards.

Proposed fix

Move the grant out of create and run it as a separate step after the CA deploy. The dashboards workflow already grants public dashboard permissions as a separate step. The step grants VIEW to every CA in the run except the ones whose create or update failed, so new, updated and skipped CAs all get it.

1. Client: one shared grant helper, no grant inside create (backends/cloud/client.py)

def create_computed_attribute(
    self, computed_attribute: dict[str, Any]
) -> requests.Response:
    """Post a computed attribute to the server."""
    url = f"api/v1/entities/workspaces/{self.ws}/computedAttributes"
    return self._post(url, computed_attribute)

def _grant_view_to_all_workspace_users(self, entity_type: str, obj_id: str) -> bool:
    """Grants VIEW on a workspace entity to all workspace users.

    Returns:
        True if the grant succeeded, False otherwise (errors are logged).
    """
    url = (
        f"api/v1/actions/workspaces/{self.ws}/{entity_type}/"
        f"{obj_id}/managePermissions"
    )
    permission = [
        {"assigneeRule": {"type": "allWorkspaceUsers"}, "permissions": ["VIEW"]}
    ]
    headers = {
        "Authorization": f"Bearer {self.token}",
        "Content-Type": "application/json",
    }
    try:
        response = self._post(url, permission, headers)
    except Exception as e:
        logger.error("Error granting VIEW on %s %s: %s", entity_type, obj_id, e)
        return False
    if not response.ok:
        logger.error(
            "Error granting VIEW on %s %s: %s - %s",
            entity_type, obj_id, response.status_code, response.text,
        )
        return False
    return True

def grant_view_to_all_on_computed_attributes(self, ids: list[str]) -> list[str]:
    """Grants VIEW to all workspace users; returns IDs where the grant failed."""
    logger.info("----Granting VIEW on computed attributes (%d)----", len(ids))
    return [
        ca_id for ca_id in ids
        if not self._grant_view_to_all_workspace_users("computedAttributes", ca_id)
    ]

create_dashboard_permissions_for_public_dashboards then becomes a loop over _grant_view_to_all_workspace_users("analyticalDashboards", ...), which removes the duplication. This also changes its success check from exactly 204 to any 2xx, a small change in behavior for dashboards.

2. Workflow: grant after the deploy (workflows/migrate_metrics.py)

CAs are always deployed with a *_WITH_RETRY operation, so process_objects returns the failed objects.

if cloud_computed_attributes:
    failed_cas, _ = process_objects(
        cloud_client, cloud_computed_attributes, "computed_attribute", ca_operation
    )
    failed_ids = {ca["data"]["id"] for ca in failed_cas}
    grant_ids = [
        ca["data"]["id"] for ca in cloud_computed_attributes
        if ca["data"]["id"] not in failed_ids
    ]
    failed_grants = cloud_client.grant_view_to_all_on_computed_attributes(grant_ids)
    if failed_grants:
        write_content_to_file(
            CLOUD_FAILED_CA_PERMISSIONS_FILE, json.dumps(failed_grants, indent=4)
        )

What this fixes:

  • Point 1: CAs that already exist are re-granted on every run, so a grant that failed once is retried next time.
  • Point 2: grant errors are caught per CA, so a created CA is never reported as failed.
  • Point 3: rerunning the migration fixes CAs migrated before this change, with or without --overwrite-existing, so no manual managePermissions call is needed.
  • Visibility: CAs whose grant failed go to a new cloud_failed_computed_attribute_permissions.json file.

One assumption to check: re-granting on every run is only safe if managePermissions with an allWorkspaceUsers rule sets the permission rather than adding to it. That's how the dashboard grant is used, but it should be confirmed for computed attributes against a real workspace.

3. Tests, type hints and README

  • Client tests: the grant helper returns False on a non-2xx response and on an exception; create_computed_attribute no longer makes the grant call.
  • Workflow test: CAs that failed are excluded from the grant, and skipped or updated CAs are included.
  • Type hints: add MockerFixture on mocker in the tests.
  • README: in the CA section (around line 393), note the VIEW grant, that rerunning fixes older migrations, and the new output file.

Addresses review on PR gooddata#27. The grant inside create_computed_attribute
was never retried after a failure, could make a created CA look failed
when it raised, and did not cover CAs from earlier migrations.

The grant now runs after the CA deploy for every CA in the run except
the ones whose create/update failed, so new, updated and skipped CAs all
get it and rerunning the migration fixes older ones. Grant errors are
caught per CA; failed IDs go to
cloud_failed_computed_attribute_permissions.json. The request is shared
with the public dashboard grant, which now treats any 2xx as success.

risk: low

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@xvalovic
xvalovic requested a review from marmil-cz November 10, 2026 16:16

@marmil-cz marmil-cz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thank you for improvement ;)

@xvalovic
xvalovic merged commit a057fa6 into gooddata:master Nov 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants