admin.spec.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. import { isExcludedBySharding, startWith } from './helpers/config'
  2. import {
  3. activateUser,
  4. createMongoUser,
  5. ensureUserExists,
  6. login,
  7. } from './helpers/login'
  8. import { v4 as uuid } from 'uuid'
  9. import { createProject } from './helpers/project'
  10. import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
  11. import { openEmail } from './helpers/email'
  12. describe('admin panel', function () {
  13. function registrationTests() {
  14. it('via GUI and opening URL manually', () => {
  15. const user = `${uuid()}@example.com`
  16. cy.get('input[name="email"]').type(user + '{enter}')
  17. cy.get('td')
  18. .contains(/\/user\/activate/)
  19. .then($td => {
  20. const url = $td.text().trim()
  21. activateUser(url)
  22. })
  23. })
  24. it('via GUI and email', () => {
  25. const user = `${uuid()}@example.com`
  26. cy.get('input[name="email"]').type(user + '{enter}')
  27. let url: string
  28. cy.get('td')
  29. .contains(/\/user\/activate/)
  30. .then($td => {
  31. url = $td.text().trim()
  32. })
  33. cy.then(() => {
  34. openEmail(
  35. 'Activate your Overleaf Community Edition Account',
  36. (frame, { url }) => {
  37. frame.contains('Set password').then(el => {
  38. expect(el.attr('href')!).to.equal(url)
  39. })
  40. },
  41. { url }
  42. )
  43. // Run activateUser in the main origin instead of inside openEmail. See docs on openEmail.
  44. activateUser(url)
  45. })
  46. })
  47. it('via script and opening URL manually', () => {
  48. const user = `${uuid()}@example.com`
  49. let url: string
  50. cy.then(async () => {
  51. ;({ url } = await createMongoUser({ email: user }))
  52. })
  53. cy.then(() => {
  54. activateUser(url)
  55. })
  56. })
  57. it('via script and email', () => {
  58. const user = `${uuid()}@example.com`
  59. let url: string
  60. cy.then(async () => {
  61. ;({ url } = await createMongoUser({ email: user }))
  62. })
  63. cy.then(() => {
  64. openEmail(
  65. 'Activate your Overleaf Community Edition Account',
  66. (frame, { url }) => {
  67. frame.contains('Set password').then(el => {
  68. expect(el.attr('href')!).to.equal(url)
  69. })
  70. },
  71. { url }
  72. )
  73. // Run activateUser in the main origin instead of inside openEmail. See docs on openEmail.
  74. activateUser(url)
  75. })
  76. })
  77. }
  78. describe('in CE', () => {
  79. if (isExcludedBySharding('CE_DEFAULT')) return
  80. startWith({ pro: false, version: 'latest' })
  81. const admin = 'admin@example.com'
  82. const user = `user+${uuid()}@example.com`
  83. ensureUserExists({ email: admin, isAdmin: true })
  84. ensureUserExists({ email: user })
  85. describe('create users', () => {
  86. beforeEach(() => {
  87. login(admin)
  88. cy.visit('/project')
  89. cy.get('nav').findByText('Admin').click()
  90. cy.get('nav').findByText('Manage Users').click()
  91. })
  92. registrationTests()
  93. })
  94. })
  95. describe('in server pro', () => {
  96. const admin = 'admin@example.com'
  97. const user1 = 'user@example.com'
  98. const user2 = 'user2@example.com'
  99. let testProjectName = ''
  100. let testProjectId = ''
  101. let deletedProjectName = ''
  102. let projectToDeleteId = ''
  103. const findProjectRow = (projectName: string) => {
  104. cy.log('find project row')
  105. return cy.findByText(projectName).parent().parent()
  106. }
  107. if (isExcludedBySharding('PRO_DEFAULT_2')) return
  108. startWith({
  109. pro: true,
  110. })
  111. ensureUserExists({ email: admin, isAdmin: true })
  112. ensureUserExists({ email: user1 })
  113. ensureUserExists({ email: user2 })
  114. beforeWithReRunOnTestRetry(() => {
  115. testProjectName = `project-${uuid()}`
  116. deletedProjectName = `deleted-project-${uuid()}`
  117. login(user1)
  118. createProject(testProjectName).then(id => (testProjectId = id))
  119. createProject(deletedProjectName).then(id => (projectToDeleteId = id))
  120. })
  121. describe('manage site', () => {
  122. beforeEach(() => {
  123. login(admin)
  124. cy.visit('/project')
  125. cy.get('nav').findByText('Admin').click()
  126. cy.get('nav').findByText('Manage Site').click()
  127. })
  128. it('publish and clear admin messages', () => {
  129. const message = 'Admin Message ' + uuid()
  130. cy.log('create system message')
  131. cy.get('[role="tab"]').contains('System Messages').click()
  132. cy.get('input[name="content"]').type(message)
  133. cy.get('button').contains('Post Message').click()
  134. cy.findByText(message)
  135. login(user1)
  136. cy.visit('/project')
  137. cy.findByText(message)
  138. cy.log('clear system messages')
  139. login(admin)
  140. cy.visit('/project')
  141. cy.get('nav').findByText('Admin').click()
  142. cy.get('nav').findByText('Manage Site').click()
  143. cy.get('[role="tab"]').contains('System Messages').click()
  144. cy.get('button').contains('Clear all messages').click()
  145. cy.log('verify system messages are no longer displayed')
  146. login(user1)
  147. cy.visit('/project')
  148. cy.findByText(message).should('not.exist')
  149. })
  150. })
  151. describe('manage users', () => {
  152. beforeEach(() => {
  153. login(admin)
  154. cy.visit('/project')
  155. cy.get('nav').findByText('Admin').click()
  156. cy.get('nav').findByText('Manage Users').click()
  157. })
  158. describe('create users', () => {
  159. beforeEach(() => {
  160. cy.get('a').contains('New User').click()
  161. })
  162. registrationTests()
  163. })
  164. it('user list RegExp search', () => {
  165. cy.get('input[name="isRegExpSearch"]').click()
  166. cy.get('input[name="email"]').type('user[0-9]{enter}')
  167. cy.findByText(user2)
  168. cy.findByText(user1).should('not.exist')
  169. })
  170. })
  171. describe('user page', () => {
  172. beforeEach(() => {
  173. login(admin)
  174. cy.visit('/project')
  175. cy.get('nav').findByText('Admin').click()
  176. cy.get('nav').findByText('Manage Users').click()
  177. cy.get('input[name="email"]').type(user1 + '{enter}')
  178. cy.findByText(user1).click()
  179. cy.url().should('match', /\/admin\/user\/[a-fA-F0-9]{24}/)
  180. })
  181. it('displays expected tabs', () => {
  182. const tabs = [
  183. 'User Info',
  184. 'Projects',
  185. 'Deleted Projects',
  186. 'Audit Log',
  187. 'Sessions',
  188. ]
  189. cy.get('[role="tab"]').each((el, index) => {
  190. cy.wrap(el).findByText(tabs[index]).click()
  191. })
  192. cy.get('[role="tab"]').should('have.length', tabs.length)
  193. })
  194. describe('user info tab', () => {
  195. beforeEach(() => {
  196. cy.get('[role="tab"]').contains('User Info').click()
  197. })
  198. it('displays required sections', () => {
  199. // not exhaustive list, checks the tab content is rendered
  200. cy.findByText('Profile')
  201. cy.findByText('Editor Settings')
  202. })
  203. it('should not display SaaS-only sections', () => {
  204. cy.findByText('Referred User Count').should('not.exist')
  205. cy.findByText('Split Test Assignments').should('not.exist')
  206. cy.findByText('Experimental Features').should('not.exist')
  207. cy.findByText('Service Integration').should('not.exist')
  208. cy.findByText('SSO Integrations').should('not.exist')
  209. cy.findByText('Security').should('not.exist')
  210. })
  211. })
  212. it('transfer project ownership', () => {
  213. cy.log("access project admin through owners' project list")
  214. cy.get('[role="tab"]').contains('Projects').click()
  215. cy.get(`a[href="/admin/project/${testProjectId}"]`).click()
  216. cy.findByText('Transfer Ownership').click()
  217. cy.get('button[type="submit"]').should('be.disabled')
  218. cy.get('input[name="user_id"]').type(user2)
  219. cy.get('button[type="submit"]').should('not.be.disabled')
  220. cy.get('button[type="submit"]').click()
  221. cy.findByText('Transfer project to this user?')
  222. cy.get('button').contains('Confirm').click()
  223. cy.log('check the project is displayed in the new owner projects tab')
  224. cy.get('input[name="email"]').type(user2 + '{enter}')
  225. cy.findByText(user2).click()
  226. cy.get('[role="tab"]').contains('Projects').click()
  227. cy.get(`a[href="/admin/project/${testProjectId}"]`)
  228. })
  229. })
  230. describe('project page', () => {
  231. beforeEach(() => {
  232. login(admin)
  233. cy.visit(`/admin/project/${testProjectId}`)
  234. })
  235. it('displays expected tabs', () => {
  236. const tabs = ['Project Info', 'Deleted Docs', 'Audit Log']
  237. cy.get('[role="tab"]').each((el, index) => {
  238. cy.wrap(el).findByText(tabs[index]).click()
  239. })
  240. cy.get('[role="tab"]').should('have.length', tabs.length)
  241. })
  242. })
  243. it('restore deleted projects', () => {
  244. login(user1)
  245. cy.visit('/project')
  246. cy.log('select project to delete')
  247. findProjectRow(deletedProjectName).within(() =>
  248. cy.get('input[type="checkbox"]').first().check()
  249. )
  250. cy.log('delete project')
  251. findProjectRow(deletedProjectName).within(() =>
  252. cy.findByRole('button', { name: 'Trash' }).click()
  253. )
  254. cy.get('button').contains('Confirm').click()
  255. cy.findByText(deletedProjectName).should('not.exist')
  256. cy.log('navigate to thrashed projects and delete the project')
  257. cy.get('.project-list-sidebar-react').within(() => {
  258. cy.findByText('Trashed Projects').click()
  259. })
  260. findProjectRow(deletedProjectName).within(() =>
  261. cy.findByRole('button', { name: 'Delete' }).click()
  262. )
  263. cy.get('button').contains('Confirm').click()
  264. cy.findByText(deletedProjectName).should('not.exist')
  265. cy.log('login as an admin and navigate to the deleted project')
  266. login(admin)
  267. cy.visit('/admin/user')
  268. cy.get('input[name="email"]').type(user1 + '{enter}')
  269. cy.get('a').contains(user1).click()
  270. cy.findByText('Deleted Projects').click()
  271. cy.get('a').contains(deletedProjectName).click()
  272. cy.log('undelete the project')
  273. cy.findByText('Undelete').click()
  274. cy.findByText('Undelete').should('not.exist')
  275. cy.url().should('contain', `/admin/project/${projectToDeleteId}`)
  276. cy.log('login as the user and verify the project is restored')
  277. login(user1)
  278. cy.visit('/project')
  279. cy.get('.project-list-sidebar-react').within(() => {
  280. cy.findByText('Trashed Projects').click()
  281. })
  282. cy.findByText(`${deletedProjectName} (Restored)`)
  283. })
  284. })
  285. })