Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routes and Controllers for the new Additional Information Page #34

Merged
merged 20 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions install/data/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

]
28 changes: 28 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -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": []
}



2 changes: 2 additions & 0 deletions public/openapi/read.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions public/openapi/read/admin/additional-info.yaml
Original file line number Diff line number Diff line change
@@ -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."

15 changes: 15 additions & 0 deletions src/controllers/additional-info.js
Original file line number Diff line number Diff line change
@@ -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);
};

9 changes: 9 additions & 0 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ middleware.privateTagListing = helpers.try(async (req, res, next) => {
next();
});


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we can probably remove this empty line but everything else lgtm!

middleware.exposeGroupName = helpers.try(async (req, res, next) => {
await expose('groupName', groups.getGroupNameByGroupSlug, 'slug', req, res, next);
});
Expand Down
7 changes: 7 additions & 0 deletions src/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

7 changes: 7 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions src/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
};

6 changes: 6 additions & 0 deletions test/controllers-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}` },
Expand Down
Loading