diff --git a/install/data/navigation.json b/install/data/navigation.json index 5a744dbdf7..2c27e60755 100644 --- a/install/data/navigation.json +++ b/install/data/navigation.json @@ -65,5 +65,14 @@ "textClass": "d-lg-none", "text": "[[global:header.admin]]", "groups": ["administrators"] + }, + { + "route": "/additional-info", + "title": "Additional Information", + "enabled": true, + "iconClass": "fa-group", + "textClass": "d-lg-none", + "text": "Additional Information" } + ] \ No newline at end of file diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000000..d7476351a5 --- /dev/null +++ b/plugin.json @@ -0,0 +1,28 @@ +{ + "id": "nodebb-plugin-additional-info", + "name": "NodeBB Additional Info", + "description": "Adds an additional info page", + "hooks": [ + { + "hook": "static:app.load", + "method": "init" + } + ], + "library": "./src/controllers/index.js", + "routes": { + "/additional-info": { + "method": "get", + "handler": "./src/controllers/additional-info" + } + }, + "admin": { + "modules": { + "settings": "./src/admin/settings" + } + }, + "dependencies": {}, + "keywords": [] +} + + + \ No newline at end of file diff --git a/public/openapi/read.yaml b/public/openapi/read.yaml index 7c4e1f9e97..8e8b26b773 100644 --- a/public/openapi/read.yaml +++ b/public/openapi/read.yaml @@ -68,6 +68,8 @@ tags: paths: /api/: $ref: 'read/index.yaml' + /api/admin/additional-info: + $ref: 'read/admin/additional-info.yaml' /api/admin: $ref: 'read/admin.yaml' /api/admin/dashboard: diff --git a/public/openapi/read/admin/additional-info.yaml b/public/openapi/read/admin/additional-info.yaml new file mode 100644 index 0000000000..81f64beca5 --- /dev/null +++ b/public/openapi/read/admin/additional-info.yaml @@ -0,0 +1,18 @@ +paths: + /api/additional-info: + get: + summary: Get Additional Information + description: Returns additional information for the user. + operationId: getAdditionalInfo + responses: + '200': + description: A JSON object containing additional information. + content: + application/json: + schema: + type: object + properties: + info: + type: string + example: "This is the additional information." + diff --git a/src/controllers/additional-info.js b/src/controllers/additional-info.js new file mode 100644 index 0000000000..fb01a3c30e --- /dev/null +++ b/src/controllers/additional-info.js @@ -0,0 +1,15 @@ +'use strict'; + +// generated by chatGPT +const additionalInfoController = module.exports; + +additionalInfoController.get = async function (req, res) { + // You can customize the data being sent to the template + const data = { + title: 'Additional Information', + }; + + // Render the additional-info template without the 'templates/' prefix + res.render('additional-info', data); +}; + diff --git a/src/controllers/index.js b/src/controllers/index.js index 2cf50a7785..2e16963dd6 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -38,6 +38,15 @@ Controllers['404'] = require('./404'); Controllers.errors = require('./errors'); Controllers.composer = require('./composer'); +Controllers.additionalInfo = require('./additional-info'); + +// Add init function to register routes - ChatGPT +Controllers.init = async function (params) { + const { router } = params; + // Register the /additional-info route + router.get('/additional-info', Controllers.additionalInfo.get); +}; + Controllers.write = require('./write'); Controllers.reset = async function (req, res) { diff --git a/src/middleware/index.js b/src/middleware/index.js index 80a5f568c6..0a96436992 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -160,6 +160,7 @@ middleware.privateTagListing = helpers.try(async (req, res, next) => { next(); }); + middleware.exposeGroupName = helpers.try(async (req, res, next) => { await expose('groupName', groups.getGroupNameByGroupSlug, 'slug', req, res, next); }); diff --git a/src/routes/api.js b/src/routes/api.js index 8d795c443e..cabbf4b633 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -42,5 +42,12 @@ module.exports = function (app, middleware, controllers) { middleware.canViewUsers, middleware.checkAccountPermissions, ], helpers.tryRoute(controllers.accounts.edit.uploadPicture)); + + router.get('/admin/additional-info', (req, res) => { + const response = { + info: 'This is the additional information.', + }; + res.status(200).json(response); + }); }; diff --git a/src/routes/index.js b/src/routes/index.js index 4008f1565a..9f8d41d1e5 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -80,6 +80,13 @@ _mounts.categories = (app, name, middleware, controllers) => { setupPageRoute(app, '/recent', [], controllers.recent.get); setupPageRoute(app, '/top', [], controllers.top.get); setupPageRoute(app, '/unread', [middleware.ensureLoggedIn], controllers.unread.get); + // setupPageRoute(app, '/additional-info', [], controllers.additionalInfo.get); +}; + +_mounts.additionalInfo = (app, name, middleware, controllers) => { + const middlewares = [middleware.canViewInfo]; + + setupPageRoute(app, `/${name}`, middlewares, controllers.additionalInfo.list); }; _mounts.category = (app, name, middleware, controllers) => { diff --git a/src/routes/user.js b/src/routes/user.js index d6c0542000..192847bc7f 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -2,6 +2,8 @@ const helpers = require('./helpers'); +const additionalInfoController = require('../controllers/additional-info');// Generated by ChatGPT + const { setupPageRoute } = helpers; module.exports = function (app, name, middleware, controllers) { @@ -56,5 +58,6 @@ module.exports = function (app, name, middleware, controllers) { setupPageRoute(app, '/chats/:roomid?/:index?', [middleware.ensureLoggedIn], controllers.accounts.chats.redirectToChat); setupPageRoute(app, `/message/:mid`, [middleware.ensureLoggedIn], controllers.accounts.chats.redirectToMessage); + setupPageRoute(app, '/additional-info', [], additionalInfoController.get); // Generated by ChatGPT }; diff --git a/test/controllers-admin.js b/test/controllers-admin.js index 7760bf128e..73f542c8a0 100644 --- a/test/controllers-admin.js +++ b/test/controllers-admin.js @@ -101,6 +101,12 @@ describe('Admin Controllers', () => { assert(body); }); + it('should load additional information page', async () => { + const { response, body } = await request.get(`${nconf.get('url')}/admin/additional-info`, { jar: jar }); + assert.equal(response.statusCode, 200); + assert(body); + }); + it('should load groups detail page', async () => { const { response, body } = await request.get(`${nconf.get('url')}/admin/manage/groups/administrators`, { jar: jar }); assert.equal(response.statusCode, 200); diff --git a/test/controllers.js b/test/controllers.js index 418420303f..5d3c92d9d5 100644 --- a/test/controllers.js +++ b/test/controllers.js @@ -92,6 +92,7 @@ describe('Controllers', () => { { it: 'should load users page', url: `/users` }, { it: 'should load users page section', url: `/users?section=online` }, { it: 'should load groups page', url: `/groups` }, + { it: 'should load additional information page', url: `/additional-info` }, { it: 'should get recent posts', url: `/api/recent/posts/month` }, { it: 'should get post data', url: `/api/v3/posts/${pid}` }, { it: 'should get topic data', url: `/api/v3/topics/${tid}` },