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

[FEATURE] Add testing mode and test users for developing locally and in workspaces #39

Open
celia-lm opened this issue Aug 29, 2024 · 1 comment

Comments

@celia-lm
Copy link

celia-lm commented Aug 29, 2024

Something like this:

import dash_enterprise_auth as auth

auth.dev(
    development=True, # or os.environ.get("DASH_ENTERPRISE_ENV", "WORKSPACE")=="WORKSPACE"
    test_users=[
        {"username":"john", "groups":["/marketing"]},
        {"username":"lisa", "groups":["/marketing", "/interns"]},
        {"username":"tim", "groups":["/hr", "/interns"]},
    ],
    active_user="lisa"
    )

# when user runs auth.get_user_data(), something like this gets run in the background:
# https://github.com/plotly/dash-enterprise-auth/blob/main/dash_enterprise_auth/__init__.py#L104
if auth.dev.get("development"):
    return auth.dev.active_user
    #return auth.dev.test_users.get(auth.dev.active_user)

People who have requested this:

  • ZD ticket 15992
  • ZD ticket 16214
@celia-lm
Copy link
Author

Workaround?

import dash_enterprise_auth as auth

class DevAuth:
    def __init__(self, test_users, active_user):
        self.test_users = test_users
        self.active_user = active_user

    def get_user_data(self):
        return self.test_users.get(self.active_user)

    def get_username(self):
        return self.active_user


DEV = False

if DEV:
# you can also create another condition 
    auth = DevAuth(
        test_users={
            "john":{"username":"john", "groups":["/marketing"]},
            "lisa":{"username":"lisa", "groups":["/marketing", "/interns"]},
            "tim":{"username":"tim", "groups":["/hr", "/interns"]},
        },
        active_user="lisa"
    )

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

No branches or pull requests

1 participant