0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Deleted concept of external user

refs https://github.com/TryGhost/Toolbox/issues/363

- AFAICT, this is an outdated and unused concept from when subscribers
  were a thing, but members are now how we do things, and this is causing code
  to linger around that we don't need
This commit is contained in:
Daniel Lockyer 2022-08-11 15:46:24 +02:00
parent 120dee86b3
commit 7d52ae52cf
4 changed files with 3 additions and 51 deletions

View file

@ -1,7 +1,6 @@
const url = require('url');
const debug = require('@tryghost/debug')('api:shared:http');
const shared = require('../shared');
const models = require('../../models');
/**
* @description HTTP wrapper.
@ -29,8 +28,7 @@ const http = (apiImpl) => {
};
}
// NOTE: "external user" is only used in the subscriber app. External user is ID "0".
if ((req.user && req.user.id) || (req.user && models.User.isExternalUser(req.user.id))) {
if (req.user && req.user.id) {
user = req.user.id;
}

View file

@ -33,7 +33,7 @@ module.exports = function (Bookshelf) {
options = options || {};
options.context = options.context || {};
if (options.context.user || Bookshelf.Model.isExternalUser(options.context.user)) {
if (options.context.user) {
return options.context.user;
} else if (options.context.integration) {
/**
@ -64,8 +64,6 @@ module.exports = function (Bookshelf) {
return Bookshelf.Model.internalUser;
} else if (this.get('id')) {
return this.get('id');
} else if (options.context.external) {
return Bookshelf.Model.externalUser;
} else {
throw new errors.NotFoundError({
message: tpl(messages.missingContext),
@ -80,15 +78,9 @@ module.exports = function (Bookshelf) {
* context.user ? true : false (if context.user is 0 as number, this condition is false)
*/
internalUser: 1,
externalUser: 0,
isInternalUser: function isInternalUser(id) {
return id === Bookshelf.Model.internalUser || id === Bookshelf.Model.internalUser.toString();
},
isExternalUser: function isExternalUser(id) {
return id === Bookshelf.Model.externalUser || id === Bookshelf.Model.externalUser.toString();
}
});
};

View file

@ -3,12 +3,11 @@
*
* Utility function, to expand strings out into objects.
* @param {Object|String} context
* @return {{internal: boolean, external: boolean, user: integer|null, public: boolean, api_key: Object|null}}
* @return {{internal: boolean, user: integer|null, public: boolean, api_key: Object|null}}
*/
module.exports = function parseContext(context) {
const parsed = {
internal: false,
external: false,
user: null,
api_key: null,
integration: null,
@ -16,12 +15,6 @@ module.exports = function parseContext(context) {
public: true
};
// NOTE: We use the `external` context for subscribers only at the moment.
if (context && (context === 'external' || context.external)) {
parsed.external = true;
parsed.public = false;
}
if (context && (context === 'internal' || context.internal)) {
parsed.internal = true;
parsed.public = false;

View file

@ -6,7 +6,6 @@ describe('Permissions', function () {
it('should return public for no context', function () {
parseContext().should.eql({
internal: false,
external: false,
user: null,
api_key: null,
member: null,
@ -15,7 +14,6 @@ describe('Permissions', function () {
});
parseContext({}).should.eql({
internal: false,
external: false,
user: null,
api_key: null,
member: null,
@ -27,7 +25,6 @@ describe('Permissions', function () {
it('should return public for random context', function () {
parseContext('public').should.eql({
internal: false,
external: false,
user: null,
api_key: null,
member: null,
@ -36,7 +33,6 @@ describe('Permissions', function () {
});
parseContext({client: 'thing'}).should.eql({
internal: false,
external: false,
user: null,
api_key: null,
member: null,
@ -48,7 +44,6 @@ describe('Permissions', function () {
it('should return user if user populated', function () {
parseContext({user: 1}).should.eql({
internal: false,
external: false,
user: 1,
api_key: null,
member: null,
@ -63,7 +58,6 @@ describe('Permissions', function () {
type: 'content'
}, integration: {id: 2}}).should.eql({
internal: false,
external: false,
user: null,
api_key: {
id: 1,
@ -81,7 +75,6 @@ describe('Permissions', function () {
type: 'admin'
}, integration: {id: 3}}).should.eql({
internal: false,
external: false,
user: null,
api_key: {
id: 1,
@ -96,7 +89,6 @@ describe('Permissions', function () {
it('should return internal if internal provided', function () {
parseContext({internal: true}).should.eql({
internal: true,
external: false,
user: null,
api_key: null,
member: null,
@ -106,29 +98,6 @@ describe('Permissions', function () {
parseContext('internal').should.eql({
internal: true,
external: false,
user: null,
api_key: null,
member: null,
public: false,
integration: null
});
});
it('should return external if external provided', function () {
parseContext({external: true}).should.eql({
internal: false,
external: true,
user: null,
api_key: null,
member: null,
public: false,
integration: null
});
parseContext('external').should.eql({
internal: false,
external: true,
user: null,
api_key: null,
member: null,