Skip to content

Commit

Permalink
Merge pull request #1982 from botpress/ya-fix-bots
Browse files Browse the repository at this point in the history
fix(bots): checking bot status & fix export
  • Loading branch information
allardy authored Jun 25, 2019
2 parents 8a6830c + 6f530a7 commit a0074ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
15 changes: 10 additions & 5 deletions src/bp/core/routers/bots/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Botpress, Inc. All rights reserved.
* Licensed under the AGPL-3.0 license. See license.txt at project root for more information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Botpress, Inc. All rights reserved.
* Licensed under the AGPL-3.0 license. See license.txt at project root for more information.
*--------------------------------------------------------------------------------------------*/

import { Logger, RouterOptions } from 'botpress/sdk'
import { Serialize } from 'cerialize'
Expand Down Expand Up @@ -29,6 +29,7 @@ import { URL } from 'url'

import { disableForModule } from '../conditionalMiddleware'
import { CustomRouter } from '../customRouter'
import { NotFoundError } from '../errors'
import { checkTokenHeader, needPermissions } from '../util'

const debugMedia = DEBUG('audit:action:media-upload')
Expand Down Expand Up @@ -91,12 +92,16 @@ export class BotsRouter extends CustomRouter {
// '___' is a non-valid botId, but here acts as for "all bots"
// This is used in modules when they setup routes that work on a global level (they are not tied to a specific bot)
// Check the 'sso-login' module for an example
if (req.params.botId === '___') {
if (req.params.botId === '___' || req.originalUrl.endsWith('env.js')) {
return next()
}

const config = await this.configProvider.getBotConfig(req.params.botId)
if (config.private && !req.originalUrl.endsWith('env.js') && !this.mediaPathRegex.test(req.originalUrl)) {
if (config.disabled) {
return next(new NotFoundError('Bot is disabled'))
}

if (config.private && !this.mediaPathRegex.test(req.originalUrl)) {
return this.checkTokenHeader(req, res, next)
}

Expand Down
4 changes: 2 additions & 2 deletions src/bp/core/services/bot-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class BotService {
}

async exportBot(botId: string): Promise<Buffer> {
return this.ghostService.forBot(botId).exportToArchiveBuffer('models/*')
return this.ghostService.forBot(botId).exportToArchiveBuffer('models/**/*')
}

async importBot(botId: string, archive: Buffer, allowOverwrite?: boolean): Promise<void> {
Expand Down Expand Up @@ -518,7 +518,7 @@ export class BotService {

const botGhost = this.ghostService.forBot(botId)
const globalGhost = this.ghostService.global()
await globalGhost.upsertFile(REVISIONS_DIR, `${revName}.tgz`, await botGhost.exportToArchiveBuffer('models/*'))
await globalGhost.upsertFile(REVISIONS_DIR, `${revName}.tgz`, await botGhost.exportToArchiveBuffer('models/**/*'))
return this._cleanupRevisions(botId)
}

Expand Down
18 changes: 11 additions & 7 deletions src/bp/ui-admin/src/Pages/Workspace/Bots/BotItemCompact.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ export default ({ bot, deleteBot, exportBot, permissions, history, createRevisio
<FaCog /> Configs
</Button>
</AccessControl>
<Button size="sm" color="link" target="_blank" href={`${window.location.origin}/s/${bot.id}`}>
<IoIosChatbubbles /> Open chat
</Button>
{!bot.disabled && (
<Button size="sm" color="link" target="_blank" href={`${window.location.origin}/s/${bot.id}`}>
<IoIosChatbubbles /> Open chat
</Button>
)}
<UncontrolledButtonDropdown>
<DropdownToggle tag="span" className="more">
<MdMoreVert />
</DropdownToggle>
<DropdownMenu>
<DropdownItem disabled={bot.locked} tag="a" href={`/studio/${bot.id}`}>
<MdModeEdit />
&nbsp;Edit in studio
</DropdownItem>
{!bot.disabled && (
<DropdownItem disabled={bot.locked} tag="a" href={`/studio/${bot.id}`}>
<MdModeEdit />
&nbsp;Edit in studio
</DropdownItem>
)}
<AccessControl permissions={permissions} resource="admin.bots.*" operation="write">
<DropdownItem onClick={createRevision}>
<MdBackup />
Expand Down
18 changes: 11 additions & 7 deletions src/bp/ui-admin/src/Pages/Workspace/Bots/BotItemPipeline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ export default ({
<MdMoreVert />
</DropdownToggle>
<DropdownMenu>
<DropdownItem tag="a" target="_blank" href={`${window.location.origin}/s/${bot.id}`}>
<IoIosChatbubbles /> &nbsp;Open chat
</DropdownItem>
<DropdownItem disabled={bot.locked} tag="a" href={`/studio/${bot.id}`}>
<MdModeEdit />
&nbsp;Edit in studio
</DropdownItem>
{!bot.disabled && (
<React.Fragment>
<DropdownItem tag="a" target="_blank" href={`${window.location.origin}/s/${bot.id}`}>
<IoIosChatbubbles /> &nbsp;Open chat
</DropdownItem>
<DropdownItem disabled={bot.locked} tag="a" href={`/studio/${bot.id}`}>
<MdModeEdit />
&nbsp;Edit in studio
</DropdownItem>
</React.Fragment>
)}
{allowStageChange && (
<DropdownItem onClick={requestStageChange}>
<MdSkipNext />
Expand Down

0 comments on commit a0074ac

Please sign in to comment.