Skip to content

Conversation

@max-zilla
Copy link
Contributor

@max-zilla max-zilla commented May 6, 2024

This adds a new API parameter called force_admin that enables you to make a call as if admin_mode were enabled even if it isn't (assuming you are admin).

Currently on one endpoint:
http://localhost:8000/api/v2/groups?force_admin=True

If this is acceptable, we can include anywhere we use the get_admin_mode dependency above it:

    force_admin: bool = False,
    admin_mode: bool = Depends(get_admin_mode),

example endpoint:

http://localhost:8000/api/v2/groups?force_admin=true

will return a list of group data.

@max-zilla max-zilla requested review from lmarini and longshuicy May 6, 2024 14:09
@lmarini lmarini requested a review from a team May 13, 2024 15:51
@max-zilla
Copy link
Contributor Author

@bingzhang please add superadmin: bool = False, to all endpoints in the project that have admin_mode: bool = Depends(get_admin_mode), argument.

@ddey2
Copy link
Member

ddey2 commented May 15, 2024

the logic looks good to me. I see that the PR is in draft state. So I will wait for now.


@router.get("/users/me/admin_mode")
async def get_admin_mode(current_username=Depends(get_current_user)) -> bool:
async def get_admin_mode(
Copy link
Member

Choose a reason for hiding this comment

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

  1. Should we split the dependency from the route and put it in dependencies.py?
  2. Should we rename superadmin to admin or force_admin or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't quite understand question 1. can you say more about "split the dependency from the route"?

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to rename superadmin to force_admin, since admin has been used in admin=Depends(get_admin)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this was introduced in this PR, but fastapi dependencies don't need to be routes. More importantly this route returns just a boolean and not a JSON document, so we could separate the two and make the route return a valid JSON document. I can make the change.

@bingzhang bingzhang marked this pull request as ready for review May 29, 2024 17:06
@lmarini
Copy link
Member

lmarini commented Jun 13, 2024

@max-zilla @bingzhang can I rename force_admin to enable_admin? what do you think?

@bingzhang
Copy link
Contributor

@max-zilla @bingzhang can I rename force_admin to enable_admin? what do you think?

I am fine with enable_admin.

@max-zilla
Copy link
Contributor Author

max-zilla commented Jun 20, 2024

Resolved merge conflicts and changed to enable_admin, a few test API endpoints worked fine.

The frontend has a bug however. The API call is returning all datasets when admin mode is enabled, but for some reason they are being hidden immediately:
image

If I toggle between Datasets and My Datasets tab, i can see Fake Dataset for just a moment before it disappears. Looking into this.

Applying Todd's fix from this PR: https://github.com/clowder-framework/clowder2/pull/1104/files
fixes the main list, but also includes other datasets in the My Datasets tab. The tabs seem to be in conflict with each other.

@bingzhang
Copy link
Contributor

@max-zilla I fixed the codegen error.

@lmarini lmarini added this to the v2.0-beta-3 milestone Jun 28, 2024
Copy link
Member

@longshuicy longshuicy left a comment

Choose a reason for hiding this comment

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

The logic looks good and I tested the list all dataset endpoint, which works as expected.

When I do a project-wide search of the admin_mode, I noticed there are one spot missing enable_admin. Could you double check?

class FeedAuthorization:
    """We use class dependency so that we can provide the `permission` parameter to the dependency.
    For more info see https://fastapi.tiangolo.com/advanced/advanced-dependencies/.
    Regular users can only see their own feeds"""

    # def __init__(self, optional_arg: str = None):
    #         self.optional_arg = optional_arg

    async def __call__(
        self,
        feed_id: str,
        current_user: str = Depends(get_current_username),
        admin_mode: bool = Depends(get_admin_mode),
        admin: bool = Depends(get_admin),

@longshuicy longshuicy merged commit c88990e into main Jul 3, 2024
@longshuicy longshuicy deleted the superadmin-api-flag branch July 3, 2024 15:47
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.

6 participants