-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add organization settings * Update test_organization.py * Fix TS issues * Improve permissioning frontend * Fix an import * minor typos * fix cypress * Make use of AnalyticsDestroyModelMixin * Solve nits * Rework Invites empty state * Update organization test * Improve organization tests and permissioning * Polish Organization Settings frontend * Improve Members UX * Use RestrictedArea in Project Settings * Fix APITestMixin._create_user * some minor copy adjustments * Use email initial in ProfilePicture * Clean up org deletion tests * Improve org/project deletion UX and reliability * Enhance org deletion test Co-authored-by: Paolo D'Amico <[email protected]>
- Loading branch information
1 parent
506d8a0
commit e50d591
Showing
28 changed files
with
524 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Tooltip } from 'antd' | ||
import { useValues } from 'kea' | ||
import React, { useMemo } from 'react' | ||
import { organizationLogic } from '../../scenes/organizationLogic' | ||
import { OrganizationMembershipLevel, organizationMembershipLevelToName } from '../constants' | ||
|
||
export interface RestrictedComponentProps { | ||
isRestricted: boolean | ||
restrictionReason: null | string | ||
} | ||
|
||
export interface RestrictedAreaProps { | ||
Component: (props: RestrictedComponentProps) => JSX.Element | ||
minimumAccessLevel: OrganizationMembershipLevel | ||
} | ||
|
||
export function RestrictedArea({ Component, minimumAccessLevel }: RestrictedAreaProps): JSX.Element { | ||
const { currentOrganization } = useValues(organizationLogic) | ||
|
||
const restrictionReason: null | string = useMemo(() => { | ||
if (!currentOrganization) { | ||
return 'Loading current organization…' | ||
} | ||
if (currentOrganization.membership_level === null) { | ||
return 'Your organization membership level is unknown.' | ||
} | ||
if (currentOrganization.membership_level < minimumAccessLevel) { | ||
if (minimumAccessLevel === OrganizationMembershipLevel.Owner) { | ||
return 'This area is restricted to the organization owner.' | ||
} | ||
return `This area is restricted to organization ${organizationMembershipLevelToName.get( | ||
minimumAccessLevel | ||
)}s and up. Your level is ${organizationMembershipLevelToName.get(currentOrganization.membership_level)}.` | ||
} | ||
return null | ||
}, [currentOrganization]) | ||
|
||
return restrictionReason ? ( | ||
<Tooltip title={restrictionReason}> | ||
<span> | ||
<Component isRestricted={true} restrictionReason={restrictionReason} /> | ||
</span> | ||
</Tooltip> | ||
) : ( | ||
<Component isRestricted={false} restrictionReason={null} /> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { useActions, useValues } from 'kea' | ||
import { DeleteOutlined } from '@ant-design/icons' | ||
import { Button, Modal } from 'antd' | ||
import { organizationLogic } from 'scenes/organizationLogic' | ||
import Paragraph from 'antd/lib/typography/Paragraph' | ||
import { RestrictedComponentProps } from '../../../lib/components/RestrictedArea' | ||
import React, { Dispatch, SetStateAction, useState } from 'react' | ||
|
||
export function DeleteOrganizationModal({ | ||
isVisible, | ||
setIsVisible, | ||
}: { | ||
isVisible: boolean | ||
setIsVisible: Dispatch<SetStateAction<boolean>> | ||
}): JSX.Element { | ||
const { currentOrganization, organizationBeingDeleted } = useValues(organizationLogic) | ||
const { deleteOrganization } = useActions(organizationLogic) | ||
|
||
const isDeletionInProgress = !!currentOrganization && organizationBeingDeleted?.id === currentOrganization.id | ||
|
||
return ( | ||
<Modal | ||
title="Delete the entire organization?" | ||
okText={`Delete ${currentOrganization ? currentOrganization.name : 'the current organization'}`} | ||
okType="danger" | ||
onOk={currentOrganization ? () => deleteOrganization(currentOrganization) : undefined} | ||
okButtonProps={{ | ||
// @ts-expect-error - data-attr works just fine despite not being in ButtonProps | ||
'data-attr': 'delete-organization-ok', | ||
loading: isDeletionInProgress, | ||
}} | ||
onCancel={() => setIsVisible(false)} | ||
cancelButtonProps={{ | ||
disabled: isDeletionInProgress, | ||
}} | ||
visible={isVisible} | ||
> | ||
Organization deletion <b>cannot be undone</b>. You will lose all data, <b>including all events</b>, related | ||
to all projects within this organization. | ||
</Modal> | ||
) | ||
} | ||
|
||
export function DangerZone({ isRestricted }: RestrictedComponentProps): JSX.Element { | ||
const { currentOrganization } = useValues(organizationLogic) | ||
|
||
const [isModalVisible, setIsModalVisible] = useState(false) | ||
|
||
return ( | ||
<> | ||
<div style={{ color: 'var(--danger)' }}> | ||
<h2 style={{ color: 'var(--danger)' }} className="subtitle"> | ||
Danger Zone | ||
</h2> | ||
<div className="mt"> | ||
{!isRestricted && ( | ||
<Paragraph type="danger"> | ||
This is <b>irreversible</b>. Please be certain. | ||
</Paragraph> | ||
)} | ||
<Button | ||
type="default" | ||
danger | ||
onClick={() => setIsModalVisible(true)} | ||
className="mr-05" | ||
data-attr="delete-project-button" | ||
icon={<DeleteOutlined />} | ||
disabled={isRestricted} | ||
> | ||
Delete {currentOrganization?.name || 'the current organization'} | ||
</Button> | ||
</div> | ||
</div> | ||
<DeleteOrganizationModal isVisible={isModalVisible} setIsVisible={setIsModalVisible} /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.