Pad: Rename `author` context properties to `authorId`

pull/5423/head
Richard Hansen 2022-02-16 22:20:18 -05:00
parent 65bd5ffa6b
commit aec512d1fa
3 changed files with 25 additions and 6 deletions

View File

@ -57,6 +57,8 @@
* The `client` context property for the `handleMessageSecurity` and
`handleMessage` server-side hooks is deprecated; use the `socket` context
property instead.
* The `author` context property for the `padCreate` and `padUpdate` server-side
hooks is deprecated; use the new `authorId` context property instead.
* Returning `true` from a `handleMessageSecurity` hook function is deprecated;
return `'permitOnce'` instead.
* Changes to the `src/static/js/Changeset.js` library:

View File

@ -213,7 +213,8 @@ Called when a new pad is created.
Context properties:
* `pad`: The Pad object.
* `author`: The ID of the author who created the pad.
* `authorId`: The ID of the author who created the pad.
* `author` (**deprecated**): Synonym of `authorId`.
## `padLoad`
@ -234,7 +235,8 @@ Called when an existing pad is updated.
Context properties:
* `pad`: The Pad object.
* `author`: The ID of the author who updated the pad.
* `authorId`: The ID of the author who updated the pad.
* `author` (**deprecated**): Synonym of `authorId`.
* `revs`: The index of the new revision.
* `changeset`: The changeset of this revision (see [Changeset
Library](#index_changeset_library)).

View File

@ -18,6 +18,7 @@ const CustomError = require('../utils/customError');
const readOnlyManager = require('./ReadOnlyManager');
const randomString = require('../utils/randomstring');
const hooks = require('../../static/js/pluginfw/hooks');
const {padutils: {warnDeprecated}} = require('../../static/js/pad_utils');
const promises = require('../utils/promises');
// serialization/deserialization attributes
@ -109,11 +110,25 @@ Pad.prototype.appendRevision = async function (aChangeset, authorId) {
// set the author to pad
if (authorId) p.push(authorManager.addPad(authorId, this.id));
if (this.head === 0) {
hooks.callAll('padCreate', {pad: this, author: authorId});
} else {
hooks.callAll('padUpdate', {pad: this, author: authorId, revs: newRev, changeset: aChangeset});
let hook = 'padCreate';
const context = {
pad: this,
authorId,
get author() {
warnDeprecated(`${hook} hook author context is deprecated; use authorId instead`);
return this.authorId;
},
set author(authorId) {
warnDeprecated(`${hook} hook author context is deprecated; use authorId instead`);
this.authorId = authorId;
},
};
if (this.head !== 0) {
hook = 'padUpdate';
context.revs = newRev;
context.changeset = aChangeset;
}
hooks.callAll(hook, context);
await Promise.all(p);
return newRev;