Skip to content

Commit

Permalink
Merge pull request #802 from RoLYroLLs/main
Browse files Browse the repository at this point in the history
Add permission to view online status
  • Loading branch information
neozhu authored Dec 6, 2024
2 parents 58f9662 + bf13c16 commit f1ed953
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Infrastructure/PermissionSet/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static class Users
public const string SendRestPasswordMail = "Permissions.Users.SendRestPasswordMail";
public const string ManagePermissions = "Permissions.Users.Permissions";
public const string Deactivation = "Permissions.Users.Activation/Deactivation";
public const string ViewOnlineStatus = "Permissions.Users.ViewOnlineStatus";
}

[DisplayName("Role Permissions")]
Expand Down
11 changes: 11 additions & 0 deletions src/Server.UI/Components/Identity/UserLoginState.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@

[Inject] private HubClient Client { get; set; } = default!;

[CascadingParameter]
private Task<AuthenticationState> AuthState { get; set; } = default!;

private bool _canViewOnlineStatus;

protected override async Task OnInitializedAsync()
{

AuthenticationState state = await AuthState;
_canViewOnlineStatus = (await AuthService.AuthorizeAsync(state.User, Permissions.Users.ViewOnlineStatus)).Succeeded;
Client.LoginEvent += _client_Login;
Client.LogoutEvent += _client_Logout;
await Client.StartAsync();

}
private void _client_Login(object? sender, UserStateChangeEventArgs args)
{
if (!_canViewOnlineStatus) return;

InvokeAsync(() =>
{
Snackbar.Add(string.Format(L["{0} has logged in."], args.UserName), Severity.Info);
Expand All @@ -35,6 +44,8 @@

private void _client_Logout(object? sender, UserStateChangeEventArgs args)
{
if (!_canViewOnlineStatus) return;

InvokeAsync(() =>
{
Snackbar.Add(string.Format(L["{0} has logged out."], args.UserName));
Expand Down
4 changes: 3 additions & 1 deletion src/Server.UI/Pages/Identity/Users/Components/UserCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@if (Item is not null)
{
<MudStack Row Spacing="2" AlignItems="AlignItems.Center">
<MudBadge Color="@(IsOnline() ? Color.Success : Color.Error)" Overlap="false" Dot="true" Bordered="true">
<MudBadge Color="@(IsOnline() ? Color.Success : Color.Error)" Overlap="false" Dot="true" Bordered="true" Visible="@DisplayOnlineStatus">
<MudAvatar>
@if (string.IsNullOrEmpty(Item.ProfilePictureDataUrl))
{
Expand Down Expand Up @@ -51,6 +51,8 @@ else
public ApplicationUserDto? Item { get; set; }
[Parameter]
public Func<ApplicationUserDto, Task>? OnSendVerify { get; set; }
[Parameter]
public bool DisplayOnlineStatus { get; set; }

private bool IsOnline()
{
Expand Down
4 changes: 3 additions & 1 deletion src/Server.UI/Pages/Identity/Users/Users.razor
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
</PropertyColumn>
<PropertyColumn Property="x => x.UserName" Title="@L[_currentDto.GetMemberDescription(x => x.UserName)]">
<CellTemplate>
<UserCard Item="@context.Item" OnSendVerify="@(x=> SendVerify(x))"></UserCard>
<UserCard Item="@context.Item" OnSendVerify="@(x=> SendVerify(x))" DisplayOnlineStatus="@_canViewOnlineStatus"></UserCard>
</CellTemplate>
</PropertyColumn>
<PropertyColumn Property="x => x.Email" Title="@L["Full Name"]">
Expand Down Expand Up @@ -279,6 +279,7 @@
private bool _loading;
private bool _exporting;
private bool _uploading;
private bool _canViewOnlineStatus;
private List<string?> _roles = new();
private string? _searchRole;

Expand All @@ -297,6 +298,7 @@
_canManagePermissions = (await AuthService.AuthorizeAsync(state.User, Permissions.Users.ManagePermissions)).Succeeded;
_canImport = (await AuthService.AuthorizeAsync(state.User, Permissions.Users.Import)).Succeeded;
_canExport = (await AuthService.AuthorizeAsync(state.User, Permissions.Users.Export)).Succeeded;
_canViewOnlineStatus = (await AuthService.AuthorizeAsync(state.User, Permissions.Users.ViewOnlineStatus)).Succeeded;
_roles = await RoleManager.Roles.Select(x => x.Name).ToListAsync();

//var list= await UserManager.Users.Include(x=>x.LastModifiedByUser).Include(x=>x.CreatedByUser).ToListAsync();
Expand Down

0 comments on commit f1ed953

Please sign in to comment.