To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 1e25b8af authored by Hermann's avatar Hermann
Browse files

Fix search for resources without searchable keys

parent 8f099e85
......@@ -155,7 +155,11 @@ export class ResourceHandler {
* when search is set, any of these keys may match the search pattern
* E.g. for an event, this may be ['title_de', 'title_en', 'location']
*/
constructor(resource, searchKeys = false) {
constructor(resource, searchKeys = []) {
// backwards compatibiliity, should be removed in future
// eslint-disable-next-line no-param-reassign
if (!searchKeys) searchKeys = [];
this.resource = resource;
this.rights = [];
this.schema = JSON.parse(JSON.stringify(getSchema().definitions[
......@@ -172,11 +176,11 @@ export class ResourceHandler {
});
// special case for users, we don't allow reverse search by legi or rfid
if (resource === 'users') this.searchKeys = ['firstname', 'lastname', 'nethz'];
else this.searchKeys = searchKeys || possibleSearchKeys;
else this.searchKeys = searchKeys.length === 0 ? possibleSearchKeys : searchKeys;
checkAuthenticated().then(() => {
// again special case for users
if (resource === 'users' && APISession.isUserAdmin) {
this.searchKeys = searchKeys || possibleSearchKeys;
this.searchKeys = searchKeys.length === 0 ? possibleSearchKeys : searchKeys;
}
});
}
......@@ -194,7 +198,8 @@ export class ResourceHandler {
const fullQuery = {};
if ('search' in query && query.search && query.search.length > 0 && this.searchKeys) {
if ('search' in query && query.search && query.search.length > 0
&& this.searchKeys.length !== 0) {
// translate search into where, we just look if any field contains search
// The search-string may match any of the keys in the object specified in the
// constructor
......
......@@ -7,7 +7,7 @@ import EditView from '../views/editView';
class NanoController {
constructor(resource) {
this.resource = resource;
this.handler = new ResourceHandler(resource, false);
this.handler = new ResourceHandler(resource);
this.data = {};
}
......
......@@ -12,7 +12,7 @@ export default class ItemController {
this.modus = 'new';
this.data = undefined;
}
this.handler = new ResourceHandler(resource, false);
this.handler = new ResourceHandler(resource);
this.embedded = embedded || {};
if (this.id) {
this.handler.getItem(this.id, this.embedded).then((item) => {
......
......@@ -4,7 +4,7 @@ import { ResourceHandler } from './auth';
import { debounce } from './utils';
export default class DatalistController {
constructor(resource, query = {}, searchKeys = false) {
constructor(resource, query = {}, searchKeys = []) {
this.handler = new ResourceHandler(resource, searchKeys);
this.query = query || {};
this.filter = null;
......
......@@ -16,9 +16,9 @@ export default class RelationlistController {
primary,
secondary,
query = {},
searchKeys = false,
searchKeys = [],
secondaryQuery = {},
secondarySearchKeys = false,
secondarySearchKeys = [],
includeWithoutRelation = false,
}) {
this.handler = new ResourceHandler(primary, searchKeys);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment