settingBody.js 13 KB

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