settingBody.js 14 KB

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