New ACS for ActivtiyPub enabled check

This commit is contained in:
Bryan Ashby 2023-02-27 12:59:35 -07:00
parent a968f21957
commit 65e5fa1b77
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
3 changed files with 22 additions and 0 deletions

View File

@ -937,6 +937,7 @@ function peg$parse(input, options) {
const Log = require('./logger.js').log; const Log = require('./logger.js').log;
const User = require('./user.js'); const User = require('./user.js');
const Config = require('./config.js').get; const Config = require('./config.js').get;
const ActivityPubSettings = require('./activitypub/settings');
const _ = require('lodash'); const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
@ -947,6 +948,17 @@ function peg$parse(input, options) {
function checkAccess(acsCode, value) { function checkAccess(acsCode, value) {
try { try {
return { return {
AE: function activityPubEnabled() {
const apSettings = ActivityPubSettings.fromUser(user);
switch (value) {
case 0:
return !apSettings.enabled;
case 1:
return apSettings.enabled;
default:
return false;
}
},
SE: function servicesEnabled() { SE: function servicesEnabled() {
if (!Array.isArray(value)) { if (!Array.isArray(value)) {
value = [value]; value = [value];

View File

@ -51,6 +51,7 @@ The following are ACS codes available as of this writing:
| AR<i>authFactorReq</i> | Current user **requires** an Authentication Factor >= _authFactorReq_ | | AR<i>authFactorReq</i> | Current user **requires** an Authentication Factor >= _authFactorReq_ |
| PV[_name,_value_] | Checks that the property by _name_ for the current user is exactly _value_. This ACS allows arbitrary user property values to be checked. For example, `PV[message_conf,local]` checks that the user is currently in the "local" message conference. | PV[_name,_value_] | Checks that the property by _name_ for the current user is exactly _value_. This ACS allows arbitrary user property values to be checked. For example, `PV[message_conf,local]` checks that the user is currently in the "local" message conference.
| SE[_service_,_service_,...] | Checks that all services listed by _service_ listed are enabled. Available services: `http`, `https`, `web` (`http` or `https`), `gopher`, `nntp`, `nntps`, `activitypub` (requires `web`), `nodeinfo2` (requires `web`), `webfinger` (requires `web`). Example: `SE[activitypub]`. | SE[_service_,_service_,...] | Checks that all services listed by _service_ listed are enabled. Available services: `http`, `https`, `web` (`http` or `https`), `gopher`, `nntp`, `nntps`, `activitypub` (requires `web`), `nodeinfo2` (requires `web`), `webfinger` (requires `web`). Example: `SE[activitypub]`.
| AE<i>enabled</i> | ActivityPub is _enabled_: 1=true, 0=false |
## ACS Strings ## ACS Strings
ACS strings are one or more ACS codes in addition to some basic language semantics. ACS strings are one or more ACS codes in addition to some basic language semantics.

View File

@ -4,6 +4,7 @@
const Log = require('./logger.js').log; const Log = require('./logger.js').log;
const User = require('./user.js'); const User = require('./user.js');
const Config = require('./config.js').get; const Config = require('./config.js').get;
const ActivityPubSettings = require('./activitypub/settings');
const _ = require('lodash'); const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
@ -14,6 +15,14 @@
function checkAccess(acsCode, value) { function checkAccess(acsCode, value) {
try { try {
return { return {
AE : function activityPubEnabled() {
const apSettings = ActivityPubSettings.fromUser(user);
switch(value) {
case 0 : return !apSettings.enabled;
case 1 : return apSettings.enabled;
default : return false;
}
},
SE : function servicesEnabled() { SE : function servicesEnabled() {
if (!Array.isArray(value)) { if (!Array.isArray(value)) {
value = [ value]; value = [ value];