settingBody.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. /*
  233. const accessibilityPageEnabled = $('input[name=accessibilityPageEnabled]:checked').val() === 'true';
  234. const accessibilityTitle = $('#accessibility-title')
  235. .val()
  236. .trim();
  237. const accessibilityContent = $('#accessibility-content')
  238. .val()
  239. .trim();
  240. */
  241. const spinnerName = $('#spinnerName').val();
  242. try {
  243. Settings.update(ReactiveCache.getCurrentSetting()._id, {
  244. $set: {
  245. productName,
  246. hideLogo: hideLogoChange,
  247. hideCardCounterList: hideCardCounterListChange,
  248. hideBoardMemberList: hideBoardMemberListChange,
  249. customLoginLogoImageUrl,
  250. customLoginLogoLinkUrl,
  251. customHelpLinkUrl,
  252. textBelowCustomLoginLogo,
  253. customTopLeftCornerLogoImageUrl,
  254. customTopLeftCornerLogoLinkUrl,
  255. customTopLeftCornerLogoHeight,
  256. displayAuthenticationMethod,
  257. defaultAuthenticationMethod,
  258. automaticLinkedUrlSchemes,
  259. spinnerName,
  260. oidcBtnText,
  261. mailDomainName,
  262. legalNotice,
  263. },
  264. });
  265. /*
  266. accessibilityPageEnabled,
  267. accessibilityTitle,
  268. accessibilityContent,
  269. */
  270. } catch (e) {
  271. return;
  272. } finally {
  273. this.setLoading(false);
  274. }
  275. DocHead.setTitle(productName);
  276. },
  277. sendSMTPTestEmail() {
  278. Meteor.call('sendSMTPTestEmail', (err, ret) => {
  279. if (!err && ret) {
  280. const message = `${TAPi18n.__(ret.message)}: ${ret.email}`;
  281. alert(message);
  282. } else {
  283. const reason = err.reason || '';
  284. const message = `${TAPi18n.__(err.error)}\n${reason}`;
  285. alert(message);
  286. }
  287. });
  288. },
  289. events() {
  290. return [
  291. {
  292. 'click a.js-toggle-forgot-password': this.toggleForgotPassword,
  293. 'click a.js-toggle-registration': this.toggleRegistration,
  294. 'click a.js-toggle-tls': this.toggleTLS,
  295. 'click a.js-setting-menu': this.switchMenu,
  296. 'click a.js-toggle-board-choose': this.checkBoard,
  297. 'click button.js-email-invite': this.inviteThroughEmail,
  298. 'click button.js-save': this.saveMailServerInfo,
  299. 'click button.js-send-smtp-test-email': this.sendSMTPTestEmail,
  300. 'click a.js-toggle-hide-logo': this.toggleHideLogo,
  301. 'click a.js-toggle-hide-card-counter-list': this.toggleHideCardCounterList,
  302. 'click a.js-toggle-hide-board-member-list': this.toggleHideBoardMemberList,
  303. 'click a.js-toggle-accessibility-page-enabled': this.toggleAccessibilityPageEnabled,
  304. 'click button.js-save-layout': this.saveLayout,
  305. 'click a.js-toggle-display-authentication-method': this
  306. .toggleDisplayAuthenticationMethod,
  307. },
  308. ];
  309. },
  310. }).register('setting');
  311. BlazeComponent.extendComponent({
  312. saveAccountsChange() {
  313. const allowEmailChange =
  314. $('input[name=allowEmailChange]:checked').val() === 'true';
  315. const allowUserNameChange =
  316. $('input[name=allowUserNameChange]:checked').val() === 'true';
  317. const allowUserDelete =
  318. $('input[name=allowUserDelete]:checked').val() === 'true';
  319. AccountSettings.update('accounts-allowEmailChange', {
  320. $set: { booleanValue: allowEmailChange },
  321. });
  322. AccountSettings.update('accounts-allowUserNameChange', {
  323. $set: { booleanValue: allowUserNameChange },
  324. });
  325. AccountSettings.update('accounts-allowUserDelete', {
  326. $set: { booleanValue: allowUserDelete },
  327. });
  328. },
  329. allowEmailChange() {
  330. return AccountSettings.findOne('accounts-allowEmailChange').booleanValue;
  331. },
  332. allowUserNameChange() {
  333. return AccountSettings.findOne('accounts-allowUserNameChange').booleanValue;
  334. },
  335. allowUserDelete() {
  336. return AccountSettings.findOne('accounts-allowUserDelete').booleanValue;
  337. },
  338. allBoardsHideActivities() {
  339. Meteor.call('setAllBoardsHideActivities', (err, ret) => {
  340. if (!err && ret) {
  341. if (ret === true) {
  342. const message = `${TAPi18n.__(
  343. 'now-activities-of-all-boards-are-hidden',
  344. )}`;
  345. alert(message);
  346. }
  347. } else {
  348. const reason = err.reason || '';
  349. const message = `${TAPi18n.__(err.error)}\n${reason}`;
  350. alert(message);
  351. }
  352. });
  353. },
  354. events() {
  355. return [
  356. {
  357. 'click button.js-accounts-save': this.saveAccountsChange,
  358. },
  359. {
  360. 'click button.js-all-boards-hide-activities': this.allBoardsHideActivities,
  361. },
  362. ];
  363. },
  364. }).register('accountSettings');
  365. BlazeComponent.extendComponent({
  366. saveTableVisibilityChange() {
  367. const allowPrivateOnly =
  368. $('input[name=allowPrivateOnly]:checked').val() === 'true';
  369. TableVisibilityModeSettings.update('tableVisibilityMode-allowPrivateOnly', {
  370. $set: { booleanValue: allowPrivateOnly },
  371. });
  372. },
  373. allowPrivateOnly() {
  374. return TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  375. },
  376. allBoardsHideActivities() {
  377. Meteor.call('setAllBoardsHideActivities', (err, ret) => {
  378. if (!err && ret) {
  379. if (ret === true) {
  380. const message = `${TAPi18n.__(
  381. 'now-activities-of-all-boards-are-hidden',
  382. )}`;
  383. alert(message);
  384. }
  385. } else {
  386. const reason = err.reason || '';
  387. const message = `${TAPi18n.__(err.error)}\n${reason}`;
  388. alert(message);
  389. }
  390. });
  391. },
  392. events() {
  393. return [
  394. {
  395. 'click button.js-tableVisibilityMode-save': this.saveTableVisibilityChange,
  396. },
  397. {
  398. 'click button.js-all-boards-hide-activities': this.allBoardsHideActivities,
  399. },
  400. ];
  401. },
  402. }).register('tableVisibilityModeSettings');
  403. BlazeComponent.extendComponent({
  404. onCreated() {
  405. this.loading = new ReactiveVar(false);
  406. },
  407. setLoading(w) {
  408. this.loading.set(w);
  409. },
  410. currentAnnouncements() {
  411. return Announcements.findOne();
  412. },
  413. saveMessage() {
  414. const message = $('#admin-announcement')
  415. .val()
  416. .trim();
  417. Announcements.update(Announcements.findOne()._id, {
  418. $set: { body: message },
  419. });
  420. },
  421. toggleActive() {
  422. this.setLoading(true);
  423. const announcements = this.currentAnnouncements();
  424. const isActive = announcements.enabled;
  425. Announcements.update(announcements._id, {
  426. $set: { enabled: !isActive },
  427. });
  428. this.setLoading(false);
  429. if (isActive) {
  430. $('.admin-announcement').slideUp();
  431. } else {
  432. $('.admin-announcement').slideDown();
  433. }
  434. },
  435. events() {
  436. return [
  437. {
  438. 'click a.js-toggle-activemessage': this.toggleActive,
  439. 'click button.js-announcement-save': this.saveMessage,
  440. },
  441. ];
  442. },
  443. }).register('announcementSettings');
  444. Template.selectAuthenticationMethod.onCreated(function() {
  445. this.authenticationMethods = new ReactiveVar([]);
  446. Meteor.call('getAuthenticationsEnabled', (_, result) => {
  447. if (result) {
  448. // TODO : add a management of different languages
  449. // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
  450. this.authenticationMethods.set([
  451. { value: 'password' },
  452. // Gets only the authentication methods availables
  453. ...Object.entries(result)
  454. .filter(e => e[1])
  455. .map(e => ({ value: e[0] })),
  456. ]);
  457. }
  458. });
  459. });
  460. Template.selectAuthenticationMethod.helpers({
  461. authentications() {
  462. return Template.instance().authenticationMethods.get();
  463. },
  464. isSelected(match) {
  465. return Template.instance().data.authenticationMethod === match;
  466. },
  467. });
  468. Template.selectSpinnerName.helpers({
  469. spinners() {
  470. return ALLOWED_WAIT_SPINNERS;
  471. },
  472. isSelected(match) {
  473. return Template.instance().data.spinnerName === match;
  474. },
  475. });