mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-10 01:10:28 +00:00
c7531e53ab
* mws authentication * add more tests and permission checkers * add logic to ensure that only authenticated users' requests are handled * add custom login page * Implement user authentication as well as session handling * work on user operations authorization * add middleware to route handlers for bags & tiddlers routes * add feature that only returns the tiddlers and bags which the user has permission to access on index page * refactor auth routes & added user management page * fix Ci Test failure issue * fix users list page, add manage roles page * add commands and scripts to create new user & assign roles and permissions * resolved ci-test failure * add ACL permissions to bags & tiddlers on creation * fix comments and access control list bug * fix indentation issues * working on user profile edit * remove list users command & added support for database in server options * implement user profile update and password change feature * update plugin readme * implement command which triggers protected mode on the server * revert server-wide auth flag. Implement selective authorization * ACL management feature * Complete Access control list implementation * Added support to manage users' assigned role by admin * fix comments * fix comment * Add user profile management and account deletion functionality
191 lines
5.1 KiB
Plaintext
191 lines
5.1 KiB
Plaintext
title: $:/plugins/tiddlywiki/multiwikiserver/templates/manage-roles
|
|
|
|
\define add-role-actions()
|
|
<$action-sendmessage $message="tm-server-request"
|
|
method="POST"
|
|
url="/admin/roles"
|
|
headers="Content-Type: application/json"
|
|
body={{{ [{"name": "$(newRoleName)$", "description": "$(newRoleDescription)$"}jsonify[]] }}}
|
|
redirectAfterSuccess="/admin/roles"/>
|
|
<$action-setfield $tiddler="$:/temp/newRoleName" text=""/>
|
|
<$action-setfield $tiddler="$:/temp/newRoleDescription" text=""/>
|
|
\end
|
|
|
|
\define edit-role-actions(role-id)
|
|
<$action-sendmessage $message="tm-server-request"
|
|
method="PUT"
|
|
url={{{ [[$:/admin/roles/]addsuffix<role-id>] }}}
|
|
headers="Content-Type: application/json"
|
|
body={{{ [{"name": "$(newRoleName)$", "description": "$(newRoleDescription)$"}jsonify[]] }}}
|
|
redirectAfterSuccess="/admin/roles"/>
|
|
\end
|
|
|
|
\define delete-role-actions(role-id)
|
|
<$action-sendmessage $message="tm-server-request"
|
|
method="DELETE"
|
|
url={{{ [[$:/admin/roles/]addsuffix<role-id>] }}}
|
|
redirectAfterSuccess="/admin/roles"/>
|
|
\end
|
|
|
|
<$tiddler tiddler="$:/plugins/tiddlywiki/multiwikiserver/templates/mws-header">
|
|
<$set name="page-title" value="Manage Roles">
|
|
<$transclude/>
|
|
</$set>
|
|
</$tiddler>
|
|
|
|
<div class="roles-container">
|
|
<div class="roles-list">
|
|
<h2>Existing Roles</h2>
|
|
<$list filter="[<roles-list>jsonindexes[]]" variable="role-index">
|
|
<$let role={{{ [<roles-list>jsonextract<role-index>] }}}>
|
|
<div class="role-item">
|
|
<div class="role-info">
|
|
<span class="role-name">
|
|
<$text text={{{ [<role>jsonget[role_name]] }}}/>
|
|
</span>
|
|
<span class="role-description">
|
|
<$text text={{{ [<role>jsonget[description]] }}}/>
|
|
</span>
|
|
</div>
|
|
<$list filter="[<role>jsonget[role_name]lowercase[]!match[admin]]" variable="ignore">
|
|
<div class="role-actions">
|
|
<a href={{{ [<role>jsonget[role_id]addprefix[/admin/roles/?edit=]] }}}>
|
|
<$button class="tc-btn-invisible btn-edit">
|
|
Edit
|
|
</$button>
|
|
</a>
|
|
<form method="POST" action="/admin/delete-role">
|
|
<input type="hidden" name="role_id" value={{{ [<role>jsonget[role_id]] }}}/>
|
|
<button type="submit" class="tc-btn-invisible btn-delete">Delete</button>
|
|
</form>
|
|
</div>
|
|
</$list>
|
|
</div>
|
|
</$let>
|
|
</$list>
|
|
</div>
|
|
|
|
<$let edit-role-id={{{ [<edit-role>jsonget[role_id]] }}}>
|
|
<div class="add-role-card">
|
|
<$list filter="[<edit-role-id>!is[blank]]" variable="ignore">
|
|
<h2>Edit Role</h2>
|
|
<form method="POST" action={{{ [<edit-role-id>addprefix[/admin/roles/]] }}} class="add-role-form">
|
|
<input name="role_name" type="text" placeholder="Role Name" required value={{{ [<edit-role>jsonget[role_name]] }}}/>
|
|
<input name="role_description" type="text" placeholder="Role Description" required value={{{ [<edit-role>jsonget[description]] }}}/>
|
|
<button type="submit" class="tc-btn-invisible btn-add">Update Role</button>
|
|
</form>
|
|
</$list>
|
|
<$list filter="[<edit-role-id>is[blank]]" variable="ignore">
|
|
<h2>Add New Role</h2>
|
|
<form method="POST" action="/admin/post-role" class="add-role-form">
|
|
<input name="role_name" type="text" placeholder="Role Name" required/>
|
|
<input name="role_description" type="text" placeholder="Role Description" required/>
|
|
<button type="submit" class="tc-btn-invisible btn-add">Add Role</button>
|
|
</form>
|
|
</$list>
|
|
</div>
|
|
</$let>
|
|
</div>
|
|
|
|
<style>
|
|
.roles-container {
|
|
max-width: 1200px;
|
|
margin: 2rem auto;
|
|
display: flex;
|
|
gap: 2rem;
|
|
flex-wrap: wrap;
|
|
}
|
|
.roles-list {
|
|
flex: 1 1 60%;
|
|
min-width: 300px;
|
|
background: #fff;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
padding: 2rem;
|
|
}
|
|
.add-role-card {
|
|
flex: 1 1 30%;
|
|
min-width: 250px;
|
|
background: #fff;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
padding: 2rem;
|
|
align-self: flex-start;
|
|
}
|
|
.role-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 1rem 0;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
.role-info {
|
|
flex-grow: 1;
|
|
}
|
|
.role-name {
|
|
font-weight: bold;
|
|
display: block;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
.role-description {
|
|
color: #666;
|
|
font-size: 0.9em;
|
|
}
|
|
.role-actions {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
}
|
|
.role-actions button {
|
|
padding: 0.5rem 1rem;
|
|
background: none;
|
|
border: none;
|
|
cursor: pointer;
|
|
border-radius: 4px;
|
|
transition: background-color 0.3s;
|
|
}
|
|
.btn-edit {
|
|
color: #007bff;
|
|
}
|
|
.btn-delete {
|
|
color: #dc3545;
|
|
}
|
|
.btn-edit:hover, .btn-delete:hover {
|
|
background-color: #f8f9fa;
|
|
}
|
|
.add-role-form {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 1rem;
|
|
}
|
|
.add-role-form input {
|
|
padding: 0.5rem;
|
|
border: 1px solid #ccc;
|
|
border-radius: 4px;
|
|
}
|
|
.btn-add {
|
|
padding: 0.5rem 1rem;
|
|
background-color: #28a745;
|
|
color: white;
|
|
border: none;
|
|
cursor: pointer;
|
|
border-radius: 4px;
|
|
transition: background-color 0.3s;
|
|
}
|
|
.btn-add:hover {
|
|
background-color: #218838;
|
|
}
|
|
h2 {
|
|
margin-top: 0;
|
|
margin-bottom: 1rem;
|
|
color: #333;
|
|
}
|
|
@media (max-width: 768px) {
|
|
.roles-container {
|
|
flex-direction: column;
|
|
}
|
|
.roles-list, .add-role-card {
|
|
width: 100%;
|
|
}
|
|
}
|
|
</style>
|