From a54c87be1ce629cf13a5bfb9c2ba26958e0e4e74 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 3 Nov 2017 23:22:38 +0100 Subject: Parse recipe author string --- package.json | 1 + src/models/Recipe.js | 16 ++++++++++++++-- yarn.lock | 10 ++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1c0aad789..fc0954e94 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "license": "Apache-2.0", "dependencies": { "@paulcbetts/system-idle-time": "^1.0.4", + "address-rfc2822": "^2.0.1", "auto-launch": "https://github.com/meetfranz/node-auto-launch.git", "babel-polyfill": "^6.23.0", "babel-runtime": "^6.23.0", diff --git a/src/models/Recipe.js b/src/models/Recipe.js index 43a3450b1..4b613a40c 100644 --- a/src/models/Recipe.js +++ b/src/models/Recipe.js @@ -1,7 +1,8 @@ +import emailParser from 'address-rfc2822'; + export default class Recipe { id = ''; name = ''; - author = ''; description = ''; version = '1.0'; path = ''; @@ -30,7 +31,7 @@ export default class Recipe { this.id = data.id || this.id; this.name = data.name || this.name; - this.author = data.author || this.author; + this.rawAuthor = data.author || this.author; this.description = data.description || this.description; this.version = data.version || this.version; this.path = data.path; @@ -49,4 +50,15 @@ export default class Recipe { this.message = data.config.message || this.message; } + + get author() { + try { + const addresses = emailParser.parse(this.rawAuthor); + return addresses.map(a => ({ email: a.address, name: a.phrase })); + } catch (err) { + console.warn(`Not a valid author for ${this.name}`); + } + + return []; + } } diff --git a/yarn.lock b/yarn.lock index 3bb344a2d..0bedbac27 100644 --- a/yarn.lock +++ b/yarn.lock @@ -80,6 +80,12 @@ acorn@^5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.1.2.tgz#911cb53e036807cf0fa778dc5d370fbd864246d7" +address-rfc2822@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/address-rfc2822/-/address-rfc2822-2.0.1.tgz#1a1bdb942b5e20e2c1ba5d5f396d5824ff7ae6ea" + dependencies: + email-addresses "^3.0.0" + after@0.8.2: version "0.8.2" resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f" @@ -2049,6 +2055,10 @@ electron@^1.7.9: electron-download "^3.0.1" extract-zip "^1.0.3" +email-addresses@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/email-addresses/-/email-addresses-3.0.1.tgz#c1fc20c189e7f96d4012d375db5feaccdd24391c" + emojis-list@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389" -- cgit v1.2.3-70-g09d2 From 7a9947a08e6acd922787d866ba2ba6fc5a779f82 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 3 Nov 2017 23:24:36 +0100 Subject: feat(Recipes): Recipe developers don't need Premium Supporter Account for debugging Closes #23 --- src/components/settings/services/EditServiceForm.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/settings/services/EditServiceForm.js b/src/components/settings/services/EditServiceForm.js index fac0f6b9a..9b359a78e 100644 --- a/src/components/settings/services/EditServiceForm.js +++ b/src/components/settings/services/EditServiceForm.js @@ -69,10 +69,6 @@ const messages = defineMessages({ export default class EditServiceForm extends Component { static propTypes = { recipe: PropTypes.instanceOf(Recipe).isRequired, - // service: PropTypes.oneOfType([ - // PropTypes.object, - // PropTypes.instanceOf(Service), - // ]), service(props, propName) { if (props.action === 'edit' && !(props[propName] instanceof Service)) { return new Error(`'${propName}'' is expected to be of type 'Service' @@ -207,7 +203,7 @@ export default class EditServiceForm extends Component { )} {recipe.hasCustomUrl && ( - {user.isPremium ? ( + {user.isPremium || recipe.author.find(a => a.email === user.email) ? (
{form.error === 'url-validation-error' && ( -- cgit v1.2.3-70-g09d2 From 71c2d4ecca28ad326ae94578acdfae12742786e3 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 3 Nov 2017 23:53:43 +0100 Subject: fix eslint issue --- src/lib/Menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Menu.js b/src/lib/Menu.js index 9f62cc8c2..8f0a92c3d 100644 --- a/src/lib/Menu.js +++ b/src/lib/Menu.js @@ -1,7 +1,7 @@ import { remote, shell } from 'electron'; import { autorun, computed, observable, toJS } from 'mobx'; -import { isMac, isLinux } from '../environment'; +import { isMac } from '../environment'; const { app, Menu, dialog } = remote; -- cgit v1.2.3-70-g09d2