From 4a27fb780c2a4e295f51497fe4c628fae30692bb Mon Sep 17 00:00:00 2001 From: pkar Date: Tue, 14 May 2024 10:25:53 +0200 Subject: [PATCH] chore: zmienione allow-deny dla peer w buforze --- PicSorter/BuildTimeTemplate.vb | 2 +- .../Browse/ProcessBrowse.xaml | 5 +- .../Browse/ProcessBrowse.xaml.vb | 12 +- .../Setting/SettingsSources.xaml | 4 +- .../OnePicContextMenu/PicMenuShareUpload.vb | 166 ++++++++++++++++-- VbLib/Structy/OnePic.lib.vb | 50 +++++- VbLib/Structy/Share.lib.vb | 4 +- lib_n6_httpSrv/httpServer.vb | 2 +- 8 files changed, 213 insertions(+), 32 deletions(-) diff --git a/PicSorter/BuildTimeTemplate.vb b/PicSorter/BuildTimeTemplate.vb index 1cd9153..bfb47dc 100644 --- a/PicSorter/BuildTimeTemplate.vb +++ b/PicSorter/BuildTimeTemplate.vb @@ -1,4 +1,4 @@  Public Module BuldTimeConstant - Public Const BUILD_TIMESTAMP As String = "2024.05.13 18:22" + Public Const BUILD_TIMESTAMP As String = "2024.05.14 10:23" End Module diff --git a/PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml b/PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml index 89658a9..655e30a 100644 --- a/PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml +++ b/PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml @@ -64,8 +64,9 @@ - - + + + diff --git a/PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml.vb b/PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml.vb index c943791..43babfc 100644 --- a/PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml.vb +++ b/PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml.vb @@ -2270,7 +2270,7 @@ Public Class ProcessBrowse Dim bWas As Boolean = False For Each thumb As ThumbPicek In _thumbsy thumb.opacity = _OpacityWygas - If thumb.oPic.IsCloudPublishMentioned("L:" & oLogin.login.ToString) Then + If thumb.oPic.PeerIsForLogin(oLogin) Then thumb.opacity = 1 bWas = True End If @@ -2301,16 +2301,16 @@ Public Class ProcessBrowse End Function Public Function WypelnMenuFilterSharingLogins() As Integer - uiFilterLogins.Items.Clear() + 'uiFilterLogins.Items.Clear() uiFilterLoginsMarked.Items.Clear() Dim iCnt As Integer = 0 For Each oLogin As Vblib.ShareLogin In Application.GetShareLogins - Dim oNew As New MenuItem With {.Header = oLogin.displayName, .DataContext = oLogin} - AddHandler oNew.Click, AddressOf FilterSharingLogin - uiFilterLogins.Items.Add(oNew) + 'Dim oNew As New MenuItem With {.Header = oLogin.displayName, .DataContext = oLogin} + 'AddHandler oNew.Click, AddressOf FilterSharingLogin + 'uiFilterLogins.Items.Add(oNew) iCnt += 1 Dim oNewMarked As New MenuItem With {.Header = oLogin.displayName, .DataContext = oLogin} @@ -2320,7 +2320,7 @@ Public Class ProcessBrowse Next - uiFilterLogins.IsEnabled = (iCnt > 0) + 'uiFilterLogins.IsEnabled = (iCnt > 0) uiFilterLoginsMarked.IsEnabled = (iCnt > 0) Return iCnt diff --git a/PicSorter/WindowsWithPages/Setting/SettingsSources.xaml b/PicSorter/WindowsWithPages/Setting/SettingsSources.xaml index 58be5f8..9900bbe 100644 --- a/PicSorter/WindowsWithPages/Setting/SettingsSources.xaml +++ b/PicSorter/WindowsWithPages/Setting/SettingsSources.xaml @@ -9,8 +9,8 @@ - - + + diff --git a/PicSorter/userControls/OnePicContextMenu/PicMenuShareUpload.vb b/PicSorter/userControls/OnePicContextMenu/PicMenuShareUpload.vb index 7c41238..d23d6d9 100644 --- a/PicSorter/userControls/OnePicContextMenu/PicMenuShareUpload.vb +++ b/PicSorter/userControls/OnePicContextMenu/PicMenuShareUpload.vb @@ -2,10 +2,16 @@ Imports Vblib +Imports pkar.DotNetExtensions + Public NotInheritable Class PicMenuShareUpload Inherits PicMenuBase + Private _menuAllow As MenuItem + Private _menuDeny As MenuItem + + Public Overrides Sub OnApplyTemplate() ' wywoÅ‚ywame byÅ‚o dwa razy! I gÅ‚upi bÅ‚Ä…d 'System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'MenuItem' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment') @@ -16,13 +22,15 @@ Public NotInheritable Class PicMenuShareUpload If Not InitEnableDisable("Share peers", "Dzielenie siÄ™ zdjÄ™ciami", True) Then Return If Application.GetShareLogins.Count > 0 Then - Dim oNew As New MenuItem With {.Header = "Mark for Login"} - Me.Items.Add(oNew) - WypelnMenuLogins(oNew, AddressOf ActionSharingLogin) + _menuAllow = New MenuItem With {.Header = "Force allow"} + AddHandler _menuAllow.SubmenuOpened, AddressOf OpeningForceAllowMenu + WypelnMenuLogins(_menuAllow, AddressOf ActionSharingLogin) + Me.Items.Add(_menuAllow) - oNew = New MenuItem With {.Header = "UnMark for Login"} - Me.Items.Add(oNew) - WypelnMenuLogins(oNew, AddressOf ActionSharingLoginUnMark) + _menuDeny = New MenuItem With {.Header = "Force deny"} + AddHandler _menuDeny.SubmenuOpened, AddressOf OpeningForceDenyMenu + WypelnMenuLogins(_menuDeny, AddressOf ActionSharingLoginUnMark) + Me.Items.Add(_menuDeny) End If @@ -34,6 +42,139 @@ Public NotInheritable Class PicMenuShareUpload _wasApplied = True End Sub + Private Sub OpeningForceDenyMenu(sender As Object, e As RoutedEventArgs) + For Each oMI As MenuItem In _menuDeny.Items + Dim oLogin As Vblib.ShareLogin = TryCast(oMI.DataContext, Vblib.ShareLogin) + If oLogin Is Nothing Then Continue For + + Dim oPic As Vblib.OnePic = GetFromDataContext() + + oMI.IsEnabled = True + + ' 1) wymuszony DENY: można go wyÅ‚Ä…czyć + If oPic.PeerIsForcedDeny(oLogin) Then + oMI.IsChecked = True + Continue For + End If + + ' 2) wymuszony ALLOW: można zablokować (jest ważniejszy niż ALLOW) + If oPic.PeerIsForceAllowed(oLogin) Then + oMI.IsChecked = False + Continue For + End If + + ' 3) podpada pod Login (bo Query): można zablokować + If oPic.PeerIsForLogin(oLogin) Then + oMI.IsChecked = False + Continue For + End If + + ' 4) nie podpada pod Login, wiÄ™c nie ma sensu blokować + oMI.IsChecked = False + oMI.IsEnabled = False + + Next + + End Sub + + Private Sub OpeningForceAllowMenu(sender As Object, e As RoutedEventArgs) + For Each oMI As MenuItem In _menuAllow.Items + Dim oLogin As Vblib.ShareLogin = TryCast(oMI.DataContext, Vblib.ShareLogin) + If oLogin Is Nothing Then Continue For + + Dim oPic As Vblib.OnePic = GetFromDataContext() + + oMI.IsEnabled = True + + ' 1) wymuszony DENY: z Allow nic nie można zrobić + If oPic.PeerIsForcedDeny(oLogin) Then + oMI.IsChecked = False + oMI.IsEnabled = False + Continue For + End If + + ' 2) wymuszony ALLOW: można wyÅ‚Ä…czyć + If oPic.PeerIsForceAllowed(oLogin) Then + oMI.IsChecked = True + Continue For + End If + + ' 3) podpada pod Login (bo Query): nie ma sensu nic robić + If oPic.PeerIsForLogin(oLogin) Then + oMI.IsChecked = True + oMI.IsEnabled = False + Continue For + End If + + ' 4) nie podpada pod Login, wiÄ™c nie ma sensu blokować + oMI.IsChecked = False + + Next + End Sub + + Private Sub OpeningForceMenu(meni As MenuItem, inDenyMenu As Boolean) + If UseSelectedItems Then Return + + For Each oMI As MenuItem In meni.Items + Dim oLogin As Vblib.ShareLogin = TryCast(oMI.DataContext, Vblib.ShareLogin) + If oLogin Is Nothing Then Continue For + + Dim oPic As Vblib.OnePic = GetFromDataContext() + + ' 1) wymuszony DENY, to nie można wÅ‚Ä…czyć - można jedynie UNCHECK w MenuDeny + If oPic.PeerIsForcedDeny(oLogin) Then + If inDenyMenu Then + oMI.IsChecked = True + oMI.IsEnabled = True + Else + oMI.IsChecked = False + oMI.IsEnabled = False + End If + + Continue For + End If + + ' 2) wymuszony ALLOW + If oPic.PeerIsForceAllowed(oLogin) Then + If inDenyMenu Then + oMI.IsChecked = False + oMI.IsEnabled = True + Else + oMI.IsChecked = True + oMI.IsEnabled = True + End If + + Continue For + End If + + + If oPic.PeerIsForLogin(oLogin) Then + If inDenyMenu Then + oMI.IsChecked = False + oMI.IsEnabled = True + Else + oMI.IsChecked = True + oMI.IsEnabled = True + End If + + Continue For + End If + + If inDenyMenu Then + oMI.IsChecked = False + oMI.IsEnabled = True + Else + oMI.IsChecked = False + oMI.IsEnabled = True + End If + + + Next + End Sub + + + + #Region "submenu logins" Private _ShareLogin As Vblib.ShareLogin @@ -42,10 +183,11 @@ Public NotInheritable Class PicMenuShareUpload oMenuItem.Items.Clear() For Each oLogin As Vblib.ShareLogin In Application.GetShareLogins - + If oLogin.displayName.EqualsCI("FORPICSEARCH") Then Continue For Dim oNew As New MenuItem oNew.Header = oLogin.displayName oNew.DataContext = oLogin + oNew.IsCheckable = True AddHandler oNew.Click, oEventHandler @@ -56,7 +198,7 @@ Public NotInheritable Class PicMenuShareUpload Private Async Sub ActionSharingLogin(sender As Object, e As RoutedEventArgs) Dim oFE As FrameworkElement = sender - _ShareLogin = oFE?.DataContext + _ShareLogin = TryCast(oFE?.DataContext, ShareLogin) If _ShareLogin Is Nothing Then Return Await OneOrManyAsync(AddressOf MarkOnePicForLogin) @@ -65,7 +207,7 @@ Public NotInheritable Class PicMenuShareUpload Private Async Sub ActionSharingLoginUnMark(sender As Object, e As RoutedEventArgs) Dim oFE As FrameworkElement = sender - _ShareLogin = oFE?.DataContext + _ShareLogin = TryCast(oFE?.DataContext, ShareLogin) If _ShareLogin Is Nothing Then Return Await OneOrManyAsync(AddressOf UnMarkOnePicForLogin) @@ -73,11 +215,13 @@ Public NotInheritable Class PicMenuShareUpload End Sub Private Async Function MarkOnePicForLogin(oPic As OnePic) As Task - oPic.AllowPeer(_ShareLogin) + ' *TODO* dla tego loginu, w zależnoÅ›ci od aktualnego stanu, dopuść sharing + oPic.PeerForceAllow(_ShareLogin) End Function Private Async Function UnMarkOnePicForLogin(oPic As OnePic) As Task - oPic.DenyPeer(_ShareLogin) + ' *TODO* dla tego loginu, w zależnoÅ›ci od aktualnego stanu, zablokuj sharing + oPic.PeerForceDeny(_ShareLogin) End Function #End Region diff --git a/VbLib/Structy/OnePic.lib.vb b/VbLib/Structy/OnePic.lib.vb index ad862ea..3d9aa1c 100644 --- a/VbLib/Structy/OnePic.lib.vb +++ b/VbLib/Structy/OnePic.lib.vb @@ -1275,23 +1275,33 @@ Public Class OnePic End If End Function - Public Function IsPeerAllowed(peer As SharePeer) As Boolean + Public Function PeerIsForceAllowed(peer As SharePeer) As Boolean If String.IsNullOrWhiteSpace(allowedPeers) Then Return False Return allowedPeers.Contains(peer.GetIdForSharing) End Function - Public Sub AllowPeer(peer As SharePeer) + Public Sub PeerForceAllow(peer As ShareLogin) ' juz jest, nie dodajemy drugi raz - If IsPeerAllowed(peer) Then Return + If PeerIsForLogin(peer) Then Return + + If PeerIsForcedDeny(peer) Then + peer.exclusions = peer.exclusions.Replace(GetFormattedSerNo(), "") + Return + End If allowedPeers &= peer.GetIdForSharing End Sub - Public Sub DenyPeer(peer As SharePeer) - If String.IsNullOrWhiteSpace(allowedPeers) Then Return - If Not IsPeerAllowed(peer) Then Return - allowedPeers = allowedPeers.Replace(peer.GetIdForSharing, "") + Public Sub PeerForceDeny(peer As ShareLogin) + If PeerIsForcedDeny(peer) Then Return + + If PeerIsForceAllowed(peer) Then + allowedPeers = allowedPeers.Replace(peer.GetIdForSharing, "") + Return + End If + + peer.exclusions = peer.exclusions & GetFormattedSerNo() & ";" End Sub ''' @@ -1329,6 +1339,32 @@ Public Class OnePic Return temp End Function + Public Function PeerIsForcedDeny(oLogin As ShareLogin) As Boolean + If oLogin?.exclusions Is Nothing Then Return False + Return oLogin.exclusions.Contains(GetFormattedSerNo() & ";") + End Function + + Public Function PeerIsForLogin(oLogin As ShareLogin) As Boolean + + If PeerIsForcedDeny(oLogin) Then Return False + + If PeerIsForceAllowed(oLogin) Then Return True + + If oLogin.channels Is Nothing Then Return False + For Each oChannel As Vblib.ShareChannelProcess In oLogin.channels + + If oChannel?.channel?.queries Is Nothing Then Continue For + + For Each oQuery As ShareQueryProcess In oChannel.channel.queries + If CheckIfMatchesQuery(oQuery.query) Then Return True + Next + + Next + + Return False + + End Function + #End Region diff --git a/VbLib/Structy/Share.lib.vb b/VbLib/Structy/Share.lib.vb index 311b845..ca257f2 100644 --- a/VbLib/Structy/Share.lib.vb +++ b/VbLib/Structy/Share.lib.vb @@ -69,9 +69,9 @@ Public Class ShareLogin 'Public Property channelNames As String ' na dysku sÄ… tylko nazwy ''' - ''' lista PicGuid wyÅ‚Ä…czanych (mimo że pasujÄ… do powyższych filtrów) + ''' lista serno wyÅ‚Ä…czanych (mimo że pasujÄ… do powyższych filtrów) ''' - Public Property exclusions As List(Of String) + Public Property exclusions As String Public Property processing As String ' skÅ‚adane do query.processing i channel.processing diff --git a/lib_n6_httpSrv/httpServer.vb b/lib_n6_httpSrv/httpServer.vb index 692e182..d9b0a3d 100644 --- a/lib_n6_httpSrv/httpServer.vb +++ b/lib_n6_httpSrv/httpServer.vb @@ -285,7 +285,7 @@ Public Class ServerWrapper Private Function SendMarkedPicsListFromBuff(oLogin As ShareLogin) As String Dim sRet As String = "" - For Each oPic As Vblib.OnePic In _buffer.GetList.Where(Function(x) Not x.sharingLockSharing AndAlso x.IsPeerAllowed(oLogin)) + For Each oPic As Vblib.OnePic In _buffer.GetList.Where(Function(x) Not x.sharingLockSharing AndAlso x.PeerIsForLogin(oLogin)) If sRet <> "" Then sRet &= "," ' usuwamy informacje które tam sie nie powinny znaleŸæ sRet &= oPic.StrippedForSharing.DumpAsJSON