Skip to content

Grant the project creator an owner role on creation - #660

Open
silentsudo-io wants to merge 1 commit into
MerginMaps:masterfrom
silentsudo-io:fix/grant-creator-owner-role
Open

Grant the project creator an owner role on creation#660
silentsudo-io wants to merge 1 commit into
MerginMaps:masterfrom
silentsudo-io:fix/grant-creator-owner-role

Conversation

@silentsudo-io

Copy link
Copy Markdown

Fixes #659.

The problem

add_project() never grants the creator a role, so a new project ends up with no rows in project_member at all. Two consequences:

  1. Sharing is broken. With no roles on the project, the Collaborators page has nothing to work with and the owner cannot add anyone — including themselves. This was the presenting symptom on our self-hosted CE server.
  2. With GLOBAL_ADMIN=True, the creator cannot see their own project. GlobalWorkspaceHandler.get_user_role() returns GUEST for non-superusers, and a GUEST reaches a project only via project_member or Project.public. So projects_query(ProjectPermissions.Read) filters the project out before the flag=created creator test is reached — GET /v1/project/paginated?flag=created returns count=0 for the user who just created it.

The change

p.set_role(current_user.id, ProjectRole.OWNER) before the commit, in both creation paths:

  • add_project()
  • clone_project() — same omission, same effect on a cloned project

ProjectRole was already imported in the module, so this adds no imports. set_role() appends to the project_users relationship, which cascades on commit, so it works on the still-pending Project.

Notes for reviewers

  • set_role() fires project_access_granted. It will now fire for the creator on every project creation. That seemed semantically right — access was granted — but if you would rather not emit it for the creator, say so and I will restructure.
  • Existing servers stay broken without a migration. Projects already created carry no project_member rows. A data migration granting owner to creator_id where a project has no members would repair them. Happy to add one to this PR if you want it here rather than separately.
  • I have not added a test. If you would like one, point me at the preferred place and I will follow up.

Verified against

Reproduced on self-hosted CE, backend image 2025.7.3, single global workspace, GLOBAL_* all at defaults. Two projects created by two different users via two different paths (web UI and REST API) both landed with zero member rows. add_project() is structurally unchanged from 2025.7.3 through 2026.6.2, so this affects all of them.

CLA: I have added silentsudo-io to the individual CLA list in LICENSES/CLA-signed-list.md in this PR.

A newly created project gets no project_member row at all, so it has no
roles whatsoever. Two consequences:

* it cannot be shared -- the Collaborators UI has no roles to work with,
  so the owner cannot add anyone, including themselves;
* with GLOBAL_ADMIN=True, the creator cannot see their own project.
  GlobalWorkspaceHandler.get_user_role returns GUEST for non-superusers,
  and a GUEST reaches a project only via project_member or Project.public,
  so projects_query(ProjectPermissions.Read) filters it out before the
  flag=created creator test is ever reached.

Both project creation paths are affected: add_project and clone_project.
Neither called set_role. ProjectRole was already imported.

Fixes MerginMaps#659

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

Newly created project gets no project_member row — creator holds no role, sharing is impossible

1 participant