From c7f62ef18bf159c231dee8bafe486cf0e4dc7ac3 Mon Sep 17 00:00:00 2001 From: Sahil Omkumar Dhillon <118592065+SahilDhillon21@users.noreply.github.com> Date: Fri, 24 Jan 2025 08:43:31 +0530 Subject: [PATCH 1/2] Search fix and enhanced UI (#3252) * frontend changes * Search bar changes * formatting changes --- website/templates/includes/header.html | 73 ++- website/templates/search.html | 753 +++++++++++++++++++++---- website/views/core.py | 93 ++- 3 files changed, 793 insertions(+), 126 deletions(-) diff --git a/website/templates/includes/header.html b/website/templates/includes/header.html index 86e57dcd1..5752c4012 100644 --- a/website/templates/includes/header.html +++ b/website/templates/includes/header.html @@ -149,9 +149,11 @@ action="{% url 'search' %}" method="get"> +
@@ -159,7 +161,7 @@ @@ -177,11 +179,31 @@ class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm"> {% trans "Projects" %} + + {% trans "Repos" %} + {% trans "Users" %} + + {% trans "Issues" %} + + + {% trans "Domains" %} + + + {% trans "Labels" %} + @@ -345,9 +367,37 @@

Chat with BLT Bot

- {% endif %}
{% if query %} -
+
{% if issues %} -
- {% for activity in issues %} - {% include "_activity.html" %} - {% endfor %} +
+
+
+
+

Issues

+
+ {% for activity in issues %} + {% include "_activity.html" %} + {% endfor %} +
+
+
+
- {% elif domains %} -
-
- {% for domain in domains %} - + {% endif %} + {% if domains %} +
+
+
+
+

Domains

+
+ {% for domain in domains %} +
+
+ {% if domain.logo %} + {{ domain.name }} Logo + {% else %} +
+ N/A +
+ {% endif %} +
+

+ {{ domain.name }} +

+ {% if domain.hostname_domain %}

{{ domain.hostname_domain }}

{% endif %} +
+
+
+ {% if domain.webshot %} + + {{ domain.name }} Webshot + + {% endif %} +
+
+
+ + Clicks: {{ domain.clicks|default:"0" }} +
+
+ + Open Issues: {{ domain.open_issues.count }} +
+
+ + Closed Issues: {{ domain.closed_issues.count }} +
+
+ {% if domain.managers.exists %} +
+ Managers: +
+ {% for manager in domain.managers.all %} + + {{ manager.get_full_name|default:manager.username }} + + {% endfor %} +
+
+ {% endif %} +
+ {% if domain.twitter %} + + + Twitter + + {% endif %} + {% if domain.facebook %} + + + Facebook + + {% endif %} + {% if domain.github %} + + + GitHub + + {% endif %} +
+ {% if domain.tags.exists %} +
+ {% for tag in domain.tags.all %} + + {{ tag.name }} + + {% endfor %} +
+ {% endif %} + {% if domain.top_tester %} +
+ + Top Tester: {{ domain.top_tester.get_full_name|default:domain.top_tester.username }} +
+ {% endif %} +
+
+ Domain Color: +
+
+
+
+ {% endfor %}
- {% endfor %} +
- {% elif users %} -
-
+
+ {% endif %} + {% if users %} +
+
+

Users

+
{% for user in users %} -
-
- {% if user.user.userprofile.avatar %} - {{ user.user.username }} - {% elif user.user.socialaccount_set.all.0.get_avatar_url %} - user image +
+ {% if user.user.userprofile.user_avatar %} + {{ user.user.username }} + {% elif user.user.socialaccount_set.all.0.get_avatar_url %} + user image + {% else %} + user image + {% endif %} +
+

+ {{ user.user.username }} + {{ user.get_title_display }} +

+
+

+ + Role: + {{ user.role|default:"Not specified" }} +

+

+ + Points: + {{ user.total_score }} +

+ {% if user.team %} +

+ + Team: + {{ user.team }} +

+ {% endif %} +
+
+ {% if user.linkedin_url %} + + + LinkedIn + + {% endif %} + {% if user.github_url %} + + + GitHub + + {% endif %} + {% if user.website_url %} + + + Website + + {% endif %} +
+
+ {% for badge in user.badges %} +
+ {{ badge.badge.title }} + {{ badge.badge.title }} +
+ {% endfor %} +
+
+ {% for tag in user.tags.all %} + + {{ tag.name }} + + {% endfor %} +
+
+
+ {% endfor %} +
+
+
+ {% endif %} + {% if organizations %} +
+
+

Organizations

+
+ {% for organization in organizations %} +
+
+ {% if organization.logo %} + {{ organization.name }} Logo + {% else %} +
+ No Logo +
+ {% endif %} +
+

+ {{ organization.name }} +

+ {% if organization.description %} +

{{ organization.description|truncatechars:150 }}

+ {% endif %} +
+ {% if organization.email %} + + + {{ organization.email }} + + {% endif %} + {% if organization.url %} + + + {{ organization.url }} + + {% endif %} + {% if organization.twitter %} + + + + {% endif %} + {% if organization.facebook %} + + + + {% endif %} +
+
+
+
+
+ Type: {{ organization.get_type_display }} +
+
+ Team Points: {{ organization.team_points }} +
+
+

+ {% if organization.is_active %} + Active + {% else %} + Inactive + {% endif %} +

+
+
+ {% if organization.tags.all %} +
+ {% for tag in organization.tags.all %} + + {{ tag.name }} + + {% endfor %} +
+ {% endif %} +
+ {% endfor %} +
+
+
+ {% endif %} + {% if projects %} +
+
+

Projects

+
+ {% for project in projects %} +
+
+ {% if project.logo %} + {{ organization.name }} Logo {% else %} - user image +
+ No Logo +
{% endif %} - {{ user.user.username }} +
+

+ {{ project.name }} +

+ {% if project.description %} +

{{ project.description|truncatechars:150 }}

+ {% endif %} +
+ {% if project.url %} + + + {{ project.url }} + + {% endif %} + {% if project.twitter %} + + + + {% endif %} + {% if project.facebook %} + + + + {% endif %} +
+
-
- - {% if user.total_score is None %} - 0 Point +
+ {% if project.organization %} + {% if project.organization.logo %} + {{ organization.name }} Logo + {% endif %} +

+ Organization: + {{ project.organization.name }} +

+ {% else %} +

+ Organization: Not Assigned +

+ {% endif %} +
+
+
+ Visits: {{ project.project_visit_count }} +
+
+ Created: {{ project.created|date:"F j, Y" }} +
+
+ Modified: {{ project.modified|date:"F j, Y" }} +
+
+ {% if project.tags.all %} +
+ {% for tag in project.tags.all %} + + {{ tag.name }} + + {% endfor %} +
+ {% endif %} +
+ {% endfor %} +
+
+
+ {% endif %} + {% if tags %} +
+
+

Tags

+
+

+ Tags +

+
+ {% for tag in tags %} + + {{ tag.name }} + + {% endfor %} +
+
+ {% if matching_organizations %} +
+

+ Matching Organizations +

+
+ {% for org in matching_organizations %} +
+ {% if org.logo %} + {{ org.name }} logo + {% endif %} + {{ org.name }} +
+ {% endfor %} +
+
+ {% endif %} + {% if matching_domains %} +
+

+ Matching Domains +

+
+ {% for domain in matching_domains %} +
+ {% if domain.logo %} + {{ domain.name }} logo + {% endif %} + {{ domain.name }} +
+ {% endfor %} +
+
+ {% endif %} + {% if matching_issues %} +
+

+ Matching Issues +

+
+ {% for issue in matching_issues %} +
+ {% if issue.logo %} + {{ issue.description }} logo + {% endif %} + {{ issue.description }} +
+ {% endfor %} +
+
+ {% endif %} + {% if matching_user_profiles %} +
+

+ Matching User Profiles +

+
+ {% for profile in matching_user_profiles %} +
+ {% if profile.user_avatar %} + {{ profile.user.username }} + {% else %} + avatar + {% endif %} + {{ profile.user.username }} +
+ {% endfor %} +
+
+ {% endif %} + {% if matching_repos %} +
+

+ Matching Repositories +

+
+ {% for repo in matching_repos %} + + {% endfor %} +
+
+ {% endif %} +
+
+ {% endif %} + {% if repos %} +
+
+

Repositories

+
+ {% for repo in repos %} +
+
+ {% if repo.logo_url %} + {{ repo.name }} Logo {% else %} - {{ user.total_score|floatformat:0 }} Points +
+ No Logo +
{% endif %} +
+

+ {{ repo.name }} +

+ {% if repo.description %}

{{ repo.description|truncatechars:150 }}

{% endif %} +
+ {% if repo.primary_language %} + {{ repo.primary_language }} + {% endif %} + {% if repo.stars %} + + + {{ repo.stars }} + + {% endif %} + {% if repo.forks %} + + + {{ repo.forks }} + + {% endif %} + {% if repo.open_issues %} + + + {{ repo.open_issues }} + + {% endif %} +
+
+
+
+
+ + Last Updated: + {{ repo.last_updated|date:"d M Y, H:i" }} +
+
+ + License: + {{ repo.license }} +
+
+ + Visits: + {{ repo.repo_visit_count }} +
- View Profile + {% if repo.tags.all %} +
+ {% for tag in repo.tags.all %} + + {{ tag.name }} + + {% endfor %} +
+ {% endif %}
{% endfor %}
- {% else %} -
- +
+ {% endif %} + {% if not issues and not domains and not users and not organizations and not projects and not tags and not repos %} +
+
+
- {% endif %} -
+
+ {% endif %} {% endif %} {% endblock content %} diff --git a/website/views/core.py b/website/views/core.py index e89f1aa79..4a6079c3a 100644 --- a/website/views/core.py +++ b/website/views/core.py @@ -37,9 +37,14 @@ Badge, Domain, Issue, + Organization, PRAnalysisReport, + Project, + Repo, Suggestion, SuggestionVotes, + Tag, + UserBadge, UserProfile, Wallet, ) @@ -300,24 +305,13 @@ def find_key(request, token): def search(request, template="search.html"): query = request.GET.get("query") - stype = request.GET.get("type") + stype = request.GET.get("type", "organizations") context = None if query is None: return render(request, template) query = query.strip() - if query[:6] == "issue:": - stype = "issue" - query = query[6:] - elif query[:7] == "domain:": - stype = "domain" - query = query[7:] - elif query[:5] == "user:": - stype = "user" - query = query[5:] - elif query[:6] == "label:": - stype = "label" - query = query[6:] - if stype == "issue" or stype is None: + + if stype == "issues": context = { "query": query, "type": stype, @@ -325,21 +319,26 @@ def search(request, template="search.html"): Q(is_hidden=True) & ~Q(user_id=request.user.id) )[0:20], } - elif stype == "domain": + elif stype == "domains": context = { "query": query, "type": stype, "domains": Domain.objects.filter(Q(url__icontains=query), hunt=None)[0:20], } - elif stype == "user": + elif stype == "users": + users = ( + UserProfile.objects.filter(Q(user__username__icontains=query)) + .annotate(total_score=Sum("user__points__score")) + .order_by("-total_score")[0:20] + ) + for userprofile in users: + userprofile.badges = UserBadge.objects.filter(user=userprofile.user) context = { "query": query, "type": stype, - "users": UserProfile.objects.filter(Q(user__username__icontains=query)) - .annotate(total_score=Sum("user__points__score")) - .order_by("-total_score")[0:20], + "users": users, } - elif stype == "label": + elif stype == "labels": context = { "query": query, "type": stype, @@ -347,7 +346,61 @@ def search(request, template="search.html"): Q(is_hidden=True) & ~Q(user_id=request.user.id) )[0:20], } + elif stype == "organizations": + organizations = Organization.objects.filter(name__icontains=query) + for org in organizations: + d = Domain.objects.filter(organization=org).first() + if d: + org.absolute_url = d.get_absolute_url() + context = { + "query": query, + "type": stype, + "organizations": Organization.objects.filter(name__icontains=query), + } + elif stype == "projects": + context = { + "query": query, + "type": stype, + "projects": Project.objects.filter( + Q(name__icontains=query) | Q(description__icontains=query) + ), + } + elif stype == "repos": + context = { + "query": query, + "type": stype, + "repos": Repo.objects.filter( + Q(name__icontains=query) | Q(description__icontains=query) + ), + } + elif stype == "tags": + tags = Tag.objects.filter(name__icontains=query) + matching_organizations = Organization.objects.filter(tags__in=tags).distinct() + matching_domains = Domain.objects.filter(tags__in=tags).distinct() + matching_issues = Issue.objects.filter(tags__in=tags).distinct() + matching_user_profiles = UserProfile.objects.filter(tags__in=tags).distinct() + matching_repos = Repo.objects.filter(tags__in=tags).distinct() + for org in matching_organizations: + d = Domain.objects.filter(organization=org).first() + if d: + org.absolute_url = d.get_absolute_url() + context = { + "query": query, + "type": stype, + "tags": tags, + "matching_organizations": matching_organizations, + "matching_domains": matching_domains, + "matching_issues": matching_issues, + "matching_user_profiles": matching_user_profiles, + "matching_repos": matching_repos, + } + elif stype == "languages": + context = { + "query": query, + "type": stype, + "repos": Repo.objects.filter(primary_language__icontains=query), + } if request.user.is_authenticated: context["wallet"] = Wallet.objects.get(user=request.user) return render(request, template, context) From 8dc96e604581b4b5b2a970adbe69c920db9e17e4 Mon Sep 17 00:00:00 2001 From: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> Date: Thu, 23 Jan 2025 22:33:54 -0500 Subject: [PATCH 2/2] Update slack_handlers.py --- website/views/slack_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/views/slack_handlers.py b/website/views/slack_handlers.py index 7d2f8e62c..182768b43 100644 --- a/website/views/slack_handlers.py +++ b/website/views/slack_handlers.py @@ -262,7 +262,7 @@ def slack_commands(request): "type": "section", "text": { "type": "mrkdwn", - "text": " 🛠 *GSOC Projects:* View this year's participating GSOC projects .", + "text": " 🛠 *GSOC Projects:* View this year's participating GSOC projects https://owasp.org/www-community/initiatives/gsoc/gsoc2025ideas", }, }, {"type": "divider"},