From 419ce712fd40f8e38766cd93f7f35cb011533171 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 10 Feb 2017 16:08:30 +0100 Subject: SONAR-8655 check `canDelete`flag --- .../organizations/components/OrganizationPage.js | 2 +- .../navigation/OrganizationNavigation.js | 13 ++- .../__tests__/OrganizationNavigation-test.js | 11 ++- .../OrganizationNavigation-test.js.snap | 103 +++++++++++++++++++++ .../src/main/js/store/organizations/duck.js | 3 +- 5 files changed, 123 insertions(+), 9 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.js index 19670aafb46..a6a2e82f165 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.js +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.js @@ -61,7 +61,7 @@ class OrganizationPage extends React.Component { render () { const { organization } = this.props; - if (!organization || organization.isDefault == null) { + if (!organization || organization.canAdmin == null) { if (this.state.loading) { return null; } else { diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigation.js b/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigation.js index 21b1ab8d074..ae69f59d20b 100644 --- a/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigation.js +++ b/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigation.js @@ -41,6 +41,7 @@ export default class OrganizationNavigation extends React.Component { key: string, name: string, canAdmin?: boolean, + canDelete?: boolean, url?: string } }; @@ -83,11 +84,13 @@ export default class OrganizationNavigation extends React.Component { {translate('edit')} -
  • - - {translate('delete')} - -
  • + {organization.canDelete && ( +
  • + + {translate('delete')} + +
  • + )} ); diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigation-test.js b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigation-test.js index e31bc4e1bc1..20d01e6f04b 100644 --- a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigation-test.js +++ b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigation-test.js @@ -22,14 +22,21 @@ import { shallow } from 'enzyme'; import OrganizationNavigation from '../OrganizationNavigation'; it('regular user', () => { - const organization = { key: 'foo', name: 'Foo', canAdmin: false }; + const organization = { key: 'foo', name: 'Foo', canAdmin: false, canDelete: false }; expect(shallow( )).toMatchSnapshot(); }); it('admin', () => { - const organization = { key: 'foo', name: 'Foo', canAdmin: true }; + const organization = { key: 'foo', name: 'Foo', canAdmin: true, canDelete: true }; + expect(shallow( + + )).toMatchSnapshot(); +}); + +it('undeletable org', () => { + const organization = { key: 'foo', name: 'Foo', canAdmin: true, canDelete: false }; expect(shallow( )).toMatchSnapshot(); diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.js.snap b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.js.snap index 62d369ad119..02421f1020d 100644 --- a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.js.snap +++ b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.js.snap @@ -152,3 +152,106 @@ exports[`test regular user 1`] = ` `; + +exports[`test undeletable org 1`] = ` + +`; diff --git a/server/sonar-web/src/main/js/store/organizations/duck.js b/server/sonar-web/src/main/js/store/organizations/duck.js index fb25f1bfce1..f1d4a1b5b7b 100644 --- a/server/sonar-web/src/main/js/store/organizations/duck.js +++ b/server/sonar-web/src/main/js/store/organizations/duck.js @@ -26,8 +26,9 @@ import without from 'lodash/without'; export type Organization = { avatar?: string, canAdmin?: boolean, + canDelete?: boolean, + canProvisionProjects?: boolean, description?: string, - isDefault?: boolean, key: string, name: string, url?: string -- cgit v1.2.3