feat: Add user edit feature
This commit is contained in:
parent
e9a986058d
commit
53e99bd291
@ -32,4 +32,6 @@ public partial class UserModel : ReactiveModel
|
||||
[Reactive] private DateTime _joinDate;
|
||||
|
||||
[Reactive] private bool _isAdmin;
|
||||
|
||||
[Reactive] private bool _isActive;
|
||||
}
|
||||
@ -856,6 +856,12 @@ namespace Flawless.Client.Remote
|
||||
[JsonPropertyName("publicEmail")]
|
||||
public bool? PublicEmail { get; set; }
|
||||
|
||||
[JsonPropertyName("isActive")]
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
[JsonPropertyName("isAdmin")]
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
[JsonPropertyName("createdAt")]
|
||||
public System.DateTimeOffset? CreatedAt { get; set; }
|
||||
|
||||
|
||||
@ -45,6 +45,9 @@ public partial class UserService : BaseService<UserService>
|
||||
user.CanEdit = info.Authorized;
|
||||
user.PhoneNumber = info.Phone;
|
||||
user.Email = info.Email;
|
||||
user.IsAdmin = info.IsAdmin;
|
||||
user.IsActive = info.IsActive;
|
||||
user.JoinDate = info.CreatedAt!.Value.LocalDateTime;
|
||||
|
||||
_cachedUsers.Add(username, user);
|
||||
}
|
||||
@ -78,6 +81,9 @@ public partial class UserService : BaseService<UserService>
|
||||
user.CanEdit = info.Authorized;
|
||||
user.PhoneNumber = info.Phone;
|
||||
user.Email = info.Email;
|
||||
user.IsAdmin = info.IsAdmin;
|
||||
user.IsActive = info.IsActive;
|
||||
user.JoinDate = info.CreatedAt!.Value.LocalDateTime;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@ -306,13 +306,13 @@ public partial class SettingViewModel : RoutableViewModelBase
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
private async Task ToSuperUserAsync(string username)
|
||||
private async Task PromoteUserAsync(string username)
|
||||
{
|
||||
await UpdateUserSuperAsync(username, true);
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
private async Task ToNormalUserAsync(string username)
|
||||
private async Task DemoteUserAsync(string username)
|
||||
{
|
||||
await UpdateUserSuperAsync(username, false);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:vm="using:Flawless.Client.ViewModels"
|
||||
xmlns:views="clr-namespace:Flawless.Client.Views"
|
||||
x:DataType="vm:SettingViewModel"
|
||||
mc:Ignorable="d" d:DesignWidth="1280" d:DesignHeight="768"
|
||||
x:Class="Flawless.Client.Views.SettingView">
|
||||
@ -80,6 +81,64 @@
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Users">
|
||||
<Grid Margin="10">
|
||||
<DataGrid ItemsSource="{Binding Users}" AutoGenerateColumns="False">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Username" Binding="{Binding Username}" Width="*"/>
|
||||
|
||||
<DataGridTextColumn Header="CreateAt" Binding="{Binding JoinDate}" Width="*"/>
|
||||
|
||||
<DataGridCheckBoxColumn Header="Active" Binding="{Binding IsActive}" Width="Auto"/>
|
||||
|
||||
<DataGridCheckBoxColumn Header="Admin" Binding="{Binding IsAdmin}" Width="Auto"/>
|
||||
|
||||
<DataGridTemplateColumn Header="Operations" Width="2*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal" Spacing="4">
|
||||
<Button Content="Enable"
|
||||
Command="{Binding $parent[views:SettingView].((vm:SettingViewModel)DataContext).InactivateUserCommand}"
|
||||
CommandParameter="{Binding Username}"
|
||||
IsEnabled="{Binding !CanEdit}"
|
||||
IsVisible="{Binding IsActive}"/>
|
||||
|
||||
<Button Content="Disable"
|
||||
Command="{Binding $parent[views:SettingView].((vm:SettingViewModel)DataContext).ActivateUserCommand}"
|
||||
CommandParameter="{Binding Username}"
|
||||
IsEnabled="{Binding !CanEdit}"
|
||||
IsVisible="{Binding !IsActive}"/>
|
||||
|
||||
<Button Content="Promote"
|
||||
Command="{Binding $parent[views:SettingView].((vm:SettingViewModel)DataContext).PromoteUserCommand}"
|
||||
CommandParameter="{Binding Username}"
|
||||
IsEnabled="{Binding !CanEdit}"
|
||||
IsVisible="{Binding !IsAdmin}"/>
|
||||
|
||||
<Button Content="Demote"
|
||||
Command="{Binding $parent[views:SettingView].((vm:SettingViewModel)DataContext).DemoteUserCommand}"
|
||||
CommandParameter="{Binding Username}"
|
||||
IsVisible="{Binding IsAdmin}"
|
||||
IsEnabled="{Binding !CanEdit}"
|
||||
Classes="Danger"/>
|
||||
|
||||
<Button Content="Delete"
|
||||
Command="{Binding $parent[views:SettingView].((vm:SettingViewModel)DataContext).DeleteUserCommand}"
|
||||
CommandParameter="{Binding Username}"
|
||||
IsEnabled="{Binding !CanEdit}"
|
||||
Classes="Danger"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<!-- 添加用户按钮 -->
|
||||
<Button Content="添加用户"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{Binding CreateUserCommand}"/>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Logfile">
|
||||
<StackPanel Spacing="8" Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
|
||||
@ -23,4 +23,6 @@ public record UserInfoResponse
|
||||
public DateTime? CreatedAt { get; set; }
|
||||
|
||||
public bool? IsAdmin { get; set; }
|
||||
|
||||
public bool IsActive { get; set; }
|
||||
}
|
||||
@ -128,7 +128,8 @@ public class UserController(
|
||||
PublicEmail = authorized ? queryUser.PublicEmail : null,
|
||||
Email = queryUser.PublicEmail || authorized ? queryUser.Email : null,
|
||||
Phone = authorized ? queryUser.PhoneNumber : null,
|
||||
IsAdmin = queryUser.Admin
|
||||
IsAdmin = queryUser.Admin,
|
||||
IsActive = queryUser.LockoutEnabled
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user