Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only show repo sign off button to permissioned users #4541

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

Jongmassey
Copy link
Contributor

bug: workspaces with private repos will show the "admin section" to all users regardless of their permissions.

cause: the display logic is to check that the repo is private OR the user has one of two relevant permissions.

fix: this changes the display logic to check that the repo is private AND the user has one of two relevant permissions.

@Jongmassey Jongmassey force-pushed the Jongmassey/fix-workspace-repo-button-bug branch from 808ca6e to aef123b Compare August 15, 2024 11:13
@Jongmassey
Copy link
Contributor Author

before:

image

after:

image

jobserver/views/workspaces.py Show resolved Hide resolved
jobserver/views/workspaces.py Outdated Show resolved Hide resolved
bug: workspaces with private repos will show the "admin section" to all
users regardless of their permissions.

cause: the display logic is to check that the repo is private OR the
user has one of two relevant permissions.

fix: this changes the display logic to check only that the user has one
of two relevant permissions.
The template contains logic to only display the repo visibility change
button for private repos so it is not needed in the view.
@Jongmassey Jongmassey force-pushed the Jongmassey/fix-workspace-repo-button-bug branch from 76652a4 to 6ee97a8 Compare August 15, 2024 16:50
Copy link
Contributor

@StevenMaude StevenMaude left a comment

Choose a reason for hiding this comment

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

I think this is fine; I had a couple of other suggestions around the tests to consider.

project_membership(
project=project,
user=user,
roles=[role_factory(permission=permissions.workspace_archive)],
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Another possible condition that will result in show_admin is permissions.workspace_toggle_notifications being enabled, which might also be worth testing.

Comment on lines +51 to +56
# this is what defines "private"
class AnotherFakeGitHubAPI:
def get_repo_is_private(self, owner, name):
return name.startswith("private")


Copy link
Contributor

Choose a reason for hiding this comment

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

👍

show_admin = (
can_archive_workspace or repo_is_private or can_toggle_notifications
)
show_admin = can_archive_workspace or can_toggle_notifications
Copy link
Contributor

Choose a reason for hiding this comment

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

thought: I have a very limited understanding of roles and permissions. But, if I look at the current roles.py, it looks as if only ProjectDeveloper has either of workspace_archive or workspace_toggle_notifications. No other role does.

It does seem a little messy that we're checking for either of these two permissions instead of a single role. But I guess that type of duplication could be cleaned up in the forthcoming work on improving roles and permissions.

(It's fine to leave this for now; it's more a general observation on the current state of roles and permissions.)

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 had similar thoughts and backed out of any major changes on the basis we're taking a more holistic look at this and it's likely to change more majorly quite soon

Comment on lines +492 to +495
# a workspace with a "private" repo
workspace = WorkspaceFactory(
project=project, repo=RepoFactory(url="http://example.com/repo/private1")
)
Copy link
Contributor

@StevenMaude StevenMaude Aug 15, 2024

Choose a reason for hiding this comment

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

thought: Without actually trying anything out, I think that regardless of the repository being private or public, it shouldn't make any difference in the test to whether show_admin is enabled — which is what we're testing. That is, the outcome of the test is now primarily based on the user's permissions.

Where we would see a difference between a private and public repository is in the rendered template, where the visibility button will appear for private repositories.

(I'm not too sure how much we favour testing content of rendered templates. Though, we do test a rendered template elsewhere in these tests though.)

@Jongmassey Jongmassey merged commit a288e11 into main Aug 15, 2024
8 checks passed
@Jongmassey Jongmassey deleted the Jongmassey/fix-workspace-repo-button-bug branch August 15, 2024 17:49
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.

2 participants