Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display a message when the categories vocabulary is missing #4169

Merged
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
4 changes: 4 additions & 0 deletions e2e/client/specs/users_spec.ts
Original file line number Diff line number Diff line change
@@ -47,6 +47,10 @@ describe('users', () => {
element(by.css('.modal__dialog .btn--primary')).click();
browser.sleep(2000); // wait for reload

// close "missing categories" vocabulary warning
// most likely it appears because refreshing the page causes test data to disappear
element(by.css('.p-dialog-header-icons')).click();

const header = element(by.css('[ng-hide="currentRoute.topTemplateUrl"]'));

browser.wait(ECE.presenceOf(header), 1000);
9 changes: 9 additions & 0 deletions scripts/index.ts
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@ import {setupTansa} from 'apps/tansa';
import {i18n} from 'core/utils';
import {configurableAlgorithms} from 'core/ui/configurable-algorithms';
import {merge} from 'lodash';
import {maybeDisplayInvalidInstanceConfigurationMessage} from 'validate-instance-configuration';
import ng from 'core/services/ng';

let body = angular.element('body');

@@ -197,6 +199,7 @@ export function startApp(
document.write('Invalid date format specified in config.view.dateFormat');
return;
}

/**
* @ngdoc module
* @name superdesk-client
@@ -210,6 +213,12 @@ export function startApp(
'superdesk.register_extensions',
].concat(appConfig.apps || []), {strictDi: true});

setTimeout(() => { // required to avoid protractor timing out and failing tests
if (ng.get('session').sessionId != null) { // user logged in
maybeDisplayInvalidInstanceConfigurationMessage();
}
});

window['superdeskIsReady'] = true;

body.attr('data-theme', 'dark-ui');
45 changes: 45 additions & 0 deletions scripts/validate-instance-configuration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import {Modal} from 'superdesk-ui-framework/react';
import ng from 'core/services/ng';
import {gettext} from 'core/utils';
import {showModal} from 'core/services/modalService';

const modalHeader = (
<span
style={{background: 'red', color: 'white', padding: 4}}
>
{gettext('Instance configuration is missing!')}
</span>
);

export function maybeDisplayInvalidInstanceConfigurationMessage() {
const issues: Array<React.ReactNode> = [];

ng.get('vocabularies').getAllActiveVocabularies().then((vocabularies) => {
const categoriesMissing = vocabularies.find(({_id}) => _id === 'categories') != null;

if (categoriesMissing) {
issues.push(
(
<>
<p>{gettext('Vocabulary with ID "categories" is required.')}</p>
<p>{gettext('Add it via Settings > Metadata')}</p>
</>
),
);
}

if (issues.length > 0) {
showModal(({closeModal}) => (
<Modal
visible={true}
headerTemplate={modalHeader}
onHide={closeModal}
zIndex={9999}
>
{issues[0]}
</Modal>
));
}
});
}