Skip to content

Commit

Permalink
Merge pull request #448 from curveball/fix-create-group-form
Browse files Browse the repository at this point in the history
Fix create group form
  • Loading branch information
evert authored Nov 10, 2022
2 parents 342c8f9 + 0112973 commit 6cc9cff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog
* Centralize CSRF token handling (for old browsers).
* Added a new 'add privilege' action, which is helpful for API clients.
* Fix bug: Incorrect url in `Location` header when creating a new user.
* #448: Fix 'create group' form.


0.22.0 (2022-09-27)
Expand Down
6 changes: 5 additions & 1 deletion src/group/controller/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class CreateGroupController extends Controller {
throw new Forbidden('Only users with the "admin" privilege can create new users');
}
ctx.response.type = 'text/html';
ctx.response.body = createGroupForm(ctx.query.msg, ctx.query.error);
ctx.response.body = createGroupForm({
csrfToken: await ctx.getCsrf(),
msg: ctx.query.msg,
error: ctx.query.error
});
}

async post(ctx: Context) {
Expand Down
19 changes: 15 additions & 4 deletions src/group/formats/html.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { render } from '../../templates';

export function createGroupForm(msg: string, error: string) {
type Options = {
csrfToken: string;
msg: string|undefined;
error: string|undefined;
}

export function createGroupForm(options: Options) {

const hiddenFields: Record<string, string> = {
'csrf-token': options.csrfToken,
};

return render('create-group', {
title: 'Create Group',
msg: msg,
error,
action: '/group/new'
msg: options.msg,
error: options.error,
action: '/group/new',
hiddenFields,
});
}

0 comments on commit 6cc9cff

Please sign in to comment.