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

Project-based permissioning TopNavigation #6027

Merged
merged 74 commits into from
Sep 29, 2021
Merged

Project-based permissioning TopNavigation #6027

merged 74 commits into from
Sep 29, 2021

Conversation

Twixes
Copy link
Collaborator

@Twixes Twixes commented Sep 20, 2021

Changes

This adjusts TopNavigation UI for #5976 like this:

Project switcher with an allowed project and a restricted project (restricted only if project-based permissioning is available and enabled)

Screen Shot 2021-09-10 at 14 45 40

Change extracted from #5976 for clarity.

Resolves #4263 when merged with #6068.

@Twixes Twixes temporarily deployed to posthog-pr-6027 September 21, 2021 17:27 Inactive
@Twixes Twixes marked this pull request as ready for review September 21, 2021 17:32
@Twixes
Copy link
Collaborator Author

Twixes commented Sep 21, 2021

@mariusandra I want to add TopNavigation to Storybook to demonstrate this PR, but despite copying code from a story that already works (Preflight I think) and following the README, TopNavigation.stories.tsx fails with this:

Err

Do you perhaps have clue what's wrong?

@Twixes Twixes changed the title Per-project access TopNavigation Project-based permissioning TopNavigation Sep 21, 2021
@mariusandra
Copy link
Collaborator

I think if you manually mount featureFlagLogic inside resetKeaWithState in kea-story.tsx, it'll work. What seems to be happening here is that some logic somewhere is calling featureFlagLogic in an afterMount block, where things do not get auto-mounted (bug in kea I guess?). That logic is normally always mounted, so we might as well always have it here.

@Twixes Twixes temporarily deployed to posthog-pr-6027 September 22, 2021 11:44 Inactive
@Twixes
Copy link
Collaborator Author

Twixes commented Sep 22, 2021

Thanks! ❤️ Mounting featureFlagLogic does allow rendering the component (seems like an issue within navigationLogic).

However there's still a different type of issue:
Providing initial state is not useful for logics that load their data from the API after mount. And since our components (especially high-level ones like TopNavigation) are very logic-heavy, there isn't a way of just passing the data to the component. Because of this, there's no data to display in the story.

404

In Jest we have a way of mocking the fetch API – I suppose this is possible for Storybook too, but as a precaution: do we have a way of doing it already?

@mariusandra
Copy link
Collaborator

We currently don't. My undocumented plan was to extend this widget:

image

... and turn it into a practical network request recording/playback tool. Basically it would have 2-4 modes: 1) live (connect somewhere like now), 2) live, but recording every fetch - maybe even saves as a .json file in the right folder for the story? 3) playback from the live state either with recorded network requests 4), and/or with recorded state.

It should be quite easy to extend it to support this, but I haven't found the time yet.

@mariusandra
Copy link
Collaborator

Here's a HN comment by somebody else who has actually done just that, but no code to share. And here's one that's also interesting from this thread.

However, I think there's also a bug here. Normally we shouldn't load users/@me as this is passed directly from django via getAppContext. This is not properly mocked in the stories...

Base automatically changed from 4263-per-project-permissions-framework to master September 22, 2021 16:30
@Twixes Twixes temporarily deployed to posthog-pr-6027 September 22, 2021 16:59 Inactive
Copy link
Contributor

@paolodamico paolodamico left a comment

Choose a reason for hiding this comment

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

lgtm! only thing is that the component doesn't seem to be rendering correctly on Storybook

frontend/src/lib/storybook/kea-story.tsx Show resolved Hide resolved
frontend/src/layout/navigation/TopNavigation.tsx Outdated Show resolved Hide resolved
frontend/src/layout/navigation/TopNavigation.tsx Outdated Show resolved Hide resolved
@@ -251,6 +282,10 @@ export function TopNavigation(): JSX.Element {
}
)
}
style={{
cursor: isProjectCreationForbidden ? 'default' : undefined,
color: isProjectCreationForbidden ? 'var(--text-muted)' : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
color: isProjectCreationForbidden ? 'var(--text-muted)' : undefined,
color: isProjectCreationForbidden ? 'var(--text-muted)' : 'var(--primary)',

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would prefer not to, to keep consistency between "Create new project" and "Create new organization"

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need consistency among these, they're in different places, plus adding a project is probably a lot more frequent than an org. I'm also wondering if the create org should also be primary color.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alrighty, made both primary

Twixes and others added 2 commits September 23, 2021 18:13
Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

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

Had a quick look, seems fine in general. Some nits though :)

Not sure if outside this PR, but there's a "cancel" icon on the mouse even though the button works:

2021-09-28 09 39 59

<Layout>
<MainNavigation />
<Layout>
<TopNavigation />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Somehow the top-right part of the navigation disappears:
2021-09-28 09 36 59

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's because of the issue discussed in #6027 (comment)
This looks like it could somehow help, but I've no idea how to make use of it:
Screen Shot 2021-09-29 at 15 23 55

function ProjectRow({ team }: { team: TeamBasicType }): JSX.Element {
const { currentTeam } = useValues(teamLogic)
const { updateCurrentTeam } = useActions(userLogic)
const { push } = router.actions
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: This could also be a useActions(router) for consistency. Makes no real difference, as push is an action and router is always mounted, but still nit nit nit.

Twixes and others added 6 commits September 29, 2021 17:40
Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
* Fix Access Control restriction tooltip

* Add `TeamMemberAccessPermission` and use it in viewsets

* Add `ErrorProjectUnavailable` scene

* Ignore mypy

* Update MainNavigation.tsx

* Update explicit_team_member.py

* Fix frontend detection of unavailable project

* Fix some tests and edge cases

* Fix basic permissions

* Add more tests

* Simplify `ExplicitTeamMemberViewSet` permissions

* Improve restrictions and add moar tests

* Update frontend

* Fix a couple of things

* Fix import

* Fix some edge cases

* Fix typing errors

* Use hedgehog instead of moth

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>

* Address feedback

* Add proper permissioning to dashboard views

* Update ee/api/test/test_dashboard.py

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>

Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
@Twixes Twixes enabled auto-merge (squash) September 29, 2021 22:43
@Twixes Twixes merged commit 3a67367 into master Sep 29, 2021
@Twixes Twixes deleted the 4263-top-nav branch September 29, 2021 22:43
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.

Project-based permissioning
4 participants