Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow right click to inspect project #13309

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions weblate/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from time import time
from typing import TYPE_CHECKING, cast

from altcha import Challenge, ChallengeOptions, create_challenge, verify_solution

Check failure on line 14 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

Skipping analyzing "altcha": module is installed, but missing library stubs or py.typed marker
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Div, Field, Fieldset, Layout, Submit
from django import forms
Expand Down Expand Up @@ -170,16 +170,16 @@
# Remove empty choice from the form. We need it at the database level
# to initialize user profile, but it is filled in later based on
# languages configured in the browser.
self.fields["language"].choices = [

Check failure on line 173 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "choices"
choice for choice in self.fields["language"].choices if choice[0]

Check failure on line 174 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "choices"
]
# Limit languages to ones which have translation, do this by generating choices
# instead of queryset as the queryset would be evaluated twice as
# ModelChoiceField copies the queryset
languages = Language.objects.have_translation()
choices = list(languages.as_choices(use_code=False))
self.fields["languages"].choices = choices

Check failure on line 181 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "choices"
self.fields["secondary_languages"].choices = choices

Check failure on line 182 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "choices"
self.helper = FormHelper(self)
self.helper.disable_csrf = True
self.helper.form_tag = False
Expand Down Expand Up @@ -212,11 +212,11 @@
site_commit_email = self.instance.get_site_commit_email()
if site_commit_email:
if not settings.PRIVATE_COMMIT_EMAIL_OPT_IN:
self.fields["commit_email"].choices = [("", site_commit_email)]

Check failure on line 215 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "choices"
else:
commit_emails.add(site_commit_email)

self.fields["commit_email"].choices += [(x, x) for x in sorted(commit_emails)]

Check failure on line 219 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "choices"

self.helper = FormHelper(self)
self.helper.disable_csrf = True
Expand Down Expand Up @@ -251,7 +251,7 @@
super().__init__(*args, **kwargs)
emails = get_all_user_mails(self.instance.user)

self.fields["public_email"].choices += [(x, x) for x in sorted(emails)]

Check failure on line 254 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "choices"

self.helper = FormHelper(self)
self.helper.disable_csrf = True
Expand All @@ -273,7 +273,10 @@
super().__init__(*args, **kwargs)
user = kwargs["instance"].user
self.fields["watched"].required = False
self.fields["watched"].queryset = user.allowed_projects

Check failure on line 276 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "queryset"
self.fields["watched"].choices = [

Check failure on line 277 in weblate/accounts/forms.py

View workflow job for this annotation

GitHub Actions / mypy

"Field" has no attribute "choices"
(x.slug, x.name) for x in user.allowed_projects
]
self.helper = FormHelper(self)
self.helper.disable_csrf = True
self.helper.form_tag = False
Expand Down
40 changes: 40 additions & 0 deletions weblate/static/js/accounts/profile/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright © Michal Čihař <[email protected]>
//
// SPDX-License-Identifier: GPL-3.0-or-later

$(document).ready(() => {
const $profileNotificationSettings = $("#notifications");
const $container = $profileNotificationSettings.find("#div_id_watched");
// Make elements link-like except click behavior
makeElementsLinkLike($container);
// Watch the container when elements are added and removed
const watchedContainerMutationObserver = new MutationObserver(() => {
makeElementsLinkLike($container);
});

watchedContainerMutationObserver.observe($container[0], {
childList: true,
subtree: true,
});

/**
* Iterate over all 'a' elements in parentElement, and if the element has
* 'data-value' attribute, change its `href` to point to project page, and
* prevent default click action.
*
* @param {Object} parentElement - The parent element to search for 'a'
* elements.
*/
function makeElementsLinkLike(parentElement) {
parentElement.find("a").each((_index, element) => {
const $element = $(element);
const dataValue = $element.attr("data-value");
if (dataValue) {
// Encode the data value to prevent unsafe HTML injection
const safeDataValue = encodeURIComponent(dataValue); // Encode the value
$element.attr("href", `/projects/${safeDataValue}`);
$element.on("click", (event) => event.preventDefault());
}
});
}
});
10 changes: 10 additions & 0 deletions weblate/templates/accounts/profile.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{% extends "base.html" %}

{% load compress %}
{% load i18n %}
{% load static %}
{% load translations %}
{% load authnames %}
{% load crispy_forms_tags %}
{% load icons %}
{% load otp_webauthn %}

{% block extra_script %}
{% compress js %}
<script defer
data-cfasync="false"
src="{% static 'js/accounts/profile/index.js' %}{{ cache_param }}"></script>
{% endcompress %}
{% endblock %}

{% block breadcrumbs %}
<li>
<a href="{% url 'profile' %}">{% trans "Your profile" %}</a>
Expand Down
Loading