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

View File

@@ -27,6 +27,7 @@ import Permissions from "../permissions/containers/Permissions";
import type { History } from "history";
import EditNavLink from "../components/EditNavLink";
import PermissionsNavLink from "../components/PermissionsNavLink";
import { getRepositoriesLink } from "../../modules/indexResource";
type Props = {
namespace: string,
@@ -34,9 +35,10 @@ type Props = {
repository: Repository,
loading: boolean,
error: Error,
repoLink: string,
// dispatch functions
fetchRepo: (namespace: string, name: string) => void,
fetchRepo: (link: string, namespace: string, name: string) => void,
deleteRepo: (repository: Repository, () => void) => void,
// context props
@@ -47,9 +49,9 @@ type Props = {
class RepositoryRoot extends React.Component<Props> {
componentDidMount() {
const { fetchRepo, namespace, name } = this.props;
const { fetchRepo, namespace, name, repoLink } = this.props;
fetchRepo(namespace, name);
fetchRepo(repoLink, namespace, name);
}
stripEndingSlash = (url: string) => {
@@ -140,19 +142,21 @@ const mapStateToProps = (state, ownProps) => {
const repository = getRepository(state, namespace, name);
const loading = isFetchRepoPending(state, namespace, name);
const error = getFetchRepoFailure(state, namespace, name);
const repoLink = getRepositoriesLink(state);
return {
namespace,
name,
repository,
loading,
error
error,
repoLink
};
};
const mapDispatchToProps = dispatch => {
return {
fetchRepo: (namespace: string, name: string) => {
dispatch(fetchRepo(namespace, name));
fetchRepo: (link: string, namespace: string, name: string) => {
dispatch(fetchRepo(link, namespace, name));
},
deleteRepo: (repository: Repository, callback: () => void) => {
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_FAILURE = `${DELETE_REPO}_${types.FAILURE_SUFFIX}`;
const REPOS_URL = "repositories";
const CONTENT_TYPE = "application/vnd.scmm-repository+json;v=2";
// fetch repos
@@ -102,11 +100,12 @@ export function fetchReposFailure(err: Error): Action {
// 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) {
dispatch(fetchRepoPending(namespace, name));
return apiClient
.get(`${REPOS_URL}/${namespace}/${name}`)
.get(`${repoUrl}${namespace}/${name}`)
.then(response => response.json())
.then(repository => {
dispatch(fetchRepoSuccess(repository));
@@ -154,11 +153,11 @@ export function fetchRepoFailure(
// create repo
export function createRepo(repository: Repository, callback?: () => void) {
export function createRepo(link: string, repository: Repository, callback?: () => void) {
return function(dispatch: any) {
dispatch(createRepoPending());
return apiClient
.post(REPOS_URL, repository, CONTENT_TYPE)
.post(link, repository, CONTENT_TYPE)
.then(() => {
dispatch(createRepoSuccess());
if (callback) {

View File

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