1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Server: Allow searching user by email or name

This commit is contained in:
Laurent Cozic 2022-10-17 16:40:52 +01:00
parent 8ac8d537c8
commit 1cfbefb76a
2 changed files with 33 additions and 0 deletions

View File

@ -99,6 +99,7 @@ router.get('admin/users', async (_path: SubPath, ctx: AppContext) => {
await userModel.checkIfAllowed(ctx.joplin.owner, AclAction.List);
const showDisabled = ctx.query.show_disabled === '1';
const searchQuery = ctx.query.query || '';
const pagination = makeTablePagination(ctx.query, 'full_name', PaginationOrderDir.ASC);
pagination.limit = 1000;
@ -107,6 +108,13 @@ router.get('admin/users', async (_path: SubPath, ctx: AppContext) => {
if (!showDisabled) {
void query.where('enabled', '=', 1);
}
if (searchQuery) {
void query.where(qb => {
void qb.whereRaw('full_name like ?', [`%${searchQuery}%`]).orWhereRaw('email like ?', [`%${searchQuery}%`]);
});
}
return query;
},
});
@ -183,6 +191,11 @@ router.get('admin/users', async (_path: SubPath, ctx: AppContext) => {
const view = defaultView('admin/users', _('Users'));
view.content = {
userTable: makeTableView(table),
queryArray: Object.entries(ctx.query).map(([name, value]) => {
return { name, value };
}).filter(e => e.name !== 'query'),
query: searchQuery,
searchUrl: setQueryParameters(adminUsersUrl(), ctx.query),
csrfTag: await createCsrfTag(ctx),
disabledToggleButtonLabel: showDisabled ? _('Hide disabled') : _('Show disabled'),
disabledToggleButtonUrl: setQueryParameters(adminUsersUrl(), { ...ctx.query, show_disabled: showDisabled ? '0' : '1' }),

View File

@ -1,3 +1,23 @@
<div class="block">
<form method="GET" action="{{searchUrl}}">
<div class="field">
<label class="label">Search user</label>
<div class="control">
<input name="query" id="query" class="input" type="text" placeholder="User name or email" value="{{query}}">
{{#queryArray}}
<input type="hidden" name="{{name}}" value="{{value}}" />
{{/queryArray}}
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button class="button is-link">Search</button>
</div>
</div>
</form>
</div>
<div class="block">
<a class="button is-primary" href="{{{global.baseUrl}}}/admin/users/new">Add user</a>
<a class="button is-link toggle-disabled-button hide-disabled" href="{{disabledToggleButtonUrl}}">{{disabledToggleButtonLabel}}</a>