2
0

settingBody.js 16 KB

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