Skip to content

Commit

Permalink
+user management and group management ui layout fixed (#715)
Browse files Browse the repository at this point in the history
*fixed level in UserInfoView
+example in sandbox
  • Loading branch information
peterbarancek authored May 29, 2024
1 parent feacf37 commit c7ef91f
Show file tree
Hide file tree
Showing 15 changed files with 420 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition MaxWidth="250"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="FirstColumn" />
<ColumnDefinition Width="24" />
<ColumnDefinition Width="50" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
Content="{x:Static p:strings.Username}" />
<TextBox
MinWidth="200"
Grid.Row="0"
Grid.Column="2"
VerticalContentAlignment="Center"
Expand Down Expand Up @@ -128,10 +129,7 @@
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition
x:Name="RolesRow"
Height="*"
MaxHeight="250" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
Expand Down Expand Up @@ -240,6 +238,7 @@
</Border>
</Grid>
<Button
Grid.Row="2"
Margin="10"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ private void CreateNew(Pwds pwds)

NewUser.SetPlainTextPassword(pwds.Pb1.Password);
UserRepository.Create(NewUser.Username, NewUser);
NewUser._Created = DateTime.Now;
NewUser._Modified = DateTime.Now;

TcoAppDomain.Current.Logger.Information($"New user '{NewUser.Username}' created. {{@sender}}", new { UserName = NewUser.Username, Roles = NewUser.Roles });

Expand Down
61 changes: 35 additions & 26 deletions src/TcOpen.Inxton/src/Security.Wpf/UserManagement/AllUsersView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.RowSpan="2">
<DataGrid
x:Name="UsersList"
HorizontalAlignment="Stretch"
Expand All @@ -82,6 +86,11 @@
Width="Auto"
Binding="{Binding CanUserChangePassword}"
Header="{x:Static p:strings.CanChangePassword}" />
<DataGridTextColumn
Width="Auto"
Binding="{Binding Level}"
Foreground="{DynamicResource OnBackground}"
Header="{x:Static p:strings.Level}" />
<DataGridTextColumn
Width="Auto"
Binding="{Binding _Created}"
Expand All @@ -96,7 +105,7 @@
</DataGrid>
</Grid>
<ScrollViewer Grid.Column="1" VerticalScrollBarVisibility="Auto">
<Grid Grid.Column="1" Margin="15,15,15,15">
<Grid Grid.Column="1" Margin="15">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
Expand Down Expand Up @@ -205,14 +214,15 @@
Grid.Row="6"
Grid.Column="2"
ItemsSource="{Binding AllGroups}" />

<!--<Label
Grid.Row="7"
Grid.Column="0"
Content="{x:Static p:strings.Level}" />
<TextBox
x:Name="Level"
Grid.Row="7"
Grid.Column="1"
Grid.Column="2"
VerticalContentAlignment="Center"
Text="{Binding ElementName=UsersList, Path=SelectedItem.Level}" />-->
<Button
Grid.Row="8"
Expand All @@ -225,11 +235,8 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition
x:Name="RolesRow"
Height=".5*"
MaxHeight="250" />
<RowDefinition Height="Auto" />
<RowDefinition />

</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
Expand Down Expand Up @@ -286,7 +293,7 @@
Grid.Row="2"
Grid.Column="2"
Padding="0"
BorderBrush="{DynamicResource MaterialDesignTextAreaBorder}"

BorderThickness=".5">
<ListView
x:Name="CurrentRoles"
Expand All @@ -308,8 +315,9 @@
Grid.Row="2"
Grid.Column="0"
Padding="0"
BorderBrush="{DynamicResource MaterialDesignTextAreaBorder}"

BorderThickness=".5">

<ListView
x:Name="AvailibleRoles"
Grid.Row="2"
Expand Down Expand Up @@ -340,30 +348,31 @@
CommandParameter="{Binding ElementName=CurrentRoles, Path=SelectedItems}"
Content="" />
</StackPanel>
<Grid
Grid.Row="3"
Grid.ColumnSpan="3"

</Grid>


</Grid>
</ScrollViewer>
<Grid
Grid.Row="2"
Grid.Column="2"
Margin="15,25,15,15">
<Button
<Button
HorizontalAlignment="Left"
Command="{Binding DeleteUserCommand}"
Content="{x:Static p:strings.Delete}" />

<Button
<Button
Margin="0,0,10,0"
HorizontalAlignment="Right"
Command="{Binding StarEditUserCommand}"
Content="{x:Static p:strings.Update}">
<Button.CommandParameter>
<local:Pwds Pb1="{Binding ElementName=pb1}" Pb2="{Binding ElementName=pb2}" />
</Button.CommandParameter>
</Button>
</Grid>
</Grid>


</Grid>
</ScrollViewer>
<Button.CommandParameter>
<local:Pwds Pb1="{Binding ElementName=pb1}" Pb2="{Binding ElementName=pb2}" />
</Button.CommandParameter>
</Button>
</Grid>
</Grid>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ private void UpdateUser(Pwds pwds)

if (pwds.Pb1.Password != pwds.Pb2.Password)
throw new Exception("Passwords do not match");


SelectedUser._Modified = DateTime.Now;
UserRepository.Update(this.SelectedUser.Username, SelectedUser);
TcoAppDomain.Current.Logger.Information($"User '{this.SelectedUser.Username}' updated. {{@sender}}", new { UserName = this.SelectedUser.Username, Roles = this.SelectedUser.Roles });
pwds.Pb1.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
</UserControl.Resources>
<Grid Margin="12" Grid.IsSharedSizeScope="True">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />

</Grid.RowDefinitions>

<StackPanel
Expand All @@ -50,7 +52,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="FirstColumn" />
<ColumnDefinition Width="50" />
<ColumnDefinition MinWidth="100" />
<ColumnDefinition MinWidth="200" />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Expand Down Expand Up @@ -119,6 +121,7 @@

</StackPanel>
<Button
Grid.Row="2"
Margin="10"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ private void CreateNew(Pwds pwds)
throw new Exception("Email does not have required format");

NewUser.SetPlainTextPassword(pwds.Pb1.Password);
NewUser._Created = DateTime.Now;
NewUser._Modified = DateTime.Now;
if (string.IsNullOrEmpty(SelectedGroup))
throw new Exception("Assign group first");
NewUser.Roles = new ObservableCollection<string>(new string[] { SelectedGroup });
NewUser.Level = SelectedGroup;
UserRepository.Create(NewUser.Username, NewUser);

TcoAppDomain.Current.Logger.Information($"New user '{NewUser.Username}' created. {{@sender}}", new { UserName = NewUser.Username, Roles = NewUser.Roles });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition />
<RowDefinition Height="Auto" />

</Grid.RowDefinitions>

<StackPanel
Expand All @@ -53,8 +55,13 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />

</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Column="0" Grid.RowSpan="2">
<DataGrid
x:Name="GroupsList"
HorizontalAlignment="Stretch"
Expand Down Expand Up @@ -136,10 +143,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition
x:Name="RolesRow"
Height=".5*"
MaxHeight="250" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -251,37 +255,39 @@
CommandParameter="{Binding ElementName=CurrentRoles, Path=SelectedItems}"
Content="" />
</StackPanel>
<Grid
Grid.Row="3"
Grid.ColumnSpan="3"
Margin="15,25,15,15">
<Button
HorizontalAlignment="Left"
Command="{Binding DeleteGroupCommand}"
Content="{x:Static p:strings.Delete}" />
</Grid>
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="24" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="24" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="Name" />
<TextBox
Grid.Column="2"
VerticalContentAlignment="Center"
Text="{Binding NewGroupName}" />
<Button
Grid.Column="5"
HorizontalAlignment="Left"
Command="{Binding CreateNewGroupCommand}"
Content="Create" />

</Grid>

</Grid>
</ScrollViewer>


<Grid Grid.Row="2" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />

<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Margin="10,0"
HorizontalAlignment="Left"
Command="{Binding DeleteGroupCommand}"
Content="{x:Static p:strings.Delete}" />

<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Label Margin="10,0" Content="Name" />
<TextBox MinWidth="200"
Grid.Column="2"
VerticalContentAlignment="Center"
Text="{Binding NewGroupName}" />
<Button
Margin="10,0"
HorizontalAlignment="Left"
Command="{Binding CreateNewGroupCommand}"
Content="Create" />
</StackPanel>
</Grid>
</Grid>


</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
Width="Auto"
Binding="{Binding CanUserChangePassword}"
Header="{x:Static p:strings.CanChangePassword}" />
<DataGridTextColumn
Width="Auto"
Binding="{Binding Level}"
Foreground="{DynamicResource OnBackground}"
Header="{x:Static p:strings.Level}" />
<DataGridTextColumn
Width="Auto"
Binding="{Binding _Created}"
Expand Down Expand Up @@ -126,7 +131,7 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="FirstColumn" />
<ColumnDefinition Width="24" />
<ColumnDefinition Width="50" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

Expand Down Expand Up @@ -207,6 +212,15 @@
DropDownOpened="Groups_DropDownOpened"
ItemsSource="{Binding Groups}"
SelectedItem="{Binding ElementName=UsersList, Path=SelectedItem.Roles[0]}"/>
<!--<Label
Grid.Row="7"
Grid.Column="0"
Content="{x:Static p:strings.Level}" />
<TextBox
Grid.Row="7"
Grid.Column="2"
VerticalContentAlignment="Center"
Text="{Binding ElementName=UsersList, Path=SelectedItem.Level}" />-->

</Grid>
<Grid Grid.Row="1" Margin="0,24,0,0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ private void UpdateUser(Pwds pwds)

if (pwds.Pb1.Password != pwds.Pb2.Password)
throw new Exception("Passwords do not match");


SelectedUser._Modified = DateTime.Now;
SelectedUser.Level = SelectedUser.Roles[0];
UserRepository.Update(this.SelectedUser.Username, SelectedUser);
TcoAppDomain.Current.Logger.Information($"User '{this.SelectedUser.Username}' updated. {{@sender}}", new { UserName = this.SelectedUser.Username, Roles = this.SelectedUser.Roles });
pwds.Pb1.Clear();
Expand Down
Loading

0 comments on commit c7ef91f

Please sign in to comment.