Skip to content

Commit c97791b

Browse files
committed
bug fix: with website search and wpsites
1 parent 6c01cd6 commit c97791b

3 files changed

Lines changed: 53 additions & 19 deletions

File tree

plogical/acl.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from loginSystem.models import Administrator, ACL
1515
from django.shortcuts import HttpResponse
1616
from packages.models import Package
17-
from websiteFunctions.models import Websites, ChildDomains, aliasDomains, DockerSites
17+
from websiteFunctions.models import Websites, ChildDomains, aliasDomains, DockerSites, WPSites
1818
import json
1919
from subprocess import call, CalledProcessError
2020
from shlex import split
@@ -582,24 +582,44 @@ def getPHPString(phpVersion):
582582

583583
@staticmethod
584584
def searchWebsiteObjects(currentACL, userID, searchTerm):
585-
586585
if currentACL['admin'] == 1:
587-
return Websites.objects.filter(domain__istartswith=searchTerm)
586+
# Get websites that match the search term
587+
websites = Websites.objects.filter(domain__istartswith=searchTerm)
588+
# Get WordPress sites that match the search term
589+
wp_sites = WPSites.objects.filter(title__icontains=searchTerm)
590+
# Add WordPress sites' parent websites to the results
591+
for wp in wp_sites:
592+
if wp.owner not in websites:
593+
websites = websites | Websites.objects.filter(pk=wp.owner.pk)
594+
return websites
588595
else:
589596
websiteList = []
590597
admin = Administrator.objects.get(pk=userID)
591598

599+
# Get websites that match the search term
592600
websites = admin.websites_set.filter(domain__istartswith=searchTerm)
593-
594601
for items in websites:
595602
websiteList.append(items)
596603

597-
admins = Administrator.objects.filter(owner=admin.pk)
604+
# Get WordPress sites that match the search term
605+
wp_sites = WPSites.objects.filter(title__icontains=searchTerm)
606+
for wp in wp_sites:
607+
if wp.owner.admin == admin and wp.owner not in websiteList:
608+
websiteList.append(wp.owner)
598609

610+
admins = Administrator.objects.filter(owner=admin.pk)
599611
for items in admins:
612+
# Get websites that match the search term
600613
webs = items.websites_set.filter(domain__istartswith=searchTerm)
601614
for web in webs:
602-
websiteList.append(web)
615+
if web not in websiteList:
616+
websiteList.append(web)
617+
618+
# Get WordPress sites that match the search term
619+
wp_sites = WPSites.objects.filter(title__icontains=searchTerm)
620+
for wp in wp_sites:
621+
if wp.owner.admin == items and wp.owner not in websiteList:
622+
websiteList.append(wp.owner)
603623

604624
return websiteList
605625

websiteFunctions/templates/websiteFunctions/listWebsites.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2 id="domainNamePage">{% trans "List Websites" %}
6666
</div>
6767

6868
<div class="col-sm-10" style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888; margin-bottom: 2%">
69-
<input ng-change="searchWebsites()" placeholder="Search..." ng-model="patternAdded" name="dom" type="text"
69+
<input ng-keypress="$event.keyCode === 13 && searchWebsites()" placeholder="Search... (Press Enter to search)" ng-model="patternAdded" name="dom" type="text"
7070
class="form-control" required>
7171
</div>
7272

websiteFunctions/website.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4566,8 +4566,7 @@ def searchWebsitesJson(self, currentlACL, userID, searchTerm):
45664566

45674567
websites = ACLManager.searchWebsiteObjects(currentlACL, userID, searchTerm)
45684568

4569-
json_data = "["
4570-
checker = 0
4569+
json_data = []
45714570

45724571
try:
45734572
ipFile = "/etc/cyberpanel/machineIP"
@@ -4598,19 +4597,34 @@ def searchWebsitesJson(self, currentlACL, userID, searchTerm):
45984597
PHPVersionActual = 'PHP 8.1'
45994598

46004599
diskUsed = "%sMB" % str(DiskUsage)
4601-
dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress,
4602-
'admin': items.admin.userName, 'package': items.package.packageName, 'state': state,
4603-
'diskUsed': diskUsed, 'phpVersion': PHPVersionActual}
46044600

4605-
if checker == 0:
4606-
json_data = json_data + json.dumps(dic)
4607-
checker = 1
4608-
else:
4609-
json_data = json_data + ',' + json.dumps(dic)
4601+
# Get WordPress sites for this website
4602+
wp_sites = []
4603+
try:
4604+
wp_sites = WPSites.objects.filter(owner=items)
4605+
wp_sites = [{
4606+
'id': wp.id,
4607+
'title': wp.title,
4608+
'url': wp.FinalURL,
4609+
'version': wp.version if hasattr(wp, 'version') else 'Unknown',
4610+
'phpVersion': wp.phpVersion if hasattr(wp, 'phpVersion') else 'Unknown'
4611+
} for wp in wp_sites]
4612+
except:
4613+
pass
46104614

4611-
json_data = json_data + ']'
4615+
json_data.append({
4616+
'domain': items.domain,
4617+
'adminEmail': items.adminEmail,
4618+
'ipAddress': ipAddress,
4619+
'admin': items.admin.userName,
4620+
'package': items.package.packageName,
4621+
'state': state,
4622+
'diskUsed': diskUsed,
4623+
'phpVersion': PHPVersionActual,
4624+
'wp_sites': wp_sites
4625+
})
46124626

4613-
return json_data
4627+
return json.dumps(json_data)
46144628

46154629
def findWebsitesJson(self, currentACL, userID, pageNumber):
46164630
finalPageNumber = ((pageNumber * 10)) - 10

0 commit comments

Comments
 (0)