odant-work 1.0.83 → 1.0.85
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/#system/package-manifest.json +20 -20
- package/$server/$folder/$class/$structure/handlers/pages/data/$handler/data.js +4 -1
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/class.js +0 -4
- package/$server/$folder/$class/$structure/handlers/pages/form/system/$handler/tabs/staff.js +1096 -257
- package/$server/$folder/$class/$structure/handlers/pages/site/$handler/site.js +1 -1
- package/$server/$folder/handlers/pages/form/$handler/form.js +65 -22
- package/$server/$folder/lib/explorer/explorer.js +12 -18
- package/oda/components/layouts/app-layout/app-layout.js +5 -9
- package/package.json +1 -1
- package/sources/data/api.js +27 -24
- package/sources/data/scope.js +49 -9
- package/sources/data/workspace.js +8 -6
- package/sources/modules/agent/node-rules.js +113 -21
- package/sources/modules/nodes/inbound.js +2 -0
- package/sources/server/access/links.js +154 -86
- package/sources/server/access/workplaces.js +231 -27
- package/sources/server/class/base-template.js +86 -86
- package/sources/server/class/security.js +34 -17
|
@@ -141,7 +141,7 @@ export default {
|
|
|
141
141
|
<div class="card" ~for="links" @tap="openLink($for.item)" :title="$for.item.path">
|
|
142
142
|
<oda-icon :icon="$for.item.icon || 'bootstrap:database'" :icon-size="28"></oda-icon>
|
|
143
143
|
<div class="name">{{$for.item.label}}</div>
|
|
144
|
-
<span class="chip">{{$for.item.access === '
|
|
144
|
+
<span class="chip">{{$for.item.access === 'delete' ? 'удаление' : $for.item.access === 'create' ? 'создание' : $for.item.access === 'write' ? 'правка' : 'чтение'}}</span>
|
|
145
145
|
</div>
|
|
146
146
|
</div>
|
|
147
147
|
</section>
|
|
@@ -39,10 +39,22 @@ export default {
|
|
|
39
39
|
pointer-events: none;
|
|
40
40
|
}
|
|
41
41
|
#tools {
|
|
42
|
-
gap:
|
|
43
|
-
|
|
42
|
+
gap: 8px;
|
|
43
|
+
flex-wrap: wrap;
|
|
44
|
+
overflow: visible;
|
|
44
45
|
align-items: center;
|
|
45
|
-
padding: 2px;
|
|
46
|
+
padding: 2px 2px 4px;
|
|
47
|
+
}
|
|
48
|
+
.form-header-inner item-node-explorer {
|
|
49
|
+
min-width: 0;
|
|
50
|
+
max-width: 100%;
|
|
51
|
+
flex-shrink: 1;
|
|
52
|
+
}
|
|
53
|
+
#formToolbar,
|
|
54
|
+
#formToolbar .toolbar-zone,
|
|
55
|
+
#formFooter {
|
|
56
|
+
flex-wrap: wrap;
|
|
57
|
+
min-width: 0;
|
|
46
58
|
}
|
|
47
59
|
#tools item-node {
|
|
48
60
|
flex-shrink: 0;
|
|
@@ -177,7 +189,7 @@ ODA({is: 'work-form',
|
|
|
177
189
|
.form-header-inner {
|
|
178
190
|
min-width: 0;
|
|
179
191
|
flex-wrap: wrap;
|
|
180
|
-
gap:
|
|
192
|
+
gap: 8px;
|
|
181
193
|
margin: 4px;
|
|
182
194
|
align-items: center;
|
|
183
195
|
}
|
|
@@ -186,21 +198,44 @@ ODA({is: 'work-form',
|
|
|
186
198
|
max-width: 100%;
|
|
187
199
|
flex-shrink: 1;
|
|
188
200
|
}
|
|
201
|
+
.mobile-back-spacer {
|
|
202
|
+
width: 36px;
|
|
203
|
+
flex-shrink: 0;
|
|
204
|
+
}
|
|
189
205
|
.consultant-btn {
|
|
190
206
|
border-radius: 50%;
|
|
191
|
-
margin-right:
|
|
207
|
+
margin-right: 4px;
|
|
192
208
|
flex-shrink: 0;
|
|
193
209
|
}
|
|
194
210
|
.call-btn {
|
|
195
211
|
border-radius: 50%;
|
|
196
|
-
margin-right:
|
|
212
|
+
margin-right: 24px;
|
|
197
213
|
flex-shrink: 0;
|
|
198
214
|
}
|
|
199
215
|
.view-selector {
|
|
200
|
-
justify-content:
|
|
201
|
-
|
|
216
|
+
justify-content: flex-end;
|
|
217
|
+
flex-wrap: wrap;
|
|
202
218
|
max-width: 100%;
|
|
203
219
|
min-width: 0;
|
|
220
|
+
overflow: visible;
|
|
221
|
+
}
|
|
222
|
+
.view-selector .flow {
|
|
223
|
+
flex-wrap: wrap;
|
|
224
|
+
gap: 8px;
|
|
225
|
+
border-radius: 4px;
|
|
226
|
+
align-items: center;
|
|
227
|
+
max-width: 100%;
|
|
228
|
+
min-width: 0;
|
|
229
|
+
}
|
|
230
|
+
#tools {
|
|
231
|
+
min-height: 32px;
|
|
232
|
+
align-items: center;
|
|
233
|
+
flex-wrap: wrap;
|
|
234
|
+
gap: 8px;
|
|
235
|
+
padding: 2px 2px 4px;
|
|
236
|
+
max-width: 100%;
|
|
237
|
+
min-width: 0;
|
|
238
|
+
border-bottom: 2px solid color-mix(in oklch, var(--accent-back) 65%, transparent);
|
|
204
239
|
}
|
|
205
240
|
#formToolbar {
|
|
206
241
|
flex-wrap: wrap;
|
|
@@ -213,15 +248,18 @@ ODA({is: 'work-form',
|
|
|
213
248
|
flex-wrap: wrap;
|
|
214
249
|
padding-bottom: max(4px, var(--safe-bottom, 0px)) !important;
|
|
215
250
|
}
|
|
216
|
-
@media (max-width:
|
|
251
|
+
@media (max-width: 768px) {
|
|
252
|
+
#formHeader {
|
|
253
|
+
align-items: flex-start !important;
|
|
254
|
+
}
|
|
217
255
|
.consultant-btn {
|
|
218
|
-
margin-right:
|
|
256
|
+
margin-right: 0;
|
|
219
257
|
}
|
|
220
258
|
.call-btn {
|
|
221
|
-
margin-right:
|
|
259
|
+
margin-right: 0;
|
|
222
260
|
}
|
|
223
|
-
.
|
|
224
|
-
|
|
261
|
+
.view-selector {
|
|
262
|
+
justify-content: flex-start;
|
|
225
263
|
}
|
|
226
264
|
}
|
|
227
265
|
@keyframes view-fade-in {
|
|
@@ -229,15 +267,20 @@ ODA({is: 'work-form',
|
|
|
229
267
|
to { opacity: 1; }
|
|
230
268
|
}
|
|
231
269
|
</style>
|
|
232
|
-
<div id="formHeader" ~show="!fullScreen" accent-invert slot="header" shadow horizontal flex
|
|
233
|
-
|
|
270
|
+
<div id="formHeader" ~show="!fullScreen" accent-invert slot="header" shadow horizontal flex
|
|
271
|
+
:style="'padding: 4px; gap: 8px; min-width: 0; align-items: ' + (ODA.states?.mobileMode ? 'flex-start' : 'center') + ';'">
|
|
272
|
+
<div center flex horizontal class="form-header-inner" style="min-width: 0; flex-wrap: wrap; gap: 8px; margin: 4px; align-items: center;">
|
|
273
|
+
<div ~if="ODA.states?.mobileMode && !isEmbeddedNoTree" class="mobile-back-spacer" style="width: 36px; flex-shrink: 0;"></div>
|
|
234
274
|
<item-node-explorer no-flex :$item="rootItem"></item-node-explorer>
|
|
235
275
|
<div flex></div>
|
|
236
|
-
<oda-button ~if="showConsultantBtn" id="consultantBtn" shadow icon="bootstrap:robot" @tap="askConsultant" title="Спросить ИИ-консультанта по текущей форме" :icon-size info class="consultant-btn"
|
|
237
|
-
|
|
276
|
+
<oda-button ~if="showConsultantBtn" id="consultantBtn" shadow icon="bootstrap:robot" @tap="askConsultant" title="Спросить ИИ-консультанта по текущей форме" :icon-size info class="consultant-btn"
|
|
277
|
+
:style="'border-radius: 50%; flex-shrink: 0; margin-right: ' + (ODA.states?.mobileMode ? '0px' : '4px') + ';'"></oda-button>
|
|
278
|
+
<oda-button shadow icon="communication:call" @tap="call" title="Call..." :icon-size success class="call-btn"
|
|
279
|
+
:style="'border-radius: 50%; flex-shrink: 0; margin-right: ' + (ODA.states?.mobileMode ? '0px' : '24px') + ';'"></oda-button>
|
|
238
280
|
<slot name="top-panel"></slot>
|
|
239
|
-
<div class="view-selector" no-flex horizontal
|
|
240
|
-
|
|
281
|
+
<div class="view-selector" no-flex horizontal
|
|
282
|
+
:style="'flex-wrap: wrap; max-width: 100%; min-width: 0; overflow: visible; justify-content: ' + (ODA.states?.mobileMode ? 'flex-start' : 'flex-end') + ';'">
|
|
283
|
+
<div class="flow" no-flex horizontal style="flex-wrap: wrap; gap: 8px; border-radius: 4px; align-items: center; max-width: 100%; min-width: 0;">
|
|
241
284
|
|
|
242
285
|
<div
|
|
243
286
|
~if="allowSave"
|
|
@@ -266,7 +309,7 @@ ODA({is: 'work-form',
|
|
|
266
309
|
></oda-button>
|
|
267
310
|
|
|
268
311
|
</div>
|
|
269
|
-
<div id="tools" no-flex horizontal style="min-height: 32px; align-items: center;
|
|
312
|
+
<div id="tools" no-flex horizontal style="min-height: 32px; align-items: center; flex-wrap: wrap; gap: 8px; padding: 2px 2px 4px; max-width: 100%; min-width: 0; border-bottom: 2px solid color-mix(in oklch, var(--accent-back) 65%, transparent);">
|
|
270
313
|
<item-node
|
|
271
314
|
~for="visibleFormViews"
|
|
272
315
|
:$item="$for.item"
|
|
@@ -282,8 +325,8 @@ ODA({is: 'work-form',
|
|
|
282
325
|
</div>
|
|
283
326
|
</div>
|
|
284
327
|
</div>
|
|
285
|
-
<oda-button @tap="toggleFullscreen" ~if="currentItem?.type === '$file'" :icon-size content icon="icons:fullscreen" style="border-radius: 50%;"></oda-button>
|
|
286
|
-
<oda-button ~if="!isEmbeddedNoTree" @tap="close" error :icon-size content-invert icon="icons:close" style="border-radius: 50%; margin: 4px;"></oda-button>
|
|
328
|
+
<oda-button @tap="toggleFullscreen" ~if="currentItem?.type === '$file'" :icon-size content icon="icons:fullscreen" style="border-radius: 50%; flex-shrink: 0;"></oda-button>
|
|
329
|
+
<oda-button ~if="!isEmbeddedNoTree" @tap="close" error :icon-size content-invert icon="icons:close" style="border-radius: 50%; margin: 4px; flex-shrink: 0;"></oda-button>
|
|
287
330
|
</div>
|
|
288
331
|
<div id="formTabsBar" slot="top" class="form-tabs-bar" accent-invert horizontal-center no-flex :hidden="!showTabsBar" ~show="showTabsBar" style="width: 100%; padding: 0 4px 0 8px; gap: 6px; box-sizing: border-box; min-height: 38px;">
|
|
289
332
|
<oda-button id="classTreeToggleBtn" ~if="hasClassTree" no-flex allow-toggle
|
|
@@ -13,20 +13,17 @@ export default {
|
|
|
13
13
|
<iframe ~show="focusedPage === $for.item" style="border: none;" flex ~for="pages" :src="$for.item"></iframe>
|
|
14
14
|
</div>
|
|
15
15
|
</div>
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
style="min-width: 0;">
|
|
28
|
-
</oda-tabs>
|
|
29
|
-
</div>
|
|
16
|
+
<oda-tabs id="bookmarksBar" slot="footer" class="pe-no-print" variant="rail" allow-close allow-drag
|
|
17
|
+
:hidden="!hasBookmarks" ~show="hasBookmarks"
|
|
18
|
+
:items="bookmarkTabItems" :focused-index="bookmarkFocusedIndex"
|
|
19
|
+
@tab-select="onBookmarkSelect($event)"
|
|
20
|
+
@tab-close="onBookmarkClose($event)"
|
|
21
|
+
@close-others="onBookmarkCloseOthers($event)"
|
|
22
|
+
@close-right="onBookmarkCloseRight($event)"
|
|
23
|
+
@close-all="closeAllBookmarks($event)"
|
|
24
|
+
@reorder="onBookmarksReorder($event)"
|
|
25
|
+
style="z-index: 2;">
|
|
26
|
+
</oda-tabs>
|
|
30
27
|
`,
|
|
31
28
|
visibleMode: 'main',
|
|
32
29
|
showSize: false,
|
|
@@ -36,10 +33,7 @@ export default {
|
|
|
36
33
|
get hasBookmarks() {
|
|
37
34
|
if (typeof window !== 'undefined' && window !== window.top)
|
|
38
35
|
return false;
|
|
39
|
-
|
|
40
|
-
if (this.left_drawer)
|
|
41
|
-
this.left_drawer.hideBackButton = Boolean(ok && this.mobile);
|
|
42
|
-
return ok;
|
|
36
|
+
return !this.mobile && Array.isArray(this.bookmarks) && this.bookmarks.length > 0 && this.visibleMode === 'main';
|
|
43
37
|
},
|
|
44
38
|
get bookmarkTabItems() {
|
|
45
39
|
return (this.bookmarks || []).map(b => ({
|
|
@@ -189,11 +189,11 @@ ODA({is: 'app-layout-drawer',
|
|
|
189
189
|
white-space: nowrap;
|
|
190
190
|
}
|
|
191
191
|
.back {
|
|
192
|
-
position:
|
|
193
|
-
|
|
194
|
-
{{align === 'right' ? 'right:
|
|
192
|
+
position: absolute;
|
|
193
|
+
top: 0px;
|
|
194
|
+
{{align === 'right' ? 'right: 0px;' : 'left: 0px;'}}
|
|
195
195
|
z-index: 100;
|
|
196
|
-
|
|
196
|
+
margin: 6px;
|
|
197
197
|
}
|
|
198
198
|
</style>
|
|
199
199
|
|
|
@@ -207,7 +207,7 @@ ODA({is: 'app-layout-drawer',
|
|
|
207
207
|
</div>
|
|
208
208
|
</div>
|
|
209
209
|
<oda-splitter ~if="!mobile && !closed" ::width right :reverse @touchstart.stop></oda-splitter>
|
|
210
|
-
<oda-button info round shadow class='back' ~if="mobile && closed && showTabs
|
|
210
|
+
<oda-button info round shadow class='back' ~if="mobile && closed && showTabs" @tap="closed = false" :rotate="align === 'right'? 180: 0" icon="icons:arrow-back" title="Навигация"></oda-button>
|
|
211
211
|
`,
|
|
212
212
|
get mobile() {
|
|
213
213
|
return this.host.mobile;
|
|
@@ -322,10 +322,6 @@ ODA({is: 'app-layout-drawer',
|
|
|
322
322
|
$def: false,
|
|
323
323
|
$type: Boolean,
|
|
324
324
|
},
|
|
325
|
-
hideBackButton: {
|
|
326
|
-
$def: false,
|
|
327
|
-
$type: Boolean,
|
|
328
|
-
},
|
|
329
325
|
width: {
|
|
330
326
|
$def: 340,
|
|
331
327
|
$save: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odant-work",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.85",
|
|
4
4
|
"description": "ODANT-WORK — платформа цифровой организации (встроенная система учёта, документооборот, управление процессами и приватный мультимодальный ИИ)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "sources/work.js",
|
package/sources/data/api.js
CHANGED
|
@@ -44,7 +44,7 @@ import { DataError } from './errors.js';
|
|
|
44
44
|
import { localDay } from './time.js';
|
|
45
45
|
import { buildWorkspace } from './workspace.js';
|
|
46
46
|
import * as SQL_INSPECTOR from './sql-inspector.js';
|
|
47
|
-
import { normalizeSecurity, walkPlaces, trailKey } from '../server/access/workplaces.js';
|
|
47
|
+
import { normalizeSecurity, walkPlaces, trailKey, hasAccess } from '../server/access/workplaces.js';
|
|
48
48
|
|
|
49
49
|
/** Ссылки рабочих мест — модулем по требованию: links.js тянет сервер, который сам импортирует этот модуль. */
|
|
50
50
|
const linksModule = () => import('../server/access/links.js');
|
|
@@ -375,35 +375,36 @@ function reportAccount(db, cls, ref) {
|
|
|
375
375
|
* админ WORK, назначение в самом классе (роль #security, системные — и сверху); для чтения —
|
|
376
376
|
* и класс, открытый гостям. Для записи назначение должно давать запись.
|
|
377
377
|
*/
|
|
378
|
-
async function fullAccess(item, p,
|
|
378
|
+
async function fullAccess(item, p, requiredLevel = 'read') {
|
|
379
|
+
const req = typeof requiredLevel === 'boolean' ? (requiredLevel ? 'write' : 'read') : (requiredLevel || 'read');
|
|
379
380
|
if (!p?.session || DEV_MODE || p.session.$user === globalThis.WORK)
|
|
380
381
|
return true;
|
|
381
382
|
const users = item.DATA?.['#security']?.USER;
|
|
382
|
-
if (
|
|
383
|
+
if (req === 'read' && Array.isArray(users) && (users.includes('GUEST') || users.includes('GUESTS')))
|
|
383
384
|
return true;
|
|
384
385
|
if (await item._isWorkBoss?.(p).catch(() => false))
|
|
385
386
|
return true;
|
|
386
387
|
const level = await (await linksModule()).directAccess(item, p).catch(() => null);
|
|
387
|
-
return
|
|
388
|
+
return hasAccess(level, req);
|
|
388
389
|
}
|
|
389
390
|
|
|
390
391
|
/**
|
|
391
392
|
* Видимость вызова: { full, links — ссылки рабочих мест пользователя на класс, его предков
|
|
392
|
-
* и поддерево, grants — права (null — всё, [] — ничего) }.
|
|
393
|
+
* и поддерево, grants — права (null — всё, [] — ничего) }.
|
|
394
|
+
* Для write/create/delete — только ссылки с достаточным уровнем RWCD.
|
|
393
395
|
*/
|
|
394
|
-
async function scopeOf(item, p, db, cls,
|
|
395
|
-
const
|
|
396
|
+
async function scopeOf(item, p, db, cls, requiredLevel = 'read') {
|
|
397
|
+
const req = typeof requiredLevel === 'boolean' ? (requiredLevel ? 'write' : 'read') : (requiredLevel || 'read');
|
|
398
|
+
const full = await fullAccess(item, p, req);
|
|
396
399
|
const uid = item.constructor.resolveUid?.(p);
|
|
397
|
-
const links = await (await linksModule()).scopeLinks(item, p).catch(() => []);
|
|
398
|
-
return { full, links, grants: full ? null : scopeGrants(db, cls, links, { uid,
|
|
400
|
+
const links = await (await linksModule()).scopeLinks(item, p, req).catch(() => []);
|
|
401
|
+
return { full, links, grants: full ? null : scopeGrants(db, cls, links, { uid, minAccess: req }) };
|
|
399
402
|
}
|
|
400
403
|
|
|
401
404
|
const admin = async (item, p) => item.assertAccess(p, item.constructor.ACCESS_LEVEL.ADMIN);
|
|
402
405
|
|
|
403
406
|
/**
|
|
404
|
-
* Обёртка метода:
|
|
405
|
-
* Чтение: страница класса видна (предок ссылки — как каркас цепочки) и есть хоть одна видимая
|
|
406
|
-
* ветка: ссылка на класс, его предка или ниже.
|
|
407
|
+
* Обёртка метода: права RWCD (`read`/`write`/`create`/`delete`/`admin`), БД, класс вызова, видимость (`vis`).
|
|
407
408
|
*/
|
|
408
409
|
function method(level, fn) {
|
|
409
410
|
return async (item, p = {}) => {
|
|
@@ -412,8 +413,10 @@ function method(level, fn) {
|
|
|
412
413
|
let uid = null;
|
|
413
414
|
if (level === 'read')
|
|
414
415
|
await item.assertAccess(p, item.constructor.ACCESS_LEVEL.READ);
|
|
415
|
-
else if (level === 'write')
|
|
416
|
-
uid =
|
|
416
|
+
else if (level === 'write' || level === 'create' || level === 'delete')
|
|
417
|
+
uid = typeof item._assertDataAccess === 'function'
|
|
418
|
+
? await item._assertDataAccess(level, p)
|
|
419
|
+
: await item._assertDataWrite(p);
|
|
417
420
|
else
|
|
418
421
|
await admin(item, p);
|
|
419
422
|
const basePath = resolveBasePath(item, p);
|
|
@@ -421,7 +424,7 @@ function method(level, fn) {
|
|
|
421
424
|
const cls = await classOf(db, item, basePath);
|
|
422
425
|
const scope = level === 'admin'
|
|
423
426
|
? { full: true, links: [], grants: null }
|
|
424
|
-
: await scopeOf(item, p, db, cls, level
|
|
427
|
+
: await scopeOf(item, p, db, cls, level);
|
|
425
428
|
if (scope.grants?.length === 0)
|
|
426
429
|
throw new Error('Доступ запрещён');
|
|
427
430
|
return fn({ db, cls, item, p, uid, scope, vis: scope.grants });
|
|
@@ -834,9 +837,9 @@ export const DATA_METHODS = Object.freeze({
|
|
|
834
837
|
|
|
835
838
|
/**
|
|
836
839
|
* Создать объект в листе: { post|body, time?, unit?, place?, ext_of?, valid_from? }.
|
|
837
|
-
*
|
|
840
|
+
* Требует уровень C (create) или выше.
|
|
838
841
|
*/
|
|
839
|
-
db_create: { level: 'write', fn: method('
|
|
842
|
+
db_create: { level: 'write', fn: method('create', async ({ db, cls, item, p, uid, scope }) => {
|
|
840
843
|
const at = await writePlace(db, cls, p, scope);
|
|
841
844
|
const obj = createObject(db, {
|
|
842
845
|
cid: cls.cid, body: bodyOf(p) ?? {}, time: p.time, unit: at.unit, place: at.place,
|
|
@@ -861,7 +864,7 @@ export const DATA_METHODS = Object.freeze({
|
|
|
861
864
|
/** Версии объекта: { id }. */
|
|
862
865
|
db_versions: { level: 'read', fn: method('read', async ({ db, cls, p, vis }) => objectVersions(db, await visibleObject(db, cls, p.id, vis, p))) },
|
|
863
866
|
|
|
864
|
-
/** Изменить
|
|
867
|
+
/** Изменить объект (уровень W и выше): { id, post|body, replace?, time?, valid_from?, version? }. */
|
|
865
868
|
db_update: { level: 'write', fn: method('write', ({ db, cls, item, p, uid, vis }) => {
|
|
866
869
|
const obj = updateObject(db, {
|
|
867
870
|
id: ownObject(db, cls, p.id, vis), body: bodyOf(p), replace: flag(p.replace), time: p.time,
|
|
@@ -872,11 +875,11 @@ export const DATA_METHODS = Object.freeze({
|
|
|
872
875
|
return obj;
|
|
873
876
|
}) },
|
|
874
877
|
|
|
875
|
-
/** Удалить объект (
|
|
876
|
-
db_delete: { level: 'write', fn: method('
|
|
878
|
+
/** Удалить объект (отметка, уровень D): { id, version? }. */
|
|
879
|
+
db_delete: { level: 'write', fn: method('delete', ({ db, cls, p, uid, vis }) => deleteObject(db, { id: ownObject(db, cls, p.id, vis), version: p.version, author: uid })) },
|
|
877
880
|
|
|
878
|
-
/** Восстановить
|
|
879
|
-
db_restore: { level: 'write', fn: method('
|
|
881
|
+
/** Восстановить удалённый (уровень D): { id }. */
|
|
882
|
+
db_restore: { level: 'write', fn: method('delete', ({ db, cls, p, uid, vis }) => restoreObject(db, { id: ownObject(db, cls, p.id, vis), author: uid })) },
|
|
880
883
|
|
|
881
884
|
/** Выборка объектов класса (с потомками): параметры queryObjects; `names` — названия объектов по ссылкам. */
|
|
882
885
|
db_query: { level: 'read', fn: method('read', ({ db, cls, p, vis }) => {
|
|
@@ -975,8 +978,8 @@ export const DATA_METHODS = Object.freeze({
|
|
|
975
978
|
});
|
|
976
979
|
}) },
|
|
977
980
|
|
|
978
|
-
/** Удалить собственный HTML-шаблон печатной формы из класса
|
|
979
|
-
db_print_delete: { level: 'write', fn: method('
|
|
981
|
+
/** Удалить собственный HTML-шаблон печатной формы из класса операции (уровень D): { name }. */
|
|
982
|
+
db_print_delete: { level: 'write', fn: method('delete', async ({ db, cls, p }) => deletePrintTemplate(db, {
|
|
980
983
|
ref: cls.cid,
|
|
981
984
|
name: p.name,
|
|
982
985
|
root: process.cwd(),
|
package/sources/data/scope.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { getClass, descendants } from './classes.js';
|
|
24
24
|
import { FAMILY } from './schema.js';
|
|
25
25
|
import { DataError } from './errors.js';
|
|
26
|
+
import { hasAccess } from '../server/access/workplaces.js';
|
|
26
27
|
|
|
27
28
|
export const SCOPES = Object.freeze(['own', 'place', 'unit', 'all']);
|
|
28
29
|
|
|
@@ -68,10 +69,11 @@ function rowsOf(db, link, scope, uid) {
|
|
|
68
69
|
* @param {object} [opts] { uid, write — только ссылки с правом записи }
|
|
69
70
|
* @returns {Array<object>|null} null — видно всё
|
|
70
71
|
*/
|
|
71
|
-
export function scopeGrants(db, cls, links, { uid, write = false } = {}) {
|
|
72
|
+
export function scopeGrants(db, cls, links, { uid, write = false, minAccess = null } = {}) {
|
|
73
|
+
const req = minAccess || (write ? 'write' : 'read');
|
|
72
74
|
const grants = new Map();
|
|
73
75
|
for (const l of links || []) {
|
|
74
|
-
if (
|
|
76
|
+
if (!hasAccess(l.access, req))
|
|
75
77
|
continue;
|
|
76
78
|
let branch = null, type = cls.type;
|
|
77
79
|
if (!under(cls.path, l.id)) {
|
|
@@ -84,11 +86,25 @@ export function scopeGrants(db, cls, links, { uid, write = false } = {}) {
|
|
|
84
86
|
if (FAMILY[c.type])
|
|
85
87
|
type = c.type;
|
|
86
88
|
}
|
|
89
|
+
const excludeSet = new Set();
|
|
90
|
+
for (const dp of l.deniedPaths || []) {
|
|
91
|
+
const dc = getClass(db, dp);
|
|
92
|
+
if (!dc)
|
|
93
|
+
continue;
|
|
94
|
+
for (const cid of descendants(db, dc.cid))
|
|
95
|
+
excludeSet.add(cid);
|
|
96
|
+
}
|
|
97
|
+
if (branch && excludeSet.size) {
|
|
98
|
+
branch = branch.filter(cid => !excludeSet.has(cid));
|
|
99
|
+
if (!branch.length)
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
87
102
|
const defScope = l.external ? 'own' : defaultScope(type);
|
|
88
103
|
const rows = rowsOf(db, l, SCOPES.includes(l.scope) ? l.scope : defScope, uid);
|
|
89
|
-
|
|
104
|
+
const excludeCids = !branch && excludeSet.size ? [...excludeSet] : null;
|
|
105
|
+
if (!branch && !excludeCids && !Object.keys(rows).length)
|
|
90
106
|
return null;
|
|
91
|
-
const g = branch ? { cids: branch, ...
|
|
107
|
+
const g = { ...(branch ? { cids: branch } : {}), ...(excludeCids ? { excludeCids } : {}), ...rows };
|
|
92
108
|
grants.set(JSON.stringify(g), g);
|
|
93
109
|
}
|
|
94
110
|
return [...grants.values()];
|
|
@@ -96,7 +112,7 @@ export function scopeGrants(db, cls, links, { uid, write = false } = {}) {
|
|
|
96
112
|
|
|
97
113
|
/** Права без веток (чтение реестра через виртуальный справочник, проводки объекта). */
|
|
98
114
|
export function withoutBranches(grants) {
|
|
99
|
-
return grants && grants.map(({ cids, ...rows }) => rows);
|
|
115
|
+
return grants && grants.map(({ cids, excludeCids, ...rows }) => rows);
|
|
100
116
|
}
|
|
101
117
|
|
|
102
118
|
/**
|
|
@@ -107,7 +123,16 @@ export function entryGrants(grants, family, objectCid) {
|
|
|
107
123
|
if (grants == null)
|
|
108
124
|
return null;
|
|
109
125
|
const out = [];
|
|
110
|
-
for (const { cids, ...rows } of grants) {
|
|
126
|
+
for (const { cids, excludeCids, ...rows } of grants) {
|
|
127
|
+
if (excludeCids?.length) {
|
|
128
|
+
if (family === 'account')
|
|
129
|
+
out.push({ ...(cids ? { accounts: cids } : {}), excludeAccounts: excludeCids, ...rows });
|
|
130
|
+
else if (family === 'operation')
|
|
131
|
+
out.push({ ...(cids ? { ops: cids } : {}), excludeOps: excludeCids, ...rows });
|
|
132
|
+
else if (objectCid === undefined || !excludeCids.includes(objectCid))
|
|
133
|
+
out.push(rows);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
111
136
|
if (!cids)
|
|
112
137
|
out.push(rows);
|
|
113
138
|
else if (family === 'account')
|
|
@@ -125,6 +150,11 @@ function inList(col, list) {
|
|
|
125
150
|
return values.length ? [`${col} IN (${values.map(() => '?').join(',')})`, values] : ['0', []];
|
|
126
151
|
}
|
|
127
152
|
|
|
153
|
+
function notInList(col, list) {
|
|
154
|
+
const values = [...new Set(list.map(String))];
|
|
155
|
+
return values.length ? [`${col} NOT IN (${values.map(() => '?').join(',')})`, values] : ['1', []];
|
|
156
|
+
}
|
|
157
|
+
|
|
128
158
|
/** Условия строк (подразделения, места, автор) на таблицу с колонками unit/place/author. */
|
|
129
159
|
function rowParts(g, alias, entries) {
|
|
130
160
|
const parts = [];
|
|
@@ -159,7 +189,11 @@ function anyOf(grants, partsOf) {
|
|
|
159
189
|
|
|
160
190
|
/** Условие видимости объектов (алиас таблицы `o`): [sql, args] или null — без ограничений. */
|
|
161
191
|
export function objectCond(grants, alias = 'o') {
|
|
162
|
-
return anyOf(grants, g => [
|
|
192
|
+
return anyOf(grants, g => [
|
|
193
|
+
...(g.cids ? [inList(`${alias}.cid`, g.cids)] : []),
|
|
194
|
+
...(g.excludeCids?.length ? [notInList(`${alias}.cid`, g.excludeCids)] : []),
|
|
195
|
+
...rowParts(g, alias, false),
|
|
196
|
+
]);
|
|
163
197
|
}
|
|
164
198
|
|
|
165
199
|
/**
|
|
@@ -173,8 +207,14 @@ export function entryCond(grants, accCols = ['e.debit_cid', 'e.credit_cid']) {
|
|
|
173
207
|
const c = accCols.map(col => inList(col, g.accounts));
|
|
174
208
|
parts.push([`(${c.map(x => x[0]).join(' OR ')})`, c.flatMap(x => x[1])]);
|
|
175
209
|
}
|
|
210
|
+
if (g.excludeAccounts?.length) {
|
|
211
|
+
const c = accCols.map(col => notInList(col, g.excludeAccounts));
|
|
212
|
+
parts.push([`(${c.map(x => x[0]).join(' AND ')})`, c.flatMap(x => x[1])]);
|
|
213
|
+
}
|
|
176
214
|
if (g.ops)
|
|
177
215
|
parts.push(inList('e.op_cid', g.ops));
|
|
216
|
+
if (g.excludeOps?.length)
|
|
217
|
+
parts.push(notInList('e.op_cid', g.excludeOps));
|
|
178
218
|
return [...parts, ...rowParts(g, 'e', true)];
|
|
179
219
|
});
|
|
180
220
|
}
|
|
@@ -198,7 +238,7 @@ export function visibleUnits(grants) {
|
|
|
198
238
|
* на класс или его предка. ADMIN подразделения — любое его место (`any`).
|
|
199
239
|
* @returns {Array<{ unit, unit_label, place, place_label, any? }>}
|
|
200
240
|
*/
|
|
201
|
-
export function writeContexts(db, cls, links) {
|
|
241
|
+
export function writeContexts(db, cls, links, minAccess = 'create') {
|
|
202
242
|
const out = new Map();
|
|
203
243
|
const add = (l, place, any = false) => {
|
|
204
244
|
const unit = unitOf(db, l.structure);
|
|
@@ -217,7 +257,7 @@ export function writeContexts(db, cls, links) {
|
|
|
217
257
|
});
|
|
218
258
|
};
|
|
219
259
|
for (const l of links || []) {
|
|
220
|
-
if ((l.access
|
|
260
|
+
if (!hasAccess(l.access, minAccess) || !under(cls.path, l.id))
|
|
221
261
|
continue;
|
|
222
262
|
if (l.relation === 'admin')
|
|
223
263
|
add(l, null, true);
|
|
@@ -11,19 +11,21 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { getClass, children } from './classes.js';
|
|
13
13
|
import { FAMILY } from './schema.js';
|
|
14
|
-
import { normalizeSecurity, walkPlaces, trailKey, memberTrailKeys } from '../server/access/workplaces.js';
|
|
14
|
+
import { normalizeSecurity, walkPlaces, trailKey, memberTrailKeys, ACCESS_RANK } from '../server/access/workplaces.js';
|
|
15
15
|
|
|
16
|
-
const RANK =
|
|
16
|
+
const RANK = ACCESS_RANK;
|
|
17
17
|
const SCOPE_RANK = { null: 0, own: 1, place: 2, unit: 3, all: 4 };
|
|
18
18
|
const LIMIT_CLASSES = 5000;
|
|
19
19
|
|
|
20
|
-
/** Права на ссылку: у BOSS и вышестоящего места — только
|
|
21
|
-
const readOnly = links => links.map(l => ({ ...l, access: 'read' }));
|
|
20
|
+
/** Права на ссылку: у BOSS и вышестоящего места — только чтение (явный none остаётся скрытым). */
|
|
21
|
+
const readOnly = links => links.filter(l => l.access !== 'none').map(l => ({ ...l, access: 'read' }));
|
|
22
22
|
|
|
23
|
-
/** Слияние ссылок по id: выше доступ, при равном — шире
|
|
23
|
+
/** Слияние ссылок по id: выше доступ, при равном — шире видимость; явные none отфильтровываются. */
|
|
24
24
|
function mergeLinks(...lists) {
|
|
25
25
|
const out = new Map();
|
|
26
26
|
for (const l of lists.flat()) {
|
|
27
|
+
if (!l || l.access === 'none')
|
|
28
|
+
continue;
|
|
27
29
|
const cur = out.get(l.id);
|
|
28
30
|
const better = !cur
|
|
29
31
|
|| (RANK[l.access] ?? 0) > (RANK[cur.access] ?? 0)
|
|
@@ -34,7 +36,7 @@ function mergeLinks(...lists) {
|
|
|
34
36
|
return [...out.values()];
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
const ownLinks = node => node.LINKS.map(l => ({ id: l.id, access: l.access, scope: l.scope ?? null }));
|
|
39
|
+
const ownLinks = node => node.LINKS.filter(l => l.access !== 'none').map(l => ({ id: l.id, access: l.access, scope: l.scope ?? null }));
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
42
|
* Подразделения и места пользователя с меню.
|