settingBody.js 16 KB

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