generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dev-api): INFRA-281 Emails 2FA and B2CAppAccessRight (#4484)
* feat(dev-api): INFRA-281 added few tests * feat(dev-api): INFRA-281 ConfirmEmailAction CRUD tests * feat(dev-api): INFRA-281 Extend dev-portal message transports * feat(dev-api): INFRA-281 fix message content * feat(dev-api): INFRA-281 added ConfirmPhoneActionService tests * feat(dev-api): INFRA-281 added B2CAppAccessRight model * feat(dev-api): INFRA-281 added RegisterAppServiceUserService pre-draft * feat(dev-api): INFRA-281 added RegisterAppServiceUserService draft * feat(dev-api): INFRA-281 added RegisterAppServiceUserService tests * feat(dev-api): INFRA-281 added some B2CAppAccessRight tests * feat(dev-api): INFRA-281 few tests added * feat(dev-api): INFRA-281 add import logic * feat(dev-api): INFRA-281 added export fields and tests * feat(dev-api): INFRA-281 more tests * feat(dev-api): INFRA-281 added publish logic * feat(dev-api): INFRA-281 added publish tests * feat(dev-api): INFRA-281 added logs * feat(dev-api): INFRA-281 fix tests * fix(dev-api): INFRA-281 import tests fix * fix(dev-api): INFRA-281 regenerate schema * fix(dev-api): INFRA-281 fix env variables * feat(keystone): INFRA-281 Select type reimplementation
- Loading branch information
1 parent
5719ce7
commit a9051d8
Showing
58 changed files
with
5,567 additions
and
1,190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
SMS_WHITE_LIST='{"+79990001234": "1234"}' | ||
IP_WHITE_LIST='["::ffff:127.0.0.1"]' | ||
SMS_PROVIDER=fake | ||
EMAIL_PROVIDER=fake | ||
FILE_FIELD_ADAPTER=local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const conf = require('@open-condo/config') | ||
|
||
const { developmentClient, productionClient } = require('@dev-api/domains/common/utils/serverClients') | ||
|
||
class FakeEmailAdapter { | ||
async sendMessage (email, subject, body) { | ||
console.log(JSON.stringify({ adapter: 'Fake Email Adapter', email, subject, body })) | ||
} | ||
} | ||
|
||
class CondoEmailAdapter { | ||
#client | ||
|
||
constructor (serverClient) { | ||
this.#client = serverClient | ||
} | ||
|
||
async sendMessage (email, subject, body) { | ||
await this.#client.sendMessage({ email }, body, { subject }) | ||
} | ||
} | ||
|
||
class EmailAdapter { | ||
#internalAdapter = null | ||
|
||
constructor (type = 'faker') { | ||
switch (type) { | ||
case 'condo-dev': | ||
this.#internalAdapter = new CondoEmailAdapter(developmentClient) | ||
break | ||
case 'condo-prod': | ||
this.#internalAdapter = new CondoEmailAdapter(productionClient) | ||
break | ||
default: | ||
this.#internalAdapter = new FakeEmailAdapter() | ||
break | ||
} | ||
} | ||
|
||
async sendMessage (email, subject, body) { | ||
await this.#internalAdapter.sendMessage(email, subject, body) | ||
} | ||
} | ||
|
||
const DEFAULT_EMAIL_ADAPTER = new EmailAdapter(conf['EMAIL_PROVIDER'] || 'fake') | ||
|
||
async function sendMessage (email, subject, body) { | ||
await DEFAULT_EMAIL_ADAPTER.sendMessage(email, subject, body) | ||
} | ||
|
||
module.exports = { | ||
sendMessage, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ class SMSAdapter { | |
break | ||
default: | ||
this.#internalAdapter = new FakeSMSAdapter() | ||
break | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Generated by `createschema miniapp.B2CAppAccessRight 'app:Relationship:B2CApp:CASCADE; condoUserId:Text'` | ||
*/ | ||
|
||
const { throwAuthenticationError } = require('@open-condo/keystone/apolloErrorFormatter') | ||
|
||
const { canReadAppLinkedModelAsOwner } = require('@dev-api/domains/miniapp/utils/serverSchema/access') | ||
|
||
async function canReadB2CAppAccessRights (args) { | ||
const { authentication: { item: user } } = args | ||
if (!user) return throwAuthenticationError() | ||
if (user.deletedAt) return false | ||
|
||
if (user.isAdmin || user.isSupport) return {} | ||
|
||
|
||
return canReadAppLinkedModelAsOwner(args) | ||
} | ||
|
||
async function canManageB2CAppAccessRights ({ authentication: { item: user } }) { | ||
if (!user) return throwAuthenticationError() | ||
if (user.deletedAt) return false | ||
|
||
return false | ||
} | ||
|
||
/* | ||
Rules are logical functions that used for list access, and may return a boolean (meaning | ||
all or no items are available) or a set of filters that limit the available items. | ||
*/ | ||
module.exports = { | ||
canReadB2CAppAccessRights, | ||
canManageB2CAppAccessRights, | ||
} |
24 changes: 24 additions & 0 deletions
24
apps/dev-api/domains/miniapp/access/RegisterAppServiceUserService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Generated by `createservice miniapp.RegisterAppServiceUserService` | ||
*/ | ||
const { throwAuthenticationError } = require('@open-condo/keystone/apolloErrorFormatter') | ||
|
||
const { canExecuteB2CAppMutationAsOwner } = require('@dev-api/domains/miniapp/utils/serverSchema/access') | ||
|
||
async function canRegisterAppUserService (params) { | ||
const { authentication: { item: user } } = params | ||
|
||
if (!user) return throwAuthenticationError() | ||
if (user.deletedAt) return false | ||
if (user.isAdmin || user.isSupport) return true | ||
|
||
return await canExecuteB2CAppMutationAsOwner(params) | ||
} | ||
|
||
/* | ||
Rules are logical functions that used for list access, and may return a boolean (meaning | ||
all or no items are available) or a set of filters that limit the available items. | ||
*/ | ||
module.exports = { | ||
canRegisterAppUserService, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const B2C_APP_BUILD_UNIQUE_VERSION_CONSTRAINT = 'b2c_app_build_unique_version_app' | ||
const B2C_APP_PUBLISH_REQUEST_UNIQUE_CONSTRAINT = 'b2c_app_publish_request_unique_app' | ||
const B2C_APP_ACCESS_RIGHT_UNIQUE_APP_CONSTRAINT = 'b2c_app_access_right_unique_app' | ||
|
||
module.exports = { | ||
B2C_APP_BUILD_UNIQUE_VERSION_CONSTRAINT, | ||
B2C_APP_PUBLISH_REQUEST_UNIQUE_CONSTRAINT, | ||
B2C_APP_ACCESS_RIGHT_UNIQUE_APP_CONSTRAINT, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* Generated by `createschema miniapp.B2CAppAccessRight 'app:Relationship:B2CApp:CASCADE; condoUserId:Text'` | ||
*/ | ||
|
||
const get = require('lodash/get') | ||
|
||
const { historical, versioned, uuided, tracked, softDeleted, dvAndSender } = require('@open-condo/keystone/plugins') | ||
const { GQLListSchema } = require('@open-condo/keystone/schema') | ||
|
||
|
||
const { GET_USER_EMAIL_QUERY } = require('@dev-api/domains/common/gql') | ||
const { productionClient, developmentClient } = require('@dev-api/domains/common/utils/serverClients') | ||
const access = require('@dev-api/domains/miniapp/access/B2CAppAccessRight') | ||
const { | ||
B2C_APP_ACCESS_RIGHT_UNIQUE_APP_CONSTRAINT, | ||
} = require('@dev-api/domains/miniapp/constants/constraints') | ||
const { AVAILABLE_ENVIRONMENTS, PROD_ENVIRONMENT } = require('@dev-api/domains/miniapp/constants/publishing') | ||
const { exportable } = require('@dev-api/domains/miniapp/plugins/exportable') | ||
|
||
|
||
|
||
const B2CAppAccessRight = new GQLListSchema('B2CAppAccessRight', { | ||
schemaDoc: | ||
'Link between service user and B2C App. ' + | ||
'The existence of this connection means that ' + | ||
'this condo user will have the rights to perform actions on behalf of the integration ' + | ||
'and modify some B2CApp-related models, such as B2CAppProperty / B2CAppBuild ' + | ||
'as soon as app will be published to specified environment', | ||
fields: { | ||
app: { | ||
schemaDoc: 'Link to B2CApp', | ||
type: 'Relationship', | ||
ref: 'B2CApp', | ||
isRequired: true, | ||
knexOptions: { isNotNullable: true }, // Required relationship only! | ||
kmigratorOptions: { null: false, on_delete: 'models.CASCADE' }, | ||
}, | ||
condoUserId: { | ||
schemaDoc: 'ID of condo user, which will be linked to the published app', | ||
type: 'Uuid', | ||
isRequired: true, | ||
}, | ||
condoUserEmail: { | ||
schemaDoc: 'Email of service condo user linked to the published app', | ||
type: 'Virtual', | ||
graphQLReturnType: 'String', | ||
resolver: async (item) => { | ||
const { condoUserId, environment } = item | ||
const serverClient = environment === PROD_ENVIRONMENT | ||
? productionClient | ||
: developmentClient | ||
const response = await serverClient.executeAuthorizedQuery({ | ||
query: GET_USER_EMAIL_QUERY, | ||
variables: { id: condoUserId }, | ||
}) | ||
|
||
return get(response, ['data', 'user', 'email'], null) | ||
}, | ||
}, | ||
environment: { | ||
schemaDoc: 'Condo environment', | ||
type: 'Select', | ||
options: AVAILABLE_ENVIRONMENTS, | ||
isRequired: true, | ||
graphQLReturnType: 'AppEnvironment', | ||
}, | ||
}, | ||
kmigratorOptions: { | ||
constraints: [ | ||
{ | ||
type: 'models.UniqueConstraint', | ||
fields: ['environment', 'app'], | ||
condition: 'Q(deletedAt__isnull=True)', | ||
name: B2C_APP_ACCESS_RIGHT_UNIQUE_APP_CONSTRAINT, | ||
}, | ||
], | ||
}, | ||
plugins: [uuided(), versioned(), tracked(), softDeleted(), dvAndSender(), exportable(), historical()], | ||
access: { | ||
read: access.canReadB2CAppAccessRights, | ||
create: access.canManageB2CAppAccessRights, | ||
update: access.canManageB2CAppAccessRights, | ||
delete: false, | ||
auth: true, | ||
}, | ||
}) | ||
|
||
module.exports = { | ||
B2CAppAccessRight, | ||
} |
Oops, something went wrong.