mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 07:46:18 +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:
|
||||
return ResponseObject(False, "Please specify one or more peers", status_code=400)
|
||||
configuration = WireguardConfigurations.get(configName)
|
||||
status, msg = configuration.deletePeers(peers)
|
||||
status, msg = configuration.deletePeers(peers, AllPeerJobs, AllPeerShareLinks)
|
||||
return ResponseObject(status, msg)
|
||||
|
||||
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)"
|
||||
|
||||
|
||||
def deletePeers(self, listOfPublicKeys) -> tuple[bool, str]:
|
||||
def deletePeers(self, listOfPublicKeys, AllPeerJobs: PeerJobs, AllPeerShareLinks: PeerShareLinks) -> tuple[bool, str]:
|
||||
numOfDeletedPeers = 0
|
||||
numOfFailedToDeletePeers = 0
|
||||
if not self.getStatus():
|
||||
@@ -604,6 +604,10 @@ class WireguardConfiguration:
|
||||
with self.engine.begin() as conn:
|
||||
for p in listOfPublicKeys:
|
||||
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:
|
||||
try:
|
||||
subprocess.check_output(f"{self.Protocol} set {self.Name} peer {pf.id} remove",
|
||||
|
Reference in New Issue
Block a user