ProjectOptionsHandler.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* eslint-disable
  2. camelcase,
  3. handle-callback-err,
  4. max-len,
  5. no-return-assign,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * DS207: Consider shorter variations of null checks
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. const { Project } = require('../../models/Project')
  16. const logger = require('logger-sharelatex')
  17. const _ = require('underscore')
  18. const settings = require('settings-sharelatex')
  19. const safeCompilers = ['xelatex', 'pdflatex', 'latex', 'lualatex']
  20. module.exports = {
  21. setCompiler(project_id, compiler, callback) {
  22. if (callback == null) {
  23. callback = function() {}
  24. }
  25. logger.log({ project_id, compiler }, 'setting the compiler')
  26. compiler = compiler.toLowerCase()
  27. if (!_.contains(safeCompilers, compiler)) {
  28. return callback()
  29. }
  30. const conditions = { _id: project_id }
  31. const update = { compiler }
  32. return Project.update(conditions, update, {}, function(err) {
  33. if (callback != null) {
  34. return callback()
  35. }
  36. })
  37. },
  38. setImageName(project_id, imageName, callback) {
  39. if (callback == null) {
  40. callback = function() {}
  41. }
  42. logger.log({ project_id, imageName }, 'setting the imageName')
  43. imageName = imageName.toLowerCase()
  44. if (
  45. !_.some(
  46. settings.allowedImageNames,
  47. allowed => imageName === allowed.imageName
  48. )
  49. ) {
  50. return callback()
  51. }
  52. const conditions = { _id: project_id }
  53. const update = { imageName: settings.imageRoot + '/' + imageName }
  54. return Project.update(conditions, update, {}, function(err) {
  55. if (callback != null) {
  56. return callback()
  57. }
  58. })
  59. },
  60. setSpellCheckLanguage(project_id, languageCode, callback) {
  61. if (callback == null) {
  62. callback = function() {}
  63. }
  64. logger.log({ project_id, languageCode }, 'setting the spell check language')
  65. let languageIsSafe = false
  66. settings.languages.forEach(function(safeLang) {
  67. if (safeLang.code === languageCode) {
  68. return (languageIsSafe = true)
  69. }
  70. })
  71. if (languageCode === '') {
  72. languageIsSafe = true
  73. }
  74. if (languageIsSafe) {
  75. const conditions = { _id: project_id }
  76. const update = { spellCheckLanguage: languageCode }
  77. return Project.update(conditions, update, {}, err => callback())
  78. } else {
  79. logger.err({ project_id, languageCode }, 'tryed to set unsafe language')
  80. return callback()
  81. }
  82. },
  83. setBrandVariationId(project_id, brandVariationId, callback) {
  84. if (callback == null) {
  85. callback = function() {}
  86. }
  87. logger.log(
  88. { project_id, brandVariationId },
  89. 'setting the brand variation id'
  90. )
  91. if (brandVariationId == null || brandVariationId === '') {
  92. return callback()
  93. }
  94. const conditions = { _id: project_id }
  95. const update = { brandVariationId }
  96. return Project.update(conditions, update, {}, function(err) {
  97. if (err != null) {
  98. logger.err({ err }, 'error setting brandVariationId')
  99. }
  100. return callback()
  101. })
  102. },
  103. unsetBrandVariationId(project_id, callback) {
  104. if (callback == null) {
  105. callback = function() {}
  106. }
  107. logger.log({ project_id }, 'unsetting the brand variation id')
  108. const conditions = { _id: project_id }
  109. const update = { $unset: { brandVariationId: 1 } }
  110. return Project.update(conditions, update, {}, function(err) {
  111. if (err != null) {
  112. logger.warn({ err }, 'error unsetting brandVariationId')
  113. return callback(err)
  114. }
  115. return callback()
  116. })
  117. }
  118. }