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

Add organization settings #3324

Merged
merged 24 commits into from Mar 10, 2021
Merged

Add organization settings #3324

merged 24 commits into from Mar 10, 2021

Conversation

Twixes
Copy link
Collaborator

@Twixes Twixes commented Feb 12, 2021

Changes

This reworks Organization Members to more robust Organization Settings.

Screen Shot 2021-02-12 at 12 34 58

Checklist

  • All querysets/queries filter by Organization, by Team, and by User
  • Django backend tests

@timgl timgl temporarily deployed to posthog-org-settings-y314lbpj1 February 12, 2021 11:40 Inactive
@Twixes Twixes temporarily deployed to posthog-org-settings-y314lbpj1 February 12, 2021 14:10 Inactive
@Twixes Twixes temporarily deployed to posthog-org-settings-y314lbpj1 February 12, 2021 19:32 Inactive
@paolodamico paolodamico mentioned this pull request Feb 15, 2021
4 tasks
@Twixes Twixes temporarily deployed to posthog-org-settings-y314lbpj1 February 17, 2021 13:55 Inactive
@Twixes Twixes had a problem deploying to posthog-org-settings-y314lbpj1 February 17, 2021 14:15 Failure
@Twixes Twixes temporarily deployed to posthog-org-settings-y314lbpj1 February 17, 2021 14:28 Inactive
@Twixes Twixes marked this pull request as ready for review February 26, 2021 15:16
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.

❤️ , fixed merge conflicts & cypress tests. Some minor comments but otherwise good to go.

  • This looks confusing when you don't have any invites, I'd add some empty state here.

)
self.assertEqual(response.status_code, 400)
self.assertTrue(Organization.objects.filter(id=org_id).exists())
self.assertEqual(response.status_code, 204)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we can now leave the user, organization-less, maybe worth changing the test name here?

createOrganization: async (name: string) => await api.create('api/organizations/', { name }),
createOrganization: async (name: string) => {
const result = await api.create('api/organizations/', { name })
teamLogic.actions.loadCurrentTeam()
Copy link
Contributor

Choose a reason for hiding this comment

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

You're re-loading these endpoints, but there's still a listener that will cause a hard refresh, rendering this unused.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll keep this as we'll be moving towards not requiring a hard refresh (#3421).

createOrganizationSuccess: () => {
window.location.href = '/organization/members'
},
},
renameCurrentOrganizationSuccess: () => {
toast.success('Organization has been renamed')
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it should be a larger question than the scope of this PR, but not showing an error message when something went wrong is not good UX.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, previously we relied on automatic API error toasts, but these got slashed and now lots of places in the UI are confusing because there's no info when something goes wrong…

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we need to start doing case-by-case error handling? Not entirely sure about the best approach here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is kind of pending #3525 and our overall approach to errors. I'm still for blanket catch-and-notify, unsure what (and whether) to do here.

<PageHeader
title="Project Settings"
caption={`Organize your analytics within the project. These settings only apply to ${
currentTeam?.name ?? '–'
Copy link
Contributor

Choose a reason for hiding this comment

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

how about a more applicable placeholder, "the current project"?

posthog/api/organization.py Outdated Show resolved Hide resolved
if (minimumAccessLevel === OrganizationMembershipLevel.Owner) {
return 'This area is restricted to the organization owner.'
}
return `This area is restricted to organization ${OrganizationMembershipLevel[minimumAccessLevel]}s and up. Your level is only ${currentOrganization.membership_level}.`
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: think I would drop the only, maybe sounds a bit aggressive?

@Twixes Twixes requested a review from paolodamico March 9, 2021 11:45
@Twixes
Copy link
Collaborator Author

Twixes commented Mar 9, 2021

How about this empty state?
empty-invites
Up for re-review @paolodamico.

@Twixes Twixes temporarily deployed to posthog-org-settings-jqqv4q6a6 March 9, 2021 14:11 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.

Some more feedback, feel free to disregard if you don't think it's useful.

  • Tried deleting a project, got this server error.
django.db.utils.IntegrityError: update or delete on table "posthog_team" violates foreign key constraint "posthog_elementgroup_team_id_3ced0286_fk_posthog_team_id" on table "posthog_elementgroup"
  • In terms of UX when you're deleting a project. After you click on delete, the buttons stay enabled and the modal can be dismissed. The toast says project is being deleted but then I get no confirmation. Further, if something went wrong I get no error message, the app just freezes there.
  • The new avatar image on invites shows a ? (presumably because first name is not set), we could use the email as a fallback.

else:
potential_err_message = f"Somehow did not delete the org as a level {level} (which is owner)"
self.assertEqual(response.status_code, 204, potential_err_message)
self.assertTrue(self.organization.name, "Woof")
Copy link
Contributor

Choose a reason for hiding this comment

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

If the organization is deleted, it shouldn't exist. I think you need to assert that the object does not exist in the DB (filtering by pk). As an alternative you can assertRaises calling object.refresh_from_db()


self.assertEqual(response_bis.status_code, 404, "Did not return a 404 on trying to delete a nonexistent org")

def test_no_delete_organization_not_owning(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would separate this into two tests, or remove the owner case altogether, makes the code confusing, and besides if the order of levels changes and owner is not last, this will lead to weird results.

self.assertTrue(self.organization.name, self.CONFIG_ORGANIZATION_NAME)
else:
potential_err_message = f"Somehow did not delete the org as a level {level} (which is owner)"
self.assertEqual(response.status_code, 204, potential_err_message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth asserting that elements that should be cascade-deleted are removed too (e.g. OrgnizationMemberships). Also, assert elements that should not be deleted (e.g. Users)

okType: 'danger',
okButtonProps: {
// @ts-expect-error - data-attr works just fine despite not being in ButtonProps
'data-attr': 'delete-organization-ok',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's worth adding a custom event when an organization is deleted, we could include too number of projects, members, persons, and events?

Copy link
Collaborator Author

@Twixes Twixes Mar 10, 2021

Choose a reason for hiding this comment

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

Alright, used get_analytics_metadata for this. Without events though, as they are more difficult to compute across Postgres and CH.

@timgl timgl temporarily deployed to posthog-org-settings-jqqv4q6a6 March 10, 2021 01:24 Inactive
@Twixes Twixes temporarily deployed to posthog-org-settings-jqqv4q6a6 March 10, 2021 11:54 Inactive
@Twixes
Copy link
Collaborator Author

Twixes commented Mar 10, 2021

Addressed all. I'll go ahead and merge. :)

@Twixes Twixes merged commit e50d591 into master Mar 10, 2021
@Twixes Twixes deleted the org-settings branch March 10, 2021 12:09
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.

None yet

3 participants