mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 15:56:17 +00:00
Fixed the issue where Job and Share link is not delete when peer deleted
This commit is contained in:
@@ -583,7 +583,7 @@ def API_deletePeers(configName: str) -> ResponseObject:
|
|||||||
if len(peers) == 0:
|
if len(peers) == 0:
|
||||||
return ResponseObject(False, "Please specify one or more peers", status_code=400)
|
return ResponseObject(False, "Please specify one or more peers", status_code=400)
|
||||||
configuration = WireguardConfigurations.get(configName)
|
configuration = WireguardConfigurations.get(configName)
|
||||||
status, msg = configuration.deletePeers(peers)
|
status, msg = configuration.deletePeers(peers, AllPeerJobs, AllPeerShareLinks)
|
||||||
return ResponseObject(status, msg)
|
return ResponseObject(status, msg)
|
||||||
|
|
||||||
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
||||||
|
@@ -596,7 +596,7 @@ class WireguardConfiguration:
|
|||||||
return False, f"Restricted {numOfRestrictedPeers} peer(s) successfully. Failed to restrict {numOfFailedToRestrictPeers} peer(s)"
|
return False, f"Restricted {numOfRestrictedPeers} peer(s) successfully. Failed to restrict {numOfFailedToRestrictPeers} peer(s)"
|
||||||
|
|
||||||
|
|
||||||
def deletePeers(self, listOfPublicKeys) -> tuple[bool, str]:
|
def deletePeers(self, listOfPublicKeys, AllPeerJobs: PeerJobs, AllPeerShareLinks: PeerShareLinks) -> tuple[bool, str]:
|
||||||
numOfDeletedPeers = 0
|
numOfDeletedPeers = 0
|
||||||
numOfFailedToDeletePeers = 0
|
numOfFailedToDeletePeers = 0
|
||||||
if not self.getStatus():
|
if not self.getStatus():
|
||||||
@@ -604,6 +604,10 @@ class WireguardConfiguration:
|
|||||||
with self.engine.begin() as conn:
|
with self.engine.begin() as conn:
|
||||||
for p in listOfPublicKeys:
|
for p in listOfPublicKeys:
|
||||||
found, pf = self.searchPeer(p)
|
found, pf = self.searchPeer(p)
|
||||||
|
for job in pf.jobs:
|
||||||
|
AllPeerJobs.deleteJob(job)
|
||||||
|
for shareLink in pf.ShareLink:
|
||||||
|
AllPeerShareLinks.updateLinkExpireDate(shareLink.ShareID, datetime.now())
|
||||||
if found:
|
if found:
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(f"{self.Protocol} set {self.Name} peer {pf.id} remove",
|
subprocess.check_output(f"{self.Protocol} set {self.Name} peer {pf.id} remove",
|
||||||
|
Reference in New Issue
Block a user