settingBody.js 15 KB

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