From 4dc2486d4b051e752a90214648dd57c2cf99a35d Mon Sep 17 00:00:00 2001 From: webplusai Date: Tue, 19 Nov 2024 12:43:07 +0100 Subject: [PATCH] Fix issue with default user role on create, profile navigation issue (#8761) --- .../modules/routes/handlers/get-index.js | 1 + .../modules/routes/handlers/manage-user.js | 1 + .../modules/routes/handlers/post-user.js | 6 ++++ .../multiwikiserver/templates/mws-header.tid | 33 ++++++++++++++++--- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/get-index.js b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/get-index.js index 32bdbc537..4973a6095 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/get-index.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/get-index.js @@ -45,6 +45,7 @@ exports.handler = function(request,response,state) { "user-is-admin": state.authenticatedUser && state.authenticatedUser.isAdmin ? "yes" : "no", "first-guest-user": state.firstGuestUser ? "yes" : "no", "show-annon-config": state.showAnonConfig ? "yes" : "no", + "user": JSON.stringify(state.authenticatedUser), }}); response.write(html); response.end(); diff --git a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/manage-user.js b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/manage-user.js index 739a6af56..f9b1ab854 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/manage-user.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/manage-user.js @@ -86,6 +86,7 @@ exports.handler = function(request,response,state) { "user-initials": user.username.split(" ").map(name => name[0]).join(""), "user-role": JSON.stringify(userRole), "all-roles": JSON.stringify(allRoles), + "first-guest-user": state.firstGuestUser ? "yes" : "no", "is-current-user-profile": state.authenticatedUser && state.authenticatedUser.user_id === $tw.utils.parseInt(user_id, 10) ? "yes" : "no", "username": state.authenticatedUser ? state.authenticatedUser.username : state.firstGuestUser ? "Annonymous User" : "Guest", "user-is-admin": state.authenticatedUser && state.authenticatedUser.isAdmin ? "yes" : "no", diff --git a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/post-user.js b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/post-user.js index df7f347f6..01955a2e9 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/post-user.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/routes/handlers/post-user.js @@ -78,6 +78,12 @@ exports.handler = function(request, response, state) { response.end(); return; } else { + // assign role to user + const roles = sqlTiddlerDatabase.listRoles(); + const roleId = roles.find(role => role.role_name.toUpperCase() !== "ADMIN")?.role_id; + if (roleId) { + sqlTiddlerDatabase.addRoleToUser(userId, roleId); + } response.writeHead(302, {"Location": "/admin/users/"+userId}); response.end(); } diff --git a/plugins/tiddlywiki/multiwikiserver/templates/mws-header.tid b/plugins/tiddlywiki/multiwikiserver/templates/mws-header.tid index 2d8e43f5e..5c597714f 100644 --- a/plugins/tiddlywiki/multiwikiserver/templates/mws-header.tid +++ b/plugins/tiddlywiki/multiwikiserver/templates/mws-header.tid @@ -1,7 +1,13 @@ title: $:/plugins/tiddlywiki/multiwikiserver/templates/mws-header
-

<$text text=<>/>

+

+ + + + | + <$text text=<>/> +

<% elseif [!match[Guest]]+[match[no]] %> - jsonget[user_id]addprefix[/admin/users/]] }}}> - - + <$set name="userId" value={{{ [jsonget[user_id]] }}}> + addprefix[/admin/users/]] }}}> + + + <% endif %>
@@ -36,6 +44,17 @@ title: $:/plugins/tiddlywiki/multiwikiserver/templates/mws-header margin-bottom: 20px; } +.mws-header h1 { + display: flex; + align-items: center; + gap: 10px; +} + +.mws-header h1 .divider { + font-size: 16px; + color: #ccc; +} + .mws-user-info { display: flex; align-items: center; @@ -126,4 +145,8 @@ title: $:/plugins/tiddlywiki/multiwikiserver/templates/mws-header .mws-admin-form-button:hover { background-color: #ddd; } - \ No newline at end of file + +.mws-logo { + font-size: 24px; +} +