settingBody.js 16 KB

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