peopleBody.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. const orgsPerPage = 25;
  2. const teamsPerPage = 25;
  3. const usersPerPage = 25;
  4. BlazeComponent.extendComponent({
  5. mixins() {
  6. return [Mixins.InfiniteScrolling];
  7. },
  8. onCreated() {
  9. this.error = new ReactiveVar('');
  10. this.loading = new ReactiveVar(false);
  11. this.orgSetting = new ReactiveVar(true);
  12. this.teamSetting = new ReactiveVar(true);
  13. this.peopleSetting = new ReactiveVar(true);
  14. this.findOrgsOptions = new ReactiveVar({});
  15. this.findTeamsOptions = new ReactiveVar({});
  16. this.findUsersOptions = new ReactiveVar({});
  17. this.numberOrgs = new ReactiveVar(0);
  18. this.numberTeams = new ReactiveVar(0);
  19. this.numberPeople = new ReactiveVar(0);
  20. this.page = new ReactiveVar(1);
  21. this.loadNextPageLocked = false;
  22. this.callFirstWith(null, 'resetNextPeak');
  23. this.autorun(() => {
  24. const limitOrgs = this.page.get() * orgsPerPage;
  25. const limitTeams = this.page.get() * teamsPerPage;
  26. const limitUsers = this.page.get() * usersPerPage;
  27. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {
  28. this.loadNextPageLocked = false;
  29. const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
  30. this.calculateNextPeak();
  31. const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
  32. if (nextPeakBefore === nextPeakAfter) {
  33. this.callFirstWith(null, 'resetNextPeak');
  34. }
  35. });
  36. this.subscribe('team', this.findTeamsOptions.get(), limitTeams, () => {
  37. this.loadNextPageLocked = false;
  38. const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
  39. this.calculateNextPeak();
  40. const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
  41. if (nextPeakBefore === nextPeakAfter) {
  42. this.callFirstWith(null, 'resetNextPeak');
  43. }
  44. });
  45. this.subscribe('people', this.findUsersOptions.get(), limitUsers, () => {
  46. this.loadNextPageLocked = false;
  47. const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
  48. this.calculateNextPeak();
  49. const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
  50. if (nextPeakBefore === nextPeakAfter) {
  51. this.callFirstWith(null, 'resetNextPeak');
  52. }
  53. });
  54. });
  55. },
  56. events() {
  57. return [
  58. {
  59. 'click #searchOrgButton'() {
  60. this.filterOrg();
  61. },
  62. 'keydown #searchOrgInput'(event) {
  63. if (event.keyCode === 13 && !event.shiftKey) {
  64. this.filterOrg();
  65. }
  66. },
  67. 'click #searchTeamButton'() {
  68. this.filterTeam();
  69. },
  70. 'keydown #searchTeamInput'(event) {
  71. if (event.keyCode === 13 && !event.shiftKey) {
  72. this.filterTeam();
  73. }
  74. },
  75. 'click #searchButton'() {
  76. this.filterPeople();
  77. },
  78. 'keydown #searchInput'(event) {
  79. if (event.keyCode === 13 && !event.shiftKey) {
  80. this.filterPeople();
  81. }
  82. },
  83. 'click #newOrgButton'() {
  84. Popup.open('newOrg');
  85. },
  86. 'click #newTeamButton'() {
  87. Popup.open('newTeam');
  88. },
  89. 'click #newUserButton'() {
  90. Popup.open('newUser');
  91. },
  92. 'click a.js-org-menu': this.switchMenu,
  93. 'click a.js-team-menu': this.switchMenu,
  94. 'click a.js-people-menu': this.switchMenu,
  95. },
  96. ];
  97. },
  98. filterPeople() {
  99. const value = $('#searchInput')
  100. .first()
  101. .val();
  102. if (value === '') {
  103. this.findUsersOptions.set({});
  104. } else {
  105. const regex = new RegExp(value, 'i');
  106. this.findUsersOptions.set({
  107. $or: [
  108. { username: regex },
  109. { 'profile.fullname': regex },
  110. { 'emails.address': regex },
  111. ],
  112. });
  113. }
  114. },
  115. loadNextPage() {
  116. if (this.loadNextPageLocked === false) {
  117. this.page.set(this.page.get() + 1);
  118. this.loadNextPageLocked = true;
  119. }
  120. },
  121. calculateNextPeak() {
  122. const element = this.find('.main-body');
  123. if (element) {
  124. const altitude = element.scrollHeight;
  125. this.callFirstWith(this, 'setNextPeak', altitude);
  126. }
  127. },
  128. reachNextPeak() {
  129. this.loadNextPage();
  130. },
  131. setError(error) {
  132. this.error.set(error);
  133. },
  134. setLoading(w) {
  135. this.loading.set(w);
  136. },
  137. orgList() {
  138. const orgs = Org.find(this.findOrgsOptions.get(), {
  139. fields: { _id: true },
  140. });
  141. this.numberOrgs.set(orgs.count(false));
  142. return orgs;
  143. },
  144. teamList() {
  145. const teams = Team.find(this.findTeamsOptions.get(), {
  146. fields: { _id: true },
  147. });
  148. this.numberTeams.set(team.count(false));
  149. return teams;
  150. },
  151. peopleList() {
  152. const users = Users.find(this.findUsersOptions.get(), {
  153. fields: { _id: true },
  154. });
  155. this.numberPeople.set(users.count(false));
  156. return users;
  157. },
  158. orgNumber() {
  159. return this.numberOrgs.get();
  160. },
  161. teamNumber() {
  162. return this.numberTeams.get();
  163. },
  164. peopleNumber() {
  165. return this.numberPeople.get();
  166. },
  167. switchMenu(event) {
  168. const target = $(event.target);
  169. if (!target.hasClass('active')) {
  170. $('.side-menu li.active').removeClass('active');
  171. target.parent().addClass('active');
  172. const targetID = target.data('id');
  173. this.orgSetting.set('org-setting' === targetID);
  174. this.teamSetting.set('team-setting' === targetID);
  175. this.peopleSetting.set('people-setting' === targetID);
  176. }
  177. },
  178. }).register('people');
  179. Template.orgRow.helpers({
  180. orgData() {
  181. const orgCollection = this.esSearch ? ESSearchResults : Org;
  182. return orgCollection.findOne(this.orgId);
  183. },
  184. });
  185. Template.teamRow.helpers({
  186. teamData() {
  187. const teamCollection = this.esSearch ? ESSearchResults : Team;
  188. return teamCollection.findOne(this.teamId);
  189. },
  190. });
  191. Template.peopleRow.helpers({
  192. userData() {
  193. const userCollection = this.esSearch ? ESSearchResults : Users;
  194. return userCollection.findOne(this.userId);
  195. },
  196. });
  197. Template.editUserPopup.onCreated(function() {
  198. this.authenticationMethods = new ReactiveVar([]);
  199. this.errorMessage = new ReactiveVar('');
  200. Meteor.call('getAuthenticationsEnabled', (_, result) => {
  201. if (result) {
  202. // TODO : add a management of different languages
  203. // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
  204. this.authenticationMethods.set([
  205. { value: 'password' },
  206. // Gets only the authentication methods availables
  207. ...Object.entries(result)
  208. .filter(e => e[1])
  209. .map(e => ({ value: e[0] })),
  210. ]);
  211. }
  212. });
  213. });
  214. Template.editOrgPopup.helpers({
  215. org() {
  216. return Org.findOne(this.orgId);
  217. },
  218. errorMessage() {
  219. return Template.instance().errorMessage.get();
  220. },
  221. });
  222. Template.editTeamPopup.helpers({
  223. team() {
  224. return Team.findOne(this.teamId);
  225. },
  226. errorMessage() {
  227. return Template.instance().errorMessage.get();
  228. },
  229. });
  230. Template.editUserPopup.helpers({
  231. user() {
  232. return Users.findOne(this.userId);
  233. },
  234. authentications() {
  235. return Template.instance().authenticationMethods.get();
  236. },
  237. isSelected(match) {
  238. const userId = Template.instance().data.userId;
  239. const selected = Users.findOne(userId).authenticationMethod;
  240. return selected === match;
  241. },
  242. isLdap() {
  243. const userId = Template.instance().data.userId;
  244. const selected = Users.findOne(userId).authenticationMethod;
  245. return selected === 'ldap';
  246. },
  247. errorMessage() {
  248. return Template.instance().errorMessage.get();
  249. },
  250. });
  251. Template.newOrgPopup.onCreated(function() {
  252. this.errorMessage = new ReactiveVar('');
  253. });
  254. Template.newTeamPopup.onCreated(function() {
  255. this.errorMessage = new ReactiveVar('');
  256. });
  257. Template.newUserPopup.onCreated(function() {
  258. this.authenticationMethods = new ReactiveVar([]);
  259. this.errorMessage = new ReactiveVar('');
  260. Meteor.call('getAuthenticationsEnabled', (_, result) => {
  261. if (result) {
  262. // TODO : add a management of different languages
  263. // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
  264. this.authenticationMethods.set([
  265. { value: 'password' },
  266. // Gets only the authentication methods availables
  267. ...Object.entries(result)
  268. .filter(e => e[1])
  269. .map(e => ({ value: e[0] })),
  270. ]);
  271. }
  272. });
  273. });
  274. Template.newOrgPopup.helpers({
  275. org() {
  276. return Org.findOne(this.orgId);
  277. },
  278. errorMessage() {
  279. return Template.instance().errorMessage.get();
  280. },
  281. });
  282. Template.newTeamPopup.helpers({
  283. team() {
  284. return Team.findOne(this.teamId);
  285. },
  286. errorMessage() {
  287. return Template.instance().errorMessage.get();
  288. },
  289. });
  290. Template.newUserPopup.helpers({
  291. user() {
  292. return Users.findOne(this.userId);
  293. },
  294. authentications() {
  295. return Template.instance().authenticationMethods.get();
  296. },
  297. isSelected(match) {
  298. const userId = Template.instance().data.userId;
  299. const selected = Users.findOne(userId).authenticationMethod;
  300. return selected === match;
  301. },
  302. isLdap() {
  303. const userId = Template.instance().data.userId;
  304. const selected = Users.findOne(userId).authenticationMethod;
  305. return selected === 'ldap';
  306. },
  307. errorMessage() {
  308. return Template.instance().errorMessage.get();
  309. },
  310. });
  311. BlazeComponent.extendComponent({
  312. onCreated() {},
  313. org() {
  314. return Org.findOne(this.orgId);
  315. },
  316. events() {
  317. return [
  318. {
  319. 'click a.edit-org': Popup.open('editOrg'),
  320. 'click a.more-settings-org': Popup.open('settingsOrg'),
  321. },
  322. ];
  323. },
  324. }).register('orgRow');
  325. BlazeComponent.extendComponent({
  326. onCreated() {},
  327. team() {
  328. return Team.findOne(this.teamId);
  329. },
  330. events() {
  331. return [
  332. {
  333. 'click a.edit-team': Popup.open('editTeam'),
  334. 'click a.more-settings-team': Popup.open('settingsTeam'),
  335. },
  336. ];
  337. },
  338. }).register('teamRow');
  339. BlazeComponent.extendComponent({
  340. onCreated() {},
  341. user() {
  342. return Users.findOne(this.userId);
  343. },
  344. events() {
  345. return [
  346. {
  347. 'click a.edit-user': Popup.open('editUser'),
  348. 'click a.more-settings-user': Popup.open('settingsUser'),
  349. },
  350. ];
  351. },
  352. }).register('peopleRow');
  353. BlazeComponent.extendComponent({
  354. events() {
  355. return [
  356. {
  357. 'click a.new-org': Popup.open('newOrg'),
  358. },
  359. ];
  360. },
  361. }).register('newOrgRow');
  362. BlazeComponent.extendComponent({
  363. events() {
  364. return [
  365. {
  366. 'click a.new-team': Popup.open('newTeam'),
  367. },
  368. ];
  369. },
  370. }).register('newTeamRow');
  371. BlazeComponent.extendComponent({
  372. events() {
  373. return [
  374. {
  375. 'click a.new-user': Popup.open('newUser'),
  376. },
  377. ];
  378. },
  379. }).register('newUserRow');
  380. Template.editOrgPopup.events({
  381. submit(event, templateInstance) {
  382. event.preventDefault();
  383. const org = Orgs.findOne(this.orgId);
  384. const orgDisplayName = templateInstance
  385. .find('.js-orgDisplayName')
  386. .value.trim();
  387. const orgDesc = templateInstance.find('.js-orgDesc').value.trim();
  388. const orgShortName = templateInstance.find('.js-orgShortName').value.trim();
  389. const orgWebsite = templateInstance.find('.js-orgWebsite').value.trim();
  390. const orgIsActive = templateInstance.find('.js-org-isactive').value.trim();
  391. const isChangeOrgDisplayName = orgDisplayName !== org.orgDisplayName;
  392. const isChangeOrgDesc = orgDesc !== org.orgDesc;
  393. const isChangeOrgShortName = orgShortName !== org.orgShortName;
  394. const isChangeOrgWebsite = orgWebsite !== org.orgWebsite;
  395. const isChangeOrgIsActive = orgIsActive !== org.orgIsActive;
  396. if (isChangeOrgDisplayName) {
  397. Meteor.call('setOrgDisplayName', org, orgDisplayName);
  398. }
  399. if (isChangeOrgDesc) {
  400. Meteor.call('setOrgDesc', org, orgDesc);
  401. }
  402. if (isChangeOrgShortName) {
  403. Meteor.call('setOrgShortName', org, orgShortName);
  404. }
  405. if (isChangeOrgIsActive) {
  406. Meteor.call('setOrgIsActive', org, orgIsActive);
  407. }
  408. Popup.close();
  409. },
  410. });
  411. Template.editTeamPopup.events({
  412. submit(event, templateInstance) {
  413. event.preventDefault();
  414. const team = Teams.findOne(this.teamId);
  415. const teamDisplayName = templateInstance
  416. .find('.js-teamDisplayName')
  417. .value.trim();
  418. const teamDesc = templateInstance.find('.js-teamDesc').value.trim();
  419. const teamShortName = templateInstance
  420. .find('.js-teamShortName')
  421. .value.trim();
  422. const teamWebsite = templateInstance.find('.js-teamWebsite').value.trim();
  423. const teamIsActive = templateInstance
  424. .find('.js-team-isactive')
  425. .value.trim();
  426. const isChangeTeamDisplayName = teamDisplayName !== team.teamDisplayName;
  427. const isChangeTeamDesc = teamDesc !== team.teamDesc;
  428. const isChangeTeamShortName = teamShortName !== team.teamShortName;
  429. const isChangeTeamWebsite = teamWebsite !== team.teamWebsite;
  430. const isChangeTeamIsActive = teamIsActive !== team.teamIsActive;
  431. if (isChangeTeamDisplayName) {
  432. Meteor.call('setTeamDisplayName', team, teamDisplayName);
  433. }
  434. if (isChangeTeamDesc) {
  435. Meteor.call('setTeamDesc', team, teamDesc);
  436. }
  437. if (isChangeTeamShortName) {
  438. Meteor.call('setTeamShortName', team, teamShortName);
  439. }
  440. if (isChangeTeamIsActive) {
  441. Meteor.call('setTeamIsActive', team, teamIsActive);
  442. }
  443. Popup.close();
  444. },
  445. });
  446. Template.editUserPopup.events({
  447. submit(event, templateInstance) {
  448. event.preventDefault();
  449. const user = Users.findOne(this.userId);
  450. const username = templateInstance.find('.js-profile-username').value.trim();
  451. const fullname = templateInstance.find('.js-profile-fullname').value.trim();
  452. const initials = templateInstance.find('.js-profile-initials').value.trim();
  453. const password = templateInstance.find('.js-profile-password').value;
  454. const isAdmin = templateInstance.find('.js-profile-isadmin').value.trim();
  455. const isActive = templateInstance.find('.js-profile-isactive').value.trim();
  456. const email = templateInstance.find('.js-profile-email').value.trim();
  457. const verified = templateInstance
  458. .find('.js-profile-email-verified')
  459. .value.trim();
  460. const authentication = templateInstance
  461. .find('.js-authenticationMethod')
  462. .value.trim();
  463. const importUsernames = templateInstance
  464. .find('.js-import-usernames')
  465. .value.trim();
  466. const isChangePassword = password.length > 0;
  467. const isChangeUserName = username !== user.username;
  468. const isChangeInitials = initials.length > 0;
  469. const isChangeEmailVerified = verified !== user.emails[0].verified;
  470. // If previously email address has not been set, it is undefined,
  471. // check for undefined, and allow adding email address.
  472. const isChangeEmail =
  473. email.toLowerCase() !==
  474. (typeof user.emails !== 'undefined'
  475. ? user.emails[0].address.toLowerCase()
  476. : false);
  477. Users.update(this.userId, {
  478. $set: {
  479. 'profile.fullname': fullname,
  480. isAdmin: isAdmin === 'true',
  481. loginDisabled: isActive === 'true',
  482. authenticationMethod: authentication,
  483. importUsernames: Users.parseImportUsernames(importUsernames),
  484. },
  485. });
  486. if (isChangePassword) {
  487. Meteor.call('setPassword', password, this.userId);
  488. }
  489. if (isChangeEmailVerified) {
  490. Meteor.call('setEmailVerified', email, verified === 'true', this.userId);
  491. }
  492. if (isChangeInitials) {
  493. Meteor.call('setInitials', initials, this.userId);
  494. }
  495. if (isChangeUserName && isChangeEmail) {
  496. Meteor.call(
  497. 'setUsernameAndEmail',
  498. username,
  499. email.toLowerCase(),
  500. this.userId,
  501. function(error) {
  502. const usernameMessageElement = templateInstance.$('.username-taken');
  503. const emailMessageElement = templateInstance.$('.email-taken');
  504. if (error) {
  505. const errorElement = error.error;
  506. if (errorElement === 'username-already-taken') {
  507. usernameMessageElement.show();
  508. emailMessageElement.hide();
  509. } else if (errorElement === 'email-already-taken') {
  510. usernameMessageElement.hide();
  511. emailMessageElement.show();
  512. }
  513. } else {
  514. usernameMessageElement.hide();
  515. emailMessageElement.hide();
  516. Popup.close();
  517. }
  518. },
  519. );
  520. } else if (isChangeUserName) {
  521. Meteor.call('setUsername', username, this.userId, function(error) {
  522. const usernameMessageElement = templateInstance.$('.username-taken');
  523. if (error) {
  524. const errorElement = error.error;
  525. if (errorElement === 'username-already-taken') {
  526. usernameMessageElement.show();
  527. }
  528. } else {
  529. usernameMessageElement.hide();
  530. Popup.close();
  531. }
  532. });
  533. } else if (isChangeEmail) {
  534. Meteor.call('setEmail', email.toLowerCase(), this.userId, function(
  535. error,
  536. ) {
  537. const emailMessageElement = templateInstance.$('.email-taken');
  538. if (error) {
  539. const errorElement = error.error;
  540. if (errorElement === 'email-already-taken') {
  541. emailMessageElement.show();
  542. }
  543. } else {
  544. emailMessageElement.hide();
  545. Popup.close();
  546. }
  547. });
  548. } else Popup.close();
  549. },
  550. });
  551. Template.newOrgPopup.events({
  552. submit(event, templateInstance) {
  553. event.preventDefault();
  554. const orgDisplayName = templateInstance
  555. .find('.js-orgDisplayName')
  556. .value.trim();
  557. const orgDesc = templateInstance.find('.js-orgDesc').value.trim();
  558. const orgShortName = templateInstance.find('.js-orgShortName').value.trim();
  559. const orgWebsite = templateInstance.find('.js-orgWebsite').value.trim();
  560. const orgIsActive = templateInstance.find('.js-org-isactive').value.trim();
  561. Meteor.call(
  562. 'setCreateOrg',
  563. orgDisplayName,
  564. orgDesc,
  565. orgShortName,
  566. orgWebsite,
  567. orgIsActive,
  568. );
  569. Popup.close();
  570. },
  571. });
  572. Template.newTeamPopup.events({
  573. submit(event, templateInstance) {
  574. event.preventDefault();
  575. const teamDisplayName = templateInstance
  576. .find('.js-teamDisplayName')
  577. .value.trim();
  578. const teamDesc = templateInstance.find('.js-teamDesc').value.trim();
  579. const teamShortName = templateInstance
  580. .find('.js-teamShortName')
  581. .value.trim();
  582. const teamWebsite = templateInstance.find('.js-teamWebsite').value.trim();
  583. const teamIsActive = templateInstance
  584. .find('.js-team-isactive')
  585. .value.trim();
  586. Meteor.call(
  587. 'setCreateTeam',
  588. teamDisplayName,
  589. teamDesc,
  590. teamShortName,
  591. teamWebsite,
  592. teamIsActive,
  593. );
  594. Popup.close();
  595. },
  596. });
  597. Template.newUserPopup.events({
  598. submit(event, templateInstance) {
  599. event.preventDefault();
  600. const fullname = templateInstance.find('.js-profile-fullname').value.trim();
  601. const username = templateInstance.find('.js-profile-username').value.trim();
  602. const initials = templateInstance.find('.js-profile-initials').value.trim();
  603. const password = templateInstance.find('.js-profile-password').value;
  604. const isAdmin = templateInstance.find('.js-profile-isadmin').value.trim();
  605. const isActive = templateInstance.find('.js-profile-isactive').value.trim();
  606. const email = templateInstance.find('.js-profile-email').value.trim();
  607. const importUsernames = Users.parseImportUsernames(
  608. templateInstance.find('.js-import-usernames').value,
  609. );
  610. Meteor.call(
  611. 'setCreateUser',
  612. fullname,
  613. username,
  614. initials,
  615. password,
  616. isAdmin,
  617. isActive,
  618. email.toLowerCase(),
  619. importUsernames,
  620. function(error) {
  621. const usernameMessageElement = templateInstance.$('.username-taken');
  622. const emailMessageElement = templateInstance.$('.email-taken');
  623. if (error) {
  624. const errorElement = error.error;
  625. if (errorElement === 'username-already-taken') {
  626. usernameMessageElement.show();
  627. emailMessageElement.hide();
  628. } else if (errorElement === 'email-already-taken') {
  629. usernameMessageElement.hide();
  630. emailMessageElement.show();
  631. }
  632. } else {
  633. usernameMessageElement.hide();
  634. emailMessageElement.hide();
  635. Popup.close();
  636. }
  637. },
  638. );
  639. Popup.close();
  640. },
  641. });
  642. Template.settingsUserPopup.events({
  643. 'click .impersonate-user'(event) {
  644. event.preventDefault();
  645. Meteor.call('impersonate', this.userId, err => {
  646. if (!err) {
  647. FlowRouter.go('/');
  648. Meteor.connection.setUserId(this.userId);
  649. }
  650. });
  651. },
  652. 'click #deleteButton'(event) {
  653. event.preventDefault();
  654. /*
  655. // Delete is not enabled yet, because it does leave empty user avatars
  656. // to boards: boards members, card members and assignees have
  657. // empty users. See:
  658. // - wekan/client/components/settings/peopleBody.jade deleteButton
  659. // - wekan/client/components/settings/peopleBody.js deleteButton
  660. // - wekan/client/components/sidebar/sidebar.js Popup.afterConfirm('removeMember'
  661. // that does now remove member from board, card members and assignees correctly,
  662. // but that should be used to remove user from all boards similarly
  663. // - wekan/models/users.js Delete is not enabled
  664. //
  665. //console.log('user id: ' + this.userId);
  666. //Popup.afterConfirm('userDelete', function(event) {
  667. //Boards.find({ members: this.userId }).forEach(board => {
  668. // console.log('board id: ' + board._id);
  669. //Cards.find({ boardId: board._id, members: this.userId }).forEach(card => {
  670. // card.unassignMember(this.userId);
  671. //});
  672. //Cards.find({ boardId: board._id, members: this.userId }).forEach(card => {
  673. // card.unassignMember(this.userId);
  674. //});
  675. //Cards.find({ boardId: board._id, assignees: this.userId }).forEach(card => {
  676. // card.unassignAssignee(this.userId);
  677. //});
  678. //Boards.findOne({ boardId: board._id }).removeMember(this.userId);
  679. //});
  680. //Users.remove(this.userId);
  681. */
  682. Popup.close();
  683. },
  684. });
  685. Template.settingsUserPopup.helpers({
  686. user() {
  687. return Users.findOne(this.userId);
  688. },
  689. authentications() {
  690. return Template.instance().authenticationMethods.get();
  691. },
  692. isSelected(match) {
  693. const userId = Template.instance().data.userId;
  694. const selected = Users.findOne(userId).authenticationMethod;
  695. return selected === match;
  696. },
  697. isLdap() {
  698. const userId = Template.instance().data.userId;
  699. const selected = Users.findOne(userId).authenticationMethod;
  700. return selected === 'ldap';
  701. },
  702. errorMessage() {
  703. return Template.instance().errorMessage.get();
  704. },
  705. });