mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 23:01:52 +01:00
Fixed: Remove User
This commit is contained in:
parent
3020024270
commit
3158295d6b
@ -56,6 +56,9 @@
|
||||
<Compile Update="Page\ScanURNPage.xaml.cs">
|
||||
<DependentUpon>ScanURNPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Page\ProfilePage.xaml.cs">
|
||||
<DependentUpon>ProfilePage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Page\UserPage.xaml.cs">
|
||||
<DependentUpon>UserPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
@ -2,8 +2,14 @@
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Borepin.Page.AddUserPage"
|
||||
xmlns:converters="clr-namespace:Borepin.Converter"
|
||||
xmlns:resource_text="clr-namespace:Borepin.Resources.Text"
|
||||
Title="{x:Static resource_text:TextResource.TITLE_AddUser}">
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
<converters:InvertBoolConverter x:Key="InvertBoolConverter"/>
|
||||
</ResourceDictionary>
|
||||
</ContentPage.Resources>
|
||||
<ContentPage.Content>
|
||||
<StackLayout Padding="20">
|
||||
<StackLayout IsVisible="{Binding IsBusy}">
|
||||
|
@ -21,7 +21,7 @@
|
||||
</StackLayout>
|
||||
<StackLayout IsVisible="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}">
|
||||
<StackLayout IsVisible="{Binding IsConnected}">
|
||||
<Label Text="{Binding UserItem.Name}" Style="{StaticResource LabelStyle_Title}"/>
|
||||
<Label Text="{Binding UserItem.Username}" Style="{StaticResource LabelStyle_Title}"/>
|
||||
<ListView ItemsSource="{Binding PermissionSelectViewModel_List}" SelectionMode="None" SeparatorColor="Transparent">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
|
@ -1,13 +1,10 @@
|
||||
using Borepin.Base;
|
||||
using Prism.Commands;
|
||||
using Prism.Navigation;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using FabAccessAPI.Schema;
|
||||
using Borepin.Model;
|
||||
using Prism.Services;
|
||||
using Borepin.Service;
|
||||
using Borepin.Base.Exceptions;
|
||||
using Capnp.Rpc;
|
||||
using System;
|
||||
using static FabAccessAPI.Schema.UserSystem.ManageInterface;
|
||||
@ -66,7 +63,7 @@ namespace Borepin.PageModel
|
||||
case AddUserErrorEnum.alreadyExists:
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, Resources.Text.TextResource.ALERT_UnableServer, Resources.Text.TextResource.OK).ConfigureAwait(false);
|
||||
await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_AddUserFailed, Resources.Text.TextResource.ALERT_UserExist, Resources.Text.TextResource.OK).ConfigureAwait(false);
|
||||
|
||||
IsBusy = false;
|
||||
});
|
||||
@ -74,7 +71,7 @@ namespace Borepin.PageModel
|
||||
case AddUserErrorEnum.usernameInvalid:
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_ConnectionFailed, "Unable to connect to server.", Resources.Text.TextResource.OK).ConfigureAwait(false);
|
||||
await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_AddUserFailed, Resources.Text.TextResource.ALERT_UsernameInvalid, Resources.Text.TextResource.OK).ConfigureAwait(false);
|
||||
|
||||
IsBusy = false;
|
||||
});
|
||||
@ -82,7 +79,7 @@ namespace Borepin.PageModel
|
||||
case AddUserErrorEnum.passwordInvalid:
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to connect to server.", "Ok").ConfigureAwait(false);
|
||||
await _PageDialogService.DisplayAlertAsync(Resources.Text.TextResource.ALERT_AddUserFailed, Resources.Text.TextResource.ALERT_PasswordInvalid, Resources.Text.TextResource.OK).ConfigureAwait(false);
|
||||
|
||||
IsBusy = false;
|
||||
});
|
||||
|
@ -30,8 +30,8 @@ namespace Borepin.PageModel
|
||||
#region LoadData
|
||||
public override Task LoadAPIData()
|
||||
{
|
||||
//UserSystem.ManageInterface_Proxy manageInterface = (UserSystem.ManageInterface_Proxy)_API.Session.UserSystem.Manage;
|
||||
//CanManageUsers = !manageInterface.IsNull;
|
||||
UserSystem.ManageInterface_Proxy manageInterface = (UserSystem.ManageInterface_Proxy)_API.Session.UserSystem.Manage;
|
||||
CanManageUsers = !manageInterface.IsNull;
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
@ -24,14 +24,15 @@ namespace Borepin.PageModel
|
||||
#region Private Fields
|
||||
private string _ID;
|
||||
private User _User;
|
||||
private bool IsDialog = false;
|
||||
private IDialogService _DialogService;
|
||||
private bool _IsDialog;
|
||||
#endregion
|
||||
|
||||
#region Contructors
|
||||
public UserPageModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService, IDialogService dialogService) : base(navigationService, pageDialogService, apiService)
|
||||
{
|
||||
_DialogService = dialogService;
|
||||
DeleteCommand = new DelegateCommand(DeleteCommandExecute);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -41,6 +42,10 @@ namespace Borepin.PageModel
|
||||
if(instance is string)
|
||||
{
|
||||
_ID = instance as string;
|
||||
}
|
||||
else if(instance == null && _IsDialog)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -52,6 +57,11 @@ namespace Borepin.PageModel
|
||||
|
||||
public override async Task LoadAPIData()
|
||||
{
|
||||
if(_IsDialog)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_User = (await _API.Session.UserSystem.Search.GetUserByName(_ID).ConfigureAwait(false)).Just;
|
||||
UserItem = new UserVisualize(_User);
|
||||
UserItem.LoadData();
|
||||
@ -67,7 +77,7 @@ namespace Borepin.PageModel
|
||||
{
|
||||
role,
|
||||
_User,
|
||||
user_role_list.Contains(role)
|
||||
user_role_list.Exists(x => string.Equals(x.Name, role.Name, StringComparison.Ordinal))
|
||||
};
|
||||
|
||||
await new_viewmodel.LoadInstance(array).ConfigureAwait(false);
|
||||
@ -78,7 +88,7 @@ namespace Borepin.PageModel
|
||||
PermissionSelectViewModel_List = viewmodel_list;
|
||||
|
||||
CanAdmin = !((UserSystem.ManageInterface_Proxy)_API.Session.UserSystem.Manage).IsNull;
|
||||
CanManage = !((User.AdminInterface_Proxy)_User.Manage).IsNull;
|
||||
CanManage = !((User.ManageInterface_Proxy)_User.Manage).IsNull;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -129,7 +139,7 @@ namespace Borepin.PageModel
|
||||
{ "instance", _User },
|
||||
};
|
||||
|
||||
IsDialog = true;
|
||||
_IsDialog = true;
|
||||
_DialogService.ShowDialog("ConfirmDialog", parameters, DeleteCommandExecute_Dialog);
|
||||
}
|
||||
|
||||
@ -137,10 +147,16 @@ namespace Borepin.PageModel
|
||||
{
|
||||
if (string.Equals(result.Parameters.GetValue<string>("result"), "confirm", StringComparison.Ordinal))
|
||||
{
|
||||
IsBusy = true;
|
||||
if (_API.IsConnected)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach(PermissionSelectViewModel viewModel in PermissionSelectViewModel_List)
|
||||
{
|
||||
viewModel.Dispose();
|
||||
}
|
||||
|
||||
await _API.Session.UserSystem.Manage.RemoveUser(_User).ConfigureAwait(false);
|
||||
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
|
@ -159,6 +159,15 @@ namespace Borepin.Resources.Text {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Add User failed.
|
||||
/// </summary>
|
||||
internal static string ALERT_AddUserFailed {
|
||||
get {
|
||||
return ResourceManager.GetString("ALERT_AddUserFailed", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unable to authenticate to server..
|
||||
/// </summary>
|
||||
@ -177,6 +186,15 @@ namespace Borepin.Resources.Text {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Password is invalid..
|
||||
/// </summary>
|
||||
internal static string ALERT_PasswordInvalid {
|
||||
get {
|
||||
return ResourceManager.GetString("ALERT_PasswordInvalid", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to QR Code is invalid.
|
||||
/// </summary>
|
||||
@ -204,6 +222,24 @@ namespace Borepin.Resources.Text {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to User allready exist..
|
||||
/// </summary>
|
||||
internal static string ALERT_UserExist {
|
||||
get {
|
||||
return ResourceManager.GetString("ALERT_UserExist", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Username is invalid..
|
||||
/// </summary>
|
||||
internal static string ALERT_UsernameInvalid {
|
||||
get {
|
||||
return ResourceManager.GetString("ALERT_UsernameInvalid", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to It's Bionade.
|
||||
/// </summary>
|
||||
|
@ -151,12 +151,18 @@
|
||||
<data name="ALERT_AddressInvalid" xml:space="preserve">
|
||||
<value>Server address is invaild.</value>
|
||||
</data>
|
||||
<data name="ALERT_AddUserFailed" xml:space="preserve">
|
||||
<value>Add User failed</value>
|
||||
</data>
|
||||
<data name="ALERT_AuthServer" xml:space="preserve">
|
||||
<value>Unable to authenticate to server.</value>
|
||||
</data>
|
||||
<data name="ALERT_ConnectionFailed" xml:space="preserve">
|
||||
<value>Connection failed</value>
|
||||
</data>
|
||||
<data name="ALERT_PasswordInvalid" xml:space="preserve">
|
||||
<value>Password is invalid.</value>
|
||||
</data>
|
||||
<data name="Alert_QRInvalid" xml:space="preserve">
|
||||
<value>QR Code is invalid</value>
|
||||
</data>
|
||||
@ -166,6 +172,12 @@
|
||||
<data name="ALERT_UnexpectedError" xml:space="preserve">
|
||||
<value>Unexpected Error.</value>
|
||||
</data>
|
||||
<data name="ALERT_UserExist" xml:space="preserve">
|
||||
<value>User allready exist.</value>
|
||||
</data>
|
||||
<data name="ALERT_UsernameInvalid" xml:space="preserve">
|
||||
<value>Username is invalid.</value>
|
||||
</data>
|
||||
<data name="Bionade" xml:space="preserve">
|
||||
<value>It's Bionade</value>
|
||||
</data>
|
||||
|
@ -12,7 +12,7 @@ using System.Windows.Input;
|
||||
|
||||
namespace Borepin.ViewModel
|
||||
{
|
||||
public class PermissionSelectViewModel : ConnectionModelBase
|
||||
public class PermissionSelectViewModel : ConnectionModelBase, IDisposable
|
||||
{
|
||||
#region Private Fields
|
||||
private User _User;
|
||||
@ -91,21 +91,21 @@ namespace Borepin.ViewModel
|
||||
return;
|
||||
}
|
||||
|
||||
if(_API.IsConnected)
|
||||
if(_API.IsConnected && _User != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Role> user_role_list = new List<Role>(await _User.Info.ListRoles().ConfigureAwait(false));
|
||||
if(IsChecked)
|
||||
{
|
||||
if(!user_role_list.Contains(_Role))
|
||||
if(!user_role_list.Exists(x => string.Equals(x.Name, _Role.Name, StringComparison.Ordinal)))
|
||||
{
|
||||
await _User.Admin.AddRole(_Role).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(user_role_list.Contains(_Role))
|
||||
if(user_role_list.Exists(x => string.Equals(x.Name, _Role.Name, StringComparison.Ordinal)))
|
||||
{
|
||||
await _User.Admin.RemoveRole(_Role).ConfigureAwait(false);
|
||||
}
|
||||
@ -117,6 +117,12 @@ namespace Borepin.ViewModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_User = null;
|
||||
_Role = null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user