diff --git a/client/src/containers/NavigationLinks/view.jsx b/client/src/containers/NavigationLinks/view.jsx index 2f8ce8ca..c1a71335 100644 --- a/client/src/containers/NavigationLinks/view.jsx +++ b/client/src/containers/NavigationLinks/view.jsx @@ -1,7 +1,7 @@ import React from 'react'; import { NavLink, withRouter } from 'react-router-dom'; import NavBarChannelOptionsDropdown from '@components/NavBarChannelOptionsDropdown'; -import isApprovedChannel from '../../utils/isApprovedChannel'; +import isApprovedChannel from '../../../../utils/isApprovedChannel'; const VIEW = 'VIEW'; const LOGOUT = 'LOGOUT'; diff --git a/server/controllers/api/channel/data/index.js b/server/controllers/api/channel/data/index.js index b9513edc..c0401e1f 100644 --- a/server/controllers/api/channel/data/index.js +++ b/server/controllers/api/channel/data/index.js @@ -1,7 +1,7 @@ const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); const getChannelData = require('./getChannelData.js'); -const isApprovedChannel = require('../../../../utils/isApprovedChannel'); -const { publishing: { serveOnlyApproved } } = require('@config/siteConfig'); +const isApprovedChannel = require('../../../../../utils/isApprovedChannel'); +const { publishing: { serveOnlyApproved, approvedChannels } } = require('@config/siteConfig'); const NO_CHANNEL = 'NO_CHANNEL'; /* @@ -18,7 +18,7 @@ const channelData = ({ ip, originalUrl, body, params }, res) => { const chanObj = {}; if (channelName) chanObj.name = channelName; if (channelClaimId) chanObj[(channelClaimId.length === 40 ? 'longId' : 'shortId')] = channelClaimId; - if (serveOnlyApproved && !isApprovedChannel(chanObj)) { + if (serveOnlyApproved && !isApprovedChannel(chanObj, approvedChannels)) { return res.status(404).json({ success: false, message: 'This content is unavailable', diff --git a/server/controllers/api/claim/publish/index.js b/server/controllers/api/claim/publish/index.js index c5a2bdbb..7fa525d0 100644 --- a/server/controllers/api/claim/publish/index.js +++ b/server/controllers/api/claim/publish/index.js @@ -3,8 +3,8 @@ const logger = require('winston'); const { details: { host }, publishing: { disabled, disabledMessage } } = require('@config/siteConfig'); const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js'); -const isApprovedChannel = require('../../../../utils/isApprovedChannel'); -const { publishing: { publishOnlyApproved } } = require('@config/siteConfig'); +const isApprovedChannel = require('../../../../../utils/isApprovedChannel'); +const { publishing: { publishOnlyApproved, approvedChannels } } = require('@config/siteConfig'); const { handleErrorResponse } = require('../../../utils/errorHandlers.js'); @@ -57,7 +57,7 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res) // check channel authorization authenticateUser(channelName, channelId, channelPassword, user) .then(({ channelName, channelClaimId }) => { - if (publishOnlyApproved && !isApprovedChannel({ longId: channelClaimId })) { + if (publishOnlyApproved && !isApprovedChannel({ longId: channelClaimId }, approvedChannels)) { const error = { name : UNAPPROVED_CHANNEL, message: 'This spee.ch instance only allows publishing to approved channels', diff --git a/server/controllers/assets/utils/getClaimIdAndServeAsset.js b/server/controllers/assets/utils/getClaimIdAndServeAsset.js index 031bfc67..1feb5ba2 100644 --- a/server/controllers/assets/utils/getClaimIdAndServeAsset.js +++ b/server/controllers/assets/utils/getClaimIdAndServeAsset.js @@ -1,7 +1,7 @@ const logger = require('winston'); const db = require('../../../models'); -const isApprovedChannel = require('../../../utils/isApprovedChannel'); +const isApprovedChannel = require('../../../../utils/isApprovedChannel'); const getClaimId = require('../../utils/getClaimId.js'); const { handleErrorResponse } = require('../../utils/errorHandlers.js'); @@ -14,7 +14,7 @@ const BLOCKED_CLAIM = 'BLOCKED_CLAIM'; const NO_FILE = 'NO_FILE'; const CONTENT_UNAVAILABLE = 'CONTENT_UNAVAILABLE'; -const { publishing: { serveOnlyApproved } } = require('@config/siteConfig'); +const { publishing: { serveOnlyApproved, approvedChannels } } = require('@config/siteConfig'); const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId, originalUrl, ip, res) => { getClaimId(channelName, channelClaimId, claimName, claimId) @@ -29,7 +29,7 @@ const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId }); }) .then(claim => { - if (serveOnlyApproved && !isApprovedChannel({ longId: claim.dataValues.certificateId })) { + if (serveOnlyApproved && !isApprovedChannel({ longId: claim.dataValues.certificateId }, approvedChannels)) { throw new Error(CONTENT_UNAVAILABLE); } logger.debug('Outpoint:', claim.dataValues.outpoint); diff --git a/server/models/claim.js b/server/models/claim.js index 8987b7a1..0385cc02 100644 --- a/server/models/claim.js +++ b/server/models/claim.js @@ -1,8 +1,8 @@ const logger = require('winston'); const returnShortId = require('./utils/returnShortId.js'); -const isApprovedChannel = require('../utils/isApprovedChannel'); +const isApprovedChannel = require('../../utils/isApprovedChannel'); const { assetDefaults: { thumbnail: defaultThumbnail }, details: { host } } = require('@config/siteConfig'); -const { publishing: { serveOnlyApproved } } = require('@config/siteConfig'); +const { publishing: { serveOnlyApproved, approvedChannels } } = require('@config/siteConfig'); const NO_CLAIM = 'NO_CLAIM'; @@ -364,7 +364,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => { where: { name, claimId }, }) .then(claimArray => { - if (serveOnlyApproved && !isApprovedChannel({ longId: claimArray[0].dataValues.certificateId })) { + if (serveOnlyApproved && !isApprovedChannel({ longId: claimArray[0].dataValues.certificateId }, approvedChannels)) { reject('This content is unavailable'); } switch (claimArray.length) { diff --git a/server/utils/isApprovedChannel.js b/server/utils/isApprovedChannel.js deleted file mode 100644 index e1b451e2..00000000 --- a/server/utils/isApprovedChannel.js +++ /dev/null @@ -1,11 +0,0 @@ -const { publishing: { approvedChannels } } = require('@config/siteConfig'); - -function isApprovedChannel (channel, channels = approvedChannels) { - const { name, shortId: short, longId: long } = channel; - return Boolean( - (long && channels.find(chan => chan.longId === long)) || - (name && short && channels.find(chan => chan.name === name && chan.shortId === short)) - ); -} - -module.exports = isApprovedChannel; diff --git a/client/src/utils/isApprovedChannel.js b/utils/isApprovedChannel.js similarity index 100% rename from client/src/utils/isApprovedChannel.js rename to utils/isApprovedChannel.js