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

FIX #18154 - Cannot change default table preferences for anonymous users #18544

Conversation

renatoalmeidaoliveira
Copy link
Contributor

Fixes: #18154

  • Change BaseTable to check if DEFAULT_USER_PREFERENCES are defined
  • Change BaseTable selected_columns behaivour to be aware of DEFAULT_USER_PREFERENCES table configuration

@@ -64,6 +66,11 @@ def __init__(self, *args, user=None, **kwargs):
selected_columns = None
if user is not None and not isinstance(user, AnonymousUser):
selected_columns = user.config.get(f"tables.{self.name}.columns")
elif isinstance(user, AnonymousUser) and hasattr(settings, 'DEFAULT_USER_PREFERENCES'):
default_user_preferences = settings.DEFAULT_USER_PREFERENCES
default_table = default_user_preferences.get('tables', {}).get(self.name, {}).get('columns', {})
Copy link
Contributor

Choose a reason for hiding this comment

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

Could probably simplify this to

selected_columns = settings.DEFAULT_USER_PREFERENCES.get('tables', {}).get(self.name, {}).get('columns')

Right? Or is there some logical case I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still need to check is settings have DEFAULT_USER_PREFERENCES attribute, my first implementation I've missed that test and a lot of unit testa fails because the DEFAULT_USER_PREFERENCES aren't a required configuration.
But the next parts is definitely simpler, gonna change to that format.

@@ -13,6 +14,7 @@
from django.utils.translation import gettext_lazy as _
from django_tables2.data import TableQuerysetData


Copy link
Contributor

Choose a reason for hiding this comment

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

This extra line should be removed

@bctiemann bctiemann merged commit 4c5fbb7 into netbox-community:main Jan 31, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot change default table preferences for anonymous users
2 participants