Skip to content

Commit

Permalink
#8754 fix issue with default user role on create, profile navigation …
Browse files Browse the repository at this point in the history
…issue
  • Loading branch information
webplusai committed Nov 19, 2024
1 parent 3836a5d commit 18a33b2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
33 changes: 28 additions & 5 deletions plugins/tiddlywiki/multiwikiserver/templates/mws-header.tid
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
title: $:/plugins/tiddlywiki/multiwikiserver/templates/mws-header

<div class="mws-header">
<h1><$text text=<<page-title>>/></h1>
<h1>
<a href="/">
<span class="mws-logo">🏠</span>
</a>
<span class="divider">|</span>
<$text text=<<page-title>>/>
</h1>
<div class="mws-user-info">
<span>Hello, <$text text=<<username>>/></span>
<% if [<user-is-admin>match[yes]] %>
Expand All @@ -16,9 +22,11 @@ title: $:/plugins/tiddlywiki/multiwikiserver/templates/mws-header
</div>
</div>
<% elseif [<username>!match[Guest]]+[<first-guest-user>match[no]] %>
<a href={{{ [<user>jsonget[user_id]addprefix[/admin/users/]] }}}>
<button class="mws-profile-btn">Profile</button>
</a>
<$set name="userId" value={{{ [<user>jsonget[user_id]] }}}>
<a href={{{ [<userId>addprefix[/admin/users/]] }}}>
<button class="mws-profile-btn">Profile</button>
</a>
</$set>
<% endif %>
<form action="/logout" method="post" class="mws-logout-form">
<input type="submit" value="Logout" class="mws-logout-button"/>
Expand All @@ -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;
Expand Down Expand Up @@ -126,4 +145,8 @@ title: $:/plugins/tiddlywiki/multiwikiserver/templates/mws-header
.mws-admin-form-button:hover {
background-color: #ddd;
}
</style>

.mws-logo {
font-size: 24px;
}
</style>

0 comments on commit 18a33b2

Please sign in to comment.