Merged in feature/session_timeout (pull request #130)

Feature/session timeout
This commit is contained in:
René Pfeuffer
2018-12-19 10:37:45 +00:00
8 changed files with 59 additions and 85 deletions

View File

@@ -2,6 +2,7 @@
import React from "react";
import { translate } from "react-i18next";
import Notification from "./Notification";
import {UNAUTHORIZED_ERROR} from "./apiclient";
type Props = {
t: string => string,
@@ -9,14 +10,25 @@ type Props = {
};
class ErrorNotification extends React.Component<Props> {
render() {
const { t, error } = this.props;
if (error) {
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong> {error.message}
</Notification>
);
if (error === UNAUTHORIZED_ERROR) {
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong> {t("error-notification.timeout")}
{" "}
<a href="javascript:window.location.reload(true)">{t("error-notification.loginLink")}</a>
</Notification>
);
} else {
return (
<Notification type="danger">
<strong>{t("error-notification.prefix")}:</strong> {error.message}
</Notification>
);
}
}
return null;
}

View File

@@ -20,7 +20,9 @@
}
},
"error-notification": {
"prefix": "Error"
"prefix": "Error",
"loginLink": "You can login here again.",
"timeout": "The session has expired."
},
"loading": {
"alt": "Loading ..."

View File

@@ -32,9 +32,8 @@ export function fetchConfig(link: string) {
.then(data => {
dispatch(fetchConfigSuccess(data));
})
.catch(cause => {
const error = new Error(`could not fetch config: ${cause.message}`);
dispatch(fetchConfigFailure(error));
.catch(err => {
dispatch(fetchConfigFailure(err));
});
};
}
@@ -73,13 +72,8 @@ export function modifyConfig(config: Config, callback?: () => void) {
callback();
}
})
.catch(cause => {
dispatch(
modifyConfigFailure(
config,
new Error(`could not modify config: ${cause.message}`)
)
);
.catch(err => {
dispatch(modifyConfigFailure(config, err));
});
};
}

View File

@@ -54,9 +54,8 @@ export function fetchGroupsByLink(link: string) {
.then(data => {
dispatch(fetchGroupsSuccess(data));
})
.catch(cause => {
const error = new Error(`could not fetch groups: ${cause.message}`);
dispatch(fetchGroupsFailure(link, error));
.catch(err => {
dispatch(fetchGroupsFailure(link, err));
});
};
}
@@ -105,9 +104,8 @@ function fetchGroup(link: string, name: string) {
.then(data => {
dispatch(fetchGroupSuccess(data));
})
.catch(cause => {
const error = new Error(`could not fetch group: ${cause.message}`);
dispatch(fetchGroupFailure(name, error));
.catch(err => {
dispatch(fetchGroupFailure(name, err));
});
};
}
@@ -151,10 +149,10 @@ export function createGroup(link: string, group: Group, callback?: () => void) {
callback();
}
})
.catch(error => {
.catch(err => {
dispatch(
createGroupFailure(
new Error(`Failed to create group ${group.name}: ${error.message}`)
err
)
);
});
@@ -201,11 +199,11 @@ export function modifyGroup(group: Group, callback?: () => void) {
.then(() => {
dispatch(fetchGroupByLink(group));
})
.catch(cause => {
.catch(err => {
dispatch(
modifyGroupFailure(
group,
new Error(`could not modify group ${group.name}: ${cause.message}`)
err
)
);
});
@@ -259,11 +257,8 @@ export function deleteGroup(group: Group, callback?: () => void) {
callback();
}
})
.catch(cause => {
const error = new Error(
`could not delete group ${group.name}: ${cause.message}`
);
dispatch(deleteGroupFailure(group, error));
.catch(err => {
dispatch(deleteGroupFailure(group, err));
});
};
}

View File

@@ -224,9 +224,8 @@ export function modifyRepo(repository: Repository, callback?: () => void) {
.then(() => {
dispatch(fetchRepoByLink(repository));
})
.catch(cause => {
const error = new Error(`failed to modify repo: ${cause.message}`);
dispatch(modifyRepoFailure(repository, error));
.catch(err => {
dispatch(modifyRepoFailure(repository, err));
});
};
}

View File

@@ -1,12 +1,16 @@
// @flow
import type {Action} from "@scm-manager/ui-components";
import {apiClient} from "@scm-manager/ui-components";
import type { Action } from "@scm-manager/ui-components";
import { apiClient } from "@scm-manager/ui-components";
import * as types from "../../../modules/types";
import type {Permission, PermissionCollection, PermissionCreateEntry} from "@scm-manager/ui-types";
import {isPending} from "../../../modules/pending";
import {getFailure} from "../../../modules/failure";
import {Dispatch} from "redux";
import type {
Permission,
PermissionCollection,
PermissionCreateEntry
} from "@scm-manager/ui-types";
import { isPending } from "../../../modules/pending";
import { getFailure } from "../../../modules/failure";
import { Dispatch } from "redux";
export const FETCH_PERMISSIONS = "scm/permissions/FETCH_PERMISSIONS";
export const FETCH_PERMISSIONS_PENDING = `${FETCH_PERMISSIONS}_${
@@ -141,13 +145,8 @@ export function modifyPermission(
callback();
}
})
.catch(cause => {
const error = new Error(
`failed to modify permission: ${cause.message}`
);
dispatch(
modifyPermissionFailure(permission, error, namespace, repoName)
);
.catch(err => {
dispatch(modifyPermissionFailure(permission, err, namespace, repoName));
});
};
}
@@ -241,15 +240,7 @@ export function createPermission(
}
})
.catch(err =>
dispatch(
createPermissionFailure(
new Error(
`failed to add permission ${permission.name}: ${err.message}`
),
namespace,
repoName
)
)
dispatch(createPermissionFailure(err, namespace, repoName))
);
};
}
@@ -318,13 +309,8 @@ export function deletePermission(
callback();
}
})
.catch(cause => {
const error = new Error(
`could not delete permission ${permission.name}: ${cause.message}`
);
dispatch(
deletePermissionFailure(permission, namespace, repoName, error)
);
.catch(err => {
dispatch(deletePermissionFailure(permission, namespace, repoName, err));
});
};
}

View File

@@ -25,8 +25,7 @@ export function fetchSources(
dispatch(fetchSourcesSuccess(repository, revision, path, sources));
})
.catch(err => {
const error = new Error(`failed to fetch sources: ${err.message}`);
dispatch(fetchSourcesFailure(repository, revision, path, error));
dispatch(fetchSourcesFailure(repository, revision, path, err));
});
};
}

View File

@@ -35,8 +35,6 @@ export const DELETE_USER_FAILURE = `${DELETE_USER}_${types.FAILURE_SUFFIX}`;
const CONTENT_TYPE_USER = "application/vnd.scmm-user+json;v=2";
// TODO i18n for error messages
// fetch users
export function fetchUsers(link: string) {
@@ -57,9 +55,8 @@ export function fetchUsersByLink(link: string) {
.then(data => {
dispatch(fetchUsersSuccess(data));
})
.catch(cause => {
const error = new Error(`could not fetch users: ${cause.message}`);
dispatch(fetchUsersFailure(link, error));
.catch(err => {
dispatch(fetchUsersFailure(link, err));
});
};
}
@@ -108,9 +105,8 @@ function fetchUser(link: string, name: string) {
.then(data => {
dispatch(fetchUserSuccess(data));
})
.catch(cause => {
const error = new Error(`could not fetch user: ${cause.message}`);
dispatch(fetchUserFailure(name, error));
.catch(err => {
dispatch(fetchUserFailure(name, err));
});
};
}
@@ -155,13 +151,7 @@ export function createUser(link: string, user: User, callback?: () => void) {
callback();
}
})
.catch(err =>
dispatch(
createUserFailure(
new Error(`failed to add user ${user.name}: ${err.message}`)
)
)
);
.catch(err => dispatch(createUserFailure(err)));
};
}
@@ -260,11 +250,8 @@ export function deleteUser(user: User, callback?: () => void) {
callback();
}
})
.catch(cause => {
const error = new Error(
`could not delete user ${user.name}: ${cause.message}`
);
dispatch(deleteUserFailure(user, error));
.catch(err => {
dispatch(deleteUserFailure(user, err));
});
};
}