settingBody.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. import { ALLOWED_WAIT_SPINNERS } from '/config/const';
  4. import LockoutSettings from '/models/lockoutSettings';
  5. // Template helpers for settingBody
  6. Template.setting.helpers({
  7. generalSetting() {
  8. const instance = Template.instance();
  9. return instance && instance.generalSetting ? instance.generalSetting.get() : false;
  10. },
  11. emailSetting() {
  12. const instance = Template.instance();
  13. return instance && instance.emailSetting ? instance.emailSetting.get() : false;
  14. },
  15. accountSetting() {
  16. const instance = Template.instance();
  17. return instance && instance.accountSetting ? instance.accountSetting.get() : false;
  18. },
  19. tableVisibilityModeSetting() {
  20. const instance = Template.instance();
  21. return instance && instance.tableVisibilityModeSetting ? instance.tableVisibilityModeSetting.get() : false;
  22. },
  23. announcementSetting() {
  24. const instance = Template.instance();
  25. return instance && instance.announcementSetting ? instance.announcementSetting.get() : false;
  26. },
  27. accessibilitySetting() {
  28. const instance = Template.instance();
  29. return instance && instance.accessibilitySetting ? instance.accessibilitySetting.get() : false;
  30. },
  31. layoutSetting() {
  32. const instance = Template.instance();
  33. return instance && instance.layoutSetting ? instance.layoutSetting.get() : false;
  34. },
  35. webhookSetting() {
  36. const instance = Template.instance();
  37. return instance && instance.webhookSetting ? instance.webhookSetting.get() : false;
  38. },
  39. attachmentSettings() {
  40. const instance = Template.instance();
  41. return instance && instance.attachmentSettings ? instance.attachmentSettings.get() : false;
  42. },
  43. cronSettings() {
  44. const instance = Template.instance();
  45. return instance && instance.cronSettings ? instance.cronSettings.get() : false;
  46. },
  47. loading() {
  48. const instance = Template.instance();
  49. return instance && instance.loading ? instance.loading.get() : false;
  50. }
  51. });
  52. BlazeComponent.extendComponent({
  53. onCreated() {
  54. this.error = new ReactiveVar('');
  55. this.loading = new ReactiveVar(false);
  56. this.forgotPasswordSetting = new ReactiveVar(true);
  57. this.generalSetting = new ReactiveVar(true);
  58. this.emailSetting = new ReactiveVar(false);
  59. this.accountSetting = new ReactiveVar(false);
  60. this.tableVisibilityModeSetting = new ReactiveVar(false);
  61. this.announcementSetting = new ReactiveVar(false);
  62. this.accessibilitySetting = new ReactiveVar(false);
  63. this.layoutSetting = new ReactiveVar(false);
  64. this.webhookSetting = new ReactiveVar(false);
  65. this.attachmentSettings = new ReactiveVar(false);
  66. this.cronSettings = new ReactiveVar(false);
  67. Meteor.subscribe('setting');
  68. Meteor.subscribe('mailServer');
  69. Meteor.subscribe('accountSettings');
  70. Meteor.subscribe('tableVisibilityModeSettings');
  71. Meteor.subscribe('announcements');
  72. Meteor.subscribe('accessibilitySettings');
  73. Meteor.subscribe('globalwebhooks');
  74. Meteor.subscribe('lockoutSettings');
  75. },
  76. setError(error) {
  77. this.error.set(error);
  78. },
  79. setLoading(w) {
  80. this.loading.set(w);
  81. },
  82. checkField(selector) {
  83. const value = $(selector).val();
  84. if (!value || value.trim() === '') {
  85. $(selector)
  86. .parents('li.smtp-form')
  87. .addClass('has-error');
  88. throw Error('blank field');
  89. } else {
  90. return value;
  91. }
  92. },
  93. boards() {
  94. const ret = ReactiveCache.getBoards(
  95. {
  96. archived: false,
  97. 'members.userId': Meteor.userId(),
  98. 'members.isAdmin': true,
  99. },
  100. {
  101. sort: { sort: 1 /* boards default sorting */ },
  102. },
  103. );
  104. return ret;
  105. },
  106. toggleForgotPassword() {
  107. this.setLoading(true);
  108. const forgotPasswordClosed = ReactiveCache.getCurrentSetting().disableForgotPassword;
  109. Settings.update(ReactiveCache.getCurrentSetting()._id, {
  110. $set: { disableForgotPassword: !forgotPasswordClosed },
  111. });
  112. this.setLoading(false);
  113. },
  114. toggleRegistration() {
  115. this.setLoading(true);
  116. const registrationClosed = ReactiveCache.getCurrentSetting().disableRegistration;
  117. Settings.update(ReactiveCache.getCurrentSetting()._id, {
  118. $set: { disableRegistration: !registrationClosed },
  119. });
  120. this.setLoading(false);
  121. if (registrationClosed) {
  122. $('.invite-people').slideUp();
  123. } else {
  124. $('.invite-people').slideDown();
  125. }
  126. },
  127. toggleTLS() {
  128. $('#mail-server-tls').toggleClass('is-checked');
  129. },
  130. toggleHideLogo() {
  131. $('#hide-logo').toggleClass('is-checked');
  132. },
  133. toggleHideCardCounterList() {
  134. $('#hide-card-counter-list').toggleClass('is-checked');
  135. },
  136. toggleHideBoardMemberList() {
  137. $('#hide-board-member-list').toggleClass('is-checked');
  138. },
  139. toggleAccessibilityPageEnabled() {
  140. $('#accessibility-page-enabled').toggleClass('is-checked');
  141. },
  142. toggleDisplayAuthenticationMethod() {
  143. $('#display-authentication-method').toggleClass('is-checked');
  144. },
  145. switchAttachmentTab(event) {
  146. event.preventDefault();
  147. const target = $(event.target);
  148. const targetID = target.data('id');
  149. // Update active tab
  150. $('.tab-nav li.active').removeClass('active');
  151. target.parent().addClass('active');
  152. // Call the attachment settings component method if available
  153. if (window.attachmentSettings && window.attachmentSettings.switchMenu) {
  154. window.attachmentSettings.switchMenu(event, targetID);
  155. }
  156. },
  157. switchCronTab(event) {
  158. event.preventDefault();
  159. const target = $(event.target);
  160. const targetID = target.data('id');
  161. // Update active tab
  162. $('.tab-nav li.active').removeClass('active');
  163. target.parent().addClass('active');
  164. // Call the cron settings template method if available
  165. const cronTemplate = Template.instance();
  166. if (cronTemplate && cronTemplate.switchMenu) {
  167. cronTemplate.switchMenu(event, targetID);
  168. }
  169. },
  170. initializeAttachmentSubMenu() {
  171. // Set default sub-menu state for attachment settings
  172. // This will be handled by the attachment settings component
  173. console.log('Initializing attachment sub-menu');
  174. },
  175. initializeCronSubMenu() {
  176. // Set default sub-menu state for cron settings
  177. // This will be handled by the cron settings template
  178. console.log('Initializing cron sub-menu');
  179. },
  180. switchMenu(event) {
  181. const target = $(event.target);
  182. if (!target.hasClass('active')) {
  183. $('.side-menu li.active').removeClass('active');
  184. target.parent().addClass('active');
  185. const targetID = target.data('id');
  186. this.forgotPasswordSetting.set('forgot-password-setting' === targetID);
  187. this.generalSetting.set('registration-setting' === targetID);
  188. this.emailSetting.set('email-setting' === targetID);
  189. this.accountSetting.set('account-setting' === targetID);
  190. this.announcementSetting.set('announcement-setting' === targetID);
  191. this.accessibilitySetting.set('accessibility-setting' === targetID);
  192. this.layoutSetting.set('layout-setting' === targetID);
  193. this.webhookSetting.set('webhook-setting' === targetID);
  194. this.attachmentSettings.set('attachment-settings' === targetID);
  195. this.cronSettings.set('cron-settings' === targetID);
  196. // Initialize sub-menu states
  197. if ('attachment-settings' === targetID) {
  198. this.initializeAttachmentSubMenu();
  199. } else if ('cron-settings' === targetID) {
  200. this.initializeCronSubMenu();
  201. }
  202. this.tableVisibilityModeSetting.set('tableVisibilityMode-setting' === targetID);
  203. }
  204. },
  205. checkBoard(event) {
  206. let target = $(event.target);
  207. if (!target.hasClass('js-toggle-board-choose')) {
  208. target = target.parent();
  209. }
  210. const checkboxId = target.attr('id');
  211. $(`#${checkboxId} .materialCheckBox`).toggleClass('is-checked');
  212. $(`#${checkboxId}`).toggleClass('is-checked');
  213. },
  214. inviteThroughEmail() {
  215. const emails = $('#email-to-invite')
  216. .val()
  217. .toLowerCase()
  218. .trim()
  219. .split('\n')
  220. .join(',')
  221. .split(',');
  222. const boardsToInvite = [];
  223. $('.js-toggle-board-choose .materialCheckBox.is-checked').each(function() {
  224. boardsToInvite.push($(this).data('id'));
  225. });
  226. const validEmails = [];
  227. emails.forEach(email => {
  228. if (email && SimpleSchema.RegEx.Email.test(email.trim())) {
  229. validEmails.push(email.trim());
  230. }
  231. });
  232. if (validEmails.length) {
  233. this.setLoading(true);
  234. Meteor.call('sendInvitation', validEmails, boardsToInvite, () => {
  235. // if (!err) {
  236. // TODO - show more info to user
  237. // }
  238. this.setLoading(false);
  239. });
  240. }
  241. },
  242. saveMailServerInfo() {
  243. this.setLoading(true);
  244. $('li').removeClass('has-error');
  245. try {
  246. const host = this.checkField('#mail-server-host');
  247. const port = this.checkField('#mail-server-port');
  248. const username = $('#mail-server-username')
  249. .val()
  250. .trim();
  251. const password = $('#mail-server-password')
  252. .val()
  253. .trim();
  254. const from = this.checkField('#mail-server-from');
  255. const tls = $('#mail-server-tls.is-checked').length > 0;
  256. Settings.update(ReactiveCache.getCurrentSetting()._id, {
  257. $set: {
  258. 'mailServer.host': host,
  259. 'mailServer.port': port,
  260. 'mailServer.username': username,
  261. 'mailServer.password': password,
  262. 'mailServer.enableTLS': tls,
  263. 'mailServer.from': from,
  264. },
  265. });
  266. } catch (e) {
  267. return;
  268. } finally {
  269. this.setLoading(false);
  270. }
  271. },
  272. saveLayout() {
  273. this.setLoading(true);
  274. $('li').removeClass('has-error');
  275. const productName = ($('#product-name').val() || '').trim();
  276. const customLoginLogoImageUrl = ($('#custom-login-logo-image-url').val() || '').trim();
  277. const customLoginLogoLinkUrl = ($('#custom-login-logo-link-url').val() || '').trim();
  278. const customHelpLinkUrl = ($('#custom-help-link-url').val() || '').trim();
  279. const textBelowCustomLoginLogo = ($('#text-below-custom-login-logo').val() || '').trim();
  280. const automaticLinkedUrlSchemes = ($('#automatic-linked-url-schemes').val() || '').trim();
  281. const customTopLeftCornerLogoImageUrl = ($('#custom-top-left-corner-logo-image-url').val() || '').trim();
  282. const customTopLeftCornerLogoLinkUrl = ($('#custom-top-left-corner-logo-link-url').val() || '').trim();
  283. const customTopLeftCornerLogoHeight = ($('#custom-top-left-corner-logo-height').val() || '').trim();
  284. const oidcBtnText = ($('#oidcBtnTextvalue').val() || '').trim();
  285. const mailDomainName = ($('#mailDomainNamevalue').val() || '').trim();
  286. const legalNotice = ($('#legalNoticevalue').val() || '').trim();
  287. const hideLogoChange = $('input[name=hideLogo]:checked').val() === 'true';
  288. const hideCardCounterListChange = $('input[name=hideCardCounterList]:checked').val() === 'true';
  289. const hideBoardMemberListChange = $('input[name=hideBoardMemberList]:checked').val() === 'true';
  290. const displayAuthenticationMethod =
  291. $('input[name=displayAuthenticationMethod]:checked').val() === 'true';
  292. const defaultAuthenticationMethod = $('#defaultAuthenticationMethod').val();
  293. const accessibilityPageEnabled = $('input[name=accessibilityPageEnabled]:checked').val() === 'true';
  294. const accessibilityTitle = ($('#accessibility-title').val() || '').trim();
  295. const accessibilityContent = ($('#accessibility-content').val() || '').trim();
  296. const spinnerName = ($('#spinnerName').val() || '').trim();
  297. try {
  298. Settings.update(ReactiveCache.getCurrentSetting()._id, {
  299. $set: {
  300. productName,
  301. hideLogo: hideLogoChange,
  302. hideCardCounterList: hideCardCounterListChange,
  303. hideBoardMemberList: hideBoardMemberListChange,
  304. customLoginLogoImageUrl,
  305. customLoginLogoLinkUrl,
  306. customHelpLinkUrl,
  307. textBelowCustomLoginLogo,
  308. customTopLeftCornerLogoImageUrl,
  309. customTopLeftCornerLogoLinkUrl,
  310. customTopLeftCornerLogoHeight,
  311. displayAuthenticationMethod,
  312. defaultAuthenticationMethod,
  313. automaticLinkedUrlSchemes,
  314. spinnerName,
  315. oidcBtnText,
  316. mailDomainName,
  317. legalNotice,
  318. accessibilityPageEnabled,
  319. accessibilityTitle,
  320. accessibilityContent,
  321. },
  322. });
  323. } catch (e) {
  324. return;
  325. } finally {
  326. this.setLoading(false);
  327. }
  328. DocHead.setTitle(productName);
  329. },
  330. sendSMTPTestEmail() {
  331. Meteor.call('sendSMTPTestEmail', (err, ret) => {
  332. if (!err && ret) {
  333. const message = `${TAPi18n.__(ret.message)}: ${ret.email}`;
  334. alert(message);
  335. } else {
  336. const reason = err.reason || '';
  337. const message = `${TAPi18n.__(err.error)}\n${reason}`;
  338. alert(message);
  339. }
  340. });
  341. },
  342. events() {
  343. return [
  344. {
  345. 'click a.js-toggle-forgot-password': this.toggleForgotPassword,
  346. 'click a.js-toggle-registration': this.toggleRegistration,
  347. 'click a.js-toggle-tls': this.toggleTLS,
  348. 'click a.js-setting-menu': this.switchMenu,
  349. 'click a.js-toggle-board-choose': this.checkBoard,
  350. 'click button.js-email-invite': this.inviteThroughEmail,
  351. 'click button.js-save': this.saveMailServerInfo,
  352. 'click button.js-send-smtp-test-email': this.sendSMTPTestEmail,
  353. 'click a.js-toggle-hide-logo': this.toggleHideLogo,
  354. 'click a.js-toggle-hide-card-counter-list': this.toggleHideCardCounterList,
  355. 'click a.js-toggle-hide-board-member-list': this.toggleHideBoardMemberList,
  356. 'click button.js-save-layout': this.saveLayout,
  357. 'click a.js-toggle-display-authentication-method': this
  358. .toggleDisplayAuthenticationMethod,
  359. 'click a.js-attachment-storage-settings': this.switchAttachmentTab,
  360. 'click a.js-attachment-migration': this.switchAttachmentTab,
  361. 'click a.js-attachment-monitoring': this.switchAttachmentTab,
  362. 'click a.js-cron-migrations': this.switchCronTab,
  363. 'click a.js-cron-board-operations': this.switchCronTab,
  364. 'click a.js-cron-jobs': this.switchCronTab,
  365. 'click a.js-cron-add': this.switchCronTab,
  366. },
  367. ];
  368. },
  369. }).register('setting');
  370. BlazeComponent.extendComponent({
  371. saveAccountsChange() {
  372. const allowEmailChange =
  373. $('input[name=allowEmailChange]:checked').val() === 'true';
  374. const allowUserNameChange =
  375. $('input[name=allowUserNameChange]:checked').val() === 'true';
  376. const allowUserDelete =
  377. $('input[name=allowUserDelete]:checked').val() === 'true';
  378. AccountSettings.update('accounts-allowEmailChange', {
  379. $set: { booleanValue: allowEmailChange },
  380. });
  381. AccountSettings.update('accounts-allowUserNameChange', {
  382. $set: { booleanValue: allowUserNameChange },
  383. });
  384. AccountSettings.update('accounts-allowUserDelete', {
  385. $set: { booleanValue: allowUserDelete },
  386. });
  387. },
  388. // Brute force lockout settings method moved to lockedUsersBody.js
  389. allowEmailChange() {
  390. return AccountSettings.findOne('accounts-allowEmailChange')?.booleanValue || false;
  391. },
  392. allowUserNameChange() {
  393. return AccountSettings.findOne('accounts-allowUserNameChange')?.booleanValue || false;
  394. },
  395. allowUserDelete() {
  396. return AccountSettings.findOne('accounts-allowUserDelete')?.booleanValue || false;
  397. },
  398. // Lockout settings helper methods moved to lockedUsersBody.js
  399. allBoardsHideActivities() {
  400. Meteor.call('setAllBoardsHideActivities', (err, ret) => {
  401. if (!err && ret) {
  402. if (ret === true) {
  403. const message = `${TAPi18n.__(
  404. 'now-activities-of-all-boards-are-hidden',
  405. )}`;
  406. alert(message);
  407. }
  408. } else {
  409. const reason = err.reason || '';
  410. const message = `${TAPi18n.__(err.error)}\n${reason}`;
  411. alert(message);
  412. }
  413. });
  414. },
  415. events() {
  416. return [
  417. {
  418. 'click button.js-accounts-save': this.saveAccountsChange,
  419. },
  420. {
  421. 'click button.js-all-boards-hide-activities': this.allBoardsHideActivities,
  422. },
  423. ];
  424. },
  425. }).register('accountSettings');
  426. BlazeComponent.extendComponent({
  427. saveTableVisibilityChange() {
  428. const allowPrivateOnly =
  429. $('input[name=allowPrivateOnly]:checked').val() === 'true';
  430. TableVisibilityModeSettings.update('tableVisibilityMode-allowPrivateOnly', {
  431. $set: { booleanValue: allowPrivateOnly },
  432. });
  433. },
  434. allowPrivateOnly() {
  435. return TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  436. },
  437. allBoardsHideActivities() {
  438. Meteor.call('setAllBoardsHideActivities', (err, ret) => {
  439. if (!err && ret) {
  440. if (ret === true) {
  441. const message = `${TAPi18n.__(
  442. 'now-activities-of-all-boards-are-hidden',
  443. )}`;
  444. alert(message);
  445. }
  446. } else {
  447. const reason = err.reason || '';
  448. const message = `${TAPi18n.__(err.error)}\n${reason}`;
  449. alert(message);
  450. }
  451. });
  452. },
  453. events() {
  454. return [
  455. {
  456. 'click button.js-tableVisibilityMode-save': this.saveTableVisibilityChange,
  457. },
  458. {
  459. 'click button.js-all-boards-hide-activities': this.allBoardsHideActivities,
  460. },
  461. ];
  462. },
  463. }).register('tableVisibilityModeSettings');
  464. BlazeComponent.extendComponent({
  465. onCreated() {
  466. this.loading = new ReactiveVar(false);
  467. },
  468. setLoading(w) {
  469. this.loading.set(w);
  470. },
  471. currentAnnouncements() {
  472. return Announcements.findOne();
  473. },
  474. saveMessage() {
  475. const message = $('#admin-announcement')
  476. .val()
  477. .trim();
  478. Announcements.update(Announcements.findOne()._id, {
  479. $set: { body: message },
  480. });
  481. },
  482. toggleActive() {
  483. this.setLoading(true);
  484. const announcements = this.currentAnnouncements();
  485. const isActive = announcements.enabled;
  486. Announcements.update(announcements._id, {
  487. $set: { enabled: !isActive },
  488. });
  489. this.setLoading(false);
  490. if (isActive) {
  491. $('.admin-announcement').slideUp();
  492. } else {
  493. $('.admin-announcement').slideDown();
  494. }
  495. },
  496. events() {
  497. return [
  498. {
  499. 'click a.js-toggle-activemessage': this.toggleActive,
  500. 'click button.js-announcement-save': this.saveMessage,
  501. },
  502. ];
  503. },
  504. }).register('announcementSettings');
  505. BlazeComponent.extendComponent({
  506. onCreated() {
  507. this.loading = new ReactiveVar(false);
  508. },
  509. setLoading(w) {
  510. this.loading.set(w);
  511. },
  512. currentAccessibility() {
  513. return AccessibilitySettings.findOne();
  514. },
  515. saveAccessibility() {
  516. const title = $('#admin-accessibility-title')
  517. .val()
  518. .trim();
  519. const content = $('#admin-accessibility-content')
  520. .val()
  521. .trim();
  522. AccessibilitySettings.update(AccessibilitySettings.findOne()._id, {
  523. $set: {
  524. title: title,
  525. body: content
  526. },
  527. });
  528. },
  529. toggleAccessibility() {
  530. this.setLoading(true);
  531. const accessibilitySetting = this.currentAccessibility();
  532. const isActive = accessibilitySetting.enabled;
  533. AccessibilitySettings.update(accessibilitySetting._id, {
  534. $set: { enabled: !isActive },
  535. });
  536. this.setLoading(false);
  537. if (isActive) {
  538. $('.accessibility-content').slideUp();
  539. } else {
  540. $('.accessibility-content').slideDown();
  541. }
  542. },
  543. events() {
  544. return [
  545. {
  546. 'click a.js-toggle-accessibility': this.toggleAccessibility,
  547. 'click button.js-accessibility-save': this.saveAccessibility,
  548. },
  549. ];
  550. },
  551. }).register('accessibilitySettings');
  552. Template.selectAuthenticationMethod.onCreated(function() {
  553. this.authenticationMethods = new ReactiveVar([]);
  554. Meteor.call('getAuthenticationsEnabled', (_, result) => {
  555. if (result) {
  556. // TODO : add a management of different languages
  557. // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
  558. this.authenticationMethods.set([
  559. { value: 'password' },
  560. // Gets only the authentication methods availables
  561. ...Object.entries(result)
  562. .filter(e => e[1])
  563. .map(e => ({ value: e[0] })),
  564. ]);
  565. }
  566. });
  567. });
  568. Template.selectAuthenticationMethod.helpers({
  569. authentications() {
  570. return Template.instance().authenticationMethods.get();
  571. },
  572. isSelected(match) {
  573. return Template.instance().data.authenticationMethod === match;
  574. },
  575. });
  576. Template.selectSpinnerName.helpers({
  577. spinners() {
  578. return ALLOWED_WAIT_SPINNERS;
  579. },
  580. isSelected(match) {
  581. return Template.instance().data.spinnerName === match;
  582. },
  583. });