Node.js based forum software built for the modern web
feat(topic-events): topic events GET route in write API
Julian Lamdc84559d0b23
diff --git a/public/openapi/write.yaml b/public/openapi/write.yamlindex c1ea408afa..9510876c44 100644--- a/public/openapi/write.yaml+++ b/public/openapi/write.yaml@@ -100,6 +100,8 @@ paths:$ref: 'write/topics/tid/tags.yaml'/topics/{tid}/thumbs:$ref: 'write/topics/tid/thumbs.yaml'+ /topics/{tid}/events:+ $ref: 'write/topics/tid/events.yaml'/posts/{pid}:$ref: 'write/posts/pid.yaml'/posts/{pid}/state:diff --git a/public/openapi/write/topics/tid/events.yaml b/public/openapi/write/topics/tid/events.yamlnew file mode 100644index 0000000000..0bf03cd604--- /dev/null+++ b/public/openapi/write/topics/tid/events.yaml@@ -0,0 +1,85 @@+get:+ tags:+ - topics+ summary: get topic events+ description: This operation retrieves a topic's events+ parameters:+ - in: path+ name: tid+ schema:+ type: string+ required: true+ description: a valid topic id+ example: 1+ responses:+ '200':+ description: Topic events successfully retrieved+ content:+ application/json:+ schema:+ type: object+ properties:+ status:+ $ref: ../../../components/schemas/Status.yaml#/Status+ response:+ type: array+ description: A list of the topic events that still remain+ items:+ type: object+ properties:+ type:+ type: string+ description: A valid event type+ id:+ type: number+ description: Unique identifier for this topic event+ timestamp:+ type: number+ timestampISO:+ type: string+ description: An ISO 8601 formatted date string (complementing `timestamp`)+ icon:+ type: string+ description: FontAwesome icon name+ example: fa-bullhorn+ text:+ type: string+ description: A language key+ uid:+ type: number+ user:+ type: object+ properties:+ uid:+ type: number+ description: A user identifier+ username:+ type: string+ description: A friendly name for a given user account+ displayname:+ type: string+ description: This is either username or fullname depending on forum and user settings+ userslug:+ type: string+ description: An URL-safe variant of the username (i.e. lower-cased, spaces+ removed, etc.)+ picture:+ nullable: true+ type: string+ icon:text:+ type: string+ description: A single-letter representation of a username. This is used in the+ auto-generated icon given to users+ without an avatar+ icon:bgColor:+ type: string+ description: A six-character hexadecimal colour code assigned to the user. This+ value is used in conjunction with+ `icon:text` for the user's+ auto-generated icon+ example: "#f44336"+ required:+ - type+ - id+ - timestamp+ - timestampISO\ No newline at end of filediff --git a/src/controllers/write/topics.js b/src/controllers/write/topics.jsindex 5696f51a07..303fa60c4f 100644--- a/src/controllers/write/topics.js+++ b/src/controllers/write/topics.js@@ -181,3 +181,11 @@ async function checkThumbPrivileges({ tid, uid, res }) {return helpers.formatApiResponse(403, res, new Error('[[error:no-privileges]]'));}}++Topics.getEvents = async (req, res) => {+ if (!await privileges.topics.can('topics:read', req.params.tid, req.uid)) {+ return helpers.formatApiResponse(403, res);+ }++ helpers.formatApiResponse(200, res, await topics.events.get(req.params.tid));+};diff --git a/src/routes/write/topics.js b/src/routes/write/topics.jsindex 465ecdea45..7276fd9a3d 100644--- a/src/routes/write/topics.js+++ b/src/routes/write/topics.js@@ -40,5 +40,7 @@ module.exports = function () {setupApiRoute(router, 'put', '/:tid/thumbs', [], controllers.write.topics.migrateThumbs);setupApiRoute(router, 'delete', '/:tid/thumbs', [...middlewares, middleware.checkRequired.bind(null, ['path'])], controllers.write.topics.deleteThumb);+ setupApiRoute(router, 'get', '/:tid/events', [middleware.authenticateOrGuest, middleware.assert.topic], controllers.write.topics.getEvents);+return router;};