Warehouse: [Project-scoped API tokens] aren't available to maintainers

Created on 25 Jul 2019  路  4Comments  路  Source: pypa/warehouse

Describe the bug

When I use a "bot" account with "Maintainer" level access to projects, there are no projects to select from in the form for the token creation.

Expected behavior

Since this "bot" can upload dists using user/password auth, it should also have similar privileges set when using tokens.

To Reproduce

Go to https://pypi.org/manage/account/token and try selecting a project where you have only "Maintainer"-level access, not "Owner".

My Platform

N/A

Additional context

N/A

bug raised in user testing tokens

All 4 comments

Yup, I can confirm this. If I am logged in as a user who has maintainer-level collaborator status on a project, that project does not appear in the Scope dropdown list at manage/account/token/.

This is a bug IMO and we should fix it before further publicizing the feature (per rollout tracked in #5661).

Thanks for finding and reporting this bug @webknjaz! :trophy:

Hmm, yeah, this is probably just a matter of how/which projects we iterate over for the user.

I'll check this out, thanks @webknjaz!

just a matter of how/which projects we iterate over

That's my guess too.

Yeah, here's the root-cause: We use the user_projects helper in manage/views.py, which returns projects based on just ownership:

def user_projects(request):
    """ Return all the projects for which the user is a sole owner """
    projects_owned = (
        request.db.query(Project.id)
        .join(Role.project)
        .filter(Role.role_name == "Owner", Role.user == request.user)
        .subquery()
    )

    with_sole_owner = (
        request.db.query(Role.project_id)
        .join(projects_owned)
        .filter(Role.role_name == "Owner")
        .group_by(Role.project_id)
        .having(func.count(Role.project_id) == 1)
        .subquery()
    )

    return {
        "projects_owned": (
            request.db.query(Project)
            .join(projects_owned, Project.id == projects_owned.c.id)
            .order_by(Project.name)
            .all()
        ),
        "projects_sole_owned": (
            request.db.query(Project).join(with_sole_owner).order_by(Project.name).all()
        ),
    }

We could either amend that helper to include a sub-dict for maintainer roles as well, or add a new helper just for macaroons that returns just project names for those two roles.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gautamkrishnar picture gautamkrishnar  路  4Comments

mahmoud picture mahmoud  路  4Comments

ewjoachim picture ewjoachim  路  3Comments

nlhkabu picture nlhkabu  路  4Comments

Lawouach picture Lawouach  路  3Comments