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

CBG-3720: Diagnostic API - get all user channels endpoint #6647

Merged
merged 26 commits into from
May 21, 2024

Conversation

mohammed-madi
Copy link
Contributor

@mohammed-madi mohammed-madi commented Jan 18, 2024

CBG-3720

Describe your PR here...

  • Add /{keyspace}/_user/{user}/all_channels endpoint, returns list of channels.
  • TestGetAllChannelsByUser added. Tests empty user channels, admin assigned channels, dynamic channel assignment and non existent user response.

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

rest/diagnostic_api.go Outdated Show resolved Hide resolved
rest/diagnostic_api.go Outdated Show resolved Hide resolved
rest/routing.go Outdated Show resolved Hide resolved
rest/diagnostic_api_test.go Outdated Show resolved Hide resolved
rest/diagnostic_api_test.go Outdated Show resolved Hide resolved
rest/diagnostic_api_test.go Outdated Show resolved Hide resolved
rest/diagnostic_api_test.go Show resolved Hide resolved
rest/diagnostic_api_test.go Outdated Show resolved Hide resolved
rest/diagnostic_api_test.go Outdated Show resolved Hide resolved
@bbrks bbrks assigned mohammed-madi and unassigned bbrks Jan 19, 2024
@mohammed-madi mohammed-madi assigned bbrks and unassigned mohammed-madi Jan 22, 2024
docs/api/admin.yaml Outdated Show resolved Hide resolved
rest/diagnostic_api.go Outdated Show resolved Hide resolved
rest/admin_api.go Outdated Show resolved Hide resolved
rest/routing.go Outdated Show resolved Hide resolved
@mohammed-madi
Copy link
Contributor Author

new Response format

{
  "admin_grants": {
    "sg_test_0.sg_test_1": {
      "!": {
        "updated_at": 0,
        "entries": [
          "1-0"
        ]
      }
    },
    "sg_test_0.sg_test_0": {
      "!": {
        "updated_at": 0,
        "entries": [
          "1-0"
        ]
      },
      "NewChannel": {
        "updated_at": 0,
        "entries": [
          "3-0"
        ]
      }
    }
  },
  "dynamic_grants": {
    "sg_test_0.sg_test_0": {},
    "sg_test_0.sg_test_1": {}
  },
  "role_history_grants": {
    "role1": {
      "sg_test_0.sg_test_0": {
        "!": {
          "updated_at": 1707410767,
          "entries": [
            "5-6"
          ]
        }
      },
      "sg_test_0.sg_test_1": {
        "role1Chan": {
          "updated_at": 1707410767,
          "entries": [
            "5-6"
          ]
        },
        "!": {
          "updated_at": 1707410767,
          "entries": [
            "5-6"
          ]
        }
      }
    }
  }
}

@mohammed-madi mohammed-madi assigned bbrks and unassigned mohammed-madi Feb 12, 2024
auth/auth.go Outdated Show resolved Hide resolved
auth/auth.go Outdated Show resolved Hide resolved
db/users.go Outdated Show resolved Hide resolved
rest/revocation_test.go Outdated Show resolved Hide resolved
rest/revocation_test.go Outdated Show resolved Hide resolved
db/users.go Outdated Show resolved Hide resolved
db/users.go Outdated Show resolved Hide resolved
docs/api/paths/admin/db-_user-name-all_channels.yaml Outdated Show resolved Hide resolved
rest/diagnostic_api.go Outdated Show resolved Hide resolved
rest/diagnostic_api.go Outdated Show resolved Hide resolved
bbrks
bbrks previously requested changes Feb 15, 2024
db/users.go Outdated Show resolved Hide resolved
auth/auth.go Outdated Show resolved Hide resolved
db/users.go Outdated Show resolved Hide resolved
docs/api/components/schemas.yaml Outdated Show resolved Hide resolved
@bbrks
Copy link
Member

bbrks commented Feb 15, 2024

Some more feedback after testing:

Default collection

The response for the default channel doesn't match the response format for collections, and doesn't contain any sequence information.

They should be consistent and use the _default scope/collection name.

After adding named collections:

Screenshot 2024-02-15 at 14 22 36

It doesn't appear to support a named default collection (e.g. a db config running with _default._default and _defualt.col1 (I have admin grants set on the default collection)

Screenshot 2024-02-15 at 14 26 20

Screenshot 2024-02-15 at 14 29 14

Copy link

github-actions bot commented Feb 15, 2024

Redocly previews

@bbrks bbrks assigned mohammed-madi and unassigned bbrks Feb 15, 2024
@mohammed-madi mohammed-madi assigned bbrks and unassigned mohammed-madi Feb 19, 2024
auth/role.go Outdated Show resolved Hide resolved
rest/diagnostic_api.go Outdated Show resolved Hide resolved
rest/diagnostic_api.go Outdated Show resolved Hide resolved
@bbrks
Copy link
Member

bbrks commented Feb 26, 2024

Can you rebase/fix tests before I review again?

@bbrks bbrks assigned mohammed-madi and unassigned bbrks Feb 26, 2024
@mohammed-madi mohammed-madi force-pushed the CBG-3720-admin_api branch 2 times, most recently from e8bc436 to 080f36b Compare February 29, 2024 17:04
@torcolvin torcolvin assigned torcolvin and unassigned mohammed-madi May 16, 2024
Comment on lines 165 to 167
if len(collectionChannels) == 0 && len(channelHistory) == 0 {
continue
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this avoid making empty maps? Hitting the continue statement is identical to going through this loop with a no-op

rest/diagnostic_api.go Outdated Show resolved Hide resolved
rest/diagnostic_api.go Outdated Show resolved Hide resolved
rest/diagnostic_api.go Outdated Show resolved Hide resolved
rest/diagnostic_api_test.go Outdated Show resolved Hide resolved
"/{{.db}}/_user/"+username+"/_all_channels", ``)
RequireStatus(rt.TB, response, http.StatusOK)
rt.TB.Logf("All channels response: %s", response.BodyString())
require.JSONEq(rt.TB, expectedOutput, convertUpdatedTimeToConstant(rt.TB, response.BodyBytes()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like these changes but I think we should test _default._default and named collections explicitly, especially because our handling of _default._default in user docs is different.

I think we can do this by adding golang templating to the output. I think we might be able to directly call

func (rt *RestTester) mustTemplateResource(resource string) string {

and replace explicit _default._default with {{.keyspace}} but you should check and let me know if this isn't true.

docs/api/components/schemas.yaml Outdated Show resolved Hide resolved
docs/api/components/schemas.yaml Outdated Show resolved Hide resolved
rest/diagnostic_api.go Outdated Show resolved Hide resolved
@torcolvin torcolvin assigned mohammed-madi and unassigned torcolvin May 21, 2024
@mohammed-madi
Copy link
Contributor Author

db/database.go Outdated Show resolved Hide resolved
docs/api/components/responses.yaml Outdated Show resolved Hide resolved
@torcolvin torcolvin enabled auto-merge (squash) May 21, 2024 15:10
@mohammed-madi mohammed-madi dismissed stale reviews from bbrks and adamcfraser May 21, 2024 15:16

out of date

@torcolvin torcolvin merged commit d106b46 into main May 21, 2024
37 checks passed
@torcolvin torcolvin deleted the CBG-3720-admin_api branch May 21, 2024 16:00
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