+ userHasDeleteRights()

+ deleteMessage()
This commit is contained in:
Bryan Ashby 2018-07-04 18:47:58 -06:00
parent ab9ffc715a
commit 514edb984f
1 changed files with 41 additions and 0 deletions

View File

@ -137,6 +137,32 @@ module.exports = class Message {
return null !== _.get(this, 'meta.System.remote_from_user', null);
}
/*
:TODO: finish me
static checkUserHasDeleteRights(user, messageIdOrUuid, cb) {
const isMessageId = _.isNumber(messageIdOrUuid);
const getMetaName = isMessageId ? 'getMetaValuesByMessageId' : 'getMetaValuesByMessageUuid';
Message[getMetaName](messageIdOrUuid, 'System', Message.SystemMetaNames.LocalToUserID, (err, localUserId) => {
if(err) {
return cb(err);
}
// expect single value
if(!_.isString(localUserId)) {
return cb(Errors.Invalid(`Invalid ${Message.SystemMetaNames.LocalToUserID} value: ${localUserId}`));
}
localUserId = parseInt(localUserId);
});
}
*/
userHasDeleteRights(user) {
const messageLocalUserId = parseInt(this.meta.System[Message.SystemMetaNames.LocalToUserID]);
return (this.isPrivate() && user.userId === messageLocalUserId) || user.isSysOp();
}
static get WellKnownAreaTags() {
return WELL_KNOWN_AREA_TAGS;
}
@ -660,6 +686,21 @@ module.exports = class Message {
);
}
deleteMessage(requestingUser, cb) {
if(!this.userHasDeleteRights(requestingUser)) {
return cb(Errors.AccessDenied('User does not have rights to delete this message'));
}
msgDb.run(
`DELETE FROM message
WHERE message_uuid = ?;`,
[ this.messageUuid ],
err => {
return cb(err);
}
);
}
// :TODO: FTN stuff doesn't have any business here
getFTNQuotePrefix(source) {
source = source || 'fromUserName';