@@ -53,6 +53,9 @@ export class DraftController extends EventListener {
53
53
private cachedData : any = { } ;
54
54
private subscribers : Subscribers = { } ;
55
55
private saveState = SaveState . NO_CHANGES ;
56
+ private autolock = false ;
57
+ private autolockReason = 'autolock' ;
58
+ private autolockApplied = false ;
56
59
started = false ;
57
60
58
61
constructor ( docId : string ) {
@@ -72,6 +75,13 @@ export class DraftController extends EventListener {
72
75
'Drafts' ,
73
76
slug
74
77
) ;
78
+ const collection = window . __ROOT_CTX . collections [ collectionId ] ;
79
+ if ( collection ) {
80
+ this . autolock = ! ! collection . autolock ;
81
+ if ( collection . autolockReason ) {
82
+ this . autolockReason = collection . autolockReason ;
83
+ }
84
+ }
75
85
}
76
86
77
87
/**
@@ -171,7 +181,6 @@ export class DraftController extends EventListener {
171
181
* Updates a group of keys. The keys can be a nested, e.g. "meta.title".
172
182
*/
173
183
async updateKeys ( updates : Record < string , any > ) {
174
- console . log ( 'updateKeys()' , updates ) ;
175
184
for ( const key in updates ) {
176
185
this . pendingUpdates . set ( key , updates [ key ] ) ;
177
186
}
@@ -230,7 +239,21 @@ export class DraftController extends EventListener {
230
239
const updates = Object . fromEntries ( this . pendingUpdates ) ;
231
240
updates [ 'sys.modifiedAt' ] = serverTimestamp ( ) ;
232
241
updates [ 'sys.modifiedBy' ] = window . firebase . user . email ;
233
- console . log ( 'flush()' , updates ) ;
242
+
243
+ // If autolock is enabled on the collection, add a publishing lock if one
244
+ // doesn't already exist on the doc.
245
+ if (
246
+ this . autolock &&
247
+ ! this . autolockApplied &&
248
+ ! this . cachedData ?. sys ?. publishingLocked
249
+ ) {
250
+ this . autolockApplied = true ;
251
+ updates [ 'sys.publishingLocked' ] = {
252
+ lockedAt : serverTimestamp ( ) ,
253
+ lockedBy : window . firebase . user . email ,
254
+ reason : this . autolockReason ,
255
+ } ;
256
+ }
234
257
235
258
// Immediately clear the pending updates so that there's no race condition
236
259
// with any new updates the user makes while the changes are being saved to
0 commit comments