Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
]),
tx.query("INSERT INTO authx.credential (id) VALUES ($1)", [
credential.data.id
]),
tx.query("INSERT INTO authx.role (id) VALUES ($1)", [role.data.id]),
tx.query("INSERT INTO authx.authorization (id) VALUES ($1)", [
authorization.data.id
])
]);
// insert the records
await Promise.all([
User.write(tx, user.data, user.metadata),
PasswordAuthority.write(tx, authority.data, authority.metadata),
PasswordCredential.write(tx, credential.data, credential.metadata),
Role.write(tx, role.data, role.metadata),
Authorization.write(tx, authorization.data, authorization.metadata)
]);
}
for (const { roleId, scopes } of input.administration) {
const role = await Role.read(tx, roleId, { forUpdate: true });
if (
!role.isAccessibleBy(realm, a, tx, {
basic: "w",
scopes: "w",
users: ""
})
) {
throw new ForbiddenError(
`You do not have permission to modify the scopes of role ${roleId}.`
);
}
await Role.write(
tx,
{
...role,
scopes: simplify([
...role.scopes,
...possibleAdministrationScopes.filter(possible =>
isSuperset(scopes, possible)
)
])
},
{
recordId: v4(),
createdByAuthorizationId: a.id,
createdAt: new Date()
}
);
insert: (tx: PoolClient) =>
Role.write(
tx,
{
id: "08e2b39e-ba9f-4de2-8dca-aef460793566",
enabled: true,
name: "HR",
description: "The best; the worst.",
userIds: ["306eabbb-cc2b-4f88-be19-4bb6ec98e5c3"],
scopes: ["authx:user.*:**"]
},
{
recordId: "f94c5316-ce81-46e6-932a-0ac2c8fc886b",
createdByAuthorizationId: "f0e54748-c7bb-4724-ad8b-7dabb66aafa9",
createdAt: new Date("2019-03-06T21:07:59.814Z")
}
)
}
for (const { roleId, scopes } of input.administration) {
const role = await Role.read(tx, roleId, { forUpdate: true });
if (
!role.isAccessibleBy(realm, a, tx, {
basic: "w",
scopes: "w",
users: ""
})
) {
throw new ForbiddenError(
`You do not have permission to modify the scopes of role ${roleId}.`
);
}
await Role.write(
tx,
{
...role,
scopes: simplify([
...role.scopes,
...possibleAdministrationScopes.filter(possible =>
isSuperset(scopes, possible)
)
])
},
{
recordId: v4(),
createdByAuthorizationId: a.id,
createdAt: new Date()
}
);
for (const { roleId, scopes } of input.administration) {
const role = await Role.read(tx, roleId, { forUpdate: true });
if (
!role.isAccessibleBy(realm, a, tx, {
basic: "w",
scopes: "w",
users: ""
})
) {
throw new ForbiddenError(
`You do not have permission to modify the scopes of role ${roleId}.`
);
}
await Role.write(
tx,
{
...role,
scopes: simplify([
...role.scopes,
...possibleAdministrationScopes.filter(possible =>
isSuperset(scopes, possible)
)
])
},
{
recordId: v4(),
createdByAuthorizationId: a.id,
createdAt: new Date()
}
);
for (const { roleId, scopes } of input.administration) {
const role = await Role.read(tx, roleId, { forUpdate: true });
if (
!role.isAccessibleBy(realm, a, tx, {
basic: "w",
scopes: "w",
users: ""
})
) {
throw new ForbiddenError(
`You do not have permission to modify the scopes of role ${roleId}.`
);
}
await Role.write(
tx,
{
...role,
scopes: simplify([
...role.scopes,
...possibleAdministrationScopes.filter(possible =>
isSuperset(scopes, possible)
)
])
},
{
recordId: v4(),
createdByAuthorizationId: a.id,
createdAt: new Date()
}
);
for (const { roleId, scopes } of input.administration) {
const role = await Role.read(tx, roleId, { forUpdate: true });
if (
!role.isAccessibleBy(realm, a, tx, {
basic: "w",
scopes: "w",
users: ""
})
) {
throw new ForbiddenError(
`You do not have permission to modify the scopes of role ${roleId}.`
);
}
await Role.write(
tx,
{
...role,
scopes: simplify([
...role.scopes,
...possibleAdministrationScopes.filter(possible =>
isSuperset(scopes, possible)
)
])
},
{
recordId: v4(),
createdByAuthorizationId: a.id,
createdAt: new Date()
}
);
for (const { roleId, scopes } of input.administration) {
const role = await Role.read(tx, roleId, { forUpdate: true });
if (
!role.isAccessibleBy(realm, a, tx, {
basic: "w",
scopes: "w",
users: ""
})
) {
throw new ForbiddenError(
`You do not have permission to modify the scopes of role ${roleId}.`
);
}
await Role.write(
tx,
{
...role,
scopes: simplify([
...role.scopes,
...possibleAdministrationScopes.filter(possible =>
isSuperset(scopes, possible)
)
])
},
{
recordId: v4(),
createdByAuthorizationId: a.id,
createdAt: new Date()
}
);
await roles.map(role =>
Role.write(
tx,
{
...role,
userIds: [...role.userIds, user.id]
},
{
recordId: v4(),
createdByAuthorizationId: authorizationId,
createdAt: new Date()
}
)
);