Просмотр исходного кода

fix(project-creation): fix access to projects/new page (#49704)

Before this fix everyone could have seen sentry/projects/new page
although they might have not be able to create a project. Setting access
to make sure they don't visit with direct link.
Athena Moghaddam 1 год назад
Родитель
Сommit
182b0562c7

+ 21 - 4
static/app/views/projectInstall/createProject.spec.tsx

@@ -77,14 +77,18 @@ describe('CreateProject', function () {
 
   it('should block if you have access to no teams', function () {
     const {container} = render(<CreateProject />, {
-      context: TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}]),
+      context: TestStubs.routerContext([
+        {organization: {id: '1', slug: 'testOrg', access: ['project:read']}},
+      ]),
     });
     expect(container).toSnapshot();
   });
 
   it('can create a new team', async function () {
     render(<CreateProject />, {
-      context: TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}]),
+      context: TestStubs.routerContext([
+        {organization: {id: '1', slug: 'testOrg', access: ['project:read']}},
+      ]),
     });
 
     renderGlobalModal();
@@ -122,10 +126,22 @@ describe('CreateProject', function () {
   });
 
   it('should fill in project name if its empty when platform is chosen', async function () {
-    const organization = TestStubs.Organization();
+    const {organization} = initializeOrg({
+      organization: {
+        access: ['project:admin'],
+      },
+    });
 
     const {container} = render(<CreateProject />, {
-      context: TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}]),
+      context: TestStubs.routerContext([
+        {
+          organization: {
+            id: '1',
+            slug: 'testOrg',
+            access: ['project:read'],
+          },
+        },
+      ]),
       organization,
     });
 
@@ -149,6 +165,7 @@ describe('CreateProject', function () {
     const {organization} = initializeOrg({
       organization: {
         features: ['onboarding-sdk-selection'],
+        access: ['project:read', 'project:write'],
       },
     });
 

+ 3 - 2
static/app/views/projectInstall/createProject.tsx

@@ -7,6 +7,7 @@ import {PlatformIcon} from 'platformicons';
 
 import {addErrorMessage} from 'sentry/actionCreators/indicator';
 import {openCreateTeamModal, openModal} from 'sentry/actionCreators/modal';
+import Access from 'sentry/components/acl/access';
 import {Alert} from 'sentry/components/alert';
 import {Button} from 'sentry/components/button';
 import Input from 'sentry/components/input';
@@ -289,7 +290,7 @@ function CreateProject() {
   );
 
   return (
-    <Fragment>
+    <Access access={canCreateProject ? ['project:read'] : ['project:write']}>
       {error && <Alert type="error">{error}</Alert>}
       <div data-test-id="onboarding-info">
         <Layout.Title withMargins>{t('Create a new project in 3 steps')}</Layout.Title>
@@ -314,7 +315,7 @@ function CreateProject() {
         <IssueAlertOptions onChange={updatedData => setAlertRuleConfig(updatedData)} />
         {createProjectForm}
       </div>
-    </Fragment>
+    </Access>
   );
 }