Skip to content

Commit 33cf7be

Browse files
committed
update rest api and handle default collection
- updated the rest api for get and post reqests - fix the case for default collection - update the open api spec
1 parent 077765b commit 33cf7be

8 files changed

Lines changed: 156 additions & 80 deletions

docs/api/admin.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ paths:
5151
$ref: './paths/admin/db-_user-name-_session.yaml'
5252
'/{db}/_user/{name}/_session/{sessionid}':
5353
$ref: './paths/admin/db-_user-name-_session-sessionid.yaml'
54-
'/{db}/_user/{name}/_history':
55-
$ref: './paths/admin/db-_user-name-_history.yaml'
54+
'/{db}/_user/{name}/_access_history':
55+
$ref: './paths/admin/db-_user-name-_access_history.yaml'
56+
'/{db}/_user/{name}/_access_history/compact':
57+
$ref: './paths/admin/db-_user-name-_access_history-compact.yaml'
5658
'/{db}/_role/':
5759
$ref: './paths/admin/db-_role-.yaml'
5860
'/{db}/_role/{name}':

docs/api/components/schemas.yaml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,21 +3505,34 @@ RegistryScope:
35053505
items:
35063506
type: string
35073507

3508+
CollectionAccessHistory:
3509+
description: Channel history organized by scope name. Each scope contains a map of collection names to arrays of channel names.
3510+
type: object
3511+
additionalProperties:
3512+
x-additionalPropertiesName: scope
3513+
type: object
3514+
additionalProperties:
3515+
x-additionalPropertiesName: collection
3516+
type: array
3517+
items:
3518+
type: string
3519+
description: Array of channel names with revocation history in this collection.
3520+
35083521
UserHistory:
3509-
description: User history containing various history types organized by scope and collection.
3522+
description: User channel history organized by scope and collection.
35103523
type: object
3524+
title: UserHistory
35113525
properties:
35123526
channels:
35133527
description: Channel history organized by scope and collection.
3514-
type: object
3515-
additionalProperties:
3516-
description: An object keyed by scope name.
3517-
type: object
3518-
x-additionalPropertiesName: scopename
3519-
additionalProperties:
3520-
description: An array of channel names for the collection.
3521-
type: array
3522-
x-additionalPropertiesName: collectionname
3523-
items:
3524-
type: string
3525-
title: UserHistory
3528+
allOf:
3529+
- $ref: '#/CollectionAccessHistory'
3530+
CompactedUserHistory:
3531+
description: User channel history organized by scope and collection.
3532+
type: object
3533+
title: CompactedUserHistory
3534+
properties:
3535+
compacted_channels:
3536+
description: Channel history organized by scope and collection.
3537+
allOf:
3538+
- $ref: '#/CollectionAccessHistory'

docs/api/paths/admin/db-_user-name-_history.yaml renamed to docs/api/paths/admin/db-_user-name-_access_history-compact.yaml

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,6 @@
88
parameters:
99
- $ref: ../../components/parameters.yaml#/db
1010
- $ref: ../../components/parameters.yaml#/user-name
11-
get:
12-
summary: Get user's channel history information
13-
description: |-
14-
Retrieve the channel history of the specified user.
15-
16-
Required Sync Gateway RBAC roles:
17-
18-
* Sync Gateway Architect
19-
* Sync Gateway Application
20-
* Sync Gateway Application Read Only
21-
responses:
22-
'200':
23-
description: User channel history information retrieved successfully
24-
content:
25-
application/json:
26-
schema:
27-
$ref: ../../components/schemas.yaml#/UserHistory
28-
example:
29-
channels:
30-
scope1:
31-
collection1:
32-
- channel1
33-
- channel2
34-
collection2:
35-
- channel3
36-
'403':
37-
$ref: ../../components/responses.yaml#/Unauthorized-database
38-
'404':
39-
$ref: ../../components/responses.yaml#/Not-found
40-
tags:
41-
- Database Security
42-
operationId: get_db-_user-name-_history
4311
post:
4412
summary: Compact user's channel history
4513
description: |-
@@ -66,9 +34,9 @@ post:
6634
content:
6735
application/json:
6836
schema:
69-
$ref: ../../components/schemas.yaml#/UserHistory
37+
$ref: ../../components/schemas.yaml#/CompactedUserHistory
7038
example:
71-
channels:
39+
compacted_channels:
7240
scope1:
7341
collection1:
7442
- scoped_channel2
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2026-Present Couchbase, Inc.
2+
#
3+
# Use of this software is governed by the Business Source License included
4+
# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
5+
# in that file, in accordance with the Business Source License, use of this
6+
# software will be governed by the Apache License, Version 2.0, included in
7+
# the file licenses/APL2.txt.
8+
parameters:
9+
- $ref: ../../components/parameters.yaml#/db
10+
- $ref: ../../components/parameters.yaml#/user-name
11+
get:
12+
summary: Get user's channel history information
13+
description: |-
14+
Retrieve the channel history of the specified user.
15+
16+
Required Sync Gateway RBAC roles:
17+
18+
* Sync Gateway Architect
19+
* Sync Gateway Application
20+
* Sync Gateway Application Read Only
21+
responses:
22+
'200':
23+
description: User channel history information retrieved successfully
24+
content:
25+
application/json:
26+
schema:
27+
$ref: ../../components/schemas.yaml#/UserHistory
28+
example:
29+
channels:
30+
scope1:
31+
collection1:
32+
- channel1
33+
- channel2
34+
collection2:
35+
- channel3
36+
'403':
37+
$ref: ../../components/responses.yaml#/Unauthorized-database
38+
'404':
39+
$ref: ../../components/responses.yaml#/Not-found
40+
tags:
41+
- Database Security
42+
operationId: get_db-_user-name-_history
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2026-Present Couchbase, Inc.
2+
#
3+
# Use of this software is governed by the Business Source License included
4+
# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
5+
# in that file, in accordance with the Business Source License, use of this
6+
# software will be governed by the Apache License, Version 2.0, included in
7+
# the file licenses/APL2.txt.
8+
parameters:
9+
- $ref: ../../components/parameters.yaml#/db
10+
- $ref: ../../components/parameters.yaml#/user-name
11+
get:
12+
summary: Get user's channel history information
13+
description: |-
14+
Retrieve the channel history of the specified user.
15+
16+
Required Sync Gateway RBAC roles:
17+
18+
* Sync Gateway Architect
19+
* Sync Gateway Application
20+
* Sync Gateway Application Read Only
21+
responses:
22+
'200':
23+
description: User channel history information retrieved successfully
24+
content:
25+
application/json:
26+
schema:
27+
$ref: ../../components/schemas.yaml#/UserHistory
28+
example:
29+
channels:
30+
scope1:
31+
collection1:
32+
- channel1
33+
- channel2
34+
collection2:
35+
- channel3
36+
'403':
37+
$ref: ../../components/responses.yaml#/Unauthorized-database
38+
'404':
39+
$ref: ../../components/responses.yaml#/Not-found
40+
tags:
41+
- Database Security
42+
operationId: get_db-_user-name-_history

rest/admin_api.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,10 @@ type UserChannelHistory struct {
25182518
Channels ColAccessHistoryMap `json:"channels"`
25192519
}
25202520

2521+
type UserChannelHistoryResp struct {
2522+
CompactedChannels ColAccessHistoryMap `json:"compacted_channels"`
2523+
}
2524+
25212525
func (h *handler) getUserChannelHistory() error {
25222526
h.assertAdminOnly()
25232527
username := internalUserName(mux.Vars(h.rq)["name"])
@@ -2531,10 +2535,15 @@ func (h *handler) getUserChannelHistory() error {
25312535
colAccess := user.GetCollectionsAccess()
25322536

25332537
colAccessHistoryMap := make(map[string]map[string][]string)
2534-
for scope, _ := range colAccess {
2535-
colAccessHistoryMap[scope] = make(map[string][]string)
2536-
for col, _ := range colAccess[scope] {
2537-
colAccessHistoryMap[scope][col] = slices.Collect(maps.Keys(colAccess[scope][col].ChannelHistory_))
2538+
if colAccess == nil {
2539+
colAccessHistoryMap[base.DefaultScope] = make(map[string][]string)
2540+
colAccessHistoryMap[base.DefaultScope][base.DefaultCollection] = slices.Collect(maps.Keys(user.ChannelHistory()))
2541+
} else {
2542+
for scope, _ := range colAccess {
2543+
colAccessHistoryMap[scope] = make(map[string][]string)
2544+
for col, _ := range colAccess[scope] {
2545+
colAccessHistoryMap[scope][col] = slices.Collect(maps.Keys(colAccess[scope][col].ChannelHistory_))
2546+
}
25382547
}
25392548
}
25402549

@@ -2573,8 +2582,8 @@ func (h *handler) compactUserChannelHistory() error {
25732582
}
25742583
}
25752584

2576-
userCompactedChannelHistory := UserChannelHistory{
2577-
Channels: colAccessHistoryMap,
2585+
userCompactedChannelHistory := UserChannelHistoryResp{
2586+
CompactedChannels: colAccessHistoryMap,
25782587
}
25792588

25802589
err = authenticator.Save(user)

rest/routing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ func CreateAdminRouter(sc *ServerContext) *mux.Router {
186186
makeHandler(sc, adminPrivs, []Permission{PermWritePrincipal}, nil, (*handler).putUser)).Methods("PUT")
187187
dbr.Handle("/_user/{name}",
188188
makeHandler(sc, adminPrivs, []Permission{PermWritePrincipal}, nil, (*handler).deleteUser)).Methods("DELETE")
189-
dbr.Handle("/_user/{name}/_channel_history",
189+
dbr.Handle("/_user/{name}/_access_history",
190190
makeHandler(sc, adminPrivs, []Permission{PermReadPrincipal}, nil, (*handler).getUserChannelHistory)).Methods("GET")
191-
dbr.Handle("/_user/{name}/_channel_history",
191+
dbr.Handle("/_user/{name}/_access_history/compact",
192192
makeHandler(sc, adminPrivs, []Permission{PermWritePrincipal}, nil, (*handler).compactUserChannelHistory)).Methods("POST")
193193

194194
dbr.Handle("/_user/{name}/_session",

0 commit comments

Comments
 (0)