mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: global switch for disabling federation, + test
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
"settings/tags": "Tags",
|
||||
"settings/notifications": "Notifications",
|
||||
"settings/api": "API Access",
|
||||
"settings/activitypub": "Federation (ActivityPub)",
|
||||
"settings/sounds": "Sounds",
|
||||
"settings/social": "Social",
|
||||
"settings/cookies": "Cookies",
|
||||
|
||||
7
public/language/en-GB/admin/settings/activitypub.json
Normal file
7
public/language/en-GB/admin/settings/activitypub.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"intro-lead": "What is Federation?",
|
||||
"intro-body": "NodeBB is able to communicate with other NodeBB instances that support it. This is achieved through a protocol called <a href=\"https://activitypub.rocks/\">ActivityPub</a>. If enabled, NodeBB will also be able to communicate with other apps and websites that use ActivityPub (e.g. Mastodon, Peertube, etc.)",
|
||||
|
||||
"general": "General",
|
||||
"enabled": "Enable Federation"
|
||||
}
|
||||
@@ -302,7 +302,7 @@ middleware.proceedOnActivityPub = (req, res, next) => {
|
||||
// For whatever reason, express accepts does not recognize "profile" as a valid differentiator
|
||||
// Therefore, manual header parsing is used here.
|
||||
const { accept } = req.headers;
|
||||
if (!accept) {
|
||||
if (!accept || !meta.config.activityPubEnabled) {
|
||||
return next('route');
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
<a class="btn-ghost-sm justify-content-start text-decoration-none" href="{relative_path}/admin/settings/pagination">[[admin/menu:settings/pagination]]</a>
|
||||
<a class="btn-ghost-sm justify-content-start text-decoration-none" href="{relative_path}/admin/settings/notifications">[[admin/menu:settings/notifications]]</a>
|
||||
<a class="btn-ghost-sm justify-content-start text-decoration-none" href="{relative_path}/admin/settings/api">[[admin/menu:settings/api]]</a>
|
||||
<a class="btn-ghost-sm justify-content-start text-decoration-none" href="{relative_path}/admin/settings/activitypub">[[admin/menu:settings/activitypub]]</a>
|
||||
<a class="btn-ghost-sm justify-content-start text-decoration-none" href="{relative_path}/admin/settings/cookies">[[admin/menu:settings/cookies]]</a>
|
||||
<a class="btn-ghost-sm justify-content-start text-decoration-none" href="{relative_path}/admin/settings/web-crawler">[[admin/menu:settings/web-crawler]]</a>
|
||||
<a class="btn-ghost-sm justify-content-start text-decoration-none" href="{relative_path}/admin/settings/advanced">[[admin/menu:settings/advanced]]</a>
|
||||
|
||||
20
src/views/admin/settings/activitypub.tpl
Normal file
20
src/views/admin/settings/activitypub.tpl
Normal file
@@ -0,0 +1,20 @@
|
||||
<!-- IMPORT admin/partials/settings/header.tpl -->
|
||||
|
||||
<p class="lead">[[admin/settings/activitypub:intro-lead]]</p>
|
||||
<p>[[admin/settings/activitypub:intro-body]]</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class="row mb-4">
|
||||
<div class="col-sm-2 col-12 settings-header">[[admin/settings/activitypub:general]]</div>
|
||||
<div class="col-sm-10 col-12">
|
||||
<form>
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input class="form-check-input" type="checkbox" data-field="activityPubEnabled">
|
||||
<label class="form-check-label">[[admin/settings/activitypub:enabled]]</label>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- IMPORT admin/partials/settings/footer.tpl -->
|
||||
@@ -8,10 +8,19 @@ const db = require('./mocks/databasemock');
|
||||
const slugify = require('../src/slugify');
|
||||
const utils = require('../src/utils');
|
||||
|
||||
const meta = require('../src/meta');
|
||||
const user = require('../src/user');
|
||||
const privileges = require('../src/privileges');
|
||||
|
||||
describe('ActivityPub integration', () => {
|
||||
before(() => {
|
||||
meta.config.activityPubEnabled = 1;
|
||||
});
|
||||
|
||||
after(() => {
|
||||
delete meta.config.activityPubEnabled;
|
||||
});
|
||||
|
||||
describe('WebFinger endpoint', () => {
|
||||
let uid;
|
||||
let slug;
|
||||
@@ -98,6 +107,26 @@ describe('ActivityPub integration', () => {
|
||||
uid = await user.create({ username: slug });
|
||||
});
|
||||
|
||||
it('should return regular user profile html if federation is disabled', async () => {
|
||||
delete meta.config.activityPubEnabled;
|
||||
|
||||
const response = await request(`${nconf.get('url')}/user/${slug}`, {
|
||||
method: 'get',
|
||||
followRedirect: true,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true,
|
||||
headers: {
|
||||
Accept: 'text/html',
|
||||
},
|
||||
});
|
||||
|
||||
assert(response);
|
||||
assert.strictEqual(response.statusCode, 200);
|
||||
assert(response.body.startsWith('<!DOCTYPE html>'));
|
||||
|
||||
meta.config.activityPubEnabled = 1;
|
||||
});
|
||||
|
||||
it('should return regular user profile html if Accept header is not ActivityPub-related', async () => {
|
||||
const response = await request(`${nconf.get('url')}/user/${slug}`, {
|
||||
method: 'get',
|
||||
|
||||
Reference in New Issue
Block a user