From a084d7dc0e4e594961907b33c575cd1457e17d87 Mon Sep 17 00:00:00 2001 From: Hermann <blumh@ethz.ch> Date: Sun, 10 Jun 2018 11:28:07 +0200 Subject: [PATCH] fix bug: adding group to a user --- src/auth.js | 6 +++--- src/users/viewUser.js | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/auth.js b/src/auth.js index 8f15d4c..86af03e 100644 --- a/src/auth.js +++ b/src/auth.js @@ -125,7 +125,7 @@ export class ResourceHandler { const fullQuery = {}; - if ('search' in query && query.search.length > 0) { + if ('search' in query && query.search && query.search.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 @@ -134,7 +134,7 @@ export class ResourceHandler { const fieldQuery = {}; fieldQuery[key] = { $regex: `${query.search}`, - $options: 'i' + $options: 'i', }; return fieldQuery; }), @@ -146,7 +146,7 @@ export class ResourceHandler { } else { fullQuery.where = JSON.stringify(searchQuery); } - } else if (query.where) { + } else if ('where' in query) { fullQuery.where = JSON.stringify(query.where); } diff --git a/src/users/viewUser.js b/src/users/viewUser.js index f257163..44d32ee 100644 --- a/src/users/viewUser.js +++ b/src/users/viewUser.js @@ -26,7 +26,7 @@ export default class UserView extends ItemView { // a controller to handle the list of possible groups to join this.groupcontroller = new DatalistController('groups', {}, ['name']); // exclude the groups where the user is already a member - this.groupmemberships.handler.get({ where: { user: this.id } }) + this.groupmemberships.handler.get({ where: { user: this.data._id } }) .then((data) => { const groupIds = data._items.map(item => item.group); this.groupcontroller.setQuery({ @@ -71,7 +71,8 @@ export default class UserView extends ItemView { // groupmemberships. Selects a group to request membership for. const groupSelect = m(SelectList, { controller: this.groupcontroller, - listTileAttrs: data => Object.assign({}, { title: data.name }), + listTileAttrs: group => Object.assign({}, { title: group.name }), + selectedText: group => group.name, onSubmit: (group) => { this.groupchoice = false; this.groupmemberships.handler.post({ @@ -81,6 +82,7 @@ export default class UserView extends ItemView { this.groupmemberships.refresh(); }); }, + onCancel: () => { this.groupchoice = false; m.redraw(); }, }); return this.layout([ @@ -119,7 +121,7 @@ export default class UserView extends ItemView { m('div.viewcontainercolumn', m(Card, { style: { height: '300px' }, content: m('div', [ - this.groupchoice ? groupSelect : '', + this.groupchoice && groupSelect, m(Toolbar, { compact: true }, [ m(ToolbarTitle, { text: 'Group Memberships' }), m(Button, { -- GitLab