Browse Source

fix admin check

push-params
Evan Feenstra 4 years ago
parent
commit
a327680d68
  1. 13
      api/controllers/actions.ts
  2. 13
      dist/api/controllers/actions.js
  3. 2
      dist/api/controllers/actions.js.map

13
api/controllers/actions.ts

@ -69,11 +69,15 @@ export async function finalAction(a:Action, bot_id:string){
const owner = await models.Contact.findOne({ where: { isOwner: true } })
let theChat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
const iAmTribeAdmin = owner.publicKey === (theChat && theChat.ownerPubkey)
console.log("=> ACTION HIT", a)
const myBot = await models.Bot.findOne({where:{
id: bot_id
}})
if(myBot) {
if(!iAmTribeAdmin) { // IM NOT ADMIN - its my bot and i need to forward to admin
const myBot = await models.Bot.findOne({where:{
id: bot_id
}})
if(!myBot) return console.log('no bot')
// THIS is a bot member cmd res (i am bot maker)
const botMember = await models.BotMember.findOne({where:{
tribeUuid: chat_uuid, botId: bot_id
@ -116,7 +120,6 @@ export async function finalAction(a:Action, bot_id:string){
} else if (action === 'broadcast') {
console.log('=> BOT BROADCAST')
if (!content) throw 'no content'
let theChat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
if (!theChat) throw 'no chat'
if (!theChat.type === constants.chat_types.tribe) throw 'not a tribe'

13
dist/api/controllers/actions.js

@ -70,11 +70,15 @@ function finalAction(a, bot_id) {
if (!chat_uuid)
throw 'no chat_uuid';
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
let theChat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
const iAmTribeAdmin = owner.publicKey === (theChat && theChat.ownerPubkey);
console.log("=> ACTION HIT", a);
const myBot = yield models_1.models.Bot.findOne({ where: {
id: bot_id
} });
if (myBot) {
if (!iAmTribeAdmin) { // IM NOT ADMIN - its my bot and i need to forward to admin
const myBot = yield models_1.models.Bot.findOne({ where: {
id: bot_id
} });
if (!myBot)
return console.log('no bot');
// THIS is a bot member cmd res (i am bot maker)
const botMember = yield models_1.models.BotMember.findOne({ where: {
tribeUuid: chat_uuid, botId: bot_id
@ -119,7 +123,6 @@ function finalAction(a, bot_id) {
console.log('=> BOT BROADCAST');
if (!content)
throw 'no content';
let theChat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (!theChat)
throw 'no chat';
if (!theChat.type === constants.chat_types.tribe)

2
dist/api/controllers/actions.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save