Skip to content

Commit

Permalink
chore: zmienione allow-deny dla peer w buforze
Browse files Browse the repository at this point in the history
  • Loading branch information
pkar70 committed May 14, 2024
1 parent 2588a9b commit 4a27fb7
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 32 deletions.
2 changes: 1 addition & 1 deletion PicSorter/BuildTimeTemplate.vb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@
<MenuItem Header="no target dir" Click="uiFilterNoTarget_Click" Name="uiFilterNoTarget"/>
<MenuItem Header="Sharing »" Name="uiFilterSharing">
<MenuItem Header="Queries for Channel" Name="uiFilterChannels" />
<MenuItem Header="Queries for Login" Name="uiFilterLogins"/>
<MenuItem Header="Marked for Login" Name="uiFilterLoginsMarked"/>
<!--<MenuItem Header="Queries for Login" Name="uiFilterLogins"/>-->
<!--<MenuItem Header="Marked for Login" Name="uiFilterLoginsMarked"/>-->
<MenuItem Header="for Login" Name="uiFilterLoginsMarked"/>
<MenuItem Header="Cudze" Click="uiFilterCudze_Click" />
<MenuItem Header="remote desc" Click="uiFilterRemoteDesc_Click" />
</MenuItem>
Expand Down
12 changes: 6 additions & 6 deletions PicSorter/WindowsWithPages/Browse/ProcessBrowse.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -2320,7 +2320,7 @@ Public Class ProcessBrowse

Next

uiFilterLogins.IsEnabled = (iCnt > 0)
'uiFilterLogins.IsEnabled = (iCnt > 0)
uiFilterLoginsMarked.IsEnabled = (iCnt > 0)

Return iCnt
Expand Down
4 changes: 2 additions & 2 deletions PicSorter/WindowsWithPages/Setting/SettingsSources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<Grid Margin="5,5,5,5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" x:Name="uiRowTitle"/>
<RowDefinition Height="10*" x:Name="uiRowSrcList" />
<RowDefinition Height="15*" x:Name="uiRowSrcProp" />
<RowDefinition Height="*" x:Name="uiRowSrcList" />
<RowDefinition Height="Auto" x:Name="uiRowSrcProp" />
<RowDefinition Height="Auto" x:Name="uiRowOK"/>
</Grid.RowDefinitions>

Expand Down
166 changes: 155 additions & 11 deletions PicSorter/userControls/OnePicContextMenu/PicMenuShareUpload.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -65,19 +207,21 @@ 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)

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
Expand Down
50 changes: 43 additions & 7 deletions VbLib/Structy/OnePic.lib.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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

''' <summary>
Expand Down Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions VbLib/Structy/Share.lib.vb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ Public Class ShareLogin
'Public Property channelNames As String ' na dysku są tylko nazwy

''' <summary>
''' lista PicGuid wyłączanych (mimo że pasują do powyższych filtrów)
''' lista serno wyłączanych (mimo że pasują do powyższych filtrów)
''' </summary>
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

Expand Down
2 changes: 1 addition & 1 deletion lib_n6_httpSrv/httpServer.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a27fb7

Please sign in to comment.