@@ -218,12 +218,23 @@ class CausalSet<T> extends BaseCausalCollection<T> implements CausalCollection<T
218218 return CausalSet . className ;
219219 }
220220
221- canAdd ( author ?: Identity , extraAuth ?: Authorizer ) : Promise < boolean > {
222- return Authorization . chain ( this . createAddAuthorizer ( author ) , extraAuth ) . attempt ( ) ;
221+ // canAdd: if a parameter is absent, interpret it as if addition is allowed for any possible value
222+
223+ // e.g.: element === undefined, can add independently of what is being added,
224+ // author === undefined, can add independently of who is doing it, etc.
225+
226+ // same goes for canDelete, canDeleteByHash.
227+
228+ canAdd ( element ?: T , author ?: Identity , extraAuth ?: Authorizer ) : Promise < boolean > {
229+ return Authorization . chain ( this . createAddAuthorizer ( element , author ) , extraAuth ) . attempt ( ) ;
230+ }
231+
232+ canDelete ( element ?: T , author ?: Identity , extraAuth ?: Authorizer ) : Promise < boolean > {
233+ return Authorization . chain ( this . createDeleteAuthorizer ( element , author ) , extraAuth ) . attempt ( ) ;
223234 }
224235
225- canDelete ( author ?: Identity , extraAuth ?: Authorizer ) : Promise < boolean > {
226- return Authorization . chain ( this . createDeleteAuthorizer ( author ) , extraAuth ) . attempt ( ) ;
236+ canDeleteByHash ( elementHash ?: Hash , author ?: Identity , extraAuth ?: Authorizer ) : Promise < boolean > {
237+ return Authorization . chain ( this . createDeleteAuthorizerByHash ( elementHash , author ) , extraAuth ) . attempt ( ) ;
227238 }
228239
229240
@@ -239,7 +250,7 @@ class CausalSet<T> extends BaseCausalCollection<T> implements CausalCollection<T
239250
240251 const addOp = new AddOp ( this , elmt , author ) ;
241252
242- const auth = Authorization . chain ( this . createAddAuthorizer ( addOp . getAuthor ( ) ) , extraAuth ) ;
253+ const auth = Authorization . chain ( this . createAddAuthorizer ( elmt , addOp . getAuthor ( ) ) , extraAuth ) ;
243254
244255 this . setCurrentPrevOpsTo ( addOp ) ;
245256
@@ -266,7 +277,7 @@ class CausalSet<T> extends BaseCausalCollection<T> implements CausalCollection<T
266277 const addOp = this . _currentAddOps . get ( addOpHash ) as AddOp < T > ;
267278 const deleteOp = new DeleteOp ( addOp , author ) ;
268279
269- const auth = Authorization . chain ( this . createDeleteAuthorizer ( deleteOp . getAuthor ( ) ) , extraAuth ) ;
280+ const auth = Authorization . chain ( this . createDeleteAuthorizerByHash ( hash , deleteOp . getAuthor ( ) ) , extraAuth ) ;
270281
271282 this . setCurrentPrevOpsTo ( deleteOp ) ;
272283
@@ -395,9 +406,9 @@ class CausalSet<T> extends BaseCausalCollection<T> implements CausalCollection<T
395406 const author = op . getAuthor ( ) ;
396407
397408 const auth = ( op instanceof AddOp ) ?
398- this . createAddAuthorizer ( author )
409+ this . createAddAuthorizer ( op . element , author )
399410 :
400- this . createDeleteAuthorizer ( author ) ; ;
411+ this . createDeleteAuthorizer ( op . getAddOp ( ) . element , author ) ; ;
401412
402413 const usedKeys = new Set < string > ( ) ;
403414
@@ -537,11 +548,15 @@ class CausalSet<T> extends BaseCausalCollection<T> implements CausalCollection<T
537548 return found ;
538549 }
539550
540- protected createAddAuthorizer ( author ?: Identity ) : Authorizer {
551+ protected createAddAuthorizer ( _element ?: T , author ?: Identity ) : Authorizer {
552+ return this . createWriteAuthorizer ( author ) ;
553+ }
554+
555+ protected createDeleteAuthorizer ( _element ?: T , author ?: Identity ) : Authorizer {
541556 return this . createWriteAuthorizer ( author ) ;
542557 }
543558
544- protected createDeleteAuthorizer ( author ?: Identity ) : Authorizer {
559+ protected createDeleteAuthorizerByHash ( _elementHash ?: Hash , author ?: Identity ) : Authorizer {
545560 return this . createWriteAuthorizer ( author ) ;
546561 }
547562
0 commit comments