admin.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  1. /* eslint-disable no-use-before-define */
  2. module.exports = function(crowi, app) {
  3. const debug = require('debug')('growi:routes:admin');
  4. const logger = require('@alias/logger')('growi:routes:admin');
  5. const models = crowi.models;
  6. const Page = models.Page;
  7. const User = models.User;
  8. const ExternalAccount = models.ExternalAccount;
  9. const UserGroup = models.UserGroup;
  10. const UserGroupRelation = models.UserGroupRelation;
  11. const GlobalNotificationSetting = models.GlobalNotificationSetting;
  12. const GlobalNotificationMailSetting = models.GlobalNotificationMailSetting;
  13. const GlobalNotificationSlackSetting = models.GlobalNotificationSlackSetting; // eslint-disable-line no-unused-vars
  14. const {
  15. configManager,
  16. aclService,
  17. slackNotificationService,
  18. customizeService,
  19. } = crowi;
  20. const recommendedWhitelist = require('@commons/service/xss/recommended-whitelist');
  21. const PluginUtils = require('../plugins/plugin-utils');
  22. const ApiResponse = require('../util/apiResponse');
  23. const importer = require('../util/importer')(crowi);
  24. const searchEvent = crowi.event('search');
  25. const pluginUtils = new PluginUtils();
  26. const MAX_PAGE_LIST = 50;
  27. const actions = {};
  28. const { check } = require('express-validator/check');
  29. const api = {};
  30. function createPager(total, limit, page, pagesCount, maxPageList) {
  31. const pager = {
  32. page,
  33. pagesCount,
  34. pages: [],
  35. total,
  36. previous: null,
  37. previousDots: false,
  38. next: null,
  39. nextDots: false,
  40. };
  41. if (page > 1) {
  42. pager.previous = page - 1;
  43. }
  44. if (page < pagesCount) {
  45. pager.next = page + 1;
  46. }
  47. let pagerMin = Math.max(1, Math.ceil(page - maxPageList / 2));
  48. let pagerMax = Math.min(pagesCount, Math.floor(page + maxPageList / 2));
  49. if (pagerMin === 1) {
  50. if (MAX_PAGE_LIST < pagesCount) {
  51. pagerMax = MAX_PAGE_LIST;
  52. }
  53. else {
  54. pagerMax = pagesCount;
  55. }
  56. }
  57. if (pagerMax === pagesCount) {
  58. if ((pagerMax - MAX_PAGE_LIST) < 1) {
  59. pagerMin = 1;
  60. }
  61. else {
  62. pagerMin = pagerMax - MAX_PAGE_LIST;
  63. }
  64. }
  65. pager.previousDots = null;
  66. if (pagerMin > 1) {
  67. pager.previousDots = true;
  68. }
  69. pager.nextDots = null;
  70. if (pagerMax < pagesCount) {
  71. pager.nextDots = true;
  72. }
  73. for (let i = pagerMin; i <= pagerMax; i++) {
  74. pager.pages.push(i);
  75. }
  76. return pager;
  77. }
  78. actions.index = function(req, res) {
  79. return res.render('admin/index', {
  80. plugins: pluginUtils.listPlugins(crowi.rootDir),
  81. });
  82. };
  83. // app.get('/admin/app' , admin.app.index);
  84. actions.app = {};
  85. actions.app.index = function(req, res) {
  86. return res.render('admin/app');
  87. };
  88. actions.app.settingUpdate = function(req, res) {
  89. };
  90. // app.get('/admin/security' , admin.security.index);
  91. actions.security = {};
  92. actions.security.index = function(req, res) {
  93. const isWikiModeForced = aclService.isWikiModeForced();
  94. const guestModeValue = aclService.getGuestModeValue();
  95. return res.render('admin/security', {
  96. isWikiModeForced,
  97. guestModeValue,
  98. });
  99. };
  100. // app.get('/admin/markdown' , admin.markdown.index);
  101. actions.markdown = {};
  102. actions.markdown.index = function(req, res) {
  103. const markdownSetting = configManager.getConfigByPrefix('markdown', 'markdown:');
  104. return res.render('admin/markdown', {
  105. markdownSetting,
  106. recommendedWhitelist,
  107. });
  108. };
  109. // app.post('/admin/markdown/lineBreaksSetting' , admin.markdown.lineBreaksSetting);
  110. actions.markdown.lineBreaksSetting = async function(req, res) {
  111. const markdownSetting = req.form.markdownSetting;
  112. if (req.form.isValid) {
  113. await configManager.updateConfigsInTheSameNamespace('markdown', markdownSetting);
  114. req.flash('successMessage', ['Successfully updated!']);
  115. }
  116. else {
  117. req.flash('errorMessage', req.form.errors);
  118. }
  119. return res.redirect('/admin/markdown');
  120. };
  121. // app.post('/admin/markdown/presentationSetting' , admin.markdown.presentationSetting);
  122. actions.markdown.presentationSetting = async function(req, res) {
  123. const markdownSetting = req.form.markdownSetting;
  124. if (req.form.isValid) {
  125. await configManager.updateConfigsInTheSameNamespace('markdown', markdownSetting);
  126. req.flash('successMessage', ['Successfully updated!']);
  127. }
  128. else {
  129. req.flash('errorMessage', req.form.errors);
  130. }
  131. return res.redirect('/admin/markdown');
  132. };
  133. // app.post('/admin/markdown/xss-setting' , admin.markdown.xssSetting);
  134. actions.markdown.xssSetting = async function(req, res) {
  135. const xssSetting = req.form.markdownSetting;
  136. xssSetting['markdown:xss:tagWhiteList'] = csvToArray(xssSetting['markdown:xss:tagWhiteList']);
  137. xssSetting['markdown:xss:attrWhiteList'] = csvToArray(xssSetting['markdown:xss:attrWhiteList']);
  138. if (req.form.isValid) {
  139. await configManager.updateConfigsInTheSameNamespace('markdown', xssSetting);
  140. req.flash('successMessage', ['Successfully updated!']);
  141. }
  142. else {
  143. req.flash('errorMessage', req.form.errors);
  144. }
  145. return res.redirect('/admin/markdown');
  146. };
  147. const csvToArray = (string) => {
  148. const array = string.split(',');
  149. return array.map((item) => { return item.trim() });
  150. };
  151. // app.get('/admin/customize' , admin.customize.index);
  152. actions.customize = {};
  153. actions.customize.index = function(req, res) {
  154. const settingForm = configManager.getConfigByPrefix('crowi', 'customize:');
  155. /* eslint-disable quote-props, no-multi-spaces */
  156. const highlightJsCssSelectorOptions = {
  157. 'github': { name: '[Light] GitHub', border: false },
  158. 'github-gist': { name: '[Light] GitHub Gist', border: true },
  159. 'atom-one-light': { name: '[Light] Atom One Light', border: true },
  160. 'xcode': { name: '[Light] Xcode', border: true },
  161. 'vs': { name: '[Light] Vs', border: true },
  162. 'atom-one-dark': { name: '[Dark] Atom One Dark', border: false },
  163. 'hybrid': { name: '[Dark] Hybrid', border: false },
  164. 'monokai': { name: '[Dark] Monokai', border: false },
  165. 'tomorrow-night': { name: '[Dark] Tomorrow Night', border: false },
  166. 'vs2015': { name: '[Dark] Vs 2015', border: false },
  167. };
  168. /* eslint-enable quote-props, no-multi-spaces */
  169. return res.render('admin/customize', {
  170. settingForm,
  171. highlightJsCssSelectorOptions,
  172. });
  173. };
  174. // app.get('/admin/notification' , admin.notification.index);
  175. actions.notification = {};
  176. actions.notification.index = async(req, res) => {
  177. const UpdatePost = crowi.model('UpdatePost');
  178. let slackSetting = configManager.getConfigByPrefix('notification', 'slack:');
  179. const hasSlackIwhUrl = !!configManager.getConfig('notification', 'slack:incomingWebhookUrl');
  180. const hasSlackToken = !!configManager.getConfig('notification', 'slack:token');
  181. if (!hasSlackIwhUrl) {
  182. slackSetting['slack:incomingWebhookUrl'] = '';
  183. }
  184. if (req.session.slackSetting) {
  185. slackSetting = req.session.slackSetting;
  186. req.session.slackSetting = null;
  187. }
  188. const globalNotifications = await GlobalNotificationSetting.findAll();
  189. const userNotifications = await UpdatePost.findAll();
  190. return res.render('admin/notification', {
  191. userNotifications,
  192. slackSetting,
  193. hasSlackIwhUrl,
  194. hasSlackToken,
  195. globalNotifications,
  196. });
  197. };
  198. // app.post('/admin/notification/slackSetting' , admin.notification.slackauth);
  199. actions.notification.slackSetting = async function(req, res) {
  200. const slackSetting = req.form.slackSetting;
  201. if (req.form.isValid) {
  202. await configManager.updateConfigsInTheSameNamespace('notification', slackSetting);
  203. req.flash('successMessage', ['Successfully Updated!']);
  204. // Re-setup
  205. crowi.setupSlack().then(() => {
  206. });
  207. }
  208. else {
  209. req.flash('errorMessage', req.form.errors);
  210. }
  211. return res.redirect('/admin/notification');
  212. };
  213. // app.get('/admin/notification/slackAuth' , admin.notification.slackauth);
  214. actions.notification.slackAuth = function(req, res) {
  215. const code = req.query.code;
  216. if (!code || !slackNotificationService.hasSlackConfig()) {
  217. return res.redirect('/admin/notification');
  218. }
  219. const slack = crowi.slack;
  220. slack.getOauthAccessToken(code)
  221. .then(async(data) => {
  222. debug('oauth response', data);
  223. try {
  224. await configManager.updateConfigsInTheSameNamespace('notification', { 'slack:token': data.access_token });
  225. req.flash('successMessage', ['Successfully Connected!']);
  226. }
  227. catch (err) {
  228. req.flash('errorMessage', ['Failed to save access_token. Please try again.']);
  229. }
  230. return res.redirect('/admin/notification');
  231. })
  232. .catch((err) => {
  233. debug('oauth response ERROR', err);
  234. req.flash('errorMessage', ['Failed to fetch access_token. Please do connect again.']);
  235. return res.redirect('/admin/notification');
  236. });
  237. };
  238. // app.post('/admin/notification/slackIwhSetting' , admin.notification.slackIwhSetting);
  239. actions.notification.slackIwhSetting = async function(req, res) {
  240. const slackIwhSetting = req.form.slackIwhSetting;
  241. if (req.form.isValid) {
  242. await configManager.updateConfigsInTheSameNamespace('notification', slackIwhSetting);
  243. req.flash('successMessage', ['Successfully Updated!']);
  244. // Re-setup
  245. crowi.setupSlack().then(() => {
  246. return res.redirect('/admin/notification#slack-incoming-webhooks');
  247. });
  248. }
  249. else {
  250. req.flash('errorMessage', req.form.errors);
  251. return res.redirect('/admin/notification#slack-incoming-webhooks');
  252. }
  253. };
  254. // app.post('/admin/notification/slackSetting/disconnect' , admin.notification.disconnectFromSlack);
  255. actions.notification.disconnectFromSlack = async function(req, res) {
  256. await configManager.updateConfigsInTheSameNamespace('notification', { 'slack:token': '' });
  257. req.flash('successMessage', ['Successfully Disconnected!']);
  258. return res.redirect('/admin/notification');
  259. };
  260. actions.globalNotification = {};
  261. actions.globalNotification.detail = async(req, res) => {
  262. const notificationSettingId = req.params.id;
  263. const renderVars = {};
  264. if (notificationSettingId) {
  265. try {
  266. renderVars.setting = await GlobalNotificationSetting.findOne({ _id: notificationSettingId });
  267. }
  268. catch (err) {
  269. logger.error(`Error in finding a global notification setting with {_id: ${notificationSettingId}}`);
  270. }
  271. }
  272. return res.render('admin/global-notification-detail', renderVars);
  273. };
  274. actions.globalNotification.create = (req, res) => {
  275. const form = req.form.notificationGlobal;
  276. let setting;
  277. switch (form.notifyToType) {
  278. case 'mail':
  279. setting = new GlobalNotificationMailSetting(crowi);
  280. setting.toEmail = form.toEmail;
  281. break;
  282. // case 'slack':
  283. // setting = new GlobalNotificationSlackSetting(crowi);
  284. // setting.slackChannels = form.slackChannels;
  285. // break;
  286. default:
  287. logger.error('GlobalNotificationSetting Type Error: undefined type');
  288. req.flash('errorMessage', 'Error occurred in creating a new global notification setting: undefined notification type');
  289. return res.redirect('/admin/notification#global-notification');
  290. }
  291. setting.triggerPath = form.triggerPath;
  292. setting.triggerEvents = getNotificationEvents(form);
  293. setting.save();
  294. return res.redirect('/admin/notification#global-notification');
  295. };
  296. actions.globalNotification.update = async(req, res) => {
  297. const form = req.form.notificationGlobal;
  298. const setting = await GlobalNotificationSetting.findOne({ _id: form.id });
  299. switch (form.notifyToType) {
  300. case 'mail':
  301. setting.toEmail = form.toEmail;
  302. break;
  303. // case 'slack':
  304. // setting.slackChannels = form.slackChannels;
  305. // break;
  306. default:
  307. logger.error('GlobalNotificationSetting Type Error: undefined type');
  308. req.flash('errorMessage', 'Error occurred in updating the global notification setting: undefined notification type');
  309. return res.redirect('/admin/notification#global-notification');
  310. }
  311. setting.triggerPath = form.triggerPath;
  312. setting.triggerEvents = getNotificationEvents(form);
  313. setting.save();
  314. return res.redirect('/admin/notification#global-notification');
  315. };
  316. actions.globalNotification.remove = async(req, res) => {
  317. const id = req.params.id;
  318. try {
  319. await GlobalNotificationSetting.findOneAndRemove({ _id: id });
  320. return res.redirect('/admin/notification#global-notification');
  321. }
  322. catch (err) {
  323. req.flash('errorMessage', 'Error in deleting global notification setting');
  324. return res.redirect('/admin/notification#global-notification');
  325. }
  326. };
  327. const getNotificationEvents = (form) => {
  328. const triggerEvents = [];
  329. const triggerEventKeys = Object.keys(form).filter((key) => { return key.match(/^triggerEvent/) });
  330. triggerEventKeys.forEach((key) => {
  331. if (form[key]) {
  332. triggerEvents.push(form[key]);
  333. }
  334. });
  335. return triggerEvents;
  336. };
  337. actions.search = {};
  338. actions.search.index = function(req, res) {
  339. const search = crowi.getSearcher();
  340. if (!search) {
  341. return res.redirect('/admin');
  342. }
  343. return res.render('admin/search', {});
  344. };
  345. actions.user = {};
  346. actions.user.index = async function(req, res) {
  347. const activeUsers = await User.countListByStatus(User.STATUS_ACTIVE);
  348. const userUpperLimit = aclService.userUpperLimit();
  349. const isUserCountExceedsUpperLimit = await User.isUserCountExceedsUpperLimit();
  350. const page = parseInt(req.query.page) || 1;
  351. const result = await User.findUsersWithPagination({
  352. page,
  353. select: User.USER_PUBLIC_FIELDS,
  354. populate: User.IMAGE_POPULATION,
  355. });
  356. const pager = createPager(result.total, result.limit, result.page, result.pages, MAX_PAGE_LIST);
  357. return res.render('admin/users', {
  358. users: result.docs,
  359. pager,
  360. activeUsers,
  361. userUpperLimit,
  362. isUserCountExceedsUpperLimit,
  363. });
  364. };
  365. actions.user.invite = function(req, res) {
  366. const form = req.form.inviteForm;
  367. const toSendEmail = form.sendEmail || false;
  368. if (req.form.isValid) {
  369. User.createUsersByInvitation(form.emailList.split('\n'), toSendEmail, (err, userList) => {
  370. if (err) {
  371. req.flash('errorMessage', req.form.errors.join('\n'));
  372. }
  373. else {
  374. req.flash('createdUser', userList);
  375. }
  376. return res.redirect('/admin/users');
  377. });
  378. }
  379. else {
  380. req.flash('errorMessage', req.form.errors.join('\n'));
  381. return res.redirect('/admin/users');
  382. }
  383. };
  384. actions.user.makeAdmin = function(req, res) {
  385. const id = req.params.id;
  386. User.findById(id, (err, userData) => {
  387. userData.makeAdmin((err, userData) => {
  388. if (err === null) {
  389. req.flash('successMessage', `${userData.name}さんのアカウントを管理者に設定しました。`);
  390. }
  391. else {
  392. req.flash('errorMessage', '更新に失敗しました。');
  393. debug(err, userData);
  394. }
  395. return res.redirect('/admin/users');
  396. });
  397. });
  398. };
  399. actions.user.removeFromAdmin = function(req, res) {
  400. const id = req.params.id;
  401. User.findById(id, (err, userData) => {
  402. userData.removeFromAdmin((err, userData) => {
  403. if (err === null) {
  404. req.flash('successMessage', `${userData.name}さんのアカウントを管理者から外しました。`);
  405. }
  406. else {
  407. req.flash('errorMessage', '更新に失敗しました。');
  408. debug(err, userData);
  409. }
  410. return res.redirect('/admin/users');
  411. });
  412. });
  413. };
  414. actions.user.activate = async function(req, res) {
  415. // check user upper limit
  416. const isUserCountExceedsUpperLimit = await User.isUserCountExceedsUpperLimit();
  417. if (isUserCountExceedsUpperLimit) {
  418. req.flash('errorMessage', 'ユーザーが上限に達したため有効化できません。');
  419. return res.redirect('/admin/users');
  420. }
  421. const id = req.params.id;
  422. User.findById(id, (err, userData) => {
  423. userData.statusActivate((err, userData) => {
  424. if (err === null) {
  425. req.flash('successMessage', `${userData.name}さんのアカウントを有効化しました`);
  426. }
  427. else {
  428. req.flash('errorMessage', '更新に失敗しました。');
  429. debug(err, userData);
  430. }
  431. return res.redirect('/admin/users');
  432. });
  433. });
  434. };
  435. actions.user.suspend = function(req, res) {
  436. const id = req.params.id;
  437. User.findById(id, (err, userData) => {
  438. userData.statusSuspend((err, userData) => {
  439. if (err === null) {
  440. req.flash('successMessage', `${userData.name}さんのアカウントを利用停止にしました`);
  441. }
  442. else {
  443. req.flash('errorMessage', '更新に失敗しました。');
  444. debug(err, userData);
  445. }
  446. return res.redirect('/admin/users');
  447. });
  448. });
  449. };
  450. actions.user.remove = function(req, res) {
  451. const id = req.params.id;
  452. let username = '';
  453. return new Promise((resolve, reject) => {
  454. User.findById(id, (err, userData) => {
  455. username = userData.username;
  456. return resolve(userData);
  457. });
  458. })
  459. .then((userData) => {
  460. return new Promise((resolve, reject) => {
  461. userData.statusDelete((err, userData) => {
  462. if (err) {
  463. reject(err);
  464. }
  465. resolve(userData);
  466. });
  467. });
  468. })
  469. .then((userData) => {
  470. // remove all External Accounts
  471. return ExternalAccount.remove({ user: userData }).then(() => { return userData });
  472. })
  473. .then((userData) => {
  474. return Page.removeByPath(`/user/${username}`).then(() => { return userData });
  475. })
  476. .then((userData) => {
  477. req.flash('successMessage', `${username} さんのアカウントを削除しました`);
  478. return res.redirect('/admin/users');
  479. })
  480. .catch((err) => {
  481. req.flash('errorMessage', '削除に失敗しました。');
  482. return res.redirect('/admin/users');
  483. });
  484. };
  485. // これやったときの relation の挙動未確認
  486. actions.user.removeCompletely = function(req, res) {
  487. // ユーザーの物理削除
  488. const id = req.params.id;
  489. User.removeCompletelyById(id, (err, removed) => {
  490. if (err) {
  491. debug('Error while removing user.', err, id);
  492. req.flash('errorMessage', '完全な削除に失敗しました。');
  493. }
  494. else {
  495. req.flash('successMessage', '削除しました');
  496. }
  497. return res.redirect('/admin/users');
  498. });
  499. };
  500. // app.post('/_api/admin/users.resetPassword' , admin.api.usersResetPassword);
  501. actions.user.resetPassword = async function(req, res) {
  502. const id = req.body.user_id;
  503. const User = crowi.model('User');
  504. try {
  505. const newPassword = await User.resetPasswordByRandomString(id);
  506. const user = await User.findById(id);
  507. const result = { user: user.toObject(), newPassword };
  508. return res.json(ApiResponse.success(result));
  509. }
  510. catch (err) {
  511. debug('Error on reseting password', err);
  512. return res.json(ApiResponse.error(err));
  513. }
  514. };
  515. actions.externalAccount = {};
  516. actions.externalAccount.index = function(req, res) {
  517. const page = parseInt(req.query.page) || 1;
  518. ExternalAccount.findAllWithPagination({ page })
  519. .then((result) => {
  520. const pager = createPager(result.total, result.limit, result.page, result.pages, MAX_PAGE_LIST);
  521. return res.render('admin/external-accounts', {
  522. accounts: result.docs,
  523. pager,
  524. });
  525. });
  526. };
  527. actions.externalAccount.remove = async function(req, res) {
  528. const id = req.params.id;
  529. let account = null;
  530. try {
  531. account = await ExternalAccount.findByIdAndRemove(id);
  532. if (account == null) {
  533. throw new Error('削除に失敗しました。');
  534. }
  535. }
  536. catch (err) {
  537. req.flash('errorMessage', err.message);
  538. return res.redirect('/admin/users/external-accounts');
  539. }
  540. req.flash('successMessage', `外部アカウント '${account.providerType}/${account.accountId}' を削除しました`);
  541. return res.redirect('/admin/users/external-accounts');
  542. };
  543. actions.userGroup = {};
  544. actions.userGroup.index = function(req, res) {
  545. const page = parseInt(req.query.page) || 1;
  546. const isAclEnabled = aclService.isAclEnabled();
  547. const renderVar = {
  548. userGroups: [],
  549. userGroupRelations: new Map(),
  550. pager: null,
  551. isAclEnabled,
  552. };
  553. UserGroup.findUserGroupsWithPagination({ page })
  554. .then((result) => {
  555. const pager = createPager(result.total, result.limit, result.page, result.pages, MAX_PAGE_LIST);
  556. const userGroups = result.docs;
  557. renderVar.userGroups = userGroups;
  558. renderVar.pager = pager;
  559. return userGroups.map((userGroup) => {
  560. return new Promise((resolve, reject) => {
  561. UserGroupRelation.findAllRelationForUserGroup(userGroup)
  562. .then((relations) => {
  563. return resolve({
  564. id: userGroup._id,
  565. relatedUsers: relations.map((relation) => {
  566. return relation.relatedUser;
  567. }),
  568. });
  569. });
  570. });
  571. });
  572. })
  573. .then((allRelationsPromise) => {
  574. return Promise.all(allRelationsPromise);
  575. })
  576. .then((relations) => {
  577. for (const relation of relations) {
  578. renderVar.userGroupRelations[relation.id] = relation.relatedUsers;
  579. }
  580. debug('in findUserGroupsWithPagination findAllRelationForUserGroupResult', renderVar.userGroupRelations);
  581. return res.render('admin/user-groups', renderVar);
  582. })
  583. .catch((err) => {
  584. debug('Error on find all relations', err);
  585. return res.json(ApiResponse.error('Error'));
  586. });
  587. };
  588. // グループ詳細
  589. actions.userGroup.detail = async function(req, res) {
  590. const userGroupId = req.params.id;
  591. const renderVar = {
  592. userGroup: null,
  593. userGroupRelations: [],
  594. notRelatedusers: [],
  595. relatedPages: [],
  596. };
  597. const userGroup = await UserGroup.findOne({ _id: userGroupId });
  598. if (userGroup == null) {
  599. logger.error('no userGroup is exists. ', userGroupId);
  600. req.flash('errorMessage', 'グループがありません');
  601. return res.redirect('/admin/user-groups');
  602. }
  603. renderVar.userGroup = userGroup;
  604. const resolves = await Promise.all([
  605. // get all user and group relations
  606. UserGroupRelation.findAllRelationForUserGroup(userGroup),
  607. // get all not related users for group
  608. UserGroupRelation.findUserByNotRelatedGroup(userGroup),
  609. // get all related pages
  610. Page.find({ grant: Page.GRANT_USER_GROUP, grantedGroup: { $in: [userGroup] } }),
  611. ]);
  612. renderVar.userGroupRelations = resolves[0];
  613. renderVar.notRelatedusers = resolves[1];
  614. renderVar.relatedPages = resolves[2];
  615. return res.render('admin/user-group-detail', renderVar);
  616. };
  617. //
  618. actions.userGroup.update = function(req, res) {
  619. const userGroupId = req.params.userGroupId;
  620. const name = crowi.xss.process(req.body.name);
  621. UserGroup.findById(userGroupId)
  622. .then((userGroupData) => {
  623. if (userGroupData == null) {
  624. req.flash('errorMessage', 'グループの検索に失敗しました。');
  625. return new Promise();
  626. }
  627. // 名前存在チェック
  628. return UserGroup.isRegisterableName(name)
  629. .then((isRegisterableName) => {
  630. // 既に存在するグループ名に更新しようとした場合はエラー
  631. if (!isRegisterableName) {
  632. req.flash('errorMessage', 'グループ名が既に存在します。');
  633. }
  634. else {
  635. return userGroupData.updateName(name)
  636. .then(() => {
  637. req.flash('successMessage', 'グループ名を更新しました。');
  638. })
  639. .catch((err) => {
  640. req.flash('errorMessage', 'グループ名の更新に失敗しました。');
  641. });
  642. }
  643. });
  644. })
  645. .then(() => {
  646. return res.redirect(`/admin/user-group-detail/${userGroupId}`);
  647. });
  648. };
  649. actions.userGroupRelation = {};
  650. actions.userGroupRelation.index = function(req, res) {
  651. };
  652. actions.userGroupRelation.create = function(req, res) {
  653. const User = crowi.model('User');
  654. const UserGroup = crowi.model('UserGroup');
  655. const UserGroupRelation = crowi.model('UserGroupRelation');
  656. // req params
  657. const userName = req.body.user_name;
  658. const userGroupId = req.body.user_group_id;
  659. let user = null;
  660. let userGroup = null;
  661. Promise.all([
  662. // ユーザグループをIDで検索
  663. UserGroup.findById(userGroupId),
  664. // ユーザを名前で検索
  665. User.findUserByUsername(userName),
  666. ])
  667. .then((resolves) => {
  668. userGroup = resolves[0];
  669. user = resolves[1];
  670. // Relation を作成
  671. UserGroupRelation.createRelation(userGroup, user);
  672. })
  673. .then((result) => {
  674. return res.redirect(`/admin/user-group-detail/${userGroup.id}`);
  675. })
  676. .catch((err) => {
  677. debug('Error on create user-group relation', err);
  678. req.flash('errorMessage', 'Error on create user-group relation');
  679. return res.redirect(`/admin/user-group-detail/${userGroup.id}`);
  680. });
  681. };
  682. actions.userGroupRelation.remove = function(req, res) {
  683. const UserGroupRelation = crowi.model('UserGroupRelation');
  684. const userGroupId = req.params.id;
  685. const relationId = req.params.relationId;
  686. UserGroupRelation.removeById(relationId)
  687. .then(() => {
  688. return res.redirect(`/admin/user-group-detail/${userGroupId}`);
  689. })
  690. .catch((err) => {
  691. debug('Error on remove user-group-relation', err);
  692. req.flash('errorMessage', 'グループのユーザ削除に失敗しました。');
  693. });
  694. };
  695. // Importer management
  696. actions.importer = {};
  697. actions.importer.api = api;
  698. api.validators = {};
  699. api.validators.importer = {};
  700. actions.importer.index = function(req, res) {
  701. const settingForm = configManager.getConfigByPrefix('crowi', 'importer:');
  702. return res.render('admin/importer', {
  703. settingForm,
  704. });
  705. };
  706. api.validators.importer.esa = function() {
  707. const validator = [
  708. check('importer:esa:team_name').not().isEmpty().withMessage('Error. Empty esa:team_name'),
  709. check('importer:esa:access_token').not().isEmpty().withMessage('Error. Empty esa:access_token'),
  710. ];
  711. return validator;
  712. };
  713. api.validators.importer.qiita = function() {
  714. const validator = [
  715. check('importer:qiita:team_name').not().isEmpty().withMessage('Error. Empty qiita:team_name'),
  716. check('importer:qiita:access_token').not().isEmpty().withMessage('Error. Empty qiita:access_token'),
  717. ];
  718. return validator;
  719. };
  720. actions.api = {};
  721. actions.api.appSetting = async function(req, res) {
  722. const form = req.form.settingForm;
  723. if (req.form.isValid) {
  724. debug('form content', form);
  725. // mail setting ならここで validation
  726. if (form['mail:from']) {
  727. validateMailSetting(req, form, async(err, data) => {
  728. debug('Error validate mail setting: ', err, data);
  729. if (err) {
  730. req.form.errors.push('SMTPを利用したテストメール送信に失敗しました。設定をみなおしてください。');
  731. return res.json({ status: false, message: req.form.errors.join('\n') });
  732. }
  733. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  734. return res.json({ status: true });
  735. });
  736. }
  737. else {
  738. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  739. return res.json({ status: true });
  740. }
  741. }
  742. else {
  743. return res.json({ status: false, message: req.form.errors.join('\n') });
  744. }
  745. };
  746. actions.api.asyncAppSetting = async(req, res) => {
  747. const form = req.form.settingForm;
  748. if (!req.form.isValid) {
  749. return res.json({ status: false, message: req.form.errors.join('\n') });
  750. }
  751. debug('form content', form);
  752. try {
  753. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  754. return res.json({ status: true });
  755. }
  756. catch (err) {
  757. logger.error(err);
  758. return res.json({ status: false });
  759. }
  760. };
  761. actions.api.securitySetting = async function(req, res) {
  762. if (!req.form.isValid) {
  763. return res.json({ status: false, message: req.form.errors.join('\n') });
  764. }
  765. const form = req.form.settingForm;
  766. if (aclService.isWikiModeForced()) {
  767. logger.debug('security:restrictGuestMode will not be changed because wiki mode is forced to set');
  768. delete form['security:restrictGuestMode'];
  769. }
  770. try {
  771. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  772. return res.json({ status: true });
  773. }
  774. catch (err) {
  775. logger.error(err);
  776. return res.json({ status: false });
  777. }
  778. };
  779. actions.api.securityPassportLdapSetting = function(req, res) {
  780. const form = req.form.settingForm;
  781. if (!req.form.isValid) {
  782. return res.json({ status: false, message: req.form.errors.join('\n') });
  783. }
  784. debug('form content', form);
  785. return configManager.updateConfigsInTheSameNamespace('crowi', form)
  786. .then(() => {
  787. // reset strategy
  788. crowi.passportService.resetLdapStrategy();
  789. // setup strategy
  790. if (configManager.getConfig('crowi', 'security:passport-ldap:isEnabled')) {
  791. crowi.passportService.setupLdapStrategy(true);
  792. }
  793. return;
  794. })
  795. .then(() => {
  796. res.json({ status: true });
  797. });
  798. };
  799. actions.api.securityPassportSamlSetting = async(req, res) => {
  800. const form = req.form.settingForm;
  801. validateSamlSettingForm(req.form, req.t);
  802. if (!req.form.isValid) {
  803. return res.json({ status: false, message: req.form.errors.join('\n') });
  804. }
  805. debug('form content', form);
  806. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  807. // reset strategy
  808. await crowi.passportService.resetSamlStrategy();
  809. // setup strategy
  810. if (configManager.getConfig('crowi', 'security:passport-saml:isEnabled')) {
  811. try {
  812. await crowi.passportService.setupSamlStrategy(true);
  813. }
  814. catch (err) {
  815. // reset
  816. await crowi.passportService.resetSamlStrategy();
  817. return res.json({ status: false, message: err.message });
  818. }
  819. }
  820. return res.json({ status: true });
  821. };
  822. actions.api.securityPassportBasicSetting = async(req, res) => {
  823. const form = req.form.settingForm;
  824. if (!req.form.isValid) {
  825. return res.json({ status: false, message: req.form.errors.join('\n') });
  826. }
  827. debug('form content', form);
  828. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  829. // reset strategy
  830. await crowi.passportService.resetBasicStrategy();
  831. // setup strategy
  832. if (configManager.getConfig('crowi', 'security:passport-basic:isEnabled')) {
  833. try {
  834. await crowi.passportService.setupBasicStrategy(true);
  835. }
  836. catch (err) {
  837. // reset
  838. await crowi.passportService.resetBasicStrategy();
  839. return res.json({ status: false, message: err.message });
  840. }
  841. }
  842. return res.json({ status: true });
  843. };
  844. actions.api.securityPassportGoogleSetting = async(req, res) => {
  845. const form = req.form.settingForm;
  846. if (!req.form.isValid) {
  847. return res.json({ status: false, message: req.form.errors.join('\n') });
  848. }
  849. debug('form content', form);
  850. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  851. // reset strategy
  852. await crowi.passportService.resetGoogleStrategy();
  853. // setup strategy
  854. if (configManager.getConfig('crowi', 'security:passport-google:isEnabled')) {
  855. try {
  856. await crowi.passportService.setupGoogleStrategy(true);
  857. }
  858. catch (err) {
  859. // reset
  860. await crowi.passportService.resetGoogleStrategy();
  861. return res.json({ status: false, message: err.message });
  862. }
  863. }
  864. return res.json({ status: true });
  865. };
  866. actions.api.securityPassportGitHubSetting = async(req, res) => {
  867. const form = req.form.settingForm;
  868. if (!req.form.isValid) {
  869. return res.json({ status: false, message: req.form.errors.join('\n') });
  870. }
  871. debug('form content', form);
  872. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  873. // reset strategy
  874. await crowi.passportService.resetGitHubStrategy();
  875. // setup strategy
  876. if (configManager.getConfig('crowi', 'security:passport-github:isEnabled')) {
  877. try {
  878. await crowi.passportService.setupGitHubStrategy(true);
  879. }
  880. catch (err) {
  881. // reset
  882. await crowi.passportService.resetGitHubStrategy();
  883. return res.json({ status: false, message: err.message });
  884. }
  885. }
  886. return res.json({ status: true });
  887. };
  888. actions.api.securityPassportTwitterSetting = async(req, res) => {
  889. const form = req.form.settingForm;
  890. if (!req.form.isValid) {
  891. return res.json({ status: false, message: req.form.errors.join('\n') });
  892. }
  893. debug('form content', form);
  894. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  895. // reset strategy
  896. await crowi.passportService.resetTwitterStrategy();
  897. // setup strategy
  898. if (configManager.getConfig('crowi', 'security:passport-twitter:isEnabled')) {
  899. try {
  900. await crowi.passportService.setupTwitterStrategy(true);
  901. }
  902. catch (err) {
  903. // reset
  904. await crowi.passportService.resetTwitterStrategy();
  905. return res.json({ status: false, message: err.message });
  906. }
  907. }
  908. return res.json({ status: true });
  909. };
  910. actions.api.securityPassportOidcSetting = async(req, res) => {
  911. const form = req.form.settingForm;
  912. if (!req.form.isValid) {
  913. return res.json({ status: false, message: req.form.errors.join('\n') });
  914. }
  915. debug('form content', form);
  916. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  917. // reset strategy
  918. await crowi.passportService.resetOidcStrategy();
  919. // setup strategy
  920. if (configManager.getConfig('crowi', 'security:passport-oidc:isEnabled')) {
  921. try {
  922. await crowi.passportService.setupOidcStrategy(true);
  923. }
  924. catch (err) {
  925. // reset
  926. await crowi.passportService.resetOidcStrategy();
  927. return res.json({ status: false, message: err.message });
  928. }
  929. }
  930. return res.json({ status: true });
  931. };
  932. actions.api.customizeSetting = async function(req, res) {
  933. const form = req.form.settingForm;
  934. if (req.form.isValid) {
  935. debug('form content', form);
  936. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  937. customizeService.initCustomCss();
  938. customizeService.initCustomTitle();
  939. return res.json({ status: true });
  940. }
  941. return res.json({ status: false, message: req.form.errors.join('\n') });
  942. };
  943. // app.post('/_api/admin/notifications.add' , admin.api.notificationAdd);
  944. actions.api.notificationAdd = function(req, res) {
  945. const UpdatePost = crowi.model('UpdatePost');
  946. const pathPattern = req.body.pathPattern;
  947. const channel = req.body.channel;
  948. debug('notification.add', pathPattern, channel);
  949. UpdatePost.create(pathPattern, channel, req.user)
  950. .then((doc) => {
  951. debug('Successfully save updatePost', doc);
  952. // fixme: うーん
  953. doc.creator = doc.creator._id.toString();
  954. return res.json(ApiResponse.success({ updatePost: doc }));
  955. })
  956. .catch((err) => {
  957. debug('Failed to save updatePost', err);
  958. return res.json(ApiResponse.error());
  959. });
  960. };
  961. // app.post('/_api/admin/notifications.remove' , admin.api.notificationRemove);
  962. actions.api.notificationRemove = function(req, res) {
  963. const UpdatePost = crowi.model('UpdatePost');
  964. const id = req.body.id;
  965. UpdatePost.remove(id)
  966. .then(() => {
  967. debug('Successfully remove updatePost');
  968. return res.json(ApiResponse.success({}));
  969. })
  970. .catch((err) => {
  971. debug('Failed to remove updatePost', err);
  972. return res.json(ApiResponse.error());
  973. });
  974. };
  975. // app.get('/_api/admin/users.search' , admin.api.userSearch);
  976. actions.api.usersSearch = function(req, res) {
  977. const User = crowi.model('User');
  978. const email = req.query.email;
  979. User.findUsersByPartOfEmail(email, {})
  980. .then((users) => {
  981. const result = {
  982. data: users,
  983. };
  984. return res.json(ApiResponse.success(result));
  985. })
  986. .catch((err) => {
  987. return res.json(ApiResponse.error());
  988. });
  989. };
  990. actions.api.toggleIsEnabledForGlobalNotification = async(req, res) => {
  991. const id = req.query.id;
  992. const isEnabled = (req.query.isEnabled === 'true');
  993. try {
  994. if (isEnabled) {
  995. await GlobalNotificationSetting.enable(id);
  996. }
  997. else {
  998. await GlobalNotificationSetting.disable(id);
  999. }
  1000. return res.json(ApiResponse.success());
  1001. }
  1002. catch (err) {
  1003. return res.json(ApiResponse.error());
  1004. }
  1005. };
  1006. /**
  1007. * save esa settings, update config cache, and response json
  1008. *
  1009. * @param {*} req
  1010. * @param {*} res
  1011. */
  1012. actions.api.importerSettingEsa = async(req, res) => {
  1013. const form = req.body;
  1014. const { validationResult } = require('express-validator');
  1015. const errors = validationResult(req);
  1016. if (!errors.isEmpty()) {
  1017. return res.json(ApiResponse.error('esa.io form is blank'));
  1018. }
  1019. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  1020. importer.initializeEsaClient(); // let it run in the back aftert res
  1021. return res.json(ApiResponse.success());
  1022. };
  1023. /**
  1024. * save qiita settings, update config cache, and response json
  1025. *
  1026. * @param {*} req
  1027. * @param {*} res
  1028. */
  1029. actions.api.importerSettingQiita = async(req, res) => {
  1030. const form = req.body;
  1031. const { validationResult } = require('express-validator');
  1032. const errors = validationResult(req);
  1033. if (!errors.isEmpty()) {
  1034. // return res.json(ApiResponse.error('Invalid comment.'));
  1035. // return res.status(422).json({ errors: errors.array() });
  1036. console.log('validator', errors);
  1037. return res.json(ApiResponse.error('Qiita form is blank'));
  1038. }
  1039. await configManager.updateConfigsInTheSameNamespace('crowi', form);
  1040. importer.initializeQiitaClient(); // let it run in the back aftert res
  1041. return res.json(ApiResponse.success());
  1042. };
  1043. /**
  1044. * Import all posts from esa
  1045. *
  1046. * @param {*} req
  1047. * @param {*} res
  1048. */
  1049. actions.api.importDataFromEsa = async(req, res) => {
  1050. const user = req.user;
  1051. let errors;
  1052. try {
  1053. errors = await importer.importDataFromEsa(user);
  1054. }
  1055. catch (err) {
  1056. errors = [err];
  1057. }
  1058. if (errors.length > 0) {
  1059. return res.json({ status: false, message: `<br> - ${errors.join('<br> - ')}` });
  1060. }
  1061. return res.json({ status: true });
  1062. };
  1063. /**
  1064. * Import all posts from qiita
  1065. *
  1066. * @param {*} req
  1067. * @param {*} res
  1068. */
  1069. actions.api.importDataFromQiita = async(req, res) => {
  1070. const user = req.user;
  1071. let errors;
  1072. try {
  1073. errors = await importer.importDataFromQiita(user);
  1074. }
  1075. catch (err) {
  1076. errors = [err];
  1077. }
  1078. if (errors.length > 0) {
  1079. return res.json({ status: false, message: `<br> - ${errors.join('<br> - ')}` });
  1080. }
  1081. return res.json({ status: true });
  1082. };
  1083. /**
  1084. * Test connection to esa and response result with json
  1085. *
  1086. * @param {*} req
  1087. * @param {*} res
  1088. */
  1089. actions.api.testEsaAPI = async(req, res) => {
  1090. try {
  1091. await importer.testConnectionToEsa();
  1092. return res.json({ status: true });
  1093. }
  1094. catch (err) {
  1095. return res.json({ status: false, message: `${err}` });
  1096. }
  1097. };
  1098. /**
  1099. * Test connection to qiita and response result with json
  1100. *
  1101. * @param {*} req
  1102. * @param {*} res
  1103. */
  1104. actions.api.testQiitaAPI = async(req, res) => {
  1105. try {
  1106. await importer.testConnectionToQiita();
  1107. return res.json({ status: true });
  1108. }
  1109. catch (err) {
  1110. return res.json({ status: false, message: `${err}` });
  1111. }
  1112. };
  1113. actions.api.searchBuildIndex = async function(req, res) {
  1114. const search = crowi.getSearcher();
  1115. if (!search) {
  1116. return res.json(ApiResponse.error('ElasticSearch Integration is not set up.'));
  1117. }
  1118. // first, delete index
  1119. try {
  1120. await search.deleteIndex();
  1121. }
  1122. catch (err) {
  1123. logger.warn('Delete index Error, but if it is initialize, its ok.', err);
  1124. }
  1125. // second, create index
  1126. try {
  1127. await search.buildIndex();
  1128. }
  1129. catch (err) {
  1130. logger.error('Error', err);
  1131. return res.json(ApiResponse.error(err));
  1132. }
  1133. searchEvent.on('addPageProgress', (total, current, skip) => {
  1134. crowi.getIo().sockets.emit('admin:addPageProgress', { total, current, skip });
  1135. });
  1136. searchEvent.on('finishAddPage', (total, current, skip) => {
  1137. crowi.getIo().sockets.emit('admin:finishAddPage', { total, current, skip });
  1138. });
  1139. // add all page
  1140. search
  1141. .addAllPages()
  1142. .then(() => {
  1143. debug('Data is successfully indexed. ------------------ ✧✧');
  1144. })
  1145. .catch((err) => {
  1146. logger.error('Error', err);
  1147. });
  1148. return res.json(ApiResponse.success());
  1149. };
  1150. function validateMailSetting(req, form, callback) {
  1151. const mailer = crowi.mailer;
  1152. const option = {
  1153. host: form['mail:smtpHost'],
  1154. port: form['mail:smtpPort'],
  1155. };
  1156. if (form['mail:smtpUser'] && form['mail:smtpPassword']) {
  1157. option.auth = {
  1158. user: form['mail:smtpUser'],
  1159. pass: form['mail:smtpPassword'],
  1160. };
  1161. }
  1162. if (option.port === 465) {
  1163. option.secure = true;
  1164. }
  1165. const smtpClient = mailer.createSMTPClient(option);
  1166. debug('mailer setup for validate SMTP setting', smtpClient);
  1167. smtpClient.sendMail({
  1168. from: form['mail:from'],
  1169. to: req.user.email,
  1170. subject: 'Wiki管理設定のアップデートによるメール通知',
  1171. text: 'このメールは、WikiのSMTP設定のアップデートにより送信されています。',
  1172. }, callback);
  1173. }
  1174. /**
  1175. * validate setting form values for SAML
  1176. *
  1177. * This validation checks, for the value of each mandatory items,
  1178. * whether it from the environment variables is empty and form value to update it is empty.
  1179. */
  1180. function validateSamlSettingForm(form, t) {
  1181. for (const key of crowi.passportService.mandatoryConfigKeysForSaml) {
  1182. const formValue = form.settingForm[key];
  1183. if (configManager.getConfigFromEnvVars('crowi', key) === null && formValue === '') {
  1184. const formItemName = t(`security_setting.form_item_name.${key}`);
  1185. form.errors.push(t('form_validation.required', formItemName));
  1186. }
  1187. }
  1188. }
  1189. return actions;
  1190. };