use link of index permissions for create and fetch repo

This commit is contained in:
Maren Süwer
2018-10-11 08:19:50 +02:00
parent f9e263fcf7
commit eb65ef1e65
4 changed files with 34 additions and 23 deletions

View File

@@ -18,16 +18,18 @@ import {
isCreateRepoPending isCreateRepoPending
} from "../modules/repos"; } from "../modules/repos";
import type { History } from "history"; import type { History } from "history";
import { getRepositoriesLink } from "../../modules/indexResource";
type Props = { type Props = {
repositoryTypes: RepositoryType[], repositoryTypes: RepositoryType[],
typesLoading: boolean, typesLoading: boolean,
createLoading: boolean, createLoading: boolean,
error: Error, error: Error,
repoLink: string,
// dispatch functions // dispatch functions
fetchRepositoryTypesIfNeeded: () => void, fetchRepositoryTypesIfNeeded: () => void,
createRepo: (Repository, callback: () => void) => void, createRepo: (link: string, Repository, callback: () => void) => void,
resetForm: () => void, resetForm: () => void,
// context props // context props
@@ -55,7 +57,7 @@ class Create extends React.Component<Props> {
error error
} = this.props; } = this.props;
const { t } = this.props; const { t, repoLink } = this.props;
return ( return (
<Page <Page
title={t("create.title")} title={t("create.title")}
@@ -68,7 +70,7 @@ class Create extends React.Component<Props> {
repositoryTypes={repositoryTypes} repositoryTypes={repositoryTypes}
loading={createLoading} loading={createLoading}
submitForm={repo => { submitForm={repo => {
createRepo(repo, this.repoCreated); createRepo(repoLink, repo, this.repoCreated);
}} }}
/> />
</Page> </Page>
@@ -82,11 +84,13 @@ const mapStateToProps = state => {
const createLoading = isCreateRepoPending(state); const createLoading = isCreateRepoPending(state);
const error = const error =
getFetchRepositoryTypesFailure(state) || getCreateRepoFailure(state); getFetchRepositoryTypesFailure(state) || getCreateRepoFailure(state);
const repoLink = getRepositoriesLink(state);
return { return {
repositoryTypes, repositoryTypes,
typesLoading, typesLoading,
createLoading, createLoading,
error error,
repoLink
}; };
}; };
@@ -95,8 +99,12 @@ const mapDispatchToProps = dispatch => {
fetchRepositoryTypesIfNeeded: () => { fetchRepositoryTypesIfNeeded: () => {
dispatch(fetchRepositoryTypesIfNeeded()); dispatch(fetchRepositoryTypesIfNeeded());
}, },
createRepo: (repository: Repository, callback: () => void) => { createRepo: (
dispatch(createRepo(repository, callback)); link: string,
repository: Repository,
callback: () => void
) => {
dispatch(createRepo(link, repository, callback));
}, },
resetForm: () => { resetForm: () => {
dispatch(createRepoReset()); dispatch(createRepoReset());

View File

@@ -27,6 +27,7 @@ import Permissions from "../permissions/containers/Permissions";
import type { History } from "history"; import type { History } from "history";
import EditNavLink from "../components/EditNavLink"; import EditNavLink from "../components/EditNavLink";
import PermissionsNavLink from "../components/PermissionsNavLink"; import PermissionsNavLink from "../components/PermissionsNavLink";
import { getRepositoriesLink } from "../../modules/indexResource";
type Props = { type Props = {
namespace: string, namespace: string,
@@ -34,9 +35,10 @@ type Props = {
repository: Repository, repository: Repository,
loading: boolean, loading: boolean,
error: Error, error: Error,
repoLink: string,
// dispatch functions // dispatch functions
fetchRepo: (namespace: string, name: string) => void, fetchRepo: (link: string, namespace: string, name: string) => void,
deleteRepo: (repository: Repository, () => void) => void, deleteRepo: (repository: Repository, () => void) => void,
// context props // context props
@@ -47,9 +49,9 @@ type Props = {
class RepositoryRoot extends React.Component<Props> { class RepositoryRoot extends React.Component<Props> {
componentDidMount() { componentDidMount() {
const { fetchRepo, namespace, name } = this.props; const { fetchRepo, namespace, name, repoLink } = this.props;
fetchRepo(namespace, name); fetchRepo(repoLink, namespace, name);
} }
stripEndingSlash = (url: string) => { stripEndingSlash = (url: string) => {
@@ -140,19 +142,21 @@ const mapStateToProps = (state, ownProps) => {
const repository = getRepository(state, namespace, name); const repository = getRepository(state, namespace, name);
const loading = isFetchRepoPending(state, namespace, name); const loading = isFetchRepoPending(state, namespace, name);
const error = getFetchRepoFailure(state, namespace, name); const error = getFetchRepoFailure(state, namespace, name);
const repoLink = getRepositoriesLink(state);
return { return {
namespace, namespace,
name, name,
repository, repository,
loading, loading,
error error,
repoLink
}; };
}; };
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
fetchRepo: (namespace: string, name: string) => { fetchRepo: (link: string, namespace: string, name: string) => {
dispatch(fetchRepo(namespace, name)); dispatch(fetchRepo(link, namespace, name));
}, },
deleteRepo: (repository: Repository, callback: () => void) => { deleteRepo: (repository: Repository, callback: () => void) => {
dispatch(deleteRepo(repository, callback)); dispatch(deleteRepo(repository, callback));

View File

@@ -35,8 +35,6 @@ export const DELETE_REPO_PENDING = `${DELETE_REPO}_${types.PENDING_SUFFIX}`;
export const DELETE_REPO_SUCCESS = `${DELETE_REPO}_${types.SUCCESS_SUFFIX}`; export const DELETE_REPO_SUCCESS = `${DELETE_REPO}_${types.SUCCESS_SUFFIX}`;
export const DELETE_REPO_FAILURE = `${DELETE_REPO}_${types.FAILURE_SUFFIX}`; export const DELETE_REPO_FAILURE = `${DELETE_REPO}_${types.FAILURE_SUFFIX}`;
const REPOS_URL = "repositories";
const CONTENT_TYPE = "application/vnd.scmm-repository+json;v=2"; const CONTENT_TYPE = "application/vnd.scmm-repository+json;v=2";
// fetch repos // fetch repos
@@ -102,11 +100,12 @@ export function fetchReposFailure(err: Error): Action {
// fetch repo // fetch repo
export function fetchRepo(namespace: string, name: string) { export function fetchRepo(link: string, namespace: string, name: string) {
const repoUrl = link.endsWith("/") ? link : link + "/";
return function(dispatch: any) { return function(dispatch: any) {
dispatch(fetchRepoPending(namespace, name)); dispatch(fetchRepoPending(namespace, name));
return apiClient return apiClient
.get(`${REPOS_URL}/${namespace}/${name}`) .get(`${repoUrl}${namespace}/${name}`)
.then(response => response.json()) .then(response => response.json())
.then(repository => { .then(repository => {
dispatch(fetchRepoSuccess(repository)); dispatch(fetchRepoSuccess(repository));
@@ -154,11 +153,11 @@ export function fetchRepoFailure(
// create repo // create repo
export function createRepo(repository: Repository, callback?: () => void) { export function createRepo(link: string, repository: Repository, callback?: () => void) {
return function(dispatch: any) { return function(dispatch: any) {
dispatch(createRepoPending()); dispatch(createRepoPending());
return apiClient return apiClient
.post(REPOS_URL, repository, CONTENT_TYPE) .post(link, repository, CONTENT_TYPE)
.then(() => { .then(() => {
dispatch(createRepoSuccess()); dispatch(createRepoSuccess());
if (callback) { if (callback) {

View File

@@ -342,7 +342,7 @@ describe("repos fetch", () => {
]; ];
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchRepo("slarti", "fjords")).then(() => { return store.dispatch(fetchRepo(URL, "slarti", "fjords")).then(() => {
expect(store.getActions()).toEqual(expectedActions); expect(store.getActions()).toEqual(expectedActions);
}); });
}); });
@@ -353,7 +353,7 @@ describe("repos fetch", () => {
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchRepo("slarti", "fjords")).then(() => { return store.dispatch(fetchRepo(URL, "slarti", "fjords")).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(FETCH_REPO_PENDING); expect(actions[0].type).toEqual(FETCH_REPO_PENDING);
expect(actions[1].type).toEqual(FETCH_REPO_FAILURE); expect(actions[1].type).toEqual(FETCH_REPO_FAILURE);
@@ -379,7 +379,7 @@ describe("repos fetch", () => {
]; ];
const store = mockStore({}); const store = mockStore({});
return store.dispatch(createRepo(slartiFjords)).then(() => { return store.dispatch(createRepo(URL, slartiFjords)).then(() => {
expect(store.getActions()).toEqual(expectedActions); expect(store.getActions()).toEqual(expectedActions);
}); });
}); });
@@ -396,7 +396,7 @@ describe("repos fetch", () => {
}; };
const store = mockStore({}); const store = mockStore({});
return store.dispatch(createRepo(slartiFjords, callback)).then(() => { return store.dispatch(createRepo(URL, slartiFjords, callback)).then(() => {
expect(callMe).toBe("yeah"); expect(callMe).toBe("yeah");
}); });
}); });
@@ -407,7 +407,7 @@ describe("repos fetch", () => {
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(createRepo(slartiFjords)).then(() => { return store.dispatch(createRepo(URL, slartiFjords)).then(() => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions[0].type).toEqual(CREATE_REPO_PENDING); expect(actions[0].type).toEqual(CREATE_REPO_PENDING);
expect(actions[1].type).toEqual(CREATE_REPO_FAILURE); expect(actions[1].type).toEqual(CREATE_REPO_FAILURE);