WIP - read only mode

pull/1348/head
Rick Carlino 2019-07-30 07:56:04 -05:00
parent 05a744df55
commit 7aaef7f93e
3 changed files with 25 additions and 1 deletions

View File

@ -11,7 +11,7 @@ module Api
CONSENT_REQUIRED =
"all device users must agree to terms of service."
NOT_JSON = "That request was not valid JSON. Consider checking the" \
" request body with a JSON validator.."
" request body with a JSON validator."
NULL = Gem::Version.new("0.0.0")
NOT_FBOS = Gem::Version.new("999.999.999")
@ -75,6 +75,10 @@ module Api
rescue_from(PG::ProgramLimitExceeded) { sorry TOO_MUCH_DATA }
rescue_from(ActionDispatch::Http::Parameters::ParseError) do
sorry NOT_JSON
end
def default_serializer_options
{ root: false, user: current_user }
end

View File

@ -23,6 +23,7 @@ import { arrayUnwrap } from "../resources/util";
import { findByUuid } from "../resources/reducer_support";
import { assign, noop } from "lodash";
import { t } from "../i18next_wrapper";
import { appIsReadonly } from "../resources/selectors";
export function edit(tr: TaggedResource, changes: Partial<typeof tr.body>):
ReduxAction<EditResourceParams> {
@ -195,6 +196,11 @@ export const destroyCatch = (p: DestroyNoProps) => (err: UnsafeError) => {
export function destroy(uuid: string, force = false) {
return function (dispatch: Function, getState: GetState) {
/** Stop user from deleting resources if app is read only. */
if (appIsReadonly(getState().resources.index)) {
return Promise.reject("Application is in read-only mode.");
}
const resource = findByUuid(getState().resources.index, uuid);
const maybeProceed = confirmationChecker(resource.kind, force);
return maybeProceed(() => {

View File

@ -20,6 +20,18 @@ import { DiagnosisSaucer } from "../devices/connectivity/diagnosis";
import { maybeSetTimezone } from "../devices/timezones/guess_timezone";
import { BooleanSetting } from "../session_keys";
const ReadOnlyIcon = (p: { locked: boolean }) => {
if (p.locked) {
return <div className="fa-stack fa-lg">
<i className="fa fa-pencil fa-stack-1x"></i>
<i className="fa fa-ban fa-stack-2x fa-rotate-90 text-danger"></i>
</div>;
} else {
return <div />;
}
};
export class NavBar extends React.Component<NavBarProps, Partial<NavBarState>> {
state: NavBarState = {
@ -57,6 +69,7 @@ export class NavBar extends React.Component<NavBarProps, Partial<NavBarState>> {
}
render() {
const isLocked = this.props.getConfigValue("user_interface_read_only_mode");
const hasName = this.props.user && this.props.user.body.name;
const firstName = hasName ?
@ -96,6 +109,7 @@ export class NavBar extends React.Component<NavBarProps, Partial<NavBarState>> {
<span className="top-menu-container">
{NavLinks({ close, alertCount })}
</span>
<ReadOnlyIcon locked={!!isLocked} />
</div>
<div className="nav-right">
<div className="menu-popover">