Initial commit - Auth.RCL
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<div class="modal-box">
|
||||
<h3 class="font-bold text-lg flex items-center gap-2">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-warning" fill="none" viewBox="0 0 24 24"
|
||||
stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||
</svg>
|
||||
Add Role
|
||||
</h3>
|
||||
|
||||
<div class="py-4">
|
||||
<select @bind="SelectedValue" class="select select-bordered w-full">
|
||||
<option value="" disabled selected>Select a role</option>
|
||||
@foreach (var role in Roles)
|
||||
{
|
||||
<option value="@role">@role</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="modal-action">
|
||||
<button class="btn" @onclick="OnCancel">Cancel</button>
|
||||
<button class="btn btn-primary" @onclick="OnAddRole">Add Role</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public List<string> Roles { get; set; } = new();
|
||||
|
||||
public string SelectedValue { get; set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnClose { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> OnConfirm { get; set; }
|
||||
|
||||
private async Task OnCancel() => await OnClose.InvokeAsync();
|
||||
|
||||
private async Task OnAddRole()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(SelectedValue))
|
||||
{
|
||||
await OnConfirm.InvokeAsync(SelectedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
@inject RoleAPIConsumer roleAPIConsumer
|
||||
|
||||
<div class="flex flex-col w-full h-full gap-5">
|
||||
<select @bind="selectedRole" class="select select-bordered w-full">
|
||||
<option value="" disabled selected>Select Role</option>
|
||||
@foreach (var role in roles)
|
||||
{
|
||||
<option value="@role">@role</option>
|
||||
}
|
||||
</select>
|
||||
<button class="w-full btn btn-primary h-full" @onclick="() => AddRole()">أضف صلاحية</button>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
string selectedRole = "";
|
||||
|
||||
[Parameter] public UserVM UserVM { get; set; }
|
||||
[Parameter] public EventCallback AddMethod { get; set; }
|
||||
|
||||
List<string> roles = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
roles = Enum.GetNames<AppEnum.Roles>().Except(UserVM.Roles).ToList();
|
||||
}
|
||||
|
||||
async Task AddRole()
|
||||
{
|
||||
if (string.IsNullOrEmpty(selectedRole)) return;
|
||||
|
||||
var result = await roleAPIConsumer.AddUserToRole(UserVM.Id, selectedRole);
|
||||
if (result)
|
||||
{
|
||||
UserVM.Roles.Add(selectedRole);
|
||||
// Snackbar removed, rely on UI update
|
||||
await AddMethod.InvokeAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Snackbar removed
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
@page "/manage-UserRole"
|
||||
@layout AdminLayout
|
||||
@inject UserAPIConsumer userAPIConsumer
|
||||
@inject RoleAPIConsumer roleAPIConsumer
|
||||
@using Auth.Contracts
|
||||
|
||||
<div class="overflow-x-auto p-4">
|
||||
<table class="table table-zebra table-bordered w-full">
|
||||
<thead>
|
||||
<tr class="text-center bg-base-200">
|
||||
<th colspan="3" class="text-xl p-4">صلاحيات الوصول للتطبيق</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>الأسم</th>
|
||||
@* <th>الوظيفة</th> *@
|
||||
<th>الصلحيات</th>
|
||||
<th>أضف صلاحية</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if (users != null)
|
||||
{
|
||||
@foreach (var user in users)
|
||||
{
|
||||
<tr>
|
||||
<td>@user.Name</td>
|
||||
@* <td>@user.JobTitle</td> *@
|
||||
<td>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
@foreach (var role in user.Roles)
|
||||
{
|
||||
<div class="badge badge-success gap-2">
|
||||
<span>@role</span>
|
||||
<button class="btn btn-xs btn-circle btn-ghost" @onclick="() => RemoveRole(user, role)"
|
||||
type="button">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24"
|
||||
stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<AddRolePopUp UserVM="user" AddMethod="AddRole"></AddRolePopUp>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
List<UserVM> users = new List<UserVM>();
|
||||
List<string> roles = new List<string>();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
users = await userAPIConsumer.GetUsers();
|
||||
users ??= new List<UserVM>();
|
||||
roles = Enum.GetNames<AppEnum.Roles>().ToList();
|
||||
}
|
||||
|
||||
async Task AddRole()
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
async Task RemoveRole(UserVM user, string role)
|
||||
{
|
||||
var result = await roleAPIConsumer.RemoveUserFromRole(user.Id, role);
|
||||
if (result)
|
||||
{
|
||||
user.Roles.Remove(role);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Error handling logic if needed
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user