aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/organizations
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2018-10-26 10:14:59 +0200
committerSonarTech <sonartech@sonarsource.com>2018-11-16 20:21:05 +0100
commitf95737b973036e12f338047d7a7995bc44ba5724 (patch)
tree2ce03e7aa32543ac5ad1632b441177af2c0b1b06 /server/sonar-web/src/main/js/apps/organizations
parent427bc6b8124d501d4d759f5e0a58c11458c79be3 (diff)
downloadsonarqube-f95737b973036e12f338047d7a7995bc44ba5724.tar.gz
sonarqube-f95737b973036e12f338047d7a7995bc44ba5724.zip
SONARCLOUD-101 Display only organization on which we have correct permissions in create pages
* Use organizations actions instead of permissions flags from api/navigation/organization
Diffstat (limited to 'server/sonar-web/src/main/js/apps/organizations')
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/OrganizationAccessContainer.tsx5
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAccessContainer-test.tsx4
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationPage-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAccessContainer-test.tsx.snap4
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationPage-test.tsx.snap4
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationAdministration.tsx8
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationMenuContainer.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationHeader-test.tsx4
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationMenuContainer-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationHeader-test.tsx.snap8
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationMenuContainer-test.tsx.snap8
12 files changed, 34 insertions, 20 deletions
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAccessContainer.tsx b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAccessContainer.tsx
index 1689dc06896..72263ccf372 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAccessContainer.tsx
+++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAccessContainer.tsx
@@ -75,8 +75,9 @@ export function hasAdminAccess({
currentUser,
organization
}: Pick<StateToProps, 'currentUser' | 'organization'>) {
- const isAdmin = isLoggedIn(currentUser) && organization && organization.canAdmin;
- return Boolean(isAdmin);
+ return Boolean(
+ isLoggedIn(currentUser) && organization && organization.actions && organization.actions.admin
+ );
}
export function OrganizationAdminAccess(props: OwnProps) {
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.tsx b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.tsx
index 5ae1a3503da..b78929a9040 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.tsx
+++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPage.tsx
@@ -99,7 +99,7 @@ export class OrganizationPage extends React.PureComponent<Props, State> {
render() {
const { organization } = this.props;
- if (!organization || organization.canAdmin == null) {
+ if (!organization || !organization.actions || organization.actions.admin == null) {
if (this.state.loading) {
return null;
} else {
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAccessContainer-test.tsx b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAccessContainer-test.tsx
index 17b1fd80bb1..961b7f6bc4b 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAccessContainer-test.tsx
+++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAccessContainer-test.tsx
@@ -39,13 +39,13 @@ const loggedInUser = {
};
const organization = {
- canAdmin: false,
+ actions: { admin: false },
key: 'foo',
name: 'Foo',
projectVisibility: Visibility.Public
};
-const adminOrganization = { ...organization, canAdmin: true };
+const adminOrganization = { ...organization, actions: { admin: true } };
describe('component', () => {
it('should render children', () => {
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationPage-test.tsx b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationPage-test.tsx
index 0f97587fa9d..5af2c96e6fe 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationPage-test.tsx
+++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationPage-test.tsx
@@ -32,7 +32,7 @@ it('smoke test', () => {
const wrapper = getWrapper();
expect(wrapper.type()).toBeNull();
- const organization = { key: 'foo', name: 'Foo', isDefault: false, canAdmin: false };
+ const organization = { actions: { admin: false }, key: 'foo', name: 'Foo', isDefault: false };
wrapper.setProps({ organization });
expect(wrapper).toMatchSnapshot();
});
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAccessContainer-test.tsx.snap b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAccessContainer-test.tsx.snap
index df4447403e6..ae075289ee9 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAccessContainer-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAccessContainer-test.tsx.snap
@@ -5,7 +5,9 @@ exports[`component should render children 1`] = `
location={Object {}}
organization={
Object {
- "canAdmin": true,
+ "actions": Object {
+ "admin": true,
+ },
"key": "foo",
"name": "Foo",
"projectVisibility": "public",
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationPage-test.tsx.snap b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationPage-test.tsx.snap
index 7c58c886214..9836ed00ed4 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationPage-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationPage-test.tsx.snap
@@ -41,7 +41,9 @@ exports[`smoke test 1`] = `
}
organization={
Object {
- "canAdmin": false,
+ "actions": Object {
+ "admin": false,
+ },
"isDefault": false,
"key": "foo",
"name": "Foo",
diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationAdministration.tsx b/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationAdministration.tsx
index 3b6f30e664f..e890a54eb11 100644
--- a/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationAdministration.tsx
+++ b/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationAdministration.tsx
@@ -41,8 +41,8 @@ const ADMIN_PATHS = [
];
export default function OrganizationNavigationAdministration({ location, organization }: Props) {
- const extensions = organization.adminPages || [];
- const adminPathsWithExtensions = extensions.map(e => `extension/${e.key}`).concat(ADMIN_PATHS);
+ const { actions = {}, adminPages = [] } = organization;
+ const adminPathsWithExtensions = adminPages.map(e => `extension/${e.key}`).concat(ADMIN_PATHS);
const adminActive = adminPathsWithExtensions.some(path =>
location.pathname.endsWith(`organizations/${organization.key}/${path}`)
);
@@ -51,7 +51,7 @@ export default function OrganizationNavigationAdministration({ location, organiz
<Dropdown
overlay={
<ul className="menu">
- {extensions.map(extension => (
+ {adminPages.map(extension => (
<li key={extension.key}>
<Link
activeClassName="active"
@@ -94,7 +94,7 @@ export default function OrganizationNavigationAdministration({ location, organiz
{translate('edit')}
</Link>
</li>
- {organization.canDelete && (
+ {actions.delete && (
<li>
<Link activeClassName="active" to={`/organizations/${organization.key}/delete`}>
{translate('delete')}
diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationMenuContainer.tsx b/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationMenuContainer.tsx
index 518a2a86c52..ba5160c5baa 100644
--- a/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationMenuContainer.tsx
+++ b/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigationMenuContainer.tsx
@@ -48,6 +48,7 @@ export function OrganizationNavigationMenu({
userOrganizations
}: Props) {
const hasPrivateRights = hasPrivateAccess(currentUser, organization, userOrganizations);
+ const { actions = {} } = organization;
return (
<NavBarTabs className="navbar-context-tabs">
<li>
@@ -92,7 +93,7 @@ export function OrganizationNavigationMenu({
</li>
)}
<OrganizationNavigationExtensions location={location} organization={organization} />
- {organization.canAdmin && (
+ {actions.admin && (
<OrganizationNavigationAdministration location={location} organization={organization} />
)}
</NavBarTabs>
diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationHeader-test.tsx b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationHeader-test.tsx
index 2d6853a617d..6b08b874b9e 100644
--- a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationHeader-test.tsx
+++ b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationHeader-test.tsx
@@ -51,8 +51,8 @@ it('renders with alm integration', () => {
it('renders dropdown', () => {
const organizations = [
- { isAdmin: true, key: 'org1', name: 'org1', projectVisibility: Visibility.Public },
- { isAdmin: false, key: 'org2', name: 'org2', projectVisibility: Visibility.Public }
+ { actions: { admin: true }, key: 'org1', name: 'org1', projectVisibility: Visibility.Public },
+ { actions: { admin: false }, key: 'org2', name: 'org2', projectVisibility: Visibility.Public }
];
const wrapper = shallow(
<OrganizationNavigationHeader
diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationMenuContainer-test.tsx b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationMenuContainer-test.tsx
index ee37622b91b..e2c37db5866 100644
--- a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationMenuContainer-test.tsx
+++ b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationMenuContainer-test.tsx
@@ -65,7 +65,7 @@ it('renders for admin', () => {
<OrganizationNavigationMenu
currentUser={loggedInUser}
location={{ pathname: '' }}
- organization={{ ...organization, canAdmin: true }}
+ organization={{ ...organization, actions: { admin: true } }}
userOrganizations={[organization]}
/>
)
diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationHeader-test.tsx.snap b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationHeader-test.tsx.snap
index ca3bd2d87cd..5ef064c39fc 100644
--- a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationHeader-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationHeader-test.tsx.snap
@@ -31,7 +31,9 @@ exports[`renders dropdown 1`] = `
<OrganizationListItem
organization={
Object {
- "isAdmin": true,
+ "actions": Object {
+ "admin": true,
+ },
"key": "org1",
"name": "org1",
"projectVisibility": "public",
@@ -41,7 +43,9 @@ exports[`renders dropdown 1`] = `
<OrganizationListItem
organization={
Object {
- "isAdmin": false,
+ "actions": Object {
+ "admin": false,
+ },
"key": "org2",
"name": "org2",
"projectVisibility": "public",
diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationMenuContainer-test.tsx.snap b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationMenuContainer-test.tsx.snap
index 1177b7604b7..46f062c94ae 100644
--- a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationMenuContainer-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigationMenuContainer-test.tsx.snap
@@ -175,7 +175,9 @@ exports[`renders for admin 1`] = `
}
organization={
Object {
- "canAdmin": true,
+ "actions": Object {
+ "admin": true,
+ },
"key": "foo",
"name": "Foo",
"projectVisibility": "public",
@@ -190,7 +192,9 @@ exports[`renders for admin 1`] = `
}
organization={
Object {
- "canAdmin": true,
+ "actions": Object {
+ "admin": true,
+ },
"key": "foo",
"name": "Foo",
"projectVisibility": "public",