diff --git a/src/Infrastructure/PermissionSet/Permissions.cs b/src/Infrastructure/PermissionSet/Permissions.cs index bfe390c34..4b6d09010 100644 --- a/src/Infrastructure/PermissionSet/Permissions.cs +++ b/src/Infrastructure/PermissionSet/Permissions.cs @@ -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")] diff --git a/src/Server.UI/Components/Identity/UserLoginState.razor b/src/Server.UI/Components/Identity/UserLoginState.razor index bf3cc00bc..382848487 100644 --- a/src/Server.UI/Components/Identity/UserLoginState.razor +++ b/src/Server.UI/Components/Identity/UserLoginState.razor @@ -17,9 +17,16 @@ [Inject] private HubClient Client { get; set; } = default!; + [CascadingParameter] + private Task 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(); @@ -27,6 +34,8 @@ } 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); @@ -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)); diff --git a/src/Server.UI/Pages/Identity/Users/Components/UserCard.razor b/src/Server.UI/Pages/Identity/Users/Components/UserCard.razor index 1c789aaec..adcd90308 100644 --- a/src/Server.UI/Pages/Identity/Users/Components/UserCard.razor +++ b/src/Server.UI/Pages/Identity/Users/Components/UserCard.razor @@ -5,7 +5,7 @@ @if (Item is not null) { - + @if (string.IsNullOrEmpty(Item.ProfilePictureDataUrl)) { @@ -51,6 +51,8 @@ else public ApplicationUserDto? Item { get; set; } [Parameter] public Func? OnSendVerify { get; set; } + [Parameter] + public bool DisplayOnlineStatus { get; set; } private bool IsOnline() { diff --git a/src/Server.UI/Pages/Identity/Users/Users.razor b/src/Server.UI/Pages/Identity/Users/Users.razor index 796efa15a..42a02576f 100644 --- a/src/Server.UI/Pages/Identity/Users/Users.razor +++ b/src/Server.UI/Pages/Identity/Users/Users.razor @@ -182,7 +182,7 @@ - + @@ -279,6 +279,7 @@ private bool _loading; private bool _exporting; private bool _uploading; + private bool _canViewOnlineStatus; private List _roles = new(); private string? _searchRole; @@ -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();