Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Jan 29, 2019
2 parents fd59ce8 + d4e987e commit 725e4c3
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 48 deletions.
9 changes: 8 additions & 1 deletion packages/demo-api/src/install/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ import cmsPlugins from "webiny-api-cms/install/plugins";

registerPlugins(securityPlugins, cmsPlugins);

export default async () => install({ config: await config() });
export default async () => {
await install({
config: await config(),
cms: { copyFiles: false },
security: { admin: { email: "[email protected]", password: "87654321" } }
});
process.exit();
};
4 changes: 1 addition & 3 deletions packages/webiny-api-cms/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"plugins": [
["@babel/plugin-proposal-class-properties"],
["@babel/plugin-proposal-object-rest-spread", {"useBuiltIns": true}],
["@babel/plugin-transform-runtime"],
["@babel/plugin-syntax-dynamic-import"],
["babel-plugin-dynamic-import-node"]
["@babel/plugin-transform-runtime"]
]
}
5 changes: 2 additions & 3 deletions packages/webiny-api-cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.0.0",
"graphql-iso-date": "^3.5.0",
"lodash": "^4.17.11",
"fs-extra": "^7.0.1",
"mdbid": "^1.0.0",
"request": "^2.88.0",
"webiny-api": "0.0.0",
Expand All @@ -25,8 +25,7 @@
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"babel-plugin-dynamic-import-node": "^2.0.0",
"flow-copy-source": "^2.0.2",
"fs-extra": "^7.0.1"
"flow-copy-source": "^2.0.2"
},
"scripts": {
"build": "babel src -d ${DEST:-build} --source-maps --copy-files",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import blocks from "./blocks";
import get from "lodash/get";
import fs from "fs-extra";
import blocks from "./blocks";

const createDefaultBlocks = async (context: Object) => {
const { Element } = context.cms.entities;
Expand All @@ -13,8 +14,10 @@ const createDefaultBlocks = async (context: Object) => {
}

// Copy images.
const pwd: string = (process.cwd(): any);
await fs.copy(`${__dirname}/blocks/images`, pwd + "/static");
if (get(context, "cms.copyFiles", true) !== false) {
const pwd: string = (process.cwd(): any);
await fs.copy(`${__dirname}/blocks/images`, pwd + "/static");
}
};

export default createDefaultBlocks;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { elementFactory } from "./../../entities/Element.entity";
import { cmsSettingsFactory } from "./../../entities/CmsSettings.entity";

export default (context: Object) => {
context.cms = { entities: {} };
context.cms = { ...context.cms, entities: {} };

context.cms.entities.Category = categoryFactory();
context.cms.entities.Page = pageFactory(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import { Entity } from "webiny-entity";
import { cloneDeep } from "lodash";
import cloneDeep from "lodash/cloneDeep";

import { listPublishedPages } from "webiny-api-cms/plugins/graphql/pageResolvers/listPublishedPages";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import { createPaginationMeta } from "webiny-entity";
import { ListResponse } from "webiny-api/graphql/responses";
import { get } from "lodash";
import get from "lodash/get";
export const listPublishedPages = async ({ args, Page, Category }: Object) => {
const {
page = 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/webiny-api-security/src/entities/User.entity.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import md5 from "md5";
import bcrypt from "bcryptjs";
import { get } from "lodash";
import get from "lodash/get";
import { Entity } from "webiny-entity";
import type { Group } from "./Group.entity";
import type { Role } from "./Role.entity";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @flow
import get from "lodash/get";
import isPlainObject from "lodash/isPlainObject";
import setupEntities from "./setupEntities";
import * as data from "./data";

Expand All @@ -11,7 +13,12 @@ export default async (context: Object) => {
const fullAccess = new Role();
await fullAccess.populate(data.fullAccessRole).save();

await user.populate({ ...data.superAdminUser, roles: [fullAccess] }).save();
let userData = get(context, "security.admin");
if (!userData || !isPlainObject(userData)) {
userData = data.superAdminUser;
}

await user.populate({ ...userData, roles: [fullAccess] }).save();

context.user = user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { roles2entitiesFactory } from "./../../entities/Roles2Entities.entity";
import { userSettingsFactory } from "./../../entities/UserSettings.entity";

export default (context: Object) => {
context.security = { entities: {} };
context.security = { ...context.security, entities: {} };
context.security.entities.User = userFactory(context);
context.security.entities.Group = groupFactory(context);
context.security.entities.Role = roleFactory(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default (entityFetcher: EntityFetcher) => async (
}

const jwt = new JwtToken({ secret: context.config.security.token.secret });
// $FlowFixMe
const access = await user.access;
const token = await jwt.encode(
// $FlowFixMe - instance that will be validated will have "password" attribute.
Expand Down
2 changes: 1 addition & 1 deletion packages/webiny-api-security/src/plugins/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { PluginType } from "webiny-plugins/types";
import authenticate from "./authentication/authenticate";
import { getPlugins } from "webiny-plugins";
import { shield } from "graphql-shield";
import { get } from "lodash";
import get from "lodash/get";

export default ([
{
Expand Down
10 changes: 1 addition & 9 deletions packages/webiny-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,14 @@
"dependencies": {
"@babel/runtime": "^7.0.0",
"apollo-server-lambda": "^2.1.0",
"bcryptjs": "^2.4.3",
"chalk": "^2.4.1",
"debug": "^3.1.0",
"file-type": "^7.6.0",
"graphql": "^0.13.2",
"graphql-iso-date": "^3.5.0",
"graphql-middleware": "^1.7.6",
"graphql-tools": "^4.0.0",
"graphql-type-json": "^0.2.0",
"invariant": "^2.2.4",
"jsonwebtoken": "^8.2.2",
"lodash": "^4.17.4",
"md5": "^2.2.1",
"webiny-compose": "0.0.0",
"webiny-entity": "0.0.0",
"webiny-service-manager": "0.0.0",
"webiny-model": "0.0.0",
"webiny-plugins": "0.0.0"
},
"devDependencies": {
Expand Down
11 changes: 6 additions & 5 deletions packages/webiny-api/src/graphql/InvalidAttributesError.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// @flow
import _ from "lodash";
import each from "lodash/each";
import get from "lodash/get";
import { ModelError } from "webiny-model";

function formatInvalidAttributes(invalidAttributes, prefix = "") {
const formatted = {};
_.each(invalidAttributes, ({ code, data, message }, name) => {
each(invalidAttributes, ({ code, data, message }, name) => {
if (code !== "INVALID_ATTRIBUTE") {
return;
}

const path = prefix ? `${prefix}.${name}` : name;

if (Array.isArray(data)) {
return _.each(data, (err, index) => {
return each(data, (err, index) => {
const {
data: { invalidAttributes },
message
Expand All @@ -29,7 +30,7 @@ function formatInvalidAttributes(invalidAttributes, prefix = "") {
});
}

formatted[path] = _.get(data, "message", message);
formatted[path] = get(data, "message", message);
});

return formatted;
Expand All @@ -41,7 +42,7 @@ class InvalidAttributesError extends ModelError {

let data: Object = (error.data: any);
data.invalidAttributes = formatInvalidAttributes(
_.get(error, "data.invalidAttributes", {})
get(error, "data.invalidAttributes", {})
);

return new InvalidAttributesError(message, code, data);
Expand Down
9 changes: 5 additions & 4 deletions packages/webiny-api/src/graphql/parseBoolean.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// @flow
import _ from "lodash";
import forOwn from "lodash/forOwn";
import isObject from "lodash/isObject";

const traverse = (obj: Object) => {
_.forOwn(obj, (val, key) => {
if (_.isArray(val)) {
forOwn(obj, (val, key) => {
if (Array.isArray(val)) {
val.forEach(el => {
traverse(el);
});
} else if (_.isObject(val)) {
} else if (isObject(val)) {
traverse(val);
} else {
if (val === "true") {
Expand Down
23 changes: 10 additions & 13 deletions packages/webiny-install/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ export default async (context: Object) => {

log(chalk.cyan("\nInstalling..."));

setTimeout(async () => {
for (let i = 0; i < plugins.length; i++) {
let plugin = plugins[i];
try {
await plugin.install(context);
} catch (e) {
log(chalk.red(`An error occurred while installing ${plugin.meta.name}!`));
log(e);
}
for (let i = 0; i < plugins.length; i++) {
let plugin = plugins[i];
try {
await plugin.install(context);
} catch (e) {
log(chalk.red(`An error occurred while installing ${plugin.meta.name}!`));
log(e);
}
}

const end = (+new Date() - start) / 1000;
log(chalk.green(`Installation completed in ${end}s.`));
process.exit(0);
}, 200);
const end = (+new Date() - start) / 1000;
log(chalk.green(`Installation completed in ${end}s.`));
};

0 comments on commit 725e4c3

Please sign in to comment.