Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 84 additions & 1 deletion cypress/component/ImportContextSchemePreview.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const MENU_SWITCH = '[data-cy="importSchemeMenu"]'
const SKIPPED = '[data-cy="importSchemeMenuSkipped"]'
const NODES_SWITCH = '[data-cy="importSchemeNodes"]'
const TO_ITEMS = '[data-cy="importSchemeMenuTo"]'
const PAGES_SWITCH = '[data-cy="importSchemePages"]'
const PAGES_SKIPPED = '[data-cy="importSchemePagesSkipped"]'
const PAGES_LIST = '[data-cy="importSchemePagesList"]'

const schemeMenu = [
{ parent: null, title: 'Reports', displayTitle: 'Reports', icon: null, description: null, target: null },
Expand Down Expand Up @@ -71,23 +74,102 @@ describe('Import application scheme preview', () => {
cy.get(TO_ITEMS).eq(3).should('contain', 'Untitled item').and('contain', 'Page')
})

it('sends the pages of the scheme with the import', () => {
mountPreview(undefined, undefined, { to: schemePages, summary: pageSummary, skipped: [] })
.then(({ wrapper }) => {
cy.get(PAGES_SWITCH).should('exist')
cy.get(PAGES_LIST).should('contain', 'Updates the start page, 0 widgets')
.and('contain', 'Updates Overview, 1 widget')
.and('contain', 'New page Reports, 3 widgets, 1 without their table or view')
cy.wrap(null).then(() => {
expect(lastPayload(wrapper).pages).to.deep.equal(schemePages)
})
})
})

it('leaves the pages out when the switch is turned off', () => {
mountPreview(undefined, undefined, { to: schemePages, summary: pageSummary, skipped: [] })
.then(({ wrapper }) => {
cy.get(PAGES_SWITCH).click({ force: true })
cy.wrap(null).then(() => {
expect(lastPayload(wrapper)).to.not.have.property('pages')
})
})
})

it('leaves out the menu items for new pages when the pages are not imported', () => {
const menu = [
{ parent: null, title: 'New report', displayTitle: 'New report', target: { page: 'reports' } },
{ parent: null, title: 'Reports', displayTitle: 'Reports', target: null },
{ parent: 1, title: 'Overview', displayTitle: 'Overview', target: { page: 'overview' } },
]
mountPreview({ from: [], to: menu, skipped: [] }, undefined, { to: schemePages, summary: pageSummary, skipped: [] })
.then(({ wrapper }) => {
cy.get(PAGES_SWITCH).click({ force: true })
cy.get(SKIPPED).should('contain', 'New report: its page is not imported')
cy.wrap(null).then(() => {
expect(lastPayload(wrapper).menu).to.deep.equal([
{ parent: null, title: 'Reports', displayTitle: 'Reports', target: null },
{ parent: 0, title: 'Overview', displayTitle: 'Overview', target: { page: 'overview' } },
])
})
})
})

it('lists the pages and widgets the import would skip, with the reason', () => {
mountPreview(undefined, undefined, {
to: [],
summary: [],
skipped: [
{ pageIndex: 0, page: 'Overview', widgetIndex: 2, widget: 'Elsewhere', reason: 'Unknown widget type "chart"' },
{ pageIndex: 1, page: 'Second start', widgetIndex: null, widget: null, reason: 'an application has one start page' },
],
})

cy.get(PAGES_SKIPPED).should('contain', 'Overview: Elsewhere: Unknown widget type "chart"').and('contain', 'Second start: an application has one start page')
})

it('shows titles with an ampersand or angle brackets as typed', () => {
mountPreview(undefined, undefined, {
to: [],
summary: [{ action: 'add', pageType: 'grid', title: 'R&D overview', currentTitle: null, slug: 'rd', widgetCount: 0, unlinkedWidgetCount: 0 }],
skipped: [{ pageIndex: 1, page: 'Sales & Marketing <Q1>', widgetIndex: 0, widget: 'A & B', reason: 'its type is not startpage or grid' }],
})

cy.get(PAGES_LIST).should('contain', 'New page R&D overview')
cy.get(PAGES_SKIPPED).should('contain', 'Sales & Marketing <Q1>: A & B')
})

it('has no menu section for a preview without a menu', () => {
mountPreview(undefined)
.then(({ wrapper }) => {
cy.get(MENU_SWITCH).should('not.exist')
cy.get(PAGES_SWITCH).should('not.exist')
cy.wrap(null).then(() => {
expect(lastPayload(wrapper)).to.not.have.property('menu')
expect(lastPayload(wrapper)).to.not.have.property('pages')
})
})
})
})

const schemePages = [
{ page_type: 'grid', slug: 'overview', title: 'Overview', widgets: [{ type: 'data', title: 'Tasks', source: { targetType: 'table', targetUuid: 'table-uuid' } }] },
]

const pageSummary = [
{ action: 'update', pageType: 'startpage', title: null, currentTitle: null, slug: 'dashboard', widgetCount: 0, unlinkedWidgetCount: 0 },
{ action: 'update', pageType: 'grid', title: 'Overview', currentTitle: 'Overview', slug: 'overview', widgetCount: 1, unlinkedWidgetCount: 0 },
{ action: 'add', pageType: 'grid', title: 'Reports', currentTitle: null, slug: 'reports', widgetCount: 3, unlinkedWidgetCount: 1 },
]

/**
* @param {object|undefined} menu the menu part of the preview response
* @param {object} nodes the nodes part of the preview response
* @param {object|undefined} pages the pages part of the preview response
* @return {Cypress.Chainable} the mount result
*/
function mountPreview(menu, nodes = { from: [], to: [] }) {
function mountPreview(menu, nodes = { from: [], to: [] }, pages = undefined) {
return cy.mount(ImportContextSchemePreview, {
props: {
previewData: {
Expand All @@ -98,6 +180,7 @@ function mountPreview(menu, nodes = { from: [], to: [] }) {
addTables: {},
modifyTables: {},
...(menu === undefined ? {} : { menu }),
...(pages === undefined ? {} : { pages }),
},
},
})
Expand Down
8 changes: 6 additions & 2 deletions lib/Controller/ContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public function previewSchemeChanges(int $contextId, array $updateScheme): DataR
* @param list<array{node_type: int, node_uuid: string, permissions: int}> $nodes Ordered meta data of the related nodes
* @psalm-param array{addTables: list<TablesTable>, modifyTables: list<TablesTable>} $tables Tables to be added or modified
* @param list<array<string, mixed>>|null $menu Menu of the scheme, replacing the menu of the context: pages by slug, tables and views by uuid, the group of an item by its position in the list; items that cannot be used here are skipped. Left out, the menu stays as it is
* @param list<array<string, mixed>>|null $pages Pages of the scheme: the start page updates the start page, a grid page the page with its slug or it is added, and its widgets replace the widgets of that page; a widget names its table or view by `targetType` and `targetUuid` in its `source`, and is kept without one when that table or view is not a resource of the application. At most 50 pages are imported; pages and widgets that cannot be used here are skipped. Left out, the pages stay as they are
*
* @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND|Http::STATUS_FORBIDDEN|Http::STATUS_BAD_REQUEST, array{message: string}, array{}>
*
Expand All @@ -354,10 +355,13 @@ public function previewSchemeChanges(int $contextId, array $updateScheme): DataR
*/
#[NoAdminRequired]
#[RequirePermission(permission: Application::PERMISSION_MANAGE, typeParam: 'context', idParam: 'contextId')]
public function importScheme(int $contextId, string $name, string $iconName, string $description, array $nodes, array $tables, ?array $menu = null): DataResponse {
public function importScheme(int $contextId, string $name, string $iconName, string $description, array $nodes, array $tables, ?array $menu = null, ?array $pages = null): DataResponse {
if ($pages !== null && !ContextService::areSchemePages($pages)) {
return $this->handleBadRequestError(new BadRequestError('The pages of a scheme must be objects.'));
}
try {
$this->db->beginTransaction();
['context' => $context, 'menuSkipped' => $menuSkipped] = $this->contextService->importScheme($contextId, $name, $iconName, $description, $nodes, $tables, $this->userId, $menu);
['context' => $context, 'menuSkipped' => $menuSkipped] = $this->contextService->importScheme($contextId, $name, $iconName, $description, $nodes, $tables, $this->userId, $menu, $pages);
$this->db->commit();
return new DataResponse($context->jsonSerialize() + ['menuSkipped' => $menuSkipped]);
} catch (BadRequestError $e) {
Expand Down
23 changes: 23 additions & 0 deletions lib/Db/ViewMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,27 @@ public function findByUuid(string $uuid): ?View {
->where($qb->expr()->eq('v.uuid', $qb->createNamedParameter($uuid)));
return $this->findEntity($qb);
}

/**
* The views of the given tables that have one of the given uuids. A uuid is unique
* within a table only.
*
* @param int[] $tableIds
* @param string[] $uuids
* @return list<View>
* @throws Exception
*/
public function findByTableIdsAndUuids(array $tableIds, array $uuids): array {
$views = [];
foreach (array_chunk($uuids, 1000) as $uuidChunk) {
$qb = $this->db->getQueryBuilder();
$qb->select('v.*', 't.ownership')
->from($this->table, 'v')
->innerJoin('v', 'tables_tables', 't', 't.id = v.table_id')
->where($qb->expr()->in('v.table_id', $qb->createNamedParameter($tableIds, IQueryBuilder::PARAM_INT_ARRAY)))
->andWhere($qb->expr()->in('v.uuid', $qb->createNamedParameter($uuidChunk, IQueryBuilder::PARAM_STR_ARRAY)));
array_push($views, ...$this->findEntities($qb));
}
return $views;
}
}
Loading
Loading