Add 'write' access for post FSE
+ hasMessageConfAndAreaWrite() + MenuModule helpers: gotoMenuOrPrev(), gotoMenuOrShowMessage(). These will likely replace many other pieces of code soon.
This commit is contained in:
parent
7783262af6
commit
1fdaaf5633
|
@ -259,6 +259,44 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
||||||
return this.client.menuStack.goto(name, options, cb);
|
return this.client.menuStack.goto(name, options, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gotoMenuOrPrev(name, options, cb) {
|
||||||
|
this.client.menuStack.goto(name, options, err => {
|
||||||
|
if(!err) {
|
||||||
|
if(cb) {
|
||||||
|
return cb(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.prevMenu(cb);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
gotoMenuOrShowMessage(name, message, options, cb) {
|
||||||
|
if(!cb && _.isFunction(options)) {
|
||||||
|
cb = options;
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
options = options || { clearScreen: true };
|
||||||
|
|
||||||
|
this.gotoMenu(name, options, err => {
|
||||||
|
if(err) {
|
||||||
|
if(options.clearScreen) {
|
||||||
|
this.client.term.rawWrite(ansi.resetScreen());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.client.term.write(`${message}\n`);
|
||||||
|
return this.pausePrompt( () => {
|
||||||
|
return this.prevMenu(cb);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cb) {
|
||||||
|
return cb(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
reload(cb) {
|
reload(cb) {
|
||||||
const prevMenu = this.client.menuStack.pop();
|
const prevMenu = this.client.menuStack.pop();
|
||||||
prevMenu.instance.leave();
|
prevMenu.instance.leave();
|
||||||
|
|
|
@ -32,6 +32,7 @@ exports.getMessageAreaByTag = getMessageAreaByTag;
|
||||||
exports.changeMessageConference = changeMessageConference;
|
exports.changeMessageConference = changeMessageConference;
|
||||||
exports.changeMessageArea = changeMessageArea;
|
exports.changeMessageArea = changeMessageArea;
|
||||||
exports.hasMessageConfAndAreaRead = hasMessageConfAndAreaRead;
|
exports.hasMessageConfAndAreaRead = hasMessageConfAndAreaRead;
|
||||||
|
exports.hasMessageConfAndAreaWrite = hasMessageConfAndAreaWrite;
|
||||||
exports.filterMessageAreaTagsByReadACS = filterMessageAreaTagsByReadACS;
|
exports.filterMessageAreaTagsByReadACS = filterMessageAreaTagsByReadACS;
|
||||||
exports.filterMessageListByReadACS = filterMessageListByReadACS;
|
exports.filterMessageListByReadACS = filterMessageListByReadACS;
|
||||||
exports.tempChangeMessageConfAndArea = tempChangeMessageConfAndArea;
|
exports.tempChangeMessageConfAndArea = tempChangeMessageConfAndArea;
|
||||||
|
@ -410,6 +411,14 @@ function hasMessageConfAndAreaRead(client, areaOrTag) {
|
||||||
return client.acs.hasMessageConfRead(conf) && client.acs.hasMessageAreaRead(areaOrTag);
|
return client.acs.hasMessageConfRead(conf) && client.acs.hasMessageAreaRead(areaOrTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasMessageConfAndAreaWrite(client, areaOrTag) {
|
||||||
|
if(_.isString(areaOrTag)) {
|
||||||
|
areaOrTag = getMessageAreaByTag(areaOrTag) || {};
|
||||||
|
}
|
||||||
|
const conf = getMessageConferenceByTag(areaOrTag.confTag);
|
||||||
|
return client.acs.hasMessageConfWrite(conf) && client.acs.hasMessageAreaWrite(areaOrTag);
|
||||||
|
}
|
||||||
|
|
||||||
function filterMessageAreaTagsByReadACS(client, areaTags) {
|
function filterMessageAreaTagsByReadACS(client, areaTags) {
|
||||||
if(!Array.isArray(areaTags)) {
|
if(!Array.isArray(areaTags)) {
|
||||||
areaTags = [ areaTags ];
|
areaTags = [ areaTags ];
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
const FullScreenEditorModule = require('./fse.js').FullScreenEditorModule;
|
const FullScreenEditorModule = require('./fse.js').FullScreenEditorModule;
|
||||||
const persistMessage = require('./message_area.js').persistMessage;
|
const persistMessage = require('./message_area.js').persistMessage;
|
||||||
const UserProps = require('./user_property.js');
|
const UserProps = require('./user_property.js');
|
||||||
|
const {
|
||||||
|
hasMessageConfAndAreaWrite,
|
||||||
|
} = require('./message_area.js');
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
|
@ -59,12 +62,25 @@ exports.getModule = class AreaPostFSEModule extends FullScreenEditorModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
enter() {
|
enter() {
|
||||||
if(_.isString(this.client.user.properties[UserProps.MessageAreaTag]) &&
|
this.messageAreaTag =
|
||||||
!_.isString(this.messageAreaTag))
|
this.messageAreaTag ||
|
||||||
{
|
this.client.user.getProperty(UserProps.MessageAreaTag);
|
||||||
this.messageAreaTag = this.client.user.properties[UserProps.MessageAreaTag];
|
|
||||||
}
|
|
||||||
|
|
||||||
super.enter();
|
super.enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initSequence() {
|
||||||
|
if(!hasMessageConfAndAreaWrite(this.client, this.messageAreaTag)) {
|
||||||
|
const noAcsMenu =
|
||||||
|
this.menuConfig.config.messageBasePostMessageNoAccess ||
|
||||||
|
'messageBasePostMessageNoAccess';
|
||||||
|
|
||||||
|
return this.gotoMenuOrShowMessage(
|
||||||
|
noAcsMenu,
|
||||||
|
'You do not have the proper access to post here!',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.initSequence();
|
||||||
|
}
|
||||||
};
|
};
|
Loading…
Reference in New Issue