Skip to content

Commit

Permalink
Merge pull request #2899 from leeagustin/deprecate-LogoutButton
Browse files Browse the repository at this point in the history
Deprecate LogoutButton
  • Loading branch information
T4rk1n authored Sep 5, 2024
2 parents 376599e + 6bd822e commit 092464f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from dash.exceptions import PreventUpdate
from dash import Dash, Input, Output, dcc, html
import flask
import pytest
import time


def test_llgo001_location_logout(dash_dcc):
@pytest.mark.parametrize("add_initial_logout_button", [False, True])
def test_llgo001_location_logout(dash_dcc, add_initial_logout_button):
app = Dash(__name__)

@app.server.route("/_logout", methods=["POST"])
Expand All @@ -13,9 +15,14 @@ def on_logout():
rep.set_cookie("logout-cookie", "", 0)
return rep

app.layout = html.Div(
[html.H2("Logout test"), dcc.Location(id="location"), html.Div(id="content")]
)
layout_children = [
html.H2("Logout test"),
dcc.Location(id="location"),
html.Div(id="content"),
]
if add_initial_logout_button:
layout_children.append(dcc.LogoutButton())
app.layout = html.Div(layout_children)

@app.callback(Output("content", "children"), [Input("location", "pathname")])
def on_location(location_path):
Expand All @@ -33,15 +40,19 @@ def _insert_cookie(rep):

return dcc.LogoutButton(id="logout-btn", logout_url="/_logout")

dash_dcc.start_server(app)
time.sleep(1)
dash_dcc.percy_snapshot("Core Logout button")
with pytest.warns(
DeprecationWarning,
match="The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A.",
):
dash_dcc.start_server(app)
time.sleep(1)
dash_dcc.percy_snapshot("Core Logout button")

assert dash_dcc.driver.get_cookie("logout-cookie")["value"] == "logged-in"
assert dash_dcc.driver.get_cookie("logout-cookie")["value"] == "logged-in"

dash_dcc.wait_for_element("#logout-btn").click()
dash_dcc.wait_for_text_to_equal("#content", "Logged out")
dash_dcc.wait_for_element("#logout-btn").click()
dash_dcc.wait_for_text_to_equal("#content", "Logged out")

assert not dash_dcc.driver.get_cookie("logout-cookie")
assert not dash_dcc.driver.get_cookie("logout-cookie")

assert dash_dcc.get_logs() == []
assert dash_dcc.get_logs() == []
19 changes: 19 additions & 0 deletions dash/_validate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
from collections import defaultdict
from collections.abc import MutableSequence
import re
import warnings
from textwrap import dedent
from keyword import iskeyword
import flask
Expand Down Expand Up @@ -422,6 +424,21 @@ def validate_layout(layout, layout_value):
component_ids = set()

def _validate(value):
def _validate_type(comp):
deprecated_components = defaultdict(lambda: defaultdict(dict))
deprecated_components["dash_core_components"][
"LogoutButton"
] = """
The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A.
eg: html.A(href=os.getenv('DASH_LOGOUT_URL'))
"""

_type = getattr(comp, "_type", "")
_ns = getattr(comp, "_namespace", "")
deprecation_message = deprecated_components[_ns][_type]
if deprecation_message:
warnings.warn(dedent(deprecation_message), DeprecationWarning)

def _validate_id(comp):
component_id = stringify_id(getattr(comp, "id", None))
if component_id and component_id in component_ids:
Expand All @@ -432,9 +449,11 @@ def _validate_id(comp):
)
component_ids.add(component_id)

_validate_type(value)
_validate_id(value)

for component in value._traverse(): # pylint: disable=protected-access
_validate_type(component)
_validate_id(component)

if isinstance(layout_value, (list, tuple)):
Expand Down

0 comments on commit 092464f

Please sign in to comment.