linking.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. })
  26. window.metaAttributesCache.set('ol-oauthProviders', {
  27. collabratec: {
  28. descriptionKey: 'linked_collabratec_description',
  29. descriptionOptions: { appName: 'Overleaf' },
  30. name: 'IEEE Collabratec®',
  31. hideWhenNotLinked: true,
  32. linkPath: '/collabratec/auth/link',
  33. },
  34. google: {
  35. descriptionKey: 'login_with_service',
  36. descriptionOptions: { service: 'Google' },
  37. name: 'Google',
  38. linkPath: '/auth/google',
  39. },
  40. orcid: {
  41. descriptionKey: 'oauth_orcid_description',
  42. descriptionOptions: {
  43. link: '/blog/434',
  44. appName: 'Overleaf',
  45. },
  46. name: 'ORCID',
  47. linkPath: '/auth/orcid',
  48. },
  49. })
  50. window.metaAttributesCache.set('ol-hideLinkingWidgets', true)
  51. window.metaAttributesCache.delete('ol-ssoErrorMessage')
  52. }
  53. export function setPersonalAccessTokensMeta() {
  54. function generateToken(_id) {
  55. const oneYearFromNow = new Date()
  56. oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1)
  57. const tokenHasBeenUsed = Math.random() > 0.5
  58. return {
  59. _id,
  60. accessTokenPartial: 'olp_abc' + _id,
  61. createdAt: new Date(),
  62. accessTokenExpiresAt: oneYearFromNow,
  63. lastUsedAt: tokenHasBeenUsed ? new Date() : undefined,
  64. }
  65. }
  66. const tokens = []
  67. for (let i = 0; i < 6; i++) {
  68. tokens.push(generateToken(i))
  69. }
  70. window.metaAttributesCache.set('ol-personalAccessTokens', tokens)
  71. }