diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2018-07-10 16:04:27 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-07-11 20:21:23 +0200 |
commit | 83d228436865d8d12abb039e264737ca59c5ed1a (patch) | |
tree | 174dc5ca4d715d79da8e8961b86ac0a256da2e03 /server/sonar-web/src/main/js | |
parent | 8b864fda418e5d8ba1a9385559ca8340203d680e (diff) | |
download | sonarqube-83d228436865d8d12abb039e264737ca59c5ed1a.tar.gz sonarqube-83d228436865d8d12abb039e264737ca59c5ed1a.zip |
SONAR-11012 Remove front end access checks on QP, QG and members page
Diffstat (limited to 'server/sonar-web/src/main/js')
11 files changed, 49 insertions, 96 deletions
diff --git a/server/sonar-web/src/main/js/app/components/NotFound.js b/server/sonar-web/src/main/js/app/components/NotFound.tsx index 37e2a27fa64..ade13464e39 100644 --- a/server/sonar-web/src/main/js/app/components/NotFound.js +++ b/server/sonar-web/src/main/js/app/components/NotFound.tsx @@ -17,17 +17,15 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import React from 'react'; +import * as React from 'react'; import { Link } from 'react-router'; import SimpleContainer from './SimpleContainer'; -/*:: -type Props = { +interface Props { withContainer?: boolean; -}; -*/ +} -export default function NotFound({ withContainer = true } /*: Props*/) { +export default function NotFound({ withContainer = true }: Props) { const Container = withContainer ? SimpleContainer : React.Fragment; return ( <Container> 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 4cef029f3df..53941adef8a 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 @@ -20,20 +20,13 @@ import * as React from 'react'; import { connect } from 'react-redux'; import { RouterState } from 'react-router'; -import { - getCurrentUser, - getMyOrganizations, - getOrganizationByKey -} from '../../../store/rootReducer'; +import { getCurrentUser, getOrganizationByKey } from '../../../store/rootReducer'; import handleRequiredAuthorization from '../../../app/utils/handleRequiredAuthorization'; import { Organization, CurrentUser, isLoggedIn } from '../../../app/types'; -import { isCurrentUserMemberOf, hasPrivateAccess } from '../../../helpers/organizations'; -import {} from '../../../store/organizations/duck'; interface StateToProps { currentUser: CurrentUser; organization?: Organization; - userOrganizations: Organization[]; } interface OwnProps extends RouterState { @@ -72,36 +65,13 @@ export class OrganizationAccess extends React.PureComponent<Props> { const mapStateToProps = (state: any, ownProps: OwnProps) => ({ currentUser: getCurrentUser(state), - organization: getOrganizationByKey(state, ownProps.params.organizationKey), - userOrganizations: getMyOrganizations(state) + organization: getOrganizationByKey(state, ownProps.params.organizationKey) }); const OrganizationAccessContainer = connect<StateToProps, {}, OwnProps>(mapStateToProps)( OrganizationAccess ); -export function OrganizationPrivateAccess(props: OwnProps) { - return ( - <OrganizationAccessContainer - hasAccess={({ currentUser, organization, userOrganizations }: StateToProps) => - hasPrivateAccess(currentUser, organization, userOrganizations) - } - {...props} - /> - ); -} - -export function OrganizationMembersAccess(props: OwnProps) { - return ( - <OrganizationAccessContainer - hasAccess={({ currentUser, organization, userOrganizations }: StateToProps) => - isCurrentUserMemberOf(currentUser, organization, userOrganizations) - } - {...props} - /> - ); -} - export function hasAdminAccess({ currentUser, organization diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationDelete.tsx b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationDelete.tsx index ce7ebfdaad9..4625032fcdd 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationDelete.tsx +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationDelete.tsx @@ -104,12 +104,12 @@ export class OrganizationDelete extends React.PureComponent<Props, State> { isDestructive={true} modalBody={ <div> - {translate('organization.delete.question')} {hasPaidPlan && ( - <p className="alert alert-warn big-spacer-top"> + <div className="alert alert-warning modal-alert"> {translate('organization.delete.sonarcloud.paid_plan_info')} - </p> + </div> )} + <p>{translate('organization.delete.question')}</p> </div> } modalHeader={translate('organization.delete')} 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 8d135c8fede..44daa37abea 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 @@ -90,7 +90,7 @@ export class OrganizationPage extends React.PureComponent<Props, State> { if (this.state.loading) { return null; } else { - return <NotFound />; + return <NotFound withContainer={false} />; } } 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 8fcb64c11f3..17b1fd80bb1 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 @@ -55,8 +55,7 @@ describe('component', () => { currentUser={loggedInUser} hasAccess={() => true} location={locationMock} - organization={adminOrganization} - userOrganizations={[]}> + organization={adminOrganization}> <div>hello</div> </OrganizationAccess> ) @@ -70,8 +69,7 @@ describe('component', () => { currentUser={loggedInUser} hasAccess={() => false} location={locationMock} - organization={adminOrganization} - userOrganizations={[]}> + organization={adminOrganization}> <div>hello</div> </OrganizationAccess> ).type() diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationDelete-test.tsx.snap b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationDelete-test.tsx.snap index 62ab31e51d2..a9184671428 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationDelete-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationDelete-test.tsx.snap @@ -31,11 +31,13 @@ exports[`should show a info message for paying organization 1`] = ` isDestructive={true} modalBody={ <div> - organization.delete.question - <p - className="alert alert-warn big-spacer-top" + <div + className="alert alert-warning modal-alert" > organization.delete.sonarcloud.paid_plan_info + </div> + <p> + organization.delete.question </p> </div> } @@ -77,7 +79,9 @@ exports[`smoke test 1`] = ` isDestructive={true} modalBody={ <div> - organization.delete.question + <p> + organization.delete.question + </p> </div> } modalHeader="organization.delete" 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 c6b612738c1..7c58c886214 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 @@ -1,6 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`not found 1`] = `<NotFound />`; +exports[`not found 1`] = ` +<NotFound + withContainer={false} +/> +`; exports[`should correctly update when the organization changes 1`] = ` Array [ diff --git a/server/sonar-web/src/main/js/apps/organizations/routes.ts b/server/sonar-web/src/main/js/apps/organizations/routes.ts index 24cd7999dcd..b6fa1ef378e 100644 --- a/server/sonar-web/src/main/js/apps/organizations/routes.ts +++ b/server/sonar-web/src/main/js/apps/organizations/routes.ts @@ -59,35 +59,17 @@ const routes = [ childRoutes: codingRulesRoutes }, { - component: lazyLoad(() => - import('./components/OrganizationAccessContainer').then(lib => ({ - default: lib.OrganizationMembersAccess - })) - ), - childRoutes: [ - { - path: 'members', - component: lazyLoad(() => import('./components/OrganizationMembersContainer')) - } - ] + path: 'members', + component: lazyLoad(() => import('./components/OrganizationMembersContainer')) }, { - component: lazyLoad(() => - import('./components/OrganizationAccessContainer').then(lib => ({ - default: lib.OrganizationPrivateAccess - })) - ), - childRoutes: [ - { - path: 'quality_profiles', - childRoutes: qualityProfilesRoutes - }, - { - path: 'quality_gates', - component: OrganizationContainer, - childRoutes: qualityGatesRoutes - } - ] + path: 'quality_profiles', + childRoutes: qualityProfilesRoutes + }, + { + path: 'quality_gates', + component: OrganizationContainer, + childRoutes: qualityGatesRoutes }, { component: lazyLoad(() => diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx index 35fd9354bff..67697a9c4f8 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx @@ -99,7 +99,7 @@ export default class App extends React.PureComponent<Props, State> { return React.cloneElement(this.props.children, { actions: this.state.actions || {}, - profiles: this.state.profiles, + profiles: this.state.profiles || [], languages: finalLanguages, exporters: this.state.exporters, updateProfiles: this.updateProfiles, diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/home/EvolutionRules.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/home/EvolutionRules.tsx index dac9e1a71be..2842268340f 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/home/EvolutionRules.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/home/EvolutionRules.tsx @@ -25,13 +25,13 @@ import { translateWithParameters, translate } from '../../../helpers/l10n'; import { getRulesUrl } from '../../../helpers/urls'; import { toShortNotSoISOString } from '../../../helpers/dates'; import { formatMeasure } from '../../../helpers/measures'; +import { Rule, RuleActivation } from '../../../app/types'; const RULES_LIMIT = 10; -function parseRules(r: any) { - const { rules, actives } = r; - return rules.map((rule: any) => { - const activations = actives[rule.key]; +function parseRules(rules: Rule[], actives?: { [rule: string]: RuleActivation[] }): ExtendedRule[] { + return rules.map(rule => { + const activations = actives && actives[rule.key]; return { ...rule, activations: activations ? activations.length : 0 }; }); } @@ -40,15 +40,12 @@ interface Props { organization: string | null; } -interface Rule { +interface ExtendedRule extends Rule { activations: number; - key: string; - langName: string; - name: string; } interface State { - latestRules?: Array<Rule>; + latestRules?: ExtendedRule[]; latestRulesTotal?: number; } @@ -84,11 +81,11 @@ export default class EvolutionRules extends React.PureComponent<Props, State> { }; searchRules(data).then( - (r: any) => { + ({ actives, rules, total }) => { if (this.mounted) { this.setState({ - latestRules: sortBy<Rule>(parseRules(r), 'langName'), - latestRulesTotal: r.total + latestRules: sortBy(parseRules(rules, actives), 'langName'), + latestRulesTotal: total }); } }, @@ -113,11 +110,11 @@ export default class EvolutionRules extends React.PureComponent<Props, State> { </div> <ul> {this.state.latestRules.map(rule => ( - <li key={rule.key} className="spacer-top"> + <li className="spacer-top" key={rule.key}> <div className="text-ellipsis"> <Link - to={getRulesUrl({ rule_key: rule.key }, this.props.organization)} - className="link-no-underline"> + className="link-no-underline" + to={getRulesUrl({ rule_key: rule.key }, this.props.organization)}> {' '} {rule.name} </Link> @@ -139,7 +136,7 @@ export default class EvolutionRules extends React.PureComponent<Props, State> { </ul> {this.state.latestRulesTotal > RULES_LIMIT && ( <div className="spacer-top"> - <Link to={newRulesUrl} className="small"> + <Link className="small" to={newRulesUrl}> {translate('see_all')} {formatMeasure(this.state.latestRulesTotal, 'SHORT_INT', null)} </Link> </div> diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/home/HomeContainer.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/home/HomeContainer.tsx index f4ae8356b27..af78f87f44e 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/home/HomeContainer.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/home/HomeContainer.tsx @@ -30,7 +30,7 @@ interface Props { location: { query: { [p: string]: string } }; onRequestFail: (reason: any) => void; organization: string | null; - profiles: Array<Profile>; + profiles: Profile[]; updateProfiles: () => Promise<void>; } |