### Apache Airflow version

Other Airflow 2 version (please specify below)

### What happened

Running this command to reset a password via the CLI raises an exception:

```
$ flask --app airflow.www.app fab reset-password --username myusername
Password: 
Repeat for confirmation: 
Traceback (most recent call last):
  File "/home/airflow/.local/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/home/airflow/.local/lib/python3.8/site-packages/flask/cli.py", line 1050, in main
    cli.main()
  File "/home/airflow/.local/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/airflow/.local/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/airflow/.local/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/airflow/.local/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/airflow/.local/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/flask/cli.py", line 357, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/flask_appbuilder/cli.py", line 157, in reset_password
    current_app.appbuilder.sm.reset_password(user.id, password)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/auth/managers/fab/security_manager/override.py", line 245, in reset_password
    self.reset_user_sessions(user)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/auth/managers/fab/security_manager/override.py", line 255, in reset_user_sessions
    flash(
  File "/home/airflow/.local/lib/python3.8/site-packages/flask/helpers.py", line 359, in flash
    flashes = session.get("_flashes", [])
  File "/home/airflow/.local/lib/python3.8/site-packages/werkzeug/local.py", line 316, in __get__
    obj = instance._get_current_object()
  File "/home/airflow/.local/lib/python3.8/site-packages/werkzeug/local.py", line 513, in _get_current_object
    raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of request context.

This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.
```

### What you think should happen instead

It should be possible to reset the password via the CLI. This is necessary for when you need to reset your own password without knowing your current password so you can't use the UI. I believe this means that the `reset_user_sessions` function can't unconditionally use `flash` without determining if it's running in a request context or not.

### How to reproduce

Run `flask --app airflow.www.app fab reset-password` with an existing username via the CLI.

### Operating System

Debian GNU/Linux 11 (bullseye)

### Versions of Apache Airflow Providers

_No response_

### Deployment

Official Apache Airflow Helm Chart

### Deployment details

_No response_

### Anything else

_No response_

### Are you willing to submit PR?

- [X] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)

"""Return a dict with a key of role name and value of role with early loaded permissions."""
        return {
            r.name: r
            for r in self.appbuilder.get_session.scalars(
                select(self.role_model).options(joinedload(self.role_model.permissions))
            ).unique()
        }
    def _get_all_non_dag_permissions(self) -> dict[tuple[str, str], Permission]:
        """
        Get permissions except those that are for specific DAGs.
        Returns a dict with a key of (action_name, resource_name) and value of permission
        with all permissions except those that are for specific DAGs.
        """
        return {
            (action_name, resource_name): viewmodel
            for action_name, resource_name, viewmodel in (
                self.appbuilder.get_session.execute(
                    select(self.action_model.name, self.resource_model.name, self.permission_model)
                    .join(self.permission_model.action)
                    .join(self.permission_model.resource)
                    .where(~self.resource_model.name.like(f"{permissions.RESOURCE_DAG_PREFIX}%"))
                )
            )
        }
    def filter_roles_by_perm_with_action(self, action_name: str, role_ids: list[int]):