odant-work 1.0.105 → 1.0.107
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/$server/$folder/$class/$structure/$user/handlers/pages/form/calendar/$handler/class.js +12 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/email/$handler/class.js +12 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/folder/$handler/class.js +12 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/search/$handler/class.js +12 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/$handler/class.js +14 -0
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/agent/$handler/class.js +5 -4
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/skills/$handler/class.js +5 -4
- package/$server/$folder/$class/$structure/$user/handlers/pages/form/system/tokens/$handler/class.js +8 -2
- package/$server/$folder/$class/$structure/handlers/pages/form/chat/$handler/class.js +73 -22
- package/$server/$folder/handlers/pages/form/$handler/class.js +255 -100
- package/$server/$folder/lib/consultant/consultant.js +123 -66
- package/$server/$folder/lib/explorer/explorer.js +19 -22
- package/$server/$folder/lib/icon/icon.js +4 -1
- package/$server/$folder/lib/prompt-bar/prompt-bar.js +24 -1
- package/$server/$folder/lib/tree/tree.js +5 -5
- package/MODULES/$domain/class.js +1 -0
- package/package.json +1 -1
- package/sources/client.js +30 -2
- package/sources/host/auth-methods.js +25 -14
- package/sources/host/http-server.js +1 -0
- package/sources/host/websocket.js +11 -8
- package/sources/modules/call/call.js +5 -1
- package/sources/modules/user-profile/user-profile.js +9 -1
- package/sources/server/access/gateway.js +3 -7
- package/sources/server/chat-threads.js +32 -3
- package/sources/server/class/feed.js +25 -13
- package/sources/server/class/security.js +97 -31
- package/sources/server/logs.js +17 -10
- package/sources/server/server.js +17 -6
- package/sources/server/user.js +20 -5
|
@@ -4,6 +4,7 @@ import { DEV_MODE, HOST, CHALLENGE_TTL_MS } from './config.js';
|
|
|
4
4
|
import { getMailer } from './mail.js';
|
|
5
5
|
import * as CORE from '../server/index.js';
|
|
6
6
|
import { $server } from '../server/server.js';
|
|
7
|
+
import { notifyUserOnline } from './websocket.js';
|
|
7
8
|
import { audit } from '../server/access/audit.js';
|
|
8
9
|
import { inspectInvite, consumeInvite } from '../server/access/invites.js';
|
|
9
10
|
import { assertWorkplaceAvailableForLogin, sendLoginCodeViaLicenseHub } from '../modules/license/index.js';
|
|
@@ -352,11 +353,13 @@ export const authMethods = {
|
|
|
352
353
|
if (!challengeId || String(challengeId).length > 64)
|
|
353
354
|
throw new Error("challengeId required");
|
|
354
355
|
let users = await WORK.$users;
|
|
355
|
-
let
|
|
356
|
-
if (
|
|
356
|
+
let accountNode = await users.get_item('//' + uid);
|
|
357
|
+
if (!accountNode)
|
|
357
358
|
throw new Error("User not registered");
|
|
358
|
-
|
|
359
|
-
await
|
|
359
|
+
accountNode.reset();
|
|
360
|
+
await accountNode.init;
|
|
361
|
+
if (typeof accountNode._ownUserEnabledSync === 'function' && !accountNode._ownUserEnabledSync())
|
|
362
|
+
throw new Error('Учётная запись отключена администратором');
|
|
360
363
|
// До проверки подписи — только ожидание входа; личность сессии не меняется.
|
|
361
364
|
// Ожидание хранится по challengeId (случайный UUID клиента), а не в сессии: параллельные запросы
|
|
362
365
|
// страницы после перезапуска могут получить разные cookie — вход от этого не рвётся.
|
|
@@ -367,11 +370,11 @@ export const authMethods = {
|
|
|
367
370
|
const key = String(challengeId);
|
|
368
371
|
if (pendingLogins.size >= 10_000)
|
|
369
372
|
throw new Error("Слишком много незавершённых входов, повторите позже");
|
|
370
|
-
const perUid = [...pendingLogins.values()].filter(c => c.uid ===
|
|
373
|
+
const perUid = [...pendingLogins.values()].filter(c => c.uid === accountNode.id).length;
|
|
371
374
|
if (perUid >= 16)
|
|
372
375
|
throw new Error("Слишком много незавершённых входов");
|
|
373
376
|
const challenge = crypto.randomUUID();
|
|
374
|
-
pendingLogins.set(key, { value: challenge, uid:
|
|
377
|
+
pendingLogins.set(key, { value: challenge, uid: accountNode.id, expiresAt: now + CHALLENGE_TTL_MS });
|
|
375
378
|
return challenge;
|
|
376
379
|
},
|
|
377
380
|
|
|
@@ -382,11 +385,17 @@ export const authMethods = {
|
|
|
382
385
|
throw new Error("uid required");
|
|
383
386
|
const challengeKey = challengeId != null ? String(challengeId) : '';
|
|
384
387
|
if (session.uid === uid) {
|
|
388
|
+
const accountNode = await (await WORK.$users).get_item('//' + uid).catch(() => null);
|
|
389
|
+
if (!accountNode || (typeof accountNode._ownUserEnabledSync === 'function' && !accountNode._ownUserEnabledSync())) {
|
|
390
|
+
WORK.constructor.clearAllSessionsForUid?.(uid);
|
|
391
|
+
throw new Error('Учётная запись отключена администратором');
|
|
392
|
+
}
|
|
385
393
|
if (challengeKey) {
|
|
386
394
|
const entry = pendingLogins.get(challengeKey);
|
|
387
395
|
if (entry?.uid === uid)
|
|
388
396
|
pendingLogins.delete(challengeKey);
|
|
389
397
|
}
|
|
398
|
+
notifyUserOnline(session, accountNode);
|
|
390
399
|
}
|
|
391
400
|
else {
|
|
392
401
|
let signature = params.post?.signature;
|
|
@@ -399,11 +408,11 @@ export const authMethods = {
|
|
|
399
408
|
throw new Error("login session break. Challenge expired.");
|
|
400
409
|
if (challengeEntry.uid !== uid)
|
|
401
410
|
throw new Error("login session break. Challenge issued for another user.");
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
411
|
+
const accountNode = await (await WORK.$users).get_item('//' + uid);
|
|
412
|
+
if (!accountNode)
|
|
404
413
|
throw new Error("User not registered");
|
|
405
|
-
await
|
|
406
|
-
let publicKey =
|
|
414
|
+
await accountNode.init;
|
|
415
|
+
let publicKey = accountNode.DATA?.keys?.[time];
|
|
407
416
|
if (!publicKey) throw new Error("login session break. Need publicKey.");
|
|
408
417
|
let PK = await crypto.subtle.importKey("spki", Buffer.from(publicKey, "base64"), { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, true, ["verify"]);
|
|
409
418
|
const isValid = await crypto.subtle.verify(
|
|
@@ -423,11 +432,10 @@ export const authMethods = {
|
|
|
423
432
|
currentSsid: session.ssid,
|
|
424
433
|
isAdmin,
|
|
425
434
|
});
|
|
426
|
-
session.credentials =
|
|
427
|
-
$server.signIn(session,
|
|
435
|
+
session.credentials = accountNode.DATA;
|
|
436
|
+
$server.signIn(session, accountNode);
|
|
428
437
|
audit('login', { params });
|
|
429
|
-
|
|
430
|
-
$user.reset();
|
|
438
|
+
notifyUserOnline(session, accountNode);
|
|
431
439
|
$server.broadcastAuthChangedToSession(session, { uid, reason: 'login' });
|
|
432
440
|
}
|
|
433
441
|
const invTok = String(params.post?.inviteToken || params.inviteToken || '').trim();
|
|
@@ -487,6 +495,9 @@ export const authMethods = {
|
|
|
487
495
|
}
|
|
488
496
|
const affected = Object.values($server.sessions).filter(s => s.uid === uid);
|
|
489
497
|
this.constructor.clearAllSessionsForUid(uid);
|
|
498
|
+
const exitNode = await (await WORK.$users).get_item('//' + uid).catch(() => null);
|
|
499
|
+
if (exitNode)
|
|
500
|
+
notifyUserOnline(null, exitNode);
|
|
490
501
|
for (const [id, c] of pendingLogins)
|
|
491
502
|
if (c?.uid === uid)
|
|
492
503
|
pendingLogins.delete(id);
|
|
@@ -351,6 +351,7 @@ export function createRequestHandler() {
|
|
|
351
351
|
else {
|
|
352
352
|
session = $server.get_session(cookies.ssid);
|
|
353
353
|
session.ip = request.socket?.remoteAddress;
|
|
354
|
+
WORK.constructor.enforceSessionEnabled?.(session);
|
|
354
355
|
}
|
|
355
356
|
const url = new URL(`https://${request.headers.host || HOST}` + request.url);
|
|
356
357
|
let path = decodeURIComponent(url.pathname);
|
|
@@ -75,12 +75,13 @@ export function broadcastChatEvent(uids, payload) {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
function notifyUserOnline(session) {
|
|
79
|
-
|
|
78
|
+
export function notifyUserOnline(session, userOverride = null) {
|
|
79
|
+
const user = userOverride || session?.$user;
|
|
80
|
+
if (!user)
|
|
80
81
|
return;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
broadcastUserPath(
|
|
82
|
+
user.online = undefined;
|
|
83
|
+
user.reset?.();
|
|
84
|
+
broadcastUserPath(user);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
export function isTaskVisibleToUser(uid, taskPath) {
|
|
@@ -159,7 +160,8 @@ export function onWebSocketConnect(ws, request) {
|
|
|
159
160
|
let wsid = $server.genGUID();
|
|
160
161
|
session.sockets[wsid] = { ws, events: [], visibleTasks: new Set() };
|
|
161
162
|
ws.send(JSON.stringify({ type: 'connect', wsid }));
|
|
162
|
-
|
|
163
|
+
if (session.uid)
|
|
164
|
+
notifyUserOnline(session);
|
|
163
165
|
ws.on('message', async (message) => {
|
|
164
166
|
try {
|
|
165
167
|
let str = new TextDecoder('utf-8').decode(message);
|
|
@@ -204,10 +206,11 @@ export function onWebSocketConnect(ws, request) {
|
|
|
204
206
|
}
|
|
205
207
|
});
|
|
206
208
|
ws.on('close', () => {
|
|
209
|
+
const hadUser = session.$user;
|
|
207
210
|
session.sockets[wsid] = undefined;
|
|
208
211
|
delete session.sockets[wsid];
|
|
209
|
-
if (!Object.keys(session.sockets).length)
|
|
210
|
-
notifyUserOnline(session);
|
|
212
|
+
if (!Object.keys(session.sockets).length && hadUser)
|
|
213
|
+
notifyUserOnline(session, hadUser);
|
|
211
214
|
});
|
|
212
215
|
// F24: слишком большое сообщение (и прочие ошибки сокета) — не роняют процесс
|
|
213
216
|
ws.on('error', e => log.debug('ws.error', e));
|
|
@@ -384,9 +384,13 @@ export class RTCCaller extends EventTarget {
|
|
|
384
384
|
|
|
385
385
|
static async sendMessage(callContext, signalMessage) {
|
|
386
386
|
console.log('sendMessage', signalMessage);
|
|
387
|
+
let target = callContext;
|
|
388
|
+
if (target?.DATA?.isUser && WORK?.uid && target.id !== WORK.uid) {
|
|
389
|
+
target = WORK.USER || await WORK.get_$user?.(WORK.uid).catch(() => null) || target;
|
|
390
|
+
}
|
|
387
391
|
let file = new File([JSON.stringify(signalMessage)], 'phone.call', { type: "application/json" });
|
|
388
392
|
let params = { receivers: signalMessage.receivers };
|
|
389
|
-
await
|
|
393
|
+
await target.save_file(file, params);
|
|
390
394
|
}
|
|
391
395
|
|
|
392
396
|
static currentAnswerDialog = null;
|
|
@@ -99,7 +99,8 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
const errMsg = String(this.error?.message || this.error || '');
|
|
102
|
-
const
|
|
102
|
+
const isDisabledAccount = /отключена администратором|account_disabled/i.test(errMsg) || Boolean(WORK?._accountDisabled);
|
|
103
|
+
const keyRejected = !isDisabledAccount && /user not registered|need publickey|login failed|challenge issued for another user/i.test(errMsg);
|
|
103
104
|
if(!this.isRegistered || !this.hasKey || keyRejected)
|
|
104
105
|
return {
|
|
105
106
|
name: 'unregistered',
|
|
@@ -115,6 +116,13 @@ ODA({ is: 'user-profile', imports: 'oda//otp.js',
|
|
|
115
116
|
legend: 'Выполняется вход в систему…',
|
|
116
117
|
class: 'info-invert'
|
|
117
118
|
}
|
|
119
|
+
if (isDisabledAccount)
|
|
120
|
+
return {
|
|
121
|
+
name: 'need-login',
|
|
122
|
+
label: 'Повторить вход',
|
|
123
|
+
legend: 'Учётная запись отключена администратором. После повторного включения нажмите «Повторить вход».',
|
|
124
|
+
class: 'error-invert'
|
|
125
|
+
}
|
|
118
126
|
return {
|
|
119
127
|
name: 'need-login',
|
|
120
128
|
label: 'Войти',
|
|
@@ -42,7 +42,7 @@ export const MEMBERS = Object.freeze({
|
|
|
42
42
|
logs: L.READ, logs_dates: L.READ, log_files: L.READ, read_log_bodies: L.READ,
|
|
43
43
|
read_log_entry: L.READ, log_index: L.READ, chatSource: L.READ,
|
|
44
44
|
chat_thread_open: L.CALL, chat_threads_list: L.READ, chat_messages_list: L.READ,
|
|
45
|
-
chat_send: L.
|
|
45
|
+
chat_send: L.CALL, chat_mark_read: L.CALL, chat_action: L.WRITE, chat_unread_summary: L.AUTH, visible_contacts: L.AUTH, my_scope: L.AUTH,
|
|
46
46
|
mail_accounts: L.READ, mail_list: L.READ, mail_read: L.READ,
|
|
47
47
|
mail_draft_save: L.WRITE, mail_send: L.WRITE, mail_state: L.WRITE, mail_refresh: L.WRITE,
|
|
48
48
|
calendar_list: L.READ, calendar_save: L.WRITE,
|
|
@@ -205,17 +205,13 @@ export function isSameOriginRequest(request) {
|
|
|
205
205
|
const normHost = stripDefaultPort(rawHost);
|
|
206
206
|
const normFwd = stripDefaultPort(fwdHost);
|
|
207
207
|
const isProxied = isLoopbackRemote(request) || Boolean(h['x-forwarded-proto'] && h['x-work-wsid'] !== undefined);
|
|
208
|
+
const isSameSiteWithWsid = Boolean(site === 'same-origin' && h['x-work-wsid'] !== undefined);
|
|
208
209
|
if (h.origin) {
|
|
209
210
|
try {
|
|
210
211
|
const originHost = stripDefaultPort(new URL(h.origin).host);
|
|
211
212
|
const matchesHost = Boolean(normHost && originHost === normHost);
|
|
212
213
|
const matchesFwd = Boolean(isProxied && normFwd && originHost === normFwd);
|
|
213
|
-
|
|
214
|
-
isLoopbackRemote(request)
|
|
215
|
-
&& site === 'same-origin'
|
|
216
|
-
&& h['x-work-wsid'] !== undefined
|
|
217
|
-
);
|
|
218
|
-
if (!matchesHost && !matchesFwd && !matchesLoopbackSameSite)
|
|
214
|
+
if (!matchesHost && !matchesFwd && !isSameSiteWithWsid)
|
|
219
215
|
return false;
|
|
220
216
|
}
|
|
221
217
|
catch { return false; }
|
|
@@ -44,6 +44,10 @@ export async function dbForThreadStorage(storage, kind = '') {
|
|
|
44
44
|
return LOGS.dbForStorage(storage);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
function isSysSession(params = {}) {
|
|
48
|
+
return DEV_MODE || !params?.session || params.session.$user === globalThis.WORK;
|
|
49
|
+
}
|
|
50
|
+
|
|
47
51
|
function resolveActorUid(storage, params = {}) {
|
|
48
52
|
const uid = storage?.constructor?.resolveUid?.(params);
|
|
49
53
|
if (uid)
|
|
@@ -127,6 +131,12 @@ export async function openThread(storage, params = {}) {
|
|
|
127
131
|
if (!peerId)
|
|
128
132
|
throw new Error('Не указан собеседник (peerId)');
|
|
129
133
|
const threadId = dmThreadId(uid, peerId);
|
|
134
|
+
const existing = getThreadWithMeta(db, threadId, uid);
|
|
135
|
+
if (!existing && peerId !== uid && !isSysSession(params)) {
|
|
136
|
+
const contacts = await visibleContacts(storage, params).catch(() => []);
|
|
137
|
+
if (!contacts.some(c => c.id === peerId))
|
|
138
|
+
throw new Error(ACCESS_DENIED);
|
|
139
|
+
}
|
|
130
140
|
const title = String(params.title || '').trim();
|
|
131
141
|
tx(db, () => {
|
|
132
142
|
db.prepare(`
|
|
@@ -354,6 +364,12 @@ export async function sendMessage(storage, params = {}) {
|
|
|
354
364
|
const isParticipant = thread.participants.some(p => p.uid === uid);
|
|
355
365
|
if (!isParticipant && !isTwinBot)
|
|
356
366
|
throw new Error(ACCESS_DENIED);
|
|
367
|
+
if (thread.kind !== 'dm' && !isTwinBot && !isSysSession(params)) {
|
|
368
|
+
const canSee = await storage.canSee?.(storage, params).catch(() => false);
|
|
369
|
+
const roles = await storage.roles?.(params).catch(() => []) || [];
|
|
370
|
+
if (!canSee && !roles.length)
|
|
371
|
+
throw new Error(ACCESS_DENIED);
|
|
372
|
+
}
|
|
357
373
|
|
|
358
374
|
const content = String(params.message ?? params.content ?? '');
|
|
359
375
|
const msgKind = String(params.kind || 'text').trim() || 'text';
|
|
@@ -561,14 +577,26 @@ export async function visibleContacts(storage, params = {}) {
|
|
|
561
577
|
});
|
|
562
578
|
}
|
|
563
579
|
|
|
580
|
+
await Promise.resolve(globalThis.WORK?.init).catch(() => {});
|
|
581
|
+
const rootBossIds = new Set(
|
|
582
|
+
(Array.isArray(globalThis.WORK?.DATA?.['#security']?.BOSS) ? globalThis.WORK.DATA['#security'].BOSS : [])
|
|
583
|
+
.filter(id => id && !WORKPLACES.isPseudoUser(id))
|
|
584
|
+
);
|
|
585
|
+
|
|
564
586
|
const isWorkBoss = uid && globalThis.WORK
|
|
565
|
-
? (
|
|
587
|
+
? (isSysSession(params) || await globalThis.WORK._isWorkBoss?.(params).catch(() => false))
|
|
566
588
|
: Boolean(DEV_MODE);
|
|
567
589
|
|
|
568
590
|
const visibleIds = new Set();
|
|
569
591
|
const externalOnlyIds = new Set();
|
|
570
592
|
if (uid && userMap.has(uid))
|
|
571
593
|
visibleIds.add(uid);
|
|
594
|
+
if (uid) {
|
|
595
|
+
for (const bossId of rootBossIds) {
|
|
596
|
+
if (userMap.has(bossId))
|
|
597
|
+
visibleIds.add(bossId);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
572
600
|
|
|
573
601
|
if (isWorkBoss) {
|
|
574
602
|
for (const id of userMap.keys())
|
|
@@ -581,7 +609,7 @@ export async function visibleContacts(storage, params = {}) {
|
|
|
581
609
|
const containers = dom ? ((await dom.items) || []).filter(c => c && c.id && c.id[0] !== '$') : [];
|
|
582
610
|
for (const base of containers) {
|
|
583
611
|
const units = [base];
|
|
584
|
-
const sub = await base.items
|
|
612
|
+
const sub = await Promise.resolve(base.items).catch(() => []) || [];
|
|
585
613
|
for (const s of sub) {
|
|
586
614
|
if (s?.type === '$structure' || s?.DATA?.isDepartment)
|
|
587
615
|
units.push(s);
|
|
@@ -590,7 +618,7 @@ export async function visibleContacts(storage, params = {}) {
|
|
|
590
618
|
const internalSet = new Set();
|
|
591
619
|
const externalSet = new Set();
|
|
592
620
|
for (const u of units) {
|
|
593
|
-
await u.init
|
|
621
|
+
await Promise.resolve(u.init).catch(() => {});
|
|
594
622
|
const sec = u.DATA?.['#security'] || {};
|
|
595
623
|
const roles = await u.roles?.(params).catch(() => []) || [];
|
|
596
624
|
if (roles.length)
|
|
@@ -650,6 +678,7 @@ export async function visibleContacts(storage, params = {}) {
|
|
|
650
678
|
out.push({
|
|
651
679
|
...entry,
|
|
652
680
|
external: externalOnlyIds.has(id),
|
|
681
|
+
superBoss: rootBossIds.has(id),
|
|
653
682
|
});
|
|
654
683
|
}
|
|
655
684
|
return out;
|
|
@@ -11,6 +11,18 @@ import { DEV_MODE } from '../../host/config.js';
|
|
|
11
11
|
|
|
12
12
|
const ACCESS_DENIED = 'Доступ запрещён';
|
|
13
13
|
|
|
14
|
+
function mergeChatPost(params = {}, post) {
|
|
15
|
+
let body = post ?? params?.post ?? params?.body ?? params?.data;
|
|
16
|
+
if (typeof body === 'string' && body.trim()) {
|
|
17
|
+
try { body = JSON.parse(body); } catch { /* ignore */ }
|
|
18
|
+
}
|
|
19
|
+
if (body && typeof body === 'object' && !Array.isArray(body)) {
|
|
20
|
+
const { session: _drop, ...safeBody } = body;
|
|
21
|
+
return { ...safeBody, ...params, session: params?.session };
|
|
22
|
+
}
|
|
23
|
+
return params;
|
|
24
|
+
}
|
|
25
|
+
|
|
14
26
|
export const classFeedMethods = {
|
|
15
27
|
/** Может ли вызывающий принудительно открыть местный лог точки (роль BOSS здесь или выше по дереву). */
|
|
16
28
|
async _canViewLocalFeed(params = {}) {
|
|
@@ -161,28 +173,28 @@ export const classFeedMethods = {
|
|
|
161
173
|
},
|
|
162
174
|
|
|
163
175
|
/** Открыть/создать беседу мессенджера (twin на $structure, dm на $user, group). */
|
|
164
|
-
async chat_thread_open(params = {}) {
|
|
165
|
-
return CHAT.openThread(this, params);
|
|
176
|
+
async chat_thread_open(params = {}, post) {
|
|
177
|
+
return CHAT.openThread(this, mergeChatPost(params, post));
|
|
166
178
|
},
|
|
167
179
|
|
|
168
180
|
/** Список бесед (mine — свои, audit — взаимодействия пользователей с Агентом для BOSS). */
|
|
169
|
-
async chat_threads_list(params = {}) {
|
|
170
|
-
return CHAT.listThreads(this, params);
|
|
181
|
+
async chat_threads_list(params = {}, post) {
|
|
182
|
+
return CHAT.listThreads(this, mergeChatPost(params, post));
|
|
171
183
|
},
|
|
172
184
|
|
|
173
185
|
/** Сообщения беседы с проверкой прав (участник или BOSS для twin-аудита). */
|
|
174
|
-
async chat_messages_list(params = {}) {
|
|
175
|
-
return CHAT.listMessages(this, params);
|
|
186
|
+
async chat_messages_list(params = {}, post) {
|
|
187
|
+
return CHAT.listMessages(this, mergeChatPost(params, post));
|
|
176
188
|
},
|
|
177
189
|
|
|
178
190
|
/** Отправить сообщение в беседу + рассылка по WebSocket. */
|
|
179
|
-
async chat_send(params = {}) {
|
|
180
|
-
return CHAT.sendMessage(this, params);
|
|
191
|
+
async chat_send(params = {}, post) {
|
|
192
|
+
return CHAT.sendMessage(this, mergeChatPost(params, post));
|
|
181
193
|
},
|
|
182
194
|
|
|
183
195
|
/** Отметить беседу прочитанной. */
|
|
184
|
-
async chat_mark_read(params = {}) {
|
|
185
|
-
return CHAT.markRead(this, params);
|
|
196
|
+
async chat_mark_read(params = {}, post) {
|
|
197
|
+
return CHAT.markRead(this, mergeChatPost(params, post));
|
|
186
198
|
},
|
|
187
199
|
|
|
188
200
|
/** Сводка непрочитанного. */
|
|
@@ -191,8 +203,8 @@ export const classFeedMethods = {
|
|
|
191
203
|
},
|
|
192
204
|
|
|
193
205
|
/** Подтвердить/отклонить карточку действия (kind = 'approval') в беседе. */
|
|
194
|
-
async chat_action(params = {}) {
|
|
195
|
-
return CHAT.resolveApproval(this, params);
|
|
206
|
+
async chat_action(params = {}, post) {
|
|
207
|
+
return CHAT.resolveApproval(this, mergeChatPost(params, post));
|
|
196
208
|
},
|
|
197
209
|
|
|
198
210
|
/** Вычисляемый список видимых контактов («Люди»). */
|
|
@@ -400,7 +412,7 @@ export const classFeedMethods = {
|
|
|
400
412
|
switch (params.mode || 'folder') {
|
|
401
413
|
case 'dates': {
|
|
402
414
|
const nonEmpty = params.nonEmpty === true || params.nonEmpty === '1' || params.nonEmpty === 'true';
|
|
403
|
-
return LOGS.datesList(this, { nonEmpty, ownOnly });
|
|
415
|
+
return LOGS.datesList(this, { nonEmpty, ownOnly, feedMode: params.feedMode || '' });
|
|
404
416
|
}
|
|
405
417
|
case 'bodies':
|
|
406
418
|
return bodies();
|
|
@@ -575,6 +575,8 @@ export const classSecurityMethods = {
|
|
|
575
575
|
}
|
|
576
576
|
if (this._isSystemItem(item))
|
|
577
577
|
return true;
|
|
578
|
+
if (this._hasRootBossOnlyAncestor(item) || this._hasRootBossOnlyAncestor(this))
|
|
579
|
+
return false;
|
|
578
580
|
if (this.areaOf(item).kind === POLICY.AREA.SECRET)
|
|
579
581
|
return false;
|
|
580
582
|
const isUserSession = Boolean(uid && params.session?.principal?.kind !== 'node');
|
|
@@ -712,41 +714,101 @@ export const classSecurityMethods = {
|
|
|
712
714
|
},
|
|
713
715
|
|
|
714
716
|
/** Есть ли у субъекта хотя бы одна внутренняя роль сотрудника (BOSS или не-external должность), а не только внешняя. */
|
|
715
|
-
async
|
|
716
|
-
if (
|
|
717
|
-
return true;
|
|
717
|
+
async _roleSummary(params = {}) {
|
|
718
|
+
if (this._isSysSession(params)) {
|
|
719
|
+
return { hasInternal: true, hasExternal: false, isWorkBoss: true, isUnitBoss: true, hasAnyRole: true };
|
|
720
|
+
}
|
|
718
721
|
const uid = this.constructor.resolveUid(params);
|
|
719
|
-
if (!uid)
|
|
720
|
-
return false;
|
|
721
|
-
|
|
722
|
-
|
|
722
|
+
if (!uid) {
|
|
723
|
+
return { hasInternal: false, hasExternal: false, isWorkBoss: false, isUnitBoss: false, hasAnyRole: false };
|
|
724
|
+
}
|
|
725
|
+
let hasInternal = false;
|
|
726
|
+
let hasExternal = false;
|
|
727
|
+
let isWorkBoss = false;
|
|
728
|
+
let isUnitBoss = false;
|
|
729
|
+
let hasAnyRole = false;
|
|
730
|
+
|
|
731
|
+
const inspectNode = async (node, isRoot = false) => {
|
|
732
|
+
const r = await Promise.resolve(node?.roles?.(params)).catch(() => []) || [];
|
|
723
733
|
if (!r.length)
|
|
724
|
-
return
|
|
734
|
+
return;
|
|
735
|
+
hasAnyRole = true;
|
|
725
736
|
const decl = node._declaredRolesSync?.() || {};
|
|
726
|
-
|
|
737
|
+
if (r.includes(this.constructor.ROLES.BOSS)) {
|
|
738
|
+
hasInternal = true;
|
|
739
|
+
if (isRoot)
|
|
740
|
+
isWorkBoss = true;
|
|
741
|
+
else
|
|
742
|
+
isUnitBoss = true;
|
|
743
|
+
}
|
|
744
|
+
for (const id of r) {
|
|
745
|
+
if (id === this.constructor.ROLES.BOSS || !decl[id]?.external)
|
|
746
|
+
hasInternal = true;
|
|
747
|
+
else
|
|
748
|
+
hasExternal = true;
|
|
749
|
+
}
|
|
727
750
|
};
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
751
|
+
|
|
752
|
+
if (globalThis.WORK)
|
|
753
|
+
await inspectNode(globalThis.WORK, true);
|
|
754
|
+
|
|
755
|
+
const dom = await globalThis.WORK?.get_item?.('/PROJECTS').catch(() => null);
|
|
756
|
+
const roots = dom ? ((await Promise.resolve(dom.items).catch(() => [])) || []).filter(b => b && b.id?.[0] !== '$') : [];
|
|
757
|
+
const stack = roots.map(node => ({ node, depth: 0 }));
|
|
758
|
+
while (stack.length) {
|
|
759
|
+
const { node, depth } = stack.pop();
|
|
760
|
+
await inspectNode(node, false);
|
|
761
|
+
if (isUnitBoss && hasInternal && hasExternal)
|
|
762
|
+
break;
|
|
763
|
+
if (depth >= 5)
|
|
764
|
+
continue;
|
|
765
|
+
const sub = await Promise.resolve(node.items).catch(() => []) || [];
|
|
766
|
+
for (const s of sub) {
|
|
767
|
+
if (s && (s.type === '$structure' || s.DATA?.isDepartment) && s.id?.[0] !== '$')
|
|
768
|
+
stack.push({ node: s, depth: depth + 1 });
|
|
745
769
|
}
|
|
770
|
+
}
|
|
771
|
+
return { hasInternal, hasExternal, isWorkBoss, isUnitBoss, hasAnyRole };
|
|
772
|
+
},
|
|
773
|
+
|
|
774
|
+
async _hasInternalWorkRole(params = {}) {
|
|
775
|
+
const sum = await this._roleSummary(params);
|
|
776
|
+
return sum.hasInternal;
|
|
777
|
+
},
|
|
778
|
+
|
|
779
|
+
_isSysSession(params) {
|
|
780
|
+
return DEV_MODE || !params?.session || params.session.$user === globalThis.WORK;
|
|
781
|
+
},
|
|
782
|
+
|
|
783
|
+
async _canAccessUsersContainer(params = {}) {
|
|
784
|
+
if (this._isSysSession(params))
|
|
785
|
+
return true;
|
|
786
|
+
if (params?.session?.principal?.kind === 'node')
|
|
787
|
+
return false;
|
|
788
|
+
const uid = this.constructor.resolveUid(params);
|
|
789
|
+
if (!uid)
|
|
746
790
|
return false;
|
|
791
|
+
const sum = await this._roleSummary(params);
|
|
792
|
+
// Внутренние сотрудники и неназначенные пользователи видят /USERS; внешние (external-only) — нет
|
|
793
|
+
return sum.hasInternal || !sum.hasExternal;
|
|
794
|
+
},
|
|
795
|
+
|
|
796
|
+
/** Сводка ролевого контекста текущего пользователя (для UI профиля и Консультанта). */
|
|
797
|
+
async my_scope(params = {}) {
|
|
798
|
+
const uid = this.constructor.resolveUid(params);
|
|
799
|
+
const sum = await this._roleSummary(params);
|
|
800
|
+
return {
|
|
801
|
+
uid: uid || '',
|
|
802
|
+
...sum,
|
|
803
|
+
isUnassigned: Boolean(uid && !sum.hasAnyRole && !sum.isWorkBoss),
|
|
747
804
|
};
|
|
748
|
-
|
|
749
|
-
|
|
805
|
+
},
|
|
806
|
+
|
|
807
|
+
_hasRootBossOnlyAncestor(node) {
|
|
808
|
+
for (let cur = node; cur && cur instanceof FS.$folder; cur = cur.$parent) {
|
|
809
|
+
if (cur.DATA?.rootBossOnly === true && (!cur.$parent || !cur.$parent.$parent))
|
|
810
|
+
return true;
|
|
811
|
+
}
|
|
750
812
|
return false;
|
|
751
813
|
},
|
|
752
814
|
|
|
@@ -769,15 +831,19 @@ export const classSecurityMethods = {
|
|
|
769
831
|
},
|
|
770
832
|
|
|
771
833
|
async allowAccess(params) {
|
|
772
|
-
const isSysSession =
|
|
834
|
+
const isSysSession = this._isSysSession(params);
|
|
773
835
|
await this.init;
|
|
774
|
-
// Раздел /USERS (usersContainer): виден внутренним
|
|
836
|
+
// Раздел /USERS (usersContainer): виден внутренним и неназначенным пользователям; скрыт от external-only и гостей
|
|
775
837
|
if (this.DATA?.usersContainer === true) {
|
|
838
|
+
return this._canAccessUsersContainer(params);
|
|
839
|
+
}
|
|
840
|
+
// Корневой контейнер с rootBossOnly (например /MODULES): виден в дереве и API только BOSS корня WORK
|
|
841
|
+
if (this._hasRootBossOnlyAncestor(this)) {
|
|
776
842
|
if (isSysSession)
|
|
777
843
|
return true;
|
|
778
844
|
if (params?.session?.principal?.kind === 'node')
|
|
779
845
|
return false;
|
|
780
|
-
return this.
|
|
846
|
+
return Boolean(await this._isWorkBoss(params));
|
|
781
847
|
}
|
|
782
848
|
// Домен-контейнер (например /PROJECTS, /MODULES): виден только BOSS или при наличии хотя бы одного доступного потомка
|
|
783
849
|
if (this.DATA?.container === true && !this.hasAssignments()) {
|
package/sources/server/logs.js
CHANGED
|
@@ -127,13 +127,19 @@ export function logExt(row) {
|
|
|
127
127
|
|
|
128
128
|
export function isSystemMetaLogRow(row) {
|
|
129
129
|
const p = String(row?.path || '').trim().replace(/\\/g, '/');
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
130
|
+
if (p) {
|
|
131
|
+
if (/(?:^|\/)(?:class\.js|readme\.md)$/i.test(p))
|
|
132
|
+
return true;
|
|
133
|
+
if (/\/history\/\d{4}-\d{2}-\d{2}\/\d+\.[^/]+\.js$/i.test(p))
|
|
134
|
+
return true;
|
|
135
|
+
// Снимки метафайлов внутри $.../#... (кроме пользовательских документов и задач .task)
|
|
136
|
+
if (/\/#(?:secret|system)\//i.test(p) && !/\.task$/i.test(p))
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
if (!String(row?.content || '').trim() && Array.isArray(row?.includes) && row.includes.length) {
|
|
140
|
+
if (row.includes.every(inc => /(?:^|\/)(?:class\.js|readme\.md)$/i.test(String(inc || '').trim().replace(/\\/g, '/'))))
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
137
143
|
return false;
|
|
138
144
|
}
|
|
139
145
|
|
|
@@ -197,8 +203,9 @@ function isVisibleChatRootRow(row, ownOnly = null) {
|
|
|
197
203
|
* Даты, за которые есть логи (по убыванию).
|
|
198
204
|
* По умолчанию сегодня всегда в списке; при `nonEmpty: true` — только дни, где есть хотя бы одна видимая корневая запись (без `mainContext`).
|
|
199
205
|
*/
|
|
200
|
-
export async function datesList(storage, { nonEmpty = false, ownOnly = null } = {}) {
|
|
206
|
+
export async function datesList(storage, { nonEmpty = false, ownOnly = null, feedMode = '' } = {}) {
|
|
201
207
|
const dateSet = new Set(nonEmpty ? [] : [today()]);
|
|
208
|
+
const skipSys = feedMode === 'dialog';
|
|
202
209
|
try {
|
|
203
210
|
const db = await dbForStorage(storage);
|
|
204
211
|
const fp = feedPathOf(storage);
|
|
@@ -209,7 +216,7 @@ export async function datesList(storage, { nonEmpty = false, ownOnly = null } =
|
|
|
209
216
|
continue;
|
|
210
217
|
try {
|
|
211
218
|
const row = typeof r.body === 'string' ? JSON.parse(r.body) : r.body;
|
|
212
|
-
if (isVisibleChatRootRow(row, ownOnly))
|
|
219
|
+
if (isVisibleChatRootRow(row, ownOnly) && (!skipSys || !isSystemMetaLogRow(row)))
|
|
213
220
|
dateSet.add(r.day);
|
|
214
221
|
}
|
|
215
222
|
catch { /* skip broken json */ }
|
|
@@ -240,7 +247,7 @@ export async function datesList(storage, { nonEmpty = false, ownOnly = null } =
|
|
|
240
247
|
for (const fname of fs.readdirSync(dayPath).filter(n => n.endsWith('.logs'))) {
|
|
241
248
|
try {
|
|
242
249
|
const row = JSON.parse(fs.readFileSync(path.join(dayPath, fname), 'utf-8'));
|
|
243
|
-
if (isVisibleChatRootRow(row, ownOnly)) {
|
|
250
|
+
if (isVisibleChatRootRow(row, ownOnly) && (!skipSys || !isSystemMetaLogRow(row))) {
|
|
244
251
|
dateSet.add(entry.name);
|
|
245
252
|
break;
|
|
246
253
|
}
|
package/sources/server/server.js
CHANGED
|
@@ -420,8 +420,8 @@ export class $server extends $class {
|
|
|
420
420
|
* Вход в сессию после успешной проверки (подпись ключа / регистрация):
|
|
421
421
|
* субъект сессии + новый ssid (старый, известный до входа, больше не действует).
|
|
422
422
|
*/
|
|
423
|
-
static signIn(session,
|
|
424
|
-
if (
|
|
423
|
+
static signIn(session, account) {
|
|
424
|
+
if (account && typeof account._ownUserEnabledSync === 'function' && !account._ownUserEnabledSync())
|
|
425
425
|
throw new Error('Учётная запись отключена администратором');
|
|
426
426
|
const old = session.ssid;
|
|
427
427
|
const id = this.newSessionId();
|
|
@@ -429,13 +429,24 @@ export class $server extends $class {
|
|
|
429
429
|
delete this.sessions[old];
|
|
430
430
|
session.ssid = id;
|
|
431
431
|
this.sessions[id] = session;
|
|
432
|
-
session.uid =
|
|
433
|
-
session.id =
|
|
434
|
-
session.$user =
|
|
435
|
-
session.principal = Object.freeze({ kind: 'user', id:
|
|
432
|
+
session.uid = account.id;
|
|
433
|
+
session.id = account.id;
|
|
434
|
+
session.$user = account;
|
|
435
|
+
session.principal = Object.freeze({ kind: 'user', id: account.id });
|
|
436
|
+
session.isAccountEnabled = () => account._ownUserEnabledSync();
|
|
436
437
|
return session;
|
|
437
438
|
}
|
|
438
439
|
|
|
440
|
+
static enforceSessionEnabled(session) {
|
|
441
|
+
if (!session?.uid || typeof session.isAccountEnabled !== 'function' || session.isAccountEnabled())
|
|
442
|
+
return true;
|
|
443
|
+
for (const sock of Object.values(session.sockets || {})) {
|
|
444
|
+
try { sock?.ws?.close?.(4403, 'account_disabled'); } catch { /* ignore */ }
|
|
445
|
+
}
|
|
446
|
+
this.clearAllSessionsForUid(session.uid);
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
|
|
439
450
|
static clearSessionAuth(session) {
|
|
440
451
|
if (!session)
|
|
441
452
|
return;
|