settingBody.js 14 KB

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