admin.js 43 KB

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