linking.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const MOCK_DELAY = 1000
  2. export function defaultSetupMocks(fetchMock) {
  3. fetchMock
  4. .post('/user/oauth-unlink', 200, { delay: MOCK_DELAY })
  5. .get(
  6. 'express:/user/tpds/queues',
  7. { tpdsToWeb: 0, webToTpds: 0 },
  8. { delay: MOCK_DELAY }
  9. )
  10. }
  11. export function setDefaultMeta() {
  12. window.metaAttributesCache.set('ol-user', {
  13. ...window.metaAttributesCache.get('ol-user'),
  14. features: { github: true, dropbox: true, mendeley: false, zotero: false },
  15. refProviders: {
  16. mendeley: true,
  17. zotero: true,
  18. },
  19. })
  20. window.metaAttributesCache.set('ol-github', { enabled: false })
  21. window.metaAttributesCache.set('ol-dropbox', { registered: true })
  22. window.metaAttributesCache.set('ol-thirdPartyIds', {
  23. collabratec: 'collabratec-id',
  24. google: 'google-id',
  25. twitter: 'twitter-id',
  26. })
  27. window.metaAttributesCache.set('ol-oauthProviders', {
  28. collabratec: {
  29. descriptionKey: 'linked_collabratec_description',
  30. descriptionOptions: { appName: 'Overleaf' },
  31. name: 'IEEE Collabratec®',
  32. hideWhenNotLinked: true,
  33. linkPath: '/collabratec/auth/link',
  34. },
  35. google: {
  36. descriptionKey: 'login_with_service',
  37. descriptionOptions: { service: 'Google' },
  38. name: 'Google',
  39. linkPath: '/auth/google',
  40. },
  41. orcid: {
  42. descriptionKey: 'oauth_orcid_description',
  43. descriptionOptions: {
  44. link: '/blog/434',
  45. appName: 'Overleaf',
  46. },
  47. name: 'ORCID',
  48. linkPath: '/auth/orcid',
  49. },
  50. twitter: {
  51. hideWhenNotLinked: true,
  52. name: 'Twitter',
  53. linkPath: '/auth/twitter',
  54. },
  55. })
  56. window.metaAttributesCache.delete('integrationLinkingWidgets')
  57. window.metaAttributesCache.delete('referenceLinkingWidgets')
  58. window.metaAttributesCache.delete('ol-ssoErrorMessage')
  59. }
  60. export function setPersonalAccessTokensMeta() {
  61. function generateToken(_id) {
  62. const oneYearFromNow = new Date()
  63. oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1)
  64. const tokenHasBeenUsed = Math.random() > 0.5
  65. return {
  66. _id,
  67. accessTokenPartial: 'olp_abc' + _id,
  68. createdAt: new Date(),
  69. accessTokenExpiresAt: oneYearFromNow,
  70. lastUsedAt: tokenHasBeenUsed ? new Date() : undefined,
  71. }
  72. }
  73. const tokens = []
  74. for (let i = 0; i < 6; i++) {
  75. tokens.push(generateToken(i))
  76. }
  77. window.metaAttributesCache.set('ol-personalAccessTokens', tokens)
  78. window.metaAttributesCache.set('ol-showPersonalAccessToken', true)
  79. }