mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 23:01:52 +01:00
Added: Change Permission
This commit is contained in:
parent
5c223fcd84
commit
3d1a212ae3
@ -13,11 +13,14 @@ namespace Borepin.Base
|
|||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
protected readonly IAPI _API;
|
protected readonly IAPI _API;
|
||||||
|
protected readonly IAPIService _APIService;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
protected ConnectionModelBase(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService)
|
protected ConnectionModelBase(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService)
|
||||||
{
|
{
|
||||||
|
_APIService = apiService;
|
||||||
|
|
||||||
_API = apiService.GetAPI();
|
_API = apiService.GetAPI();
|
||||||
_API.ConnectionStatusChanged += OnConnectionStatusChanged;
|
_API.ConnectionStatusChanged += OnConnectionStatusChanged;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
</ListView>
|
</ListView>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<StackLayout IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}">
|
<StackLayout IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}">
|
||||||
<Label Text="Please connect to Server" ></Label>
|
<Label Text="Please connect to Server"/>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="Borepin.Page.UserPage"
|
x:Class="Borepin.Page.UserPage"
|
||||||
xmlns:converters="clr-namespace:Borepin.Converter"
|
xmlns:converters="clr-namespace:Borepin.Converter" xmlns:views="clr-namespace:Borepin.View"
|
||||||
Title="Machine">
|
Title="Machine">
|
||||||
<ContentPage.Resources>
|
<ContentPage.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
@ -19,9 +19,20 @@
|
|||||||
</StackLayout>
|
</StackLayout>
|
||||||
<StackLayout IsVisible="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}">
|
<StackLayout IsVisible="{Binding IsBusy, Converter={StaticResource InvertBoolConverter}}">
|
||||||
<StackLayout IsVisible="{Binding IsConnected}">
|
<StackLayout IsVisible="{Binding IsConnected}">
|
||||||
<Label Text="{Binding UserItem.Username}" Style="{StaticResource LabelStyle_Title}"/>
|
<Label Text="{Binding UserItem.Name}" Style="{StaticResource LabelStyle_Title}"/>
|
||||||
|
<ListView ItemsSource="{Binding PermissionSelectViewModel_List}" SelectionMode="None" SeparatorColor="Transparent">
|
||||||
|
<ListView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<ViewCell>
|
||||||
|
<views:PermissionSelectView />
|
||||||
|
</ViewCell>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListView.ItemTemplate>
|
||||||
|
</ListView>
|
||||||
|
</StackLayout>
|
||||||
|
<StackLayout IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}">
|
||||||
|
<Label Text="Please connect to Server"/>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<Label Text="Please connect to Server" IsVisible="{Binding IsConnected, Converter={StaticResource InvertBoolConverter}}"></Label>
|
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
</ContentPage.Content>
|
</ContentPage.Content>
|
||||||
|
@ -134,11 +134,17 @@ namespace Borepin.PageModel
|
|||||||
|
|
||||||
if (_API.IsConnected)
|
if (_API.IsConnected)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Machine.IManageInterface manageInterface = _Machine.Manage;
|
||||||
|
|
||||||
Machine.IManageInterface manageInterface = _Machine.Manage;
|
await manageInterface.ForceFree().ConfigureAwait(false);
|
||||||
|
await LoadAPIData().ConfigureAwait(false);
|
||||||
await manageInterface.ForceFree().ConfigureAwait(false);
|
}
|
||||||
await LoadAPIData().ConfigureAwait(false);
|
catch (RpcException exception) when (string.Equals(exception.Message, "RPC connection is broken. Task would never return.", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
Log.Debug("RPC Connection Loss");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IsBusy = false;
|
IsBusy = false;
|
||||||
|
@ -36,7 +36,7 @@ namespace Borepin.PageModel
|
|||||||
viewmodel_list.Add(new_viewmodel);
|
viewmodel_list.Add(new_viewmodel);
|
||||||
}
|
}
|
||||||
|
|
||||||
user_list.OrderBy(x => x.Username, StringComparison.OrdinalIgnoreCase.WithNaturalSort());
|
viewmodel_list.OrderBy(x => x.Instance.Username, StringComparison.OrdinalIgnoreCase.WithNaturalSort());
|
||||||
UserListItemViewModel_List = viewmodel_list;
|
UserListItemViewModel_List = viewmodel_list;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -10,6 +10,10 @@ using Borepin.Service;
|
|||||||
using Borepin.Base.Exceptions;
|
using Borepin.Base.Exceptions;
|
||||||
using Capnp.Rpc;
|
using Capnp.Rpc;
|
||||||
using System;
|
using System;
|
||||||
|
using Borepin.ViewModel;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NaturalSort.Extension;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Borepin.PageModel
|
namespace Borepin.PageModel
|
||||||
{
|
{
|
||||||
@ -47,10 +51,38 @@ namespace Borepin.PageModel
|
|||||||
_User = (await _API.Session.UserSystem.Search.GetUserByName(_ID).ConfigureAwait(false)).Just;
|
_User = (await _API.Session.UserSystem.Search.GetUserByName(_ID).ConfigureAwait(false)).Just;
|
||||||
UserItem = new UserVisualize(_User);
|
UserItem = new UserVisualize(_User);
|
||||||
UserItem.LoadData();
|
UserItem.LoadData();
|
||||||
|
|
||||||
|
IReadOnlyList<Role> role_list = await _API.Session.PermissionSystem.Info.GetRoleList().ConfigureAwait(false);
|
||||||
|
List<Role> user_role_list = new List<Role>(await _User.Info.ListRoles().ConfigureAwait(false));
|
||||||
|
|
||||||
|
List<PermissionSelectViewModel> viewmodel_list = new List<PermissionSelectViewModel>();
|
||||||
|
foreach (Role role in role_list)
|
||||||
|
{
|
||||||
|
PermissionSelectViewModel new_viewmodel = new PermissionSelectViewModel(_NavigationService, _PageDialogService, _APIService);
|
||||||
|
object[] array = new object[]
|
||||||
|
{
|
||||||
|
role,
|
||||||
|
_User,
|
||||||
|
user_role_list.Contains(role)
|
||||||
|
};
|
||||||
|
|
||||||
|
await new_viewmodel.LoadInstance(array).ConfigureAwait(false);
|
||||||
|
viewmodel_list.Add(new_viewmodel);
|
||||||
|
}
|
||||||
|
|
||||||
|
viewmodel_list.OrderBy(x => x.RoleName, StringComparison.OrdinalIgnoreCase.WithNaturalSort());
|
||||||
|
PermissionSelectViewModel_List = viewmodel_list;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Fields
|
#region Fields
|
||||||
|
private IList<PermissionSelectViewModel> _PermissionSelectViewModel_List;
|
||||||
|
public IList<PermissionSelectViewModel> PermissionSelectViewModel_List
|
||||||
|
{
|
||||||
|
get => _PermissionSelectViewModel_List;
|
||||||
|
set => SetProperty(ref _PermissionSelectViewModel_List, value);
|
||||||
|
}
|
||||||
|
|
||||||
private UserVisualize _UserItem;
|
private UserVisualize _UserItem;
|
||||||
public UserVisualize UserItem
|
public UserVisualize UserItem
|
||||||
{
|
{
|
||||||
|
23
Borepin/Borepin/View/PermissionSelectView.xaml
Normal file
23
Borepin/Borepin/View/PermissionSelectView.xaml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="Borepin.View.PermissionSelectView">
|
||||||
|
<ContentView.Content>
|
||||||
|
<Grid RowSpacing="0">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="5" />
|
||||||
|
<ColumnDefinition Width="3*" />
|
||||||
|
<ColumnDefinition Width="2*" />
|
||||||
|
<ColumnDefinition Width="1*" />
|
||||||
|
<ColumnDefinition Width="1" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="1"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Label Grid.Row="0" Grid.Column="1" Text="{Binding RoleName, StringFormat='{0}'}" Style="{StaticResource LabelStyle_Primary}" VerticalOptions="Center"/>
|
||||||
|
<CheckBox Grid.Row="0" Grid.Column="3" Margin="0, 3, 0, 3" IsChecked="{Binding IsChecked}" IsEnabled="{Binding CanChange}" VerticalOptions="Center"/>
|
||||||
|
<BoxView Grid.Row="1" Grid.ColumnSpan="5" BackgroundColor="{StaticResource FifthColor}"/>
|
||||||
|
</Grid>
|
||||||
|
</ContentView.Content>
|
||||||
|
</ContentView>
|
20
Borepin/Borepin/View/PermissionSelectView.xaml.cs
Normal file
20
Borepin/Borepin/View/PermissionSelectView.xaml.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
|
namespace Borepin.View
|
||||||
|
{
|
||||||
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||||
|
public partial class PermissionSelectView : ContentView
|
||||||
|
{
|
||||||
|
public PermissionSelectView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
121
Borepin/Borepin/ViewModel/PermissionSelectViewModel.cs
Normal file
121
Borepin/Borepin/ViewModel/PermissionSelectViewModel.cs
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
using Borepin.Base;
|
||||||
|
using Borepin.Service;
|
||||||
|
using Capnp.Rpc;
|
||||||
|
using FabAccessAPI.Schema;
|
||||||
|
using Prism.Commands;
|
||||||
|
using Prism.Navigation;
|
||||||
|
using Prism.Services;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace Borepin.ViewModel
|
||||||
|
{
|
||||||
|
public class PermissionSelectViewModel : ConnectionModelBase
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
private User _User;
|
||||||
|
private Role _Role;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public PermissionSelectViewModel(INavigationService navigationService, IPageDialogService pageDialogService, IAPIService apiService) : base(navigationService, pageDialogService, apiService)
|
||||||
|
{
|
||||||
|
UpdateRoleCommand = new DelegateCommand(UpdateRoleCommandExecute);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region LoadData
|
||||||
|
public override Task LoadInstance(object instance)
|
||||||
|
{
|
||||||
|
if(instance is object[])
|
||||||
|
{
|
||||||
|
object[] array = instance as object[];
|
||||||
|
if (array[0] is Role && array[1] is User && array[2] is bool)
|
||||||
|
{
|
||||||
|
_Role = array[0] as Role;
|
||||||
|
_User = array[1] as User;
|
||||||
|
|
||||||
|
RoleName = _Role.Name;
|
||||||
|
|
||||||
|
CanChange = !((User.AdminInterface_Proxy)_User.Admin).IsNull;
|
||||||
|
IsChecked = (bool)array[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Fields
|
||||||
|
private bool _IsChecked;
|
||||||
|
public bool IsChecked
|
||||||
|
{
|
||||||
|
get => _IsChecked;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty(ref _IsChecked, value);
|
||||||
|
UpdateRoleCommand.Execute(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _CanChange;
|
||||||
|
public bool CanChange
|
||||||
|
{
|
||||||
|
get => _CanChange;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty(ref _CanChange, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string _RoleName;
|
||||||
|
public string RoleName
|
||||||
|
{
|
||||||
|
get => _RoleName;
|
||||||
|
set => SetProperty(ref _RoleName, value);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Commands
|
||||||
|
private ICommand _UpdateRoleCommand;
|
||||||
|
public ICommand UpdateRoleCommand
|
||||||
|
{
|
||||||
|
get => _UpdateRoleCommand;
|
||||||
|
set => SetProperty(ref _UpdateRoleCommand, value);
|
||||||
|
}
|
||||||
|
public async void UpdateRoleCommandExecute()
|
||||||
|
{
|
||||||
|
if(!CanChange)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_API.IsConnected)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<Role> user_role_list = new List<Role>(await _User.Info.ListRoles().ConfigureAwait(false));
|
||||||
|
if(IsChecked)
|
||||||
|
{
|
||||||
|
if(!user_role_list.Contains(_Role))
|
||||||
|
{
|
||||||
|
await _User.Admin.AddRole(_Role).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(user_role_list.Contains(_Role))
|
||||||
|
{
|
||||||
|
await _User.Admin.RemoveRole(_Role).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (RpcException exception) when (string.Equals(exception.Message, "RPC connection is broken. Task would never return.", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
Log.Debug("RPC Connection Loss");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
2
external/capnproto-dotnetcore
vendored
2
external/capnproto-dotnetcore
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 63e63853c1d5ca9f223aa3627ad391ce434a0683
|
Subproject commit 086bbc2497785d2cc63e9252df6f6d3ee7599579
|
Loading…
x
Reference in New Issue
Block a user