@ossy/resources 3.6.2 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/access-filter.spec.js +39 -1
- package/src/resources.queries.js +13 -8
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/resources",
|
|
3
3
|
"description": "Resource domain — aggregate and events for the Ossy resource model",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.7.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./src/index.js",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"src": "./src"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@ossy/event-store": "^3.
|
|
26
|
+
"@ossy/event-store": "^3.7.0",
|
|
27
27
|
"@ossy/fold": "^3.4.0",
|
|
28
|
-
"@ossy/platform": "^3.
|
|
28
|
+
"@ossy/platform": "^3.7.0",
|
|
29
29
|
"@ossy/schema": "^3.6.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"/src",
|
|
50
50
|
"README.md"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "622d97535abad08415963405ace2f5aaaecd7ca4"
|
|
53
53
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { accessFilter } from './resources.queries.js'
|
|
1
|
+
import { accessFilter, ResourcesQueries } from './resources.queries.js'
|
|
2
2
|
|
|
3
3
|
// Helper to build a minimal Policy aggregate document that policyToQueryClause expects.
|
|
4
4
|
function makePolicy({ effect = 'allow', actions = ['resource:read'], where = {} } = {}) {
|
|
@@ -132,3 +132,41 @@ describe('accessFilter', () => {
|
|
|
132
132
|
})
|
|
133
133
|
|
|
134
134
|
})
|
|
135
|
+
|
|
136
|
+
describe('ResourcesQueries.buildMongoQuery', () => {
|
|
137
|
+
it('scopes a folder list to belongsTo, location, and status — not document type', () => {
|
|
138
|
+
const query = ResourcesQueries.buildMongoQuery({
|
|
139
|
+
belongsTo: 'ws-1',
|
|
140
|
+
location: '/Marketing/',
|
|
141
|
+
})
|
|
142
|
+
expect(query).toEqual({
|
|
143
|
+
'state.belongsTo': 'ws-1',
|
|
144
|
+
'state.location': '/Marketing/',
|
|
145
|
+
'state.status': { $ne: 'removed' },
|
|
146
|
+
})
|
|
147
|
+
expect(query.type).toBeUndefined()
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('does not add a schema-id type regex', () => {
|
|
151
|
+
const query = ResourcesQueries.buildMongoQuery({ belongsTo: 'ws-1', location: '/' })
|
|
152
|
+
expect(JSON.stringify(query)).not.toMatch(/schema\//)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('AND-combines the folder query with accessFilter when a user is passed', () => {
|
|
156
|
+
const user = { id: 'u-1', workspaces: ['ws-1'], policies: [] }
|
|
157
|
+
const query = ResourcesQueries.buildMongoQuery(
|
|
158
|
+
{ belongsTo: 'ws-1', location: '/@ossy/jobs/' },
|
|
159
|
+
user,
|
|
160
|
+
)
|
|
161
|
+
expect(query).toEqual({
|
|
162
|
+
$and: [
|
|
163
|
+
{
|
|
164
|
+
'state.belongsTo': 'ws-1',
|
|
165
|
+
'state.location': '/@ossy/jobs/',
|
|
166
|
+
'state.status': { $ne: 'removed' },
|
|
167
|
+
},
|
|
168
|
+
accessFilter(user),
|
|
169
|
+
],
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
})
|
package/src/resources.queries.js
CHANGED
|
@@ -67,18 +67,23 @@ export class ResourcesQueries {
|
|
|
67
67
|
return query
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Folder list/search query. Scope is `state.belongsTo` + `state.location`
|
|
72
|
+
* (any schema in that folder). Do not filter document `type` with a schema-id
|
|
73
|
+
* regex — that matches audit snapshots in the same collection and hides
|
|
74
|
+
* leftover `Resource` docs that still live in folders.
|
|
75
|
+
*/
|
|
76
|
+
static buildMongoQuery(_query = {}, user = null) {
|
|
77
|
+
const query = ResourcesQueries.#prefixQuery({ ..._query, status: { $ne: 'removed' } })
|
|
78
|
+
return user ? { $and: [query, accessFilter(user)] } : query
|
|
79
|
+
}
|
|
80
|
+
|
|
70
81
|
static GetResources(_query = {}, user = null) {
|
|
71
82
|
log.info('[ResourcesQueries][GetResources] Building query')
|
|
72
|
-
const
|
|
73
|
-
const workspaceScope =
|
|
83
|
+
const mongoQuery = ResourcesQueries.buildMongoQuery(_query, user)
|
|
84
|
+
const workspaceScope = _query.belongsTo ?? '(no workspace scope)'
|
|
74
85
|
log.info(`[ResourcesQueries][GetResources] Fetching resources for ${workspaceScope}`)
|
|
75
86
|
|
|
76
|
-
const baseQuery = {
|
|
77
|
-
...query,
|
|
78
|
-
type: { $regex: /^@[^/]+\/[^/]+\/schema\// },
|
|
79
|
-
}
|
|
80
|
-
const mongoQuery = user ? { $and: [baseQuery, accessFilter(user)] } : baseQuery
|
|
81
|
-
|
|
82
87
|
return Aggregate.Collection.find(mongoQuery, { state: true }).toArray()
|
|
83
88
|
.then(resources => {
|
|
84
89
|
log.info(`[ResourcesQueries][GetResources] Found ${resources.length} resources`)
|