notifications-controller.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-undef,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS101: Remove unnecessary use of Array.from
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. define(['base'], function(App) {
  15. App.controller('NotificationsController', function($scope, $http) {
  16. for (let notification of Array.from($scope.notifications)) {
  17. notification.hide = false
  18. }
  19. $scope.samlInitPath = ExposedSettings.samlInitPath
  20. return ($scope.dismiss = notification =>
  21. $http({
  22. url: `/notifications/${notification._id}`,
  23. method: 'DELETE',
  24. headers: {
  25. 'X-Csrf-Token': window.csrfToken
  26. }
  27. }).then(() => (notification.hide = true)))
  28. })
  29. App.controller('ProjectInviteNotificationController', function(
  30. $scope,
  31. $http
  32. ) {
  33. // Shortcuts for translation keys
  34. $scope.projectName = $scope.notification.messageOpts.projectName
  35. $scope.userName = $scope.notification.messageOpts.userName
  36. return ($scope.accept = function() {
  37. $scope.notification.inflight = true
  38. return $http({
  39. url: `/project/${
  40. $scope.notification.messageOpts.projectId
  41. }/invite/token/${$scope.notification.messageOpts.token}/accept`,
  42. method: 'POST',
  43. headers: {
  44. 'X-Csrf-Token': window.csrfToken,
  45. 'X-Requested-With': 'XMLHttpRequest'
  46. }
  47. })
  48. .then(() => {
  49. $scope.notification.accepted = true
  50. })
  51. .catch(({ status }) => {
  52. if (status === 404) {
  53. // 404 probably means the invite has already been accepted and
  54. // deleted. Treat as success
  55. $scope.notification.accepted = true
  56. } else {
  57. $scope.notification.error = true
  58. }
  59. })
  60. .finally(() => {
  61. $scope.notification.inflight = false
  62. })
  63. })
  64. })
  65. App.controller('OverleafV2NotificationController', function(
  66. $scope,
  67. localStorage
  68. ) {
  69. $scope.visible = !localStorage('overleaf_v2_2_notification_hidden_at')
  70. return ($scope.dismiss = function() {
  71. $scope.visible = false
  72. return localStorage('overleaf_v2_2_notification_hidden_at', Date.now())
  73. })
  74. })
  75. App.controller('OverleafV1NotificationController', function(
  76. $scope,
  77. localStorage
  78. ) {
  79. $scope.visible = !localStorage('overleaf_v1_notification_hidden_at')
  80. return ($scope.toggle = function() {
  81. $scope.visible = !$scope.visible
  82. if (!$scope.visible) {
  83. return localStorage('overleaf_v1_notification_hidden_at', Date.now())
  84. } else {
  85. return localStorage('overleaf_v1_notification_hidden_at', null)
  86. }
  87. })
  88. })
  89. return App.controller('EmailNotificationController', function(
  90. $scope,
  91. $http,
  92. UserAffiliationsDataService
  93. ) {
  94. $scope.userEmails = []
  95. $scope.showConfirmEmail = email => {
  96. if (ExposedSettings.emailConfirmationDisabled) {
  97. return false
  98. }
  99. if (!email.confirmedAt && !email.hide) {
  100. if (
  101. email.affiliation &&
  102. email.affiliation.institution &&
  103. email.affiliation.institution.ssoEnabled &&
  104. (ExposedSettings.hasSamlBeta || ExposedSettings.hasSamlFeature)
  105. ) {
  106. return false
  107. }
  108. return true
  109. }
  110. }
  111. for (let userEmail of Array.from($scope.userEmails)) {
  112. userEmail.hide = false
  113. }
  114. const _getUserEmails = () =>
  115. UserAffiliationsDataService.getUserEmails().then(function(emails) {
  116. $scope.userEmails = emails
  117. return $scope.$emit('project-list:notifications-received')
  118. })
  119. _getUserEmails()
  120. return ($scope.resendConfirmationEmail = function(userEmail) {
  121. userEmail.confirmationInflight = true
  122. return UserAffiliationsDataService.resendConfirmationEmail(
  123. userEmail.email
  124. ).then(function() {
  125. userEmail.hide = true
  126. userEmail.confirmationInflight = false
  127. return $scope.$emit('project-list:notifications-received')
  128. })
  129. })
  130. })
  131. })