Skip to content

Commit

Permalink
fix: fix error in sidbar tabs refresh when using guest override and f…
Browse files Browse the repository at this point in the history
…ix an error in other info text

move calls to sidebar_tabs append to a dedicated function(reload_sidebar_tabs)
reload_menu now reload the sidebar
make sidebar_tabs dynamic (avoid issue whith freezed widgets when refreshing)
simplify sidebar_person_column
fix error in user_group evaluation inside the function build_stats_and_info_text (admin always evaluated to guest)
  • Loading branch information
Michele-Alberti committed Jan 2, 2024
1 parent a4ea532 commit 008c196
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
3 changes: 3 additions & 0 deletions data_lunch_app/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ def reload_menu(
id=f"{pn.state.user}_guest_override",
value_if_missing=False,
)
# Reload tabs according to auth.is_guest results and guest_override
# flag
gi.reload_sidebar_tabs(config=config)

# Guest graphic configuration
if auth.is_guest(user=pn.state.user, config=config):
Expand Down
41 changes: 24 additions & 17 deletions data_lunch_app/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,10 @@ def reload_on_no_more_order_callback(
person_text,
self.person_widget,
pn.Spacer(height=5),
self.additional_items_details,
name="User",
width=sidebar_content_width,
)
# Add salads
self.sidebar_person_column.append(
self.additional_items_details,
)
# Leave an empty widget for the 'other info' section
self.sidebar_person_column.append(
pn.pane.HTML(),
Expand Down Expand Up @@ -628,21 +625,15 @@ def reload_on_no_more_order_callback(
)

# TABS
# The person column is defined in the app factory function because lunch
# times are configurable
# The person widget is defined in the app factory function because
# lunch times are configurable
self.sidebar_tabs = pn.Tabs(
self.sidebar_person_column,
width=sidebar_content_width,
dynamic=True,
)

# Append upload, download and stats only for non-guest
# Append password only for non-guest users if auth is active
if not auth.is_guest(user=pn.state.user, config=config):
self.sidebar_tabs.append(self.sidebar_menu_upload_col)
self.sidebar_tabs.append(self.sidebar_download_orders_col)
self.sidebar_tabs.append(self.sidebar_stats_col)
if auth.is_basic_auth_active(config=config):
self.sidebar_tabs.append(self.sidebar_password)
# Reload tabs according to auth.is_guest results and guest_override
# flag
self.reload_sidebar_tabs(config=config)

# CALLBACKS
# Build menu button callback
Expand Down Expand Up @@ -718,6 +709,22 @@ def build_time_label(
return time_label

# SIDEBAR SECTION
def reload_sidebar_tabs(self, config: DictConfig):
# Clean tabs
self.sidebar_tabs.clear()
# Append User tab
self.sidebar_tabs.append(self.sidebar_person_column)
# Append upload, download and stats only for non-guest
# Append password only for non-guest users if auth is active
if not auth.is_guest(user=pn.state.user, config=config):
self.sidebar_tabs.append(self.sidebar_menu_upload_col)
self.sidebar_tabs.append(self.sidebar_download_orders_col)
self.sidebar_tabs.append(self.sidebar_stats_col)
if auth.is_basic_auth_active(config=config):
self.sidebar_tabs.append(self.sidebar_password)
# Focus to first tab
self.sidebar_tabs.active = 0

def build_stats_and_info_text(
self,
config: DictConfig,
Expand Down Expand Up @@ -749,7 +756,7 @@ def build_stats_and_info_text(
if auth.is_guest(user=user, config=config, allow_override=False):
user_group = "guest"
elif auth.is_admin(user=user, config=config):
user_group = "guest"
user_group = "admin"
else:
user_group = "user"
# Other info
Expand Down

0 comments on commit 008c196

Please sign in to comment.