Skip to content
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

Fix ds.object with_relations #356

Merged
merged 5 commits into from Mar 27, 2024
Merged

Fix ds.object with_relations #356

merged 5 commits into from Mar 27, 2024

Conversation

ronenh
Copy link
Contributor

@ronenh ronenh commented Mar 26, 2024

Passing the with_relations: true option to ds.object had no effect because the builtin was assigning the returned object as the result.

This PR adds an options relations field alongside type and id.

Example:

obj := ds.object({
  "object_type": "user",
  "object_id": "morty@the-citadel.com",
  "with_relations": true
})
obj.id == "morty@the-citadel.com"
obj.type == "user"
obj.relations == [<array of relations>]

Passing the `with_relations: true` option to `ds.object` has no
effect because the builtin was assigning the returned object as
the result.

To preserve compatibility with current signature of `ds.object`
this commit only sets the result to the full `GetObjectResponse`
if `with_relations` is true.
@ronenh ronenh requested a review from gertd March 26, 2024 23:18
Copy link

Pull Request Test Coverage Report for Build 8444132412

Details

  • 0 of 7 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 24.647%

Changes Missing Coverage Covered Lines Changed/Added Lines %
builtins/edge/ds/object.go 0 7 0.0%
Totals Coverage Status
Change from base Build 8439955094: -0.02%
Covered Lines: 1151
Relevant Lines: 4670

💛 - Coveralls

@gertd
Copy link
Member

gertd commented Mar 26, 2024

Why not make the output be like:

resp := ds.object({
  "object_type": "user",
  "object_id": "morty@the-citadel.com",
  "with_relations": true
})
resp.id == "morty@the-citadel.com"
resp.type == "user"
resp.relations == [<array of relations>]

?

@gertd
Copy link
Member

gertd commented Mar 27, 2024

Restructure the output, ensuring timestamppb.Timestamp values are marshaled as strings.

x = ds.object({"object_id": "rick@the-citadel.com", "object_type": "user", "with_relations": true})

results in:

{
  "result": [
    {
      "bindings": {
        "x": {
          "created_at": "2024-03-26T23:55:34.370254093Z",
          "display_name": "Rick Sanchez",
          "etag": "948604866316391264",
          "id": "rick@the-citadel.com",
          "properties": {
            "email": "rick@the-citadel.com",
            "picture": "https://www.topaz.sh/assets/templates/citadel/img/Rick%20Sanchez.jpg",
            "roles": [
              "admin",
              "evil_genius"
            ],
            "status": "USER_STATUS_ACTIVE"
          },
          "relations": [
            {
              "created_at": "2024-03-26T23:55:34.380667635Z",
              "etag": "9644710518185364647",
              "object_id": "CiRmZDA2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs",
              "object_type": "identity",
              "relation": "identifier",
              "subject_id": "rick@the-citadel.com",
              "subject_type": "user",
              "updated_at": "2024-03-26T23:55:34.380667635Z"
            },
            {
              "created_at": "2024-03-26T23:55:34.380842885Z",
              "etag": "12808372912248398855",
              "object_id": "rick@the-citadel.com",
              "object_type": "identity",
              "relation": "identifier",
              "subject_id": "rick@the-citadel.com",
              "subject_type": "user",
              "updated_at": "2024-03-26T23:55:34.380842885Z"
            },
            {
              "created_at": "2024-03-26T23:55:34.380907260Z",
              "etag": "7520381670766297568",
              "object_id": "admin",
              "object_type": "group",
              "relation": "member",
              "subject_id": "rick@the-citadel.com",
              "subject_type": "user",
              "updated_at": "2024-03-26T23:55:34.380907260Z"
            },
            {
              "created_at": "2024-03-26T23:55:34.381005093Z",
              "etag": "15435570770464182199",
              "object_id": "evil_genius",
              "object_type": "group",
              "relation": "member",
              "subject_id": "rick@the-citadel.com",
              "subject_type": "user",
              "updated_at": "2024-03-26T23:55:34.381005093Z"
            },
            {
              "created_at": "2024-03-26T23:55:34.381494843Z",
              "etag": "8106136184379167691",
              "object_id": "rick.inventions",
              "object_type": "doc",
              "relation": "owner",
              "subject_id": "rick@the-citadel.com",
              "subject_type": "user",
              "updated_at": "2024-03-26T23:55:34.381494843Z"
            },
            {
              "created_at": "2024-03-26T23:55:34.381448051Z",
              "etag": "9386898667536603368",
              "object_id": "rick",
              "object_type": "folder",
              "relation": "owner",
              "subject_id": "rick@the-citadel.com",
              "subject_type": "user",
              "updated_at": "2024-03-26T23:55:34.381448051Z"
            },
            {
              "created_at": "2024-03-26T23:55:34.380565218Z",
              "etag": "10161026355443023840",
              "object_id": "rick@the-citadel.com",
              "object_type": "user",
              "relation": "manager",
              "subject_id": "beth@the-smiths.com",
              "subject_type": "user",
              "updated_at": "2024-03-26T23:55:34.380565218Z"
            },
            {
              "created_at": "2024-03-26T23:55:34.380591885Z",
              "etag": "12277185316701905682",
              "object_id": "rick@the-citadel.com",
              "object_type": "user",
              "relation": "manager",
              "subject_id": "morty@the-citadel.com",
              "subject_type": "user",
              "updated_at": "2024-03-26T23:55:34.380591885Z"
            },
            {
              "created_at": "2024-03-26T23:55:34.380615176Z",
              "etag": "7613861344324539156",
              "object_id": "rick@the-citadel.com",
              "object_type": "user",
              "relation": "manager",
              "subject_id": "summer@the-smiths.com",
              "subject_type": "user",
              "updated_at": "2024-03-26T23:55:34.380615176Z"
            }
          ],
          "type": "user",
          "updated_at": "2024-03-26T23:55:34.370254093Z"
        }
      },
      "expressions": [
        {
          "location": {
            "col": 1,
            "row": 1
          },
          "text": "x = ds.object({\"object_id\": \"rick@the-citadel.com\", \n\"object_type\": \"user\", \"with_relations\": true})",
          "value": true
        }
      ]
    }
  ]
}

@gertd gertd merged commit f9b99c5 into main Mar 27, 2024
5 checks passed
@gertd gertd deleted the object-with-relations branch March 27, 2024 13:51
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.

None yet

2 participants