superset icon indicating copy to clipboard operation
superset copied to clipboard

superset fab list-users return username, email, role but not firstname, lastname, active

Open xavier-GitHub76 opened this issue 1 year ago • 1 comments

Bug description

Hello,

superset fab list-users list all users on the database but all colums are not returned. image

username, email, role are listed but not firstname, lastname, active

colums in database are : image

Best regards

How to reproduce the bug

superset fab list-users

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [ ] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [ ] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

xavier-GitHub76 avatar May 24 '24 09:05 xavier-GitHub76

The superset fab list-users command does not include the firstname, lastname, and active columns in its output because these columns are not specified in the list_columns attribute of the UserModelView class. The list_columns attribute determines which columns are displayed when listing users.

To include the firstname, lastname, and active columns in the output, you need to modify the UserModelView class to specify these columns in the list_columns attribute. Here is an example of how you can do this:

from flask_appbuilder import ModelView
from flask_appbuilder.security.sqla.models import User

class CustomUserModelView(ModelView):
    datamodel = SQLAInterface(User)
    list_columns = ["id", "username", "firstname", "lastname", "active", "email"]

appbuilder.add_view(
    CustomUserModelView,
    "List Users",
    icon="fa-user",
    label=_("List Users"),
    category="Security",
    category_icon="fa-cogs",
)

By adding the firstname, lastname, and active columns to the list_columns attribute, they will be included in the output of the superset fab list-users command [1].

Details

About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar May 24 '24 09:05 dosubot[bot]

@dosu where the superset fab list-users command is defined ?

xavier-GitHub76 avatar May 29 '24 09:05 xavier-GitHub76

The superset fab list-users command is implemented in the superset/cli/fab.py file. The entry point for the CLI is the superset function in the superset/cli/main.py file, which dynamically adds sub-commands from the superset.cli package, including the list-users command.

Here is a snippet showing how sub-commands are added:

# superset/cli/main.py
@click.group(
    cls=FlaskGroup,
    context_settings={"token_normalize_func": normalize_token},
)
@with_appcontext
def superset() -> None:
    """\033[1;37mThe Apache Superset CLI\033[0m"""
    @app.shell_context_processor
    def make_shell_context() -> dict[str, Any]:
        return {"app": app, "db": db}

# add sub-commands
for load, module_name, is_pkg in pkgutil.walk_packages(
    cli.__path__, cli.__name__ + "."
):
    module = importlib.import_module(module_name)
    for attribute in module.__dict__.values():
        if isinstance(attribute, (click.core.Command, click.core.Group)):
            superset.add_command(attribute)

            if isinstance(attribute, click.core.Group):
                break

This setup allows the superset CLI to include various sub-commands defined in the superset.cli package [1].

Details

About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar May 29 '24 09:05 dosubot[bot]

@dosu I find superset/cli/main.py file but not superset/cli/fab.py file

xavier-GitHub76 avatar May 29 '24 09:05 xavier-GitHub76

It appears there might be some confusion or outdated information regarding the file structure. The list-users command and its related functionalities might be located in a different file or have been refactored.

To locate the exact implementation of the list-users command, you can search for the command definition within the superset/cli directory. Look for files that define CLI commands using the click library, as this is commonly used for command-line interfaces in Python.

If you need to modify the output of the list-users command to include firstname, lastname, and active columns, you can refer to the UserResponseSchema class in the superset/views/users/schemas.py file, which already includes these fields:

class UserResponseSchema(Schema):
    id = Integer()
    username = String()
    email = String()
    first_name = String()
    last_name = String()
    is_active = Boolean()
    is_anonymous = Boolean()

Additionally, the bootstrap_user_data function in the superset/views/utils.py file can be used to fetch these details:

def bootstrap_user_data(user: User, include_perms: bool = False) -> dict[str, Any]:
    payload = {
        "username": user.username,
        "firstName": user.first_name,
        "lastName": user.last_name,
        "isActive": user.is_active,
        "isAnonymous": user.is_anonymous,
    }
    return payload

These utilities can help you extend the list-users command to include the desired columns [1][2].

Details

About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar May 29 '24 09:05 dosubot[bot]

@dpgaspar might know if this is a bug or intentional by design for some reason.

rusackas avatar May 29 '24 17:05 rusackas

Is this still the case in 4.1.1? I seem to recall a PR that added some of these fields, but I haven't gone to check yet.

rusackas avatar Mar 20 '25 22:03 rusackas

It's present on 5.0.0RC1

Image

xavier-GitHub76 avatar Mar 26 '25 10:03 xavier-GitHub76