diff --git a/client/cypress/support/commands.ts b/client/cypress/support/commands.ts index fb1f22dd..96ce3e14 100644 --- a/client/cypress/support/commands.ts +++ b/client/cypress/support/commands.ts @@ -113,6 +113,26 @@ const mockGraphqlOps = (options) => { cy.get('@mockGraphqlOps').invoke('setOperations' as any, options); }; +const login = (username: string, password: string, visitLogin = false) => { + if (visitLogin) { + cy.visit('/beta-login'); + } + + if (username !== '') { + cy.get('[data-cy=email-input]').type(username); + } + + if (password !== '') { + cy.get('[data-cy=password-input]').type(password); + } + cy.get('[data-cy=login-button]').click(); +}; + +const fakeLogin = () => { + cy.log('Logging in (fake)'); + cy.setCookie('loginStatus', 'true'); +}; + declare global { namespace Cypress { interface Chainable { @@ -136,9 +156,9 @@ declare global { selectClass(schoolClass: string): void; - login(username: string, password: string, visitLogin?: boolean): void; + login: typeof login; - fakeLogin(username: string, password: string): void; + fakeLogin: typeof fakeLogin; isSubmissionReadOnly(myText: string): void; @@ -180,20 +200,7 @@ Cypress.Commands.add('apolloLogin', (username, password) => { }); // todo: replace with apollo call -Cypress.Commands.add('login', (username, password, visitLogin = false) => { - if (visitLogin) { - cy.visit('/beta-login'); - } - - if (username !== '') { - cy.get('[data-cy=email-input]').type(username); - } - - if (password !== '') { - cy.get('[data-cy=password-input]').type(password); - } - cy.get('[data-cy=login-button]').click(); -}); +Cypress.Commands.add('login', login); Cypress.Commands.add('getByDataCy', getByDataCy); @@ -203,10 +210,7 @@ Cypress.Commands.add('selectClass', (schoolClass) => { cy.getByDataCy('class-selection-entry').contains(schoolClass).click(); }); -Cypress.Commands.add('fakeLogin', () => { - cy.log('Logging in (fake)'); - cy.setCookie('loginStatus', 'true'); -}); +Cypress.Commands.add('fakeLogin', fakeLogin); Cypress.Commands.add('isSubmissionReadOnly', (myText) => { cy.get('.submission-form__textarea--readonly').as('textarea'); diff --git a/server/books/models/contentblock.py b/server/books/models/contentblock.py index f2f6a43c..772fa2ff 100644 --- a/server/books/models/contentblock.py +++ b/server/books/models/contentblock.py @@ -137,9 +137,11 @@ class ContentBlock(StrictHierarchyPage, GraphqlNodeMixin): ) def save(self, *args, **kwargs): + # todo: move this to the after_create_page and after_edit_page hooks, and remove from here. for data in self.contents.raw_data: block_type, value = get_type_and_value(data) + # todo: also do the same for assignments if block_type == "survey": module = self.module survey = value["survey_id"] diff --git a/server/core/wagtail_hooks.py b/server/core/wagtail_hooks.py index fc979dd7..85bed065 100644 --- a/server/core/wagtail_hooks.py +++ b/server/core/wagtail_hooks.py @@ -4,6 +4,9 @@ from wagtail import hooks from basicknowledge.models import BasicKnowledge from books.models import ContentBlockSnapshot +from core.logger import get_logger + +logger = get_logger(__name__) # 1. Use the register_rich_text_features hook. @@ -88,3 +91,17 @@ def register_secondary_feature(features): @hooks.register('construct_explorer_page_queryset') def remove_page_types_from_menu(parent_page, pages, request): return pages.not_type(ContentBlockSnapshot).not_type(BasicKnowledge).exclude(contentblock__user_created=True) + +@hooks.register('after_copy_page') +def after_copy_hook(request, page, new_page): + # todo: find every ContentBlock further down in the tree, see if there are any Surveys or Assignments and copy them and reassign them + logger.debug(f'After copy page {page.title}, {new_page.title}') + +@hooks.register('after_edit_page') +def after_edit_hook(request, page): + logger.debug(f'After edit page {page.title}, {type(page).__name__}') + +@hooks.register('after_create_page') +def after_create_hook(request, page): + logger.debug(f'After create page {page.title}') +