mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 14:05:44 +01:00
only show entries in navigaton that user is allowed to
This commit is contained in:
@@ -2,40 +2,62 @@
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import PrimaryNavigationLink from "./PrimaryNavigationLink";
|
||||
import type {Link} from "@scm-manager/ui-types";
|
||||
|
||||
type Props = {
|
||||
t: string => string
|
||||
t: string => string,
|
||||
repositoriesLink: Link,
|
||||
usersLink: Link,
|
||||
groupsLink: Link,
|
||||
configLink: Link,
|
||||
logoutLink: Link
|
||||
};
|
||||
|
||||
class PrimaryNavigation extends React.Component<Props> {
|
||||
render() {
|
||||
const { t } = this.props;
|
||||
return (
|
||||
<nav className="tabs is-boxed">
|
||||
<ul>
|
||||
const { t, repositoriesLink, usersLink, groupsLink, configLink, logoutLink } = this.props;
|
||||
|
||||
const _repositoriesLink = repositoriesLink ? (
|
||||
<PrimaryNavigationLink
|
||||
to="/repos"
|
||||
match="/(repo|repos)"
|
||||
label={t("primary-navigation.repositories")}
|
||||
/>
|
||||
/>): null;
|
||||
|
||||
const _usersLink = usersLink ? (
|
||||
<PrimaryNavigationLink
|
||||
to="/users"
|
||||
match="/(user|users)"
|
||||
label={t("primary-navigation.users")}
|
||||
/>
|
||||
/>) : null;
|
||||
|
||||
const _groupsLink = groupsLink ? (
|
||||
<PrimaryNavigationLink
|
||||
to="/groups"
|
||||
match="/(group|groups)"
|
||||
label={t("primary-navigation.groups")}
|
||||
/>
|
||||
/>) : null;
|
||||
|
||||
const _configLink = configLink ? (
|
||||
<PrimaryNavigationLink
|
||||
to="/config"
|
||||
label={t("primary-navigation.config")}
|
||||
/>
|
||||
/>) : null;
|
||||
|
||||
const _logoutLink = logoutLink ? (
|
||||
<PrimaryNavigationLink
|
||||
to="/logout"
|
||||
label={t("primary-navigation.logout")}
|
||||
/>
|
||||
/>) : null;
|
||||
|
||||
return (
|
||||
<nav className="tabs is-boxed">
|
||||
<ul>
|
||||
{_repositoriesLink}
|
||||
{_usersLink}
|
||||
{_groupsLink}
|
||||
{_configLink}
|
||||
{_logoutLink}
|
||||
</ul>
|
||||
</nav>
|
||||
);
|
||||
|
||||
@@ -19,10 +19,15 @@ import {
|
||||
Footer,
|
||||
Header
|
||||
} from "@scm-manager/ui-components";
|
||||
import type { Me, IndexResources } from "@scm-manager/ui-types";
|
||||
import type { Me, Link } from "@scm-manager/ui-types";
|
||||
import {
|
||||
fetchIndexResources,
|
||||
getConfigLink,
|
||||
getFetchIndexResourcesFailure,
|
||||
getGroupsLink,
|
||||
getLogoutLink,
|
||||
getRepositoriesLink,
|
||||
getUsersLink,
|
||||
isFetchIndexResourcesPending
|
||||
} from "../modules/indexResource";
|
||||
|
||||
@@ -31,7 +36,11 @@ type Props = {
|
||||
authenticated: boolean,
|
||||
error: Error,
|
||||
loading: boolean,
|
||||
indexResources: IndexResources,
|
||||
repositoriesLink: Link,
|
||||
usersLink: Link,
|
||||
groupsLink: Link,
|
||||
configLink: Link,
|
||||
logoutLink: Link,
|
||||
|
||||
// dispatcher functions
|
||||
fetchMe: () => void,
|
||||
@@ -48,10 +57,31 @@ class App extends Component<Props> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { me, loading, error, authenticated, t } = this.props;
|
||||
const {
|
||||
me,
|
||||
loading,
|
||||
error,
|
||||
authenticated,
|
||||
t,
|
||||
repositoriesLink,
|
||||
usersLink,
|
||||
groupsLink,
|
||||
configLink,
|
||||
logoutLink
|
||||
} = this.props;
|
||||
|
||||
let content;
|
||||
const navigation = authenticated ? <PrimaryNavigation /> : "";
|
||||
const navigation = authenticated ? (
|
||||
<PrimaryNavigation
|
||||
repositoriesLink={repositoriesLink}
|
||||
usersLink={usersLink}
|
||||
groupsLink={groupsLink}
|
||||
configLink={configLink}
|
||||
logoutLink={logoutLink}
|
||||
/>
|
||||
) : (
|
||||
""
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
content = <Loading />;
|
||||
@@ -90,11 +120,21 @@ const mapStateToProps = state => {
|
||||
isFetchMePending(state) || isFetchIndexResourcesPending(state);
|
||||
const error =
|
||||
getFetchMeFailure(state) || getFetchIndexResourcesFailure(state);
|
||||
const repositoriesLink = getRepositoriesLink(state);
|
||||
const usersLink = getUsersLink(state);
|
||||
const groupsLink = getGroupsLink(state);
|
||||
const configLink = getConfigLink(state);
|
||||
const logoutLink = getLogoutLink(state);
|
||||
return {
|
||||
authenticated,
|
||||
me,
|
||||
loading,
|
||||
error
|
||||
error,
|
||||
repositoriesLink,
|
||||
usersLink,
|
||||
groupsLink,
|
||||
configLink,
|
||||
logoutLink
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -86,70 +86,72 @@ export function getFetchIndexResourcesFailure(state: Object) {
|
||||
return getFailure(state, FETCH_INDEXRESOURCES);
|
||||
}
|
||||
|
||||
export function getLinks(state: Object){
|
||||
export function getLinks(state: Object) {
|
||||
return state.indexResources.links;
|
||||
}
|
||||
|
||||
export function getUiPluginsLink(state: Object) {
|
||||
if (state.indexResources.links && state.indexResources.links["uiPlugins"])
|
||||
return state.indexResources.links["uiPlugins"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getMeLink(state: Object) {
|
||||
if (state.indexResources.links["me"])
|
||||
if (state.indexResources.links && state.indexResources.links["me"])
|
||||
return state.indexResources.links["me"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getLogoutLink(state: Object) {
|
||||
if (state.indexResources.links["logout"])
|
||||
if (state.indexResources.links && state.indexResources.links["logout"])
|
||||
return state.indexResources.links["logout"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getLoginLink(state: Object) {
|
||||
if (state.indexResources.links["login"])
|
||||
if (state.indexResources.links && state.indexResources.links["login"])
|
||||
return state.indexResources.links["login"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getUsersLink(state: Object) {
|
||||
if (state.indexResources.links["users"])
|
||||
if (state.indexResources.links && state.indexResources.links["users"])
|
||||
return state.indexResources.links["users"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getGroupsLink(state: Object) {
|
||||
if (state.indexResources.links["groups"])
|
||||
if (state.indexResources.links && state.indexResources.links["groups"])
|
||||
return state.indexResources.links["groups"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getConfigLink(state: Object) {
|
||||
if (state.indexResources.links["config"])
|
||||
if (state.indexResources.links && state.indexResources.links["config"])
|
||||
return state.indexResources.links["config"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getRepositoriesLink(state: Object) {
|
||||
if (state.indexResources.links["repositories"])
|
||||
if (state.indexResources.links && state.indexResources.links["repositories"])
|
||||
return state.indexResources.links["repositories"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getHgConfigLink(state: Object) {
|
||||
if (state.indexResources.links["hgConfig"])
|
||||
if (state.indexResources.links && state.indexResources.links["hgConfig"])
|
||||
return state.indexResources.links["hgConfig"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getGitConfigLink(state: Object) {
|
||||
if (state.indexResources.links["gitConfig"])
|
||||
if (state.indexResources.links && state.indexResources.links["gitConfig"])
|
||||
return state.indexResources.links["gitConfig"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function getSvnConfigLink(state: Object) {
|
||||
if (state.indexResources.links["svnConfig"])
|
||||
if (state.indexResources.links && state.indexResources.links["svnConfig"])
|
||||
return state.indexResources.links["svnConfig"].href;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import reducer, {
|
||||
getHgConfigLink,
|
||||
getGitConfigLink,
|
||||
getSvnConfigLink,
|
||||
getLinks
|
||||
getLinks, getGroupsLink
|
||||
} from "./indexResource";
|
||||
|
||||
const indexResourcesUnauthenticated = {
|
||||
@@ -307,7 +307,7 @@ describe("index resources selectors", () => {
|
||||
links: indexResourcesAuthenticated._links
|
||||
}
|
||||
};
|
||||
expect(getUsersLink(state)).toBe("http://localhost:8081/scm/api/v2/users/");
|
||||
expect(getGroupsLink(state)).toBe("http://localhost:8081/scm/api/v2/groups/");
|
||||
});
|
||||
|
||||
it("should return undefined for groups link when unauthenticated or has not permission to see it", () => {
|
||||
@@ -316,7 +316,7 @@ describe("index resources selectors", () => {
|
||||
links: indexResourcesUnauthenticated._links
|
||||
}
|
||||
};
|
||||
expect(getUsersLink(state)).toBe(undefined);
|
||||
expect(getGroupsLink(state)).toBe(undefined);
|
||||
});
|
||||
|
||||
// config link
|
||||
|
||||
Reference in New Issue
Block a user