Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 8ed0518

Browse files
committed
Add server side code to expose readonly property and use it in the frontend
1 parent 60daf3d commit 8ed0518

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

app/Document.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class Document extends Record({
99
last_modified: null, // defined by the server
1010
last_modified_locally: null,
1111
template: '',
12+
readonly: false,
1213
}) {
1314

1415
hasDefaultContent() {
@@ -26,4 +27,8 @@ export default class Document extends Record({
2627
isDefault() {
2728
return this.hasDefaultContent() && this.hasNeverBeenSync() && this.hasNoLocalChanges();
2829
}
30+
31+
isReadOnly() {
32+
return true === this.readonly;
33+
}
2934
}

app/__tests__/server-test.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ describe('Express app', () => {
3737
.expect(200, {
3838
content: { ba: 'bar' },
3939
last_modified: 1459441561629,
40-
uuid: '9950e80b-f214-45d0-a98c-bffee2582c71'
40+
uuid: '9950e80b-f214-45d0-a98c-bffee2582c71',
41+
readonly: false,
4142
}, done);
4243
});
4344

@@ -49,6 +50,7 @@ describe('Express app', () => {
4950
content: { ba: 'bar' },
5051
last_modified: 1459441561629,
5152
uuid: READONLY_DOCUMENT_UUID,
53+
readonly: true,
5254
}, done);
5355
});
5456
});
@@ -128,7 +130,7 @@ describe('Express app', () => {
128130
content: content,
129131
uuid: EXISTING_DOCUMENT_UUID,
130132
template: '',
131-
last_modified: 'date'
133+
last_modified: 'date',
132134
}, done);
133135
});
134136

@@ -143,6 +145,7 @@ describe('Express app', () => {
143145
},
144146
last_modified: 1459441561629,
145147
uuid: READONLY_DOCUMENT_UUID,
148+
readonly: true,
146149
}, done);
147150
});
148151
});

app/modules/monod.js

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function load(id, secret) {
7676
content: res.body.content,
7777
last_modified: res.body.last_modified,
7878
template: res.body.template || '', // avoid BC break
79+
readonly: res.body.readonly || false, // avoid BC break
7980
}));
8081
})
8182
.catch((err) => {

app/modules/persistence.js

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function serverPersist() {
7676
last_modified: res.body.last_modified,
7777
last_modified_locally: null,
7878
template: res.body.template || '',
79+
readonly: res.body.readonly || false,
7980
});
8081

8182
return Promise.resolve(current);
@@ -107,6 +108,7 @@ export function serverPersist() {
107108
last_modified: res.body.last_modified,
108109
last_modified_locally: null,
109110
template: res.body.template || '',
111+
readonly: res.body.readonly || false,
110112
});
111113

112114
dispatch(warning(config.READONLY_MESSAGE));

app/modules/sync.js

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export function synchronize() { // eslint-disable-line import/prefer-default-exp
6666
content: res.body.content,
6767
last_modified: res.body.last_modified,
6868
template: res.body.template || '', // avoid BC break
69+
readonly: res.body.readonly || false, // avoid BC break
6970
}));
7071
})
7172
.catch((err) => {
@@ -140,6 +141,7 @@ export function synchronize() { // eslint-disable-line import/prefer-default-exp
140141
content: serverDoc.get('content'),
141142
last_modified: serverDoc.get('last_modified'),
142143
template: serverDoc.get('template'),
144+
readonly: serverDoc.get('readonly'),
143145
});
144146

145147
return db

server.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ if ('production' === process.env.NODE_ENV || 'test' === process.env.NODE_ENV) {
4747
}
4848

4949
const document = JSON.parse(data);
50-
51-
if (document.readonly) {
52-
delete(document.readonly);
53-
}
50+
document.readonly = !!document.readonly;
5451

5552
return res.json(document);
5653
});
@@ -70,8 +67,6 @@ if ('production' === process.env.NODE_ENV || 'test' === process.env.NODE_ENV) {
7067
const document = readErr ? {} : JSON.parse(data);
7168

7269
if (!!document.readonly) {
73-
delete(document.readonly);
74-
7570
return res.status(403).json(document);
7671
}
7772

0 commit comments

Comments
 (0)