@itleadopencommerce/api-plugin-accounts
Advanced tools
Comparing version 2.11.0 to 2.13.0
{ | ||
"name": "@itleadopencommerce/api-plugin-accounts", | ||
"description": "Accounts plugin for the Reaction API", | ||
"version": "2.11.0", | ||
"version": "2.13.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "type": "module", |
@@ -12,4 +12,5 @@ import pkg from "../package.json"; | ||
import accountByUserId from "./util/accountByUserId.js"; | ||
import { Account, Group, Profile } from "./simpleSchemas.js"; | ||
import { Account, Group, Profile, Impersonation } from "./simpleSchemas.js"; | ||
console.log(resolvers); | ||
/** | ||
@@ -28,3 +29,3 @@ * @summary Import and call this function to add this plugin to your API. | ||
preStartup: [extendAccountSchema, checkDatabaseVersion], | ||
startup: [afterShopCreate] | ||
startup: [afterShopCreate], | ||
}, | ||
@@ -40,21 +41,22 @@ collections: { | ||
[{ userId: 1 }, { name: "c2_userId" }], | ||
[{ shopId: 1, slug: 1 }] | ||
] | ||
[{ shopId: 1, slug: 1 }], | ||
], | ||
}, | ||
AccountInvites: { | ||
name: "AccountInvites", | ||
indexes: [ | ||
[{ email: 1 }] | ||
] | ||
indexes: [[{ email: 1 }]], | ||
}, | ||
Groups: { | ||
name: "Groups" | ||
} | ||
name: "Groups", | ||
}, | ||
Impersonations: { | ||
name: "Impersonations", | ||
}, | ||
}, | ||
auth: { | ||
accountByUserId | ||
accountByUserId, | ||
}, | ||
graphQL: { | ||
resolvers, | ||
schemas | ||
schemas, | ||
}, | ||
@@ -67,5 +69,6 @@ mutations, | ||
Group, | ||
Profile | ||
} | ||
Profile, | ||
Impersonation, | ||
}, | ||
}); | ||
} |
@@ -28,4 +28,9 @@ import Logger from "@reactioncommerce/logger"; | ||
const status = "REQUIRE_VERIFICATION"; | ||
let status = "REQUIRE_VERIFICATION"; | ||
const anyAccount = await Accounts.findOne(); | ||
if (!anyAccount) { | ||
status = "VERIFIED"; | ||
} | ||
const { | ||
@@ -117,3 +122,3 @@ emails, | ||
// `system-manager` and `accounts-manager` groups | ||
const anyAccount = await Accounts.findOne(); | ||
if (company || isSeller) { | ||
@@ -120,0 +125,0 @@ await ensureAndAddSellerGroups(); |
@@ -23,6 +23,6 @@ import addressBookAdd from "./addressBookAdd.js"; | ||
import sendVerifyAccountEmail from "./sendVerifyAccountEmail.js"; | ||
import startIdentityEmailVerification from "./startIdentityEmailVerification"; | ||
import startIdentityEmailVerification from "./startIdentityEmailVerification.js"; | ||
import verifyJsonToken from "./verifyJsonToken.js"; | ||
import createImpersonationRecord from "./createImpersonationRecord.js"; | ||
import updateImpersonationRecord from "./updateImpersonationRecord.js"; | ||
export default { | ||
@@ -52,3 +52,5 @@ addressBookAdd, | ||
startIdentityEmailVerification, | ||
verifyJsonToken | ||
verifyJsonToken, | ||
createImpersonationRecord, | ||
updateImpersonationRecord, | ||
}; |
@@ -35,2 +35,6 @@ import SimpleSchema from "simpl-schema"; | ||
}, | ||
status: { | ||
type: String, | ||
optional: true, | ||
}, | ||
note: { | ||
@@ -50,15 +54,15 @@ type: String, | ||
type: Boolean, | ||
required: true, | ||
optional: true, | ||
}, | ||
isAdult: { | ||
type: Boolean, | ||
required: true, | ||
optional: true, | ||
}, | ||
personalDataToOtherCompanies: { | ||
type: Boolean, | ||
required: true, | ||
optional: true, | ||
}, | ||
personalDataToPromotionalOffers: { | ||
type: Boolean, | ||
required: true, | ||
optional: true, | ||
}, | ||
@@ -116,3 +120,3 @@ }); | ||
if (!account) throw new ReactionError("not-found", "No account found"); | ||
console.log(account); | ||
await context.validatePermissions( | ||
@@ -128,3 +132,2 @@ `reaction:legacy:accounts:${accountId}`, | ||
const updatedFields = []; | ||
if (typeof currencyCode === "string" || currencyCode === null) { | ||
@@ -174,5 +177,5 @@ if (currencyCode !== null && !CurrencyDefinitions[currencyCode]) { | ||
if (typeof status === "string" || note === null) { | ||
if (typeof status === "string" || status === null) { | ||
updates.status = status; | ||
updatedFields.push("note"); | ||
updatedFields.push("status"); | ||
} | ||
@@ -251,4 +254,3 @@ | ||
}); | ||
return updatedAccount; | ||
} |
@@ -20,7 +20,7 @@ import ReactionError from "@reactioncommerce/reaction-error"; | ||
// Check to make sure current user has permissions to view queried user | ||
await context.validatePermissions("reaction:legacy:accounts", "read", { | ||
owner: account.userId | ||
}); | ||
// await context.validatePermissions("reaction:legacy:accounts", "read", { | ||
// owner: account.userId | ||
// }); | ||
return account; | ||
} |
@@ -10,2 +10,3 @@ import accountByUserId from "./accountByUserId.js"; | ||
import userAccount from "./userAccount.js"; | ||
import getImpersonationByUser from "./getImpersonationByUser.js"; | ||
@@ -21,3 +22,4 @@ export default { | ||
invitations, | ||
userAccount | ||
userAccount, | ||
getImpersonationByUser, | ||
}; |
@@ -12,9 +12,15 @@ /** | ||
export default async function adminUIShops(account, args, context) { | ||
if (!account || !account.adminUIShopIds || account.adminUIShopIds.length === 0) { | ||
if ( | ||
!account || | ||
!account.adminUIShopIds || | ||
account.adminUIShopIds.length === 0 | ||
) { | ||
return []; | ||
} | ||
const shopCursor = await context.queries.shops(context, { shopIds: account.adminUIShopIds }); | ||
const shopCursor = await context.queries.shops(context, { | ||
shopIds: account.adminUIShopIds, | ||
}); | ||
return shopCursor.toArray(); | ||
} |
@@ -9,2 +9,3 @@ import getConnectionTypeResolvers from "@reactioncommerce/api-utils/graphql/getConnectionTypeResolvers.js"; | ||
import Shop from "./Shop/index.js"; | ||
import Subscription from "./Subscription/index.js"; | ||
@@ -23,5 +24,6 @@ /** | ||
Query, | ||
Subscription, | ||
Shop, | ||
...getConnectionTypeResolvers("Account"), | ||
...getConnectionTypeResolvers("Group") | ||
...getConnectionTypeResolvers("Group"), | ||
}; |
@@ -22,2 +22,3 @@ import addAccountAddressBookEntry from "./addAccountAddressBookEntry.js"; | ||
import verifyJsonToken from "./verifyJsonToken.js"; | ||
import updateImpersonationRecord from "./updateImpersonationRecord.js"; | ||
@@ -45,3 +46,4 @@ export default { | ||
sendVerifyAccountEmail, | ||
verifyJsonToken | ||
verifyJsonToken, | ||
updateImpersonationRecord, | ||
}; |
@@ -8,2 +8,3 @@ import account from "./account.js"; | ||
import viewer from "./viewer.js"; | ||
import getImpersonationByUser from "./getImpersonationByUser.js"; | ||
@@ -17,3 +18,4 @@ export default { | ||
invitations, | ||
viewer | ||
viewer, | ||
getImpersonationByUser, | ||
}; |
@@ -22,3 +22,5 @@ import optimizeIdOnly from "@reactioncommerce/api-utils/graphql/optimizeIdOnly.js"; | ||
viewer.isInpersonated = context.isInpersonated; | ||
viewer.isInpersonated = context.isInpersonated || null; | ||
viewer.impersonatedBy = context.impersonatedBy || null; | ||
viewer.sessionId = context.sessionId || null; | ||
@@ -25,0 +27,0 @@ return new Promise((resolve, reject) => { |
@@ -7,3 +7,4 @@ import importAsString from "@reactioncommerce/api-utils/importAsString.js"; | ||
const inviteShopMember = importAsString("./inviteShopMember.graphql"); | ||
const impersonation = importAsString("./impersonation.graphql"); | ||
export default [account, adminUIAccess, group, inviteShopMember]; | ||
export default [account, adminUIAccess, group, inviteShopMember, impersonation]; |
@@ -543,1 +543,33 @@ import SimpleSchema from "simpl-schema"; | ||
}); | ||
/** | ||
* @name Impersonation | ||
* @memberof Schemas | ||
* @type {SimpleSchema} | ||
* @property {String} _id required | ||
* @property {Date} startedAt required | ||
* @property {Date} endedAt required | ||
* @property {String} userId required | ||
* @property {String} impersonatedUserId optional | ||
*/ | ||
export const Impersonation = new SimpleSchema({ | ||
_id: String, | ||
startedAt: Date, | ||
endedAt: Date, | ||
userId: String, | ||
impersonatedBy: String, | ||
sessionId: String, | ||
isActive: { | ||
type: Boolean, | ||
autoValue: function () { | ||
const started = this.field("startedAt"); | ||
const ended = this.field("endedAt"); | ||
if (started.value === ended.value) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}, | ||
optional: true, | ||
}, | ||
}); |
@@ -14,6 +14,3 @@ import ReactionError from "@reactioncommerce/reaction-error"; | ||
context.appEvents.on("afterShopCreate", async (payload) => { | ||
const { | ||
createdBy: userId, | ||
shop | ||
} = payload; | ||
const { createdBy: userId, shop } = payload; | ||
@@ -23,7 +20,10 @@ const account = await Accounts.findOne({ userId }); | ||
if (!account) { | ||
throw new ReactionError("not-found", `Could not find account for user ${userId} when granting admin UI access for shop ${shop._id}`); | ||
throw new ReactionError( | ||
"not-found", | ||
`Could not find account for user ${userId} when granting admin UI access for shop ${shop._id}` | ||
); | ||
} else { | ||
await context.mutations.grantAdminUIAccess(context, { | ||
accountId: account._id, | ||
shopId: shop._id | ||
shopId: shop._id, | ||
}); | ||
@@ -30,0 +30,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
320589
180
6329