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

Waffles Part 1: Import config waffles to django waffles 🧇 #15195

Merged
merged 1 commit into from
Oct 2, 2024
Merged
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
29 changes: 29 additions & 0 deletions bedrock/base/management/commands/import_waffle_switches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

from django.core.management.base import BaseCommand

from waffle.models import Switch

from bedrock.base.models import ConfigValue
from bedrock.utils.management.decorators import alert_sentry_on_exception


@alert_sentry_on_exception
class Command(BaseCommand):
def handle(self, *args, **options):
prefix = "SWITCH_"

for config in ConfigValue.objects.all():
# Ignore funnelcakes and other yummy things.
if not config.name.startswith(prefix):
continue
Comment on lines +19 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove mention of funnalcakes here?


# Remove prefix.
name = config.name[len(prefix) :]
# Set active to boolean.
active = config.value == "on"

switch, created = Switch.objects.update_or_create(name=name, defaults={"active": active})
print(f"{'Created new' if created else 'Updated'} switch: {name} = {'on' if active else 'off'}")
27 changes: 1 addition & 26 deletions bedrock/firefox/firefox_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

# coding=utf-8

import re
from collections import OrderedDict
from operator import itemgetter
from urllib.parse import urlencode

from django.conf import settings

from everett.manager import ListOf
from product_details import ProductDetails

from bedrock.base.waffle import config


# TODO: port this to django-mozilla-product-details
class _ProductDetails(ProductDetails):
Expand Down Expand Up @@ -225,8 +220,6 @@ def get_download_url(
locale,
force_direct=False,
force_full_installer=False,
force_funnelcake=False,
funnelcake_id=None,
locale_in_transition=False,
):
"""
Expand All @@ -239,9 +232,6 @@ def get_download_url(
always True for non-release URLs.
:param force_full_installer: Force the installer download to not be
the stub installer (for aurora).
:param force_funnelcake: Force the download version for en-US Windows to be
'latest', which bouncer will translate to the funnelcake build.
:param funnelcake_id: ID for the the funnelcake build.
:param locale_in_transition: Include the locale in the transition URL
:return: string url
"""
Expand All @@ -253,29 +243,18 @@ def get_download_url(
force_direct = True if channel != "release" else force_direct
stub_platforms = ["win", "win64"]
esr_channels = ["esr", "esr_next"]
include_funnelcake_param = False

# support optional MSI installer downloads
# bug 1493205
is_msi = platform.endswith("-msi")
if is_msi:
platform = platform[:-4]

# Bug 1345467 - Only allow specifically configured funnelcake builds
if funnelcake_id:
fc_platforms = config(f"FUNNELCAKE_{funnelcake_id}_PLATFORMS", default="", parser=ListOf(str))
fc_locales = config(f"FUNNELCAKE_{funnelcake_id}_LOCALES", default="", parser=ListOf(str))
include_funnelcake_param = platform in fc_platforms and _locale in fc_locales

# Check if direct download link has been requested
# if not just use transition URL
if not force_direct:
# build a link to the transition page
transition_url = self.download_base_url_transition
if funnelcake_id:
# include funnelcake in scene 2 URL
transition_url += f"?f={funnelcake_id}"

if locale_in_transition:
transition_url = f"/{locale}{transition_url}"

Expand All @@ -294,11 +273,7 @@ def get_download_url(
prod_name = "firefox-esr-next"
elif platform in stub_platforms and not is_msi and not force_full_installer:
# Use the stub installer for approved platforms
# append funnelcake id to version if we have one
if include_funnelcake_param:
suffix = f"stub-f{funnelcake_id}"
else:
suffix = "stub"
suffix = "stub"
elif channel == "nightly" and locale != "en-US":
# Nightly uses a different product name for localized builds,
# and is the only one ಠ_ಠ
Expand Down
25 changes: 4 additions & 21 deletions bedrock/firefox/templatetags/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ def desktop_builds(
locale=None,
force_direct=False,
force_full_installer=False,
force_funnelcake=False,
funnelcake_id=False,
locale_in_transition=False,
classified=False,
):
Expand Down Expand Up @@ -65,8 +63,6 @@ def desktop_builds(
locale,
force_direct=force_direct,
force_full_installer=force_full_installer,
force_funnelcake=force_funnelcake,
funnelcake_id=funnelcake_id,
locale_in_transition=locale_in_transition,
)

Expand All @@ -83,8 +79,6 @@ def desktop_builds(
locale,
force_direct=True,
force_full_installer=force_full_installer,
force_funnelcake=force_funnelcake,
funnelcake_id=funnelcake_id,
)
if download_link_direct == download_link:
download_link_direct = False
Expand Down Expand Up @@ -120,7 +114,6 @@ def download_firefox(
locale=None,
force_direct=False,
force_full_installer=False,
force_funnelcake=False,
alt_copy=None,
button_class="mzp-t-xl",
locale_in_transition=False,
Expand All @@ -136,8 +129,6 @@ def download_firefox(
:param force_direct: Force the download URL to be direct.
:param force_full_installer: Force the installer download to not be
the stub installer (for aurora).
:param force_funnelcake: Force the download version for en-US Windows to be
'latest', which bouncer will translate to the funnelcake build.
:param alt_copy: Specifies alternate copy to use for download buttons.
:param button_class: Classes to add to the download button, contains size mzp-t-xl by default
:param locale_in_transition: Include the page locale in transitional download link.
Expand All @@ -149,15 +140,14 @@ def download_firefox(
show_ios = platform in ["all", "ios"]
alt_channel = "" if channel == "release" else channel
locale = locale or get_locale(ctx["request"])
funnelcake_id = ctx.get("funnelcake_id", False)
dom_id = dom_id or f"download-button-{'desktop' if platform == 'all' else platform}-{channel}"

# Gather data about the build for each platform
builds = []

if show_desktop:
version = firefox_desktop.latest_version(channel)
builds = desktop_builds(channel, builds, locale, force_direct, force_full_installer, force_funnelcake, funnelcake_id, locale_in_transition)
builds = desktop_builds(channel, builds, locale, force_direct, force_full_installer, locale_in_transition)

if show_android:
version = firefox_android.latest_version(channel)
Expand Down Expand Up @@ -208,16 +198,10 @@ def download_firefox_thanks(ctx, dom_id=None, locale=None, alt_copy=None, button

channel = "release"
locale = locale or get_locale(ctx["request"])
funnelcake_id = ctx.get("funnelcake_id", False)
dom_id = dom_id or "download-button-thanks"
transition_url = "/firefox/download/thanks/"
version = firefox_desktop.latest_version(channel)

# if there's a funnelcake param in the page URL e.g. ?f=123
if funnelcake_id:
# include param in transitional URL e.g. /firefox/download/thanks/?f=123
transition_url += f"?f={funnelcake_id}"

if locale_in_transition:
transition_url = f"/{locale}{transition_url}"

Expand All @@ -228,8 +212,6 @@ def download_firefox_thanks(ctx, dom_id=None, locale=None, alt_copy=None, button
locale,
force_direct=True,
force_full_installer=False,
force_funnelcake=False,
funnelcake_id=funnelcake_id,
)

data = {
Expand Down Expand Up @@ -262,8 +244,9 @@ def download_firefox_desktop_list(ctx, channel="release", dom_id=None, locale=No
dom_id = dom_id or f"download-platform-list-{channel}"
locale = locale or get_locale(ctx["request"])

# Make sure funnelcake_id is not passed as builds are often Windows only.
builds = desktop_builds(channel, None, locale, True, force_full_installer, False, False, False, True)
builds = desktop_builds(
channel, builds=None, locale=locale, force_direct=True, force_full_installer=force_full_installer, locale_in_transition=False, classified=True
)

recommended_builds = []
traditional_builds = []
Expand Down
86 changes: 0 additions & 86 deletions bedrock/firefox/tests/test_firefox_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,28 +655,6 @@ def test_get_download_url_nightly_l10n(self):
],
)

def test_get_download_url_scene2_funnelcake(self):
scene2 = self.firefox_desktop.download_base_url_transition
url = self.firefox_desktop.get_download_url("release", "45.0", "win", "en-US")
self.assertEqual(url, scene2)
url = self.firefox_desktop.get_download_url("release", "45.0", "win", "en-US", funnelcake_id="64")
self.assertEqual(url, scene2 + "?f=64")

def test_get_download_url_scene2_with_locale(self):
scene2 = self.firefox_desktop.download_base_url_transition
url = self.firefox_desktop.get_download_url("release", "45.0", "win", "de", locale_in_transition=True)
self.assertEqual(url, "/de" + scene2)

url = self.firefox_desktop.get_download_url(
"release",
"45.0",
"win",
"fr",
locale_in_transition=True,
funnelcake_id="64",
)
self.assertEqual(url, "/fr" + scene2 + "?f=64")

def get_download_url_ssl(self):
"""
SSL-enabled links should always be used except Windows stub installers.
Expand Down Expand Up @@ -810,70 +788,6 @@ def test_latest_major_version_no_int(self):
):
assert self.firefox_desktop.latest_major_version("release") == 0

@patch.dict(os.environ, FUNNELCAKE_64_LOCALES="en-US", FUNNELCAKE_64_PLATFORMS="win")
def test_funnelcake_direct_links_en_us_win_only(self):
"""
Ensure funnelcake params are included for Windows en-US builds only.
"""
url = self.firefox_desktop.get_download_url("release", "45.0", "win", "en-US", force_direct=True, funnelcake_id="64")
assert "product=firefox-stub-f64" in url

url = self.firefox_desktop.get_download_url("release", "45.0", "win64", "en-US", force_direct=True, funnelcake_id="64")
assert "product=firefox-stub-f64" not in url

url = self.firefox_desktop.get_download_url("release", "45.0", "win", "de", force_direct=True, funnelcake_id="64")
assert "product=firefox-stub-f64" not in url

url = self.firefox_desktop.get_download_url("release", "45.0", "osx", "en-US", force_direct=True, funnelcake_id="64")
assert "product=firefox-stub-f64" not in url

def test_no_funnelcake_direct_links_if_not_configured(self):
"""
Ensure funnelcake params are included for Linux and OSX en-US builds only.
"""
url = self.firefox_desktop.get_download_url("release", "45.0", "win", "en-US", force_direct=True, funnelcake_id="64")
assert "-f64" not in url

url = self.firefox_desktop.get_download_url(
"release",
"45.0",
"win",
"en-US",
force_direct=True,
force_full_installer=True,
funnelcake_id="64",
)
assert "-f64" not in url

url = self.firefox_desktop.get_download_url(
"release",
"45.0",
"win",
"en-US",
force_direct=True,
force_funnelcake=True,
funnelcake_id="64",
)
assert "-f64" not in url

url = self.firefox_desktop.get_download_url("release", "45.0", "osx", "de", force_direct=True, funnelcake_id="64")
assert "-f64" not in url

url = self.firefox_desktop.get_download_url("release", "45.0", "osx", "en-US", force_direct=True, funnelcake_id="64")
assert "-f64" not in url

url = self.firefox_desktop.get_download_url("release", "45.0", "osx", "fr", force_direct=True, funnelcake_id="64")
assert "-f64" not in url

url = self.firefox_desktop.get_download_url("release", "45.0", "linux", "de", force_direct=True, funnelcake_id="64")
assert "-f64" not in url

url = self.firefox_desktop.get_download_url("release", "45.0", "linux", "en-US", force_direct=True, funnelcake_id="64")
assert "-f64" not in url

url = self.firefox_desktop.get_download_url("release", "45.0", "linux", "fr", force_direct=True, funnelcake_id="64")
assert "-f64" not in url

def test_stub_installer_win_only(self):
"""
Ensure that builds not in the setting don't get stub.
Expand Down
17 changes: 0 additions & 17 deletions bedrock/mozorg/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from datetime import datetime

from django.conf import settings
from django.urls import reverse

# match 1 - 4 digits only
FC_RE = re.compile(r"^\d{1,4}$")
Expand All @@ -26,21 +25,5 @@ def current_year(request):
return {"current_year": datetime.today().year}


def funnelcake_param(request):
"""If a query param for a funnelcake is sent, add it to the context."""
fc_id = request.GET.get("f", None)
context = {}

if fc_id and FC_RE.match(fc_id):
# special case for installer-help page
# bug 933852
installer_help_url = reverse("firefox.installer-help")
if installer_help_url in request.path_info:
fc_id = str(int(fc_id) + 1)
context["funnelcake_id"] = fc_id

return context


def contrib_numbers(request):
return settings.CONTRIBUTE_NUMBERS
43 changes: 0 additions & 43 deletions bedrock/mozorg/tests/test_context_processors.py

This file was deleted.

Loading