mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Added new admin API for members (#10435)
no issue - Added read and browse admin API for members
This commit is contained in:
parent
5bd509c873
commit
8fd4b3f09f
@ -63,6 +63,10 @@ module.exports = {
|
||||
return shared.pipeline(require('./subscribers'), localUtils);
|
||||
},
|
||||
|
||||
get members() {
|
||||
return shared.pipeline(require('./members'), localUtils);
|
||||
},
|
||||
|
||||
get upload() {
|
||||
return shared.pipeline(require('./upload'), localUtils);
|
||||
},
|
||||
|
35
core/server/api/v2/members.js
Normal file
35
core/server/api/v2/members.js
Normal file
@ -0,0 +1,35 @@
|
||||
const memberUserObject = require('../../services/members').api.memberUserObject;
|
||||
|
||||
const members = {
|
||||
docName: 'members',
|
||||
browse: {
|
||||
options: [
|
||||
'limit',
|
||||
'fields',
|
||||
'filter',
|
||||
'order',
|
||||
'debug',
|
||||
'page'
|
||||
],
|
||||
permissions: true,
|
||||
validation: {},
|
||||
query(frame) {
|
||||
return memberUserObject.list(frame.options);
|
||||
}
|
||||
},
|
||||
|
||||
read: {
|
||||
headers: {},
|
||||
data: [
|
||||
'id',
|
||||
'email'
|
||||
],
|
||||
validation: {},
|
||||
permissions: true,
|
||||
query(frame) {
|
||||
return memberUserObject.get(frame.data, frame.options);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = members;
|
@ -55,6 +55,10 @@ module.exports = {
|
||||
return require('./subscribers');
|
||||
},
|
||||
|
||||
get members() {
|
||||
return require('./members');
|
||||
},
|
||||
|
||||
get upload() {
|
||||
return require('./upload');
|
||||
},
|
||||
|
24
core/server/api/v2/utils/serializers/output/members.js
Normal file
24
core/server/api/v2/utils/serializers/output/members.js
Normal file
@ -0,0 +1,24 @@
|
||||
const common = require('../../../../../lib/common');
|
||||
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:output:members');
|
||||
|
||||
module.exports = {
|
||||
browse(data, apiConfig, frame) {
|
||||
debug('browse');
|
||||
|
||||
frame.response = data;
|
||||
},
|
||||
|
||||
read(data, apiConfig, frame) {
|
||||
debug('read');
|
||||
|
||||
if (!data) {
|
||||
return Promise.reject(new common.errors.NotFoundError({
|
||||
message: common.i18n.t('errors.api.members.memberNotFound')
|
||||
}));
|
||||
}
|
||||
|
||||
frame.response = {
|
||||
members: [data]
|
||||
};
|
||||
}
|
||||
};
|
@ -20,6 +20,7 @@ module.exports = function MembersApi({
|
||||
validateMember,
|
||||
updateMember,
|
||||
getMember,
|
||||
listMembers,
|
||||
sendEmail
|
||||
}) {
|
||||
const {encodeToken, decodeToken, getPublicKeys} = Tokens({privateKey, publicKey, issuer});
|
||||
@ -31,6 +32,7 @@ module.exports = function MembersApi({
|
||||
validateMember,
|
||||
sendEmail,
|
||||
encodeToken,
|
||||
listMembers,
|
||||
decodeToken
|
||||
});
|
||||
|
||||
|
@ -2,13 +2,14 @@ module.exports = function ({
|
||||
createMember,
|
||||
updateMember,
|
||||
getMember,
|
||||
listMembers,
|
||||
validateMember,
|
||||
sendEmail,
|
||||
encodeToken,
|
||||
decodeToken
|
||||
}) {
|
||||
function requestPasswordReset({email}) {
|
||||
return getMember({email}).then((member) => {
|
||||
return getMember({email}, {require: true}).then((member) => {
|
||||
return encodeToken({
|
||||
sub: member.id
|
||||
}).then((token) => {
|
||||
@ -30,6 +31,7 @@ module.exports = function ({
|
||||
resetPassword,
|
||||
create: createMember,
|
||||
validate: validateMember,
|
||||
get: getMember
|
||||
get: getMember,
|
||||
list: listMembers
|
||||
};
|
||||
};
|
||||
|
@ -25,11 +25,22 @@ function updateMember(member, newData) {
|
||||
});
|
||||
}
|
||||
|
||||
function getMember(member) {
|
||||
return models.Member.findOne(member, {
|
||||
require: true
|
||||
}).then((member) => {
|
||||
return member.toJSON();
|
||||
function getMember(data, options) {
|
||||
options = options || {};
|
||||
return models.Member.findOne(data, options).then((model) => {
|
||||
if (!model) {
|
||||
return null;
|
||||
}
|
||||
return model.toJSON(options);
|
||||
});
|
||||
}
|
||||
|
||||
function listMembers(options) {
|
||||
return models.Member.findPage(options).then((models) => {
|
||||
return {
|
||||
members: models.data.map(model => model.toJSON(options)),
|
||||
meta: models.meta
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@ -104,6 +115,7 @@ const api = MembersApi({
|
||||
validateAudience,
|
||||
createMember,
|
||||
getMember,
|
||||
listMembers,
|
||||
validateMember,
|
||||
updateMember,
|
||||
sendEmail
|
||||
|
@ -403,6 +403,10 @@
|
||||
"subscriberNotFound": "Subscriber not found.",
|
||||
"subscriberAlreadyExists": "Email address is already subscribed."
|
||||
},
|
||||
"members": {
|
||||
"memberNotFound": "Member not found.",
|
||||
"memberAlreadyExists": "Email address is already member."
|
||||
},
|
||||
"tags": {
|
||||
"tagNotFound": "Tag not found."
|
||||
},
|
||||
|
@ -94,6 +94,10 @@ module.exports = function apiRoutes() {
|
||||
router.del('/subscribers/:id', shared.middlewares.labs.subscribers, mw.authAdminApi, apiv2.http(apiv2.subscribers.destroy));
|
||||
router.del('/subscribers/email/:email', shared.middlewares.labs.subscribers, mw.authAdminApi, apiv2.http(apiv2.subscribers.destroy));
|
||||
|
||||
// ## Members
|
||||
router.get('/members', shared.middlewares.labs.members, mw.authAdminApi, apiv2.http(apiv2.members.browse));
|
||||
router.get('/members/:id', shared.middlewares.labs.members, mw.authAdminApi, apiv2.http(apiv2.members.read));
|
||||
|
||||
// ## Roles
|
||||
router.get('/roles/', mw.authAdminApi, apiv2.http(apiv2.roles.browse));
|
||||
|
||||
|
@ -8,6 +8,13 @@ const labs = {
|
||||
} else {
|
||||
return next(new common.errors.NotFoundError());
|
||||
}
|
||||
},
|
||||
members(req, res, next) {
|
||||
if (labsUtil.isSet('members') === true) {
|
||||
return next();
|
||||
} else {
|
||||
return next(new common.errors.NotFoundError());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user