Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

feat(plugins): require permissions to include content on the app #1191

Merged
merged 4 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ module.exports = {
require('tailwindcss')('./tailwind.js'),
require('autoprefixer')
]
}
}
11 changes: 6 additions & 5 deletions src/renderer/services/plugin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs-extra'
import * as os from 'os'
import * as path from 'path'
import * as vm2 from 'vm2'
import { camelCase, uniq, upperFirst } from 'lodash'

class PluginManager {
constructor () {
Expand Down Expand Up @@ -67,11 +68,11 @@ class PluginManager {
profileId
})

await this.loadComponents(pluginObject, plugin)
await this.loadRoutes(pluginObject, plugin)
await this.loadMenuItems(pluginObject, plugin, profileId)
await this.loadAvatars(pluginObject, plugin, profileId)
await this.loadWalletTabs(pluginObject, plugin, profileId)
// COMPONENTS, ROUTES, MENU_ITEMS, AVATARS, WALLET_TABS
for (const permission of uniq(plugin.config.permissions)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it needs a validation before calling the method:

Suggested change
for (const permission of uniq(plugin.config.permissions)) {
for (const permission of ['COMPONENTS, ROUTES, MENU_ITEMS, AVATARS, WALLET_TABS']) {
if (plugin.config.permission[permission]) {
// ...
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, permissions is an Array, so it wouldn't be necessary to do that. The only possible problem that it could cause it's that some permissions should be loaded in order. I'll change it now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are considering that all plugins will write the permissions correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an array of permissions, if someone uses numbers, null or an object, it wouldn't work and it would throw an Error, so they could realize that it's a mistake.

const method = `load${upperFirst(camelCase(permission))}`
await this[method](pluginObject, plugin, profileId)
}
}

async disablePlugin (pluginId) {
Expand Down