odant-work 1.0.106 → 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.
@@ -2082,9 +2082,14 @@ ODA({
2082
2082
  if (!Array.isArray(rows)) rows = [];
2083
2083
  const isDialogMetaRow = r => {
2084
2084
  const p = String(r?.path || '').trim().replace(/\\/g, '/');
2085
- if (!p) return false;
2086
- if (/(?:^|\/)class\.js$/i.test(p)) return true;
2087
- if (/\/#(?:secret|system)\//i.test(p) && !/\.task$/i.test(p)) return true;
2085
+ if (p) {
2086
+ if (/(?:^|\/)(?:class\.js|readme\.md)$/i.test(p)) return true;
2087
+ if (/\/history\/\d{4}-\d{2}-\d{2}\/\d+\.[^/]+\.js$/i.test(p)) return true;
2088
+ if (/\/#(?:secret|system)\//i.test(p) && !/\.task$/i.test(p)) return true;
2089
+ }
2090
+ if (!String(r?.content || '').trim() && Array.isArray(r?.includes) && r.includes.length) {
2091
+ if (r.includes.every(inc => /(?:^|\/)(?:class\.js|readme\.md)$/i.test(String(inc || '').trim().replace(/\\/g, '/')))) return true;
2092
+ }
2088
2093
  return false;
2089
2094
  };
2090
2095
  const hasVisibleRowPayload = r => {
@@ -939,7 +939,7 @@ ODA({is: 'work-form',
939
939
  <div ~if="!isTaskForm" flex></div>
940
940
  <oda-button ~if="showConsultantBtn" id="consultantBtn" shadow icon="bootstrap:robot" @tap="askConsultant" title="Спросить ИИ-консультанта по текущей форме" :icon-size info class="consultant-btn"
941
941
  :style="'border-radius: 50%; flex-shrink: 0; margin-right: ' + (ODA.states?.mobileMode ? '0px' : '4px') + ';'"></oda-button>
942
- <oda-button ~if="!isTaskForm" shadow icon="communication:call" @tap="call" title="Call..." :icon-size success class="call-btn"
942
+ <oda-button ~if="showCallBtn" shadow icon="communication:call" @tap="call" title="Позвонить" :icon-size success class="call-btn"
943
943
  :style="'border-radius: 50%; flex-shrink: 0; margin-right: ' + (ODA.states?.mobileMode ? '0px' : '24px') + ';'"></oda-button>
944
944
  <slot name="top-panel"></slot>
945
945
  <div ~if="!isTaskForm || visibleFormViews.length > 1 || allowSave" class="view-selector" no-flex horizontal
@@ -1037,16 +1037,25 @@ ODA({is: 'work-form',
1037
1037
  </div>
1038
1038
  `,
1039
1039
  async call(e) {
1040
- const el = ODA.createComponent('call-users-list');
1041
- const users = await el.users;
1042
- if (users.length === 1) {
1043
- el.selectedUsers.push(users[0]);
1040
+ const cur = this.currentItem || await this.$item;
1041
+ if (cur?.DATA?.isUser && WORK?.uid && cur.id && cur.id !== WORK.uid) {
1042
+ WORK.top.RTCCaller.startCall(cur, [cur.id]);
1043
+ return;
1044
+ }
1045
+ const candidates = Array.isArray(this._callCandidates) && this._callCandidates.length
1046
+ ? this._callCandidates
1047
+ : await this._resolveCallCandidates(cur);
1048
+ if (!candidates.length)
1049
+ return;
1050
+ const el = ODA.createComponent('call-users-list', { users: candidates });
1051
+ if (candidates.length === 1) {
1052
+ el.selectedUsers = [candidates[0]];
1044
1053
  }
1045
1054
  const updateEnable = () => {
1046
- const cond = el.selectedUsers.length > 0;
1047
- if (el.domParent) {
1048
- if (cond) {
1049
- el.domParent.OK.label = 'Позвонить [' + el.selectedUsers.length + ']';
1055
+ const count = el.selectedUsers.length;
1056
+ if (el.domParent?.OK) {
1057
+ if (count > 0) {
1058
+ el.domParent.OK.label = `Позвонить (${count})`;
1050
1059
  el.domParent.OK.icon = 'communication:call';
1051
1060
  }
1052
1061
  else {
@@ -1057,26 +1066,29 @@ ODA({is: 'work-form',
1057
1066
  };
1058
1067
  el.addEventListener('changed', updateEnable);
1059
1068
  try {
1060
- this.async(() => { updateEnable() }, 100);
1069
+ this.async(() => { updateEnable(); }, 50);
1061
1070
  const res = await WORK.showDialog(el, {
1062
- TITLE: { label: 'Выбор собеседников', icon: 'communication:call' },
1063
- OK: { label: 'позвонить', icon: 'communication:call' },
1071
+ allowClose: true,
1072
+ TITLE: { label: 'Позвонить', icon: 'communication:call' },
1073
+ OK: { label: 'Позвонить', icon: 'communication:call' },
1074
+ CANCEL: { label: 'Отмена', icon: 'icons:close' },
1064
1075
  });
1065
1076
  if (res === 'ok') {
1066
1077
  const receivers = el.selectedUsers;
1067
1078
  if (receivers.length > 0) {
1068
- WORK.top.RTCCaller.startCall(await this.$item, receivers.map(u => u.id));
1079
+ WORK.top.RTCCaller.startCall(cur, receivers.map(u => u.id));
1069
1080
  }
1070
1081
  else {
1071
- WORK.top.RTCCaller.startRecord(await this.$item);
1082
+ WORK.top.RTCCaller.startRecord(cur);
1072
1083
  }
1073
1084
  }
1074
1085
  }
1075
1086
  catch (err) {
1076
- console.log(err);
1087
+ if (!(err instanceof WORK.CancelError))
1088
+ console.log(err);
1077
1089
  }
1078
1090
  finally {
1079
- el.removeEventListener('selected-users-changed', updateEnable);
1091
+ el.removeEventListener('changed', updateEnable);
1080
1092
  }
1081
1093
  },
1082
1094
  allowZoom: true,
@@ -1704,12 +1716,13 @@ ODA({is: 'work-form',
1704
1716
  this._appliedRoleItem = n;
1705
1717
  this._appliedRole = n.role || '';
1706
1718
  this._rootHasChildClasses = await this._detectHasChildClasses(n);
1707
- if (globalThis.WORK?.uid && !globalThis.WORK?.DEV_MODE && n?.DATA?.isUser && !n?.DATA?.usersContainer) {
1719
+ if (globalThis.WORK?.uid && !globalThis.WORK?.DEV_MODE && (n?.DATA?.isUser || n?.isUser) && !n?.DATA?.usersContainer) {
1708
1720
  this._myScope = await globalThis.WORK.fetch('/', 'my_scope').catch(() => null);
1709
1721
  }
1710
1722
  else {
1711
1723
  this._myScope = null;
1712
1724
  }
1725
+ this._callCandidates = await this._resolveCallCandidates(n);
1713
1726
  }
1714
1727
  finally {
1715
1728
  this._initializingItem = false;
@@ -1758,6 +1771,35 @@ ODA({is: 'work-form',
1758
1771
  get isEmbeddedNoTree() {
1759
1772
  return typeof location !== 'undefined' && new URLSearchParams(location.search).get('noTree') === '1';
1760
1773
  },
1774
+ _callCandidates: [],
1775
+ get showCallBtn() {
1776
+ return Boolean(!this.isTaskForm && Array.isArray(this._callCandidates) && this._callCandidates.length > 0);
1777
+ },
1778
+ async _resolveCallCandidates(n) {
1779
+ if (!n || n.DATA?.usersContainer || n.DATA?.container || n.DATA?.objects)
1780
+ return [];
1781
+ if (n.DATA?.isUser || n.isUser) {
1782
+ return (WORK?.uid && n.id && n.id !== WORK.uid) ? [n] : [];
1783
+ }
1784
+ if (!n.DATA?.isStructure)
1785
+ return [];
1786
+ try {
1787
+ const raw = typeof n.fetch === 'function' ? await n.fetch('assignedUsers').catch(() => []) : [];
1788
+ const seen = new Set();
1789
+ const out = [];
1790
+ for (const u of (Array.isArray(raw) ? raw : [])) {
1791
+ const id = u?.id;
1792
+ if (!id || id === WORK?.uid || seen.has(id))
1793
+ continue;
1794
+ seen.add(id);
1795
+ out.push(u);
1796
+ }
1797
+ return out;
1798
+ }
1799
+ catch {
1800
+ return [];
1801
+ }
1802
+ },
1761
1803
  get showConsultantBtn() {
1762
1804
  if (!this.currentItem || this.isTaskForm)
1763
1805
  return false;
@@ -2786,107 +2828,204 @@ ODA({
2786
2828
  is: 'call-users-list',
2787
2829
  template: /*html*/`
2788
2830
  <style>
2789
- :host{
2831
+ :host {
2790
2832
  @apply --vertical;
2833
+ width: min(420px, 92vw);
2834
+ max-height: min(460px, 70vh);
2791
2835
  overflow: hidden;
2792
- min-width: 300px;
2793
-
2794
- .filter-box{
2795
- @apply --horizontal;
2796
- @apply --header;
2797
- @apply --no-flex;
2798
- padding: 4px;
2799
-
2800
- input{
2801
- @apply --flex;
2802
- @apply --content;
2803
- margin: auto;
2804
- padding: 8px;
2805
- width: 0px;
2806
- border: none;
2807
- outline: none;
2808
- border-radius: 2em;
2809
- }
2810
- }
2811
-
2812
- .users-box{
2813
- @apply --vertical;
2814
- overflow-x: hidden;
2815
- text-overflow: ellipsis;
2816
- overflow-y: auto;
2817
- gap: 4px;
2818
- padding: 8px;
2819
- min-height: calc(52px * 5);
2820
-
2821
- .user-row{
2822
- @apply --horizontal;
2823
- align-items: center;
2824
- min-height: fit-content;
2825
- flex-wrap: nowrap;
2826
- overflow: hidden;
2827
- text-overflow: ellipsis;
2828
- border-radius: 0em;
2829
- padding: 0px 3px;
2830
- transition: border-radius, background-color 0.3s ease;
2831
-
2832
- &[selected]{
2833
- border-radius: 2em;
2834
- }
2835
-
2836
- item-node{
2837
- pointer-events: none;
2838
- }
2839
- }
2840
- .nope-row{
2841
- text-align: center;
2842
- opacity: 0.25;
2843
- }
2844
-
2845
- }
2836
+ background: var(--content-background, #ffffff);
2837
+ color: var(--content-color, #0f172a);
2838
+ box-sizing: border-box;
2839
+ }
2840
+ .search-wrap {
2841
+ display: flex;
2842
+ align-items: center;
2843
+ gap: 8px;
2844
+ margin: 10px 12px 6px;
2845
+ padding: 6px 10px;
2846
+ border-radius: 10px;
2847
+ border: 1px solid var(--border-color, #cbd5e1);
2848
+ background: var(--subtle-background, #f8fafc);
2849
+ flex-shrink: 0;
2850
+ }
2851
+ .search-wrap input {
2852
+ flex: 1 1 auto;
2853
+ min-width: 0;
2854
+ border: none;
2855
+ outline: none;
2856
+ background: transparent;
2857
+ color: inherit;
2858
+ font: inherit;
2859
+ font-size: 13.5px;
2860
+ }
2861
+ .bar-meta {
2862
+ display: flex;
2863
+ align-items: center;
2864
+ justify-content: space-between;
2865
+ padding: 2px 14px 6px;
2866
+ font-size: 12px;
2867
+ color: var(--muted-color, #64748b);
2868
+ flex-shrink: 0;
2869
+ }
2870
+ .toggle-all {
2871
+ border: none;
2872
+ background: transparent;
2873
+ color: var(--accent-color, #2563eb);
2874
+ font: inherit;
2875
+ font-size: 12px;
2876
+ font-weight: 600;
2877
+ cursor: pointer;
2878
+ padding: 2px 4px;
2879
+ border-radius: 6px;
2880
+ }
2881
+ .toggle-all:hover {
2882
+ background: color-mix(in oklch, var(--accent-color, #2563eb) 10%, transparent);
2883
+ }
2884
+ .users-box {
2885
+ @apply --vertical;
2886
+ flex: 1 1 auto;
2887
+ min-height: 120px;
2888
+ overflow-y: auto;
2889
+ gap: 4px;
2890
+ padding: 4px 12px 12px;
2891
+ box-sizing: border-box;
2892
+ }
2893
+ .user-row {
2894
+ display: flex;
2895
+ align-items: center;
2896
+ gap: 10px;
2897
+ padding: 8px 10px;
2898
+ border-radius: 10px;
2899
+ border: 1px solid transparent;
2900
+ cursor: pointer;
2901
+ user-select: none;
2902
+ transition: background-color 0.15s ease, border-color 0.15s ease;
2903
+ }
2904
+ .user-row:hover {
2905
+ background: var(--subtle-background, rgba(148, 163, 184, 0.12));
2906
+ }
2907
+ .user-row[selected] {
2908
+ background: color-mix(in oklch, var(--accent-color, #2563eb) 10%, transparent);
2909
+ border-color: color-mix(in oklch, var(--accent-color, #2563eb) 40%, transparent);
2910
+ }
2911
+ .avatar-wrap {
2912
+ position: relative;
2913
+ flex-shrink: 0;
2914
+ width: 36px;
2915
+ height: 36px;
2916
+ display: flex;
2917
+ align-items: center;
2918
+ justify-content: center;
2919
+ }
2920
+ .online-dot {
2921
+ position: absolute;
2922
+ right: -1px;
2923
+ bottom: -1px;
2924
+ width: 10px;
2925
+ height: 10px;
2926
+ border-radius: 50%;
2927
+ background: #22c55e;
2928
+ border: 2px solid var(--content-background, #ffffff);
2929
+ box-sizing: border-box;
2930
+ }
2931
+ .user-info {
2932
+ flex: 1 1 auto;
2933
+ min-width: 0;
2934
+ display: flex;
2935
+ flex-direction: column;
2936
+ gap: 1px;
2937
+ }
2938
+ .user-name {
2939
+ font-size: 13.5px;
2940
+ font-weight: 600;
2941
+ white-space: nowrap;
2942
+ overflow: hidden;
2943
+ text-overflow: ellipsis;
2944
+ }
2945
+ .user-sub {
2946
+ font-size: 11.5px;
2947
+ color: var(--muted-color, #64748b);
2948
+ white-space: nowrap;
2949
+ overflow: hidden;
2950
+ text-overflow: ellipsis;
2951
+ }
2952
+ .check-ic {
2953
+ flex-shrink: 0;
2954
+ color: var(--muted-color, #94a3b8);
2955
+ }
2956
+ .user-row[selected] .check-ic {
2957
+ color: var(--accent-color, #2563eb);
2958
+ }
2959
+ .empty-msg {
2960
+ padding: 28px 12px;
2961
+ text-align: center;
2962
+ font-size: 13px;
2963
+ color: var(--muted-color, #64748b);
2846
2964
  }
2847
2965
  </style>
2848
- <div ~if="users?.length" class="filter-box">
2849
- <input type="search" ::value="filterVal" placeholder="filter">
2850
- </div>
2851
- <div ~if="users?.length" class="users-box">
2852
- <div class="user-row" ~for="filteredUsers" @click="select_user($for.item)" :selected="isSelected($for.item)">
2853
- <oda-icon :icon="isSelected($for.item) ? 'icons:check' : ''" icon-size="48" :success="isSelected($for.item)" style="border-radius: 50%;"></oda-icon>
2854
- <item-node :$item="$for.item" icon-size="48"></item-node>
2966
+ <div class="wrap" style="display:flex;flex-direction:column;flex:1;min-height:0;overflow:hidden;">
2967
+ <div ~if="users?.length" class="search-wrap">
2968
+ <oda-icon icon="carbon:search" :icon-size="15" style="opacity: 0.6;"></oda-icon>
2969
+ <input type="search" ::value="filterVal" placeholder="Поиск сотрудника…">
2970
+ </div>
2971
+ <div ~if="users?.length > 1" class="bar-meta">
2972
+ <span>Выбрано: {{selectedUsers.length}} из {{users.length}}</span>
2973
+ <button type="button" class="toggle-all" @tap="toggleAll()">
2974
+ {{selectedUsers.length === users.length ? 'Снять выбор' : 'Выбрать всех'}}
2975
+ </button>
2855
2976
  </div>
2856
- <h2 ~if="filteredUsers.length === 0" class="nope-row">не найдено</h2>
2977
+ <div ~if="users?.length" class="users-box">
2978
+ <div class="user-row" ~for="filteredUsers" @tap="select_user($for.item)" :selected="isSelected($for.item)">
2979
+ <div class="avatar-wrap">
2980
+ <oda-icon round :icon="$for.item.icon || 'icons:account-circle'" :icon-size="36" :style="'background:' + ($for.item.iconColor || 'transparent') + ';color:white;fill:white;'"></oda-icon>
2981
+ <span ~if="$for.item.online" class="online-dot" title="В сети"></span>
2982
+ </div>
2983
+ <div class="user-info">
2984
+ <span class="user-name">{{$for.item.label || $for.item.DATA?.label || $for.item.id}}</span>
2985
+ <span ~if="$for.item.email || $for.item.DATA?.email" class="user-sub">{{$for.item.email || $for.item.DATA?.email}}</span>
2986
+ </div>
2987
+ <oda-icon class="check-ic" :icon="isSelected($for.item) ? 'icons:check-box' : 'icons:check-box-outline-blank'" :icon-size="20"></oda-icon>
2988
+ </div>
2989
+ <div ~if="filteredUsers.length === 0" class="empty-msg">Никого не найдено</div>
2990
+ </div>
2991
+ <div ~if="!users" class="empty-msg">Загрузка списка…</div>
2992
+ <div ~if="users?.length === 0" class="empty-msg">Нет доступных собеседников</div>
2857
2993
  </div>
2858
- <h1 center ~if="!users">Загрузка...</h1>
2859
- <h1 center ~if="users?.length === 0">пользователи не найдены</h1>
2860
2994
  `,
2861
- get users() {
2862
- return (async () => {
2863
- const $users = await WORK.get_item('/USERS');
2864
- const users = await $users.items;
2865
- return (users || []).filter(u => u.id !== WORK.uid);
2866
- })();
2867
- },
2995
+ users: [],
2868
2996
  filterVal: '',
2869
2997
  get filteredUsers() {
2870
- if (!this.users) return;
2871
- return this.filterVal
2872
- ? this.users.filter(u => [u.label, u.id].some(s => s.includes(this.filterVal)))
2873
- : this.users;
2998
+ const list = Array.isArray(this.users) ? this.users : [];
2999
+ const q = String(this.filterVal || '').trim().toLowerCase();
3000
+ if (!q)
3001
+ return list;
3002
+ return list.filter(u => {
3003
+ const lbl = String(u?.label || u?.DATA?.label || '').toLowerCase();
3004
+ const eml = String(u?.email || u?.DATA?.email || '').toLowerCase();
3005
+ const id = String(u?.id || '').toLowerCase();
3006
+ return lbl.includes(q) || eml.includes(q) || id.includes(q);
3007
+ });
2874
3008
  },
2875
3009
  selectedUsers: [],
2876
3010
  getIndex($user) {
2877
- return this.selectedUsers.findIndex(u => u.id === $user.id)
3011
+ return this.selectedUsers.findIndex(u => u.id === $user.id);
2878
3012
  },
2879
3013
  isSelected($user) {
2880
3014
  return this.getIndex($user) > -1;
2881
3015
  },
2882
3016
  select_user($user) {
2883
3017
  const idx = this.getIndex($user);
2884
- if (idx > -1) {
2885
- this.selectedUsers.splice(idx, 1);
2886
- }
2887
- else {
2888
- this.selectedUsers.push($user);
2889
- }
3018
+ const next = [...this.selectedUsers];
3019
+ if (idx > -1)
3020
+ next.splice(idx, 1);
3021
+ else
3022
+ next.push($user);
3023
+ this.selectedUsers = next;
3024
+ this.fire('changed');
3025
+ },
3026
+ toggleAll() {
3027
+ const list = Array.isArray(this.users) ? this.users : [];
3028
+ this.selectedUsers = this.selectedUsers.length === list.length ? [] : [...list];
2890
3029
  this.fire('changed');
2891
3030
  }
2892
3031
  });
@@ -829,7 +829,16 @@ export default {
829
829
  WORK.authEvents?.addEventListener('auth', () => {
830
830
  this._resolvedUserIcon = '';
831
831
  this.user_icon = undefined;
832
- if (WORK.uid && this._autoOpenedLogin && this.visibleMode === 'user') {
832
+ if (!WORK.uid && !WORK.DEV_MODE) {
833
+ this.focusedPage = '';
834
+ this.pages = [];
835
+ this.bookmarks = [];
836
+ this._autoOpenedLogin = true;
837
+ this.visibleMode = 'user';
838
+ if (this.left_drawer)
839
+ this.left_drawer.closed = true;
840
+ }
841
+ else if (WORK.uid && this._autoOpenedLogin && this.visibleMode === 'user') {
833
842
  this._autoOpenedLogin = false;
834
843
  this.visibleMode = 'main';
835
844
  if (this.left_drawer)
@@ -46,8 +46,11 @@ export default {
46
46
  $def: false,
47
47
  $attr: true,
48
48
  get() {
49
- if (this.isUser)
49
+ if (this.isUser) {
50
+ if (this.$item?.DATA?.enabled === false || this.$item?.DATA?.blocked === true)
51
+ return false;
50
52
  return this.$item?.online;
53
+ }
51
54
  return false;
52
55
  }
53
56
  },
@@ -697,7 +697,6 @@ ODA({is: 'oda-tree-node',
697
697
  :host {
698
698
  @apply --vertical;
699
699
  overflow: visible;
700
- padding: 4px;
701
700
  min-width: 0;
702
701
  }
703
702
  .node {
@@ -713,12 +712,12 @@ ODA({is: 'oda-tree-node',
713
712
  color: var(--content-color);
714
713
  }
715
714
  .node.large-icon-node {
716
- height: 52px;
717
- min-height: 52px;
715
+ height: 64px;
716
+ min-height: 64px;
718
717
  }
719
718
  .node.medium-icon-node {
720
- height: 38px;
721
- min-height: 38px;
719
+ height: 42px;
720
+ min-height: 42px;
722
721
  }
723
722
  .node.structure-only-node {
724
723
  height: 36px;
@@ -742,6 +741,7 @@ ODA({is: 'oda-tree-node',
742
741
  }
743
742
  .node.module-blocked item-node {
744
743
  opacity: .5;
744
+ filter: grayscale(1);
745
745
  }
746
746
  .sub-nodes {
747
747
  @apply --vertical;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "odant-work",
3
- "version": "1.0.106",
3
+ "version": "1.0.107",
4
4
  "description": "ODANT-WORK — платформа цифровой организации (встроенная система учёта, документооборот, управление процессами и приватный мультимодальный ИИ)",
5
5
  "type": "module",
6
6
  "main": "sources/work.js",
package/sources/client.js CHANGED
@@ -403,6 +403,20 @@ WORK.onAuthChanged = function (payload = {}) {
403
403
  } catch {}
404
404
  return;
405
405
  }
406
+ if (payload.reason === 'disabled') {
407
+ WORK.clearSessionCache?.();
408
+ WORK.uid = '';
409
+ WORK.USER = undefined;
410
+ WORK._accountDisabled = true;
411
+ WORK._loginError = new Error('Учётная запись отключена администратором');
412
+ WORK._loginPromise = null;
413
+ WORK.syncAuthUI();
414
+ try {
415
+ WORK.authEvents?.dispatchEvent(new CustomEvent('auth', { detail: { uid: '', reason: 'disabled' } }));
416
+ WORK.authEvents?.dispatchEvent(new CustomEvent('login-state', { detail: { pending: false, error: WORK._loginError, uid: '' } }));
417
+ } catch {}
418
+ return;
419
+ }
406
420
  if (payload.reason === 'logout' && !newUid && !credUid) {
407
421
  WORK.uid = '';
408
422
  WORK.USER = undefined;
@@ -483,6 +497,7 @@ WORK.login = async function(force = false){
483
497
  const prevUid = WORK.uid || '';
484
498
  const authChanged = !WORK._authNotifiedOnce || prevUid !== uid;
485
499
  WORK.uid = uid;
500
+ WORK._accountDisabled = false;
486
501
  WORK._loginError = null;
487
502
  WORK._anonExitSynced = false;
488
503
  if (authChanged || !WORK.USER)
@@ -517,7 +532,20 @@ WORK.login = async function(force = false){
517
532
  }
518
533
  }
519
534
  catch (err) {
520
- WORK._loginError = err;
535
+ const errText = String(err?.message || err || '');
536
+ if (/отключена администратором|account_disabled/i.test(errText)) {
537
+ WORK._accountDisabled = true;
538
+ WORK.uid = '';
539
+ WORK.USER = undefined;
540
+ WORK._loginError = new Error('Учётная запись отключена администратором');
541
+ WORK.syncAuthUI();
542
+ try {
543
+ WORK.authEvents?.dispatchEvent(new CustomEvent('auth', { detail: { uid: '', reason: 'disabled' } }));
544
+ } catch {}
545
+ }
546
+ else {
547
+ WORK._loginError = err;
548
+ }
521
549
  if (WORK._loginPromise === run)
522
550
  WORK._loginPromise = null;
523
551
  throw err;
@@ -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 $user = await users.get_item('//' + uid);
356
- if (!$user)
356
+ let accountNode = await users.get_item('//' + uid);
357
+ if (!accountNode)
357
358
  throw new Error("User not registered");
358
- $user.reset();
359
- await $user.init;
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 === $user.id).length;
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: $user.id, expiresAt: now + CHALLENGE_TTL_MS });
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 $user = await (await WORK.$users).get_item('//' + uid);
403
- if (!$user)
411
+ const accountNode = await (await WORK.$users).get_item('//' + uid);
412
+ if (!accountNode)
404
413
  throw new Error("User not registered");
405
- await $user.init;
406
- let publicKey = $user.DATA?.keys?.[time];
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 = $user.DATA;
427
- $server.signIn(session, $user);
435
+ session.credentials = accountNode.DATA;
436
+ $server.signIn(session, accountNode);
428
437
  audit('login', { params });
429
- $user.online = undefined;
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
- if (!session?.$user)
78
+ export function notifyUserOnline(session, userOverride = null) {
79
+ const user = userOverride || session?.$user;
80
+ if (!user)
80
81
  return;
81
- session.$user.online = undefined;
82
- session.$user.reset();
83
- broadcastUserPath(session.$user);
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
- notifyUserOnline(session);
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 callContext.save_file(file, params);
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 keyRejected = /user not registered|need publickey|login failed|challenge issued for another user/i.test(errMsg);
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: 'Войти',
@@ -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
- const matchesLoopbackSameSite = Boolean(
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; }
@@ -412,7 +412,7 @@ export const classFeedMethods = {
412
412
  switch (params.mode || 'folder') {
413
413
  case 'dates': {
414
414
  const nonEmpty = params.nonEmpty === true || params.nonEmpty === '1' || params.nonEmpty === 'true';
415
- return LOGS.datesList(this, { nonEmpty, ownOnly });
415
+ return LOGS.datesList(this, { nonEmpty, ownOnly, feedMode: params.feedMode || '' });
416
416
  }
417
417
  case 'bodies':
418
418
  return bodies();
@@ -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 (!p)
131
- return false;
132
- if (/(?:^|\/)class\.js$/i.test(p))
133
- return true;
134
- // Снимки метафайлов внутри $.../#... (кроме пользовательских документов и задач .task)
135
- if (/\/#(?:secret|system)\//i.test(p) && !/\.task$/i.test(p))
136
- return true;
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
  }
@@ -420,8 +420,8 @@ export class $server extends $class {
420
420
  * Вход в сессию после успешной проверки (подпись ключа / регистрация):
421
421
  * субъект сессии + новый ssid (старый, известный до входа, больше не действует).
422
422
  */
423
- static signIn(session, $user) {
424
- if ($user && typeof $user._ownUserEnabledSync === 'function' && !$user._ownUserEnabledSync())
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 = $user.id;
433
- session.id = $user.id;
434
- session.$user = $user;
435
- session.principal = Object.freeze({ kind: 'user', id: $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;
@@ -25,7 +25,11 @@ export class $user extends $class {
25
25
  get $public() {
26
26
  return {
27
27
  get online() {
28
- return !!Object.values(globalThis.$server?.sessions || {})?.find(u => u.uid === this.id);
28
+ if (!this._ownUserEnabledSync())
29
+ return false;
30
+ return Object.values(globalThis.$server?.sessions || {}).some(
31
+ s => s?.uid === this.id && Object.keys(s.sockets || {}).length > 0
32
+ );
29
33
  },
30
34
  get enabled() {
31
35
  return this._ownUserEnabledSync();
@@ -33,6 +37,9 @@ export class $user extends $class {
33
37
  get usersContainer() {
34
38
  return this.DATA?.usersContainer === true ? true : undefined;
35
39
  },
40
+ get isUser() {
41
+ return this.DATA?.usersContainer === true ? undefined : true;
42
+ },
36
43
  icon: {
37
44
  get() {
38
45
  let icon = this.DATA?.icon;
@@ -1,30 +0,0 @@
1
- import '/sources/modules/user-profile/user-profile.js';
2
- export default {
3
- label: 'Профиль',
4
- description: 'Личные данные и контактная информация пользователя',
5
- icon: 'icons:account-circle',
6
- order: 15,
7
- async allowUse($context, params) {
8
- if (!$context?.id || $context?.DATA?.usersContainer)
9
- return false;
10
- const uid = $context?.constructor?.resolveUid?.(params) || params?.session?.uid || '';
11
- if (!uid || $context.id === uid)
12
- return false;
13
- if (globalThis.WORK?.DEV_MODE)
14
- return false;
15
- const isBoss = await globalThis.WORK?._isWorkBoss?.(params).catch(() => false);
16
- return !isBoss;
17
- },
18
- component: {
19
- template: /* html */`
20
- <style>
21
- :host {
22
- @apply --vertical;
23
- @apply --flex;
24
- overflow: hidden;
25
- }
26
- </style>
27
- <user-profile :$item flex></user-profile>
28
- `
29
- }
30
- };