Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/condo/domains/miniapp/access/SendVoIPStartMessageService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { throwAuthenticationError } = require('@open-condo/keystone/apolloErrorFormatter')

const { canExecuteServiceAsB2CAppServiceUser } = require('@condo/domains/miniapp/utils/b2cAppServiceUserAccess/server.utils')
const { SERVICE } = require('@condo/domains/user/constants/common')

async function canSendVoIPStartMessage (args) {
const { authentication: { item: user } } = args

if (!user) return throwAuthenticationError()
if (user.deletedAt) return false
if (user.isAdmin) return true

if (user.type === SERVICE) {
Comment thread
YEgorLu marked this conversation as resolved.
return await canExecuteServiceAsB2CAppServiceUser(args)
}

return false
}

module.exports = {
canSendVoIPStartMessage,
}
9 changes: 9 additions & 0 deletions apps/condo/domains/miniapp/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const ACCESS_TOKEN_WRONG_RIGHT_SET_TYPE = 'ACCESS_TOKEN_WRONG_RIGHT_SET_TYPE'
const ACCESS_TOKEN_CONTEXT_DOES_NOT_MATCH_RIGHT_SET = 'ACCESS_TOKEN_CONTEXT_DOES_NOT_MATCH_RIGHT_SET'
const ACCESS_TOKEN_SERVICE_USER_DOES_NOT_MATCH_CONTEXT = 'ACCESS_TOKEN_SERVICE_USER_DOES_NOT_MATCH_CONTEXT'
const ACCESS_TOKEN_NEGATIVE_TTL = 'ACCESS_TOKEN_NEGATIVE_TTL'
const CALL_DATA_NOT_PROVIDED_ERROR = 'CALL_DATA_NOT_PROVIDED'

const MAX_PERMISSION_NAME_LENGTH = 50
const MIN_PERMISSION_NAME_LENGTH = 1
Expand Down Expand Up @@ -132,6 +133,9 @@ const ACCESS_TOKEN_SESSION_ID_PREFIX = `${Buffer.from('b2bAccessToken').toString

const ACCESS_TOKEN_UPDATE_MANY_CHUNK_SIZE = 500

const NATIVE_VOIP_TYPE = 'sip'
const B2C_APP_VOIP_TYPE = 'b2cApp'

module.exports = {
ALL_APPS_CATEGORY,
CONNECTED_APPS_CATEGORY,
Expand Down Expand Up @@ -207,4 +211,9 @@ module.exports = {

DEFAULT_NOTIFICATION_WINDOW_MAX_COUNT,
DEFAULT_NOTIFICATION_WINDOW_DURATION_IN_SECONDS,

CALL_DATA_NOT_PROVIDED_ERROR,

NATIVE_VOIP_TYPE,
B2C_APP_VOIP_TYPE,
}
7 changes: 7 additions & 0 deletions apps/condo/domains/miniapp/gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const SEND_B2C_APP_PUSH_MESSAGE_MUTATION = gql`
}
`

const SEND_VOIP_START_MESSAGE_MUTATION = gql`
mutation sendVoIPStartMessage ($data: SendVoIPStartMessageInput!) {
result: sendVoIPStartMessage(data: $data) { verifiedContactsCount createdMessagesCount erroredMessagesCount }
}
`

const B2B_APP_NEWS_SHARING_CONFIG_FIELDS = `{ publishUrl previewUrl pushNotificationSettings customFormUrl getRecipientsUrl getRecipientsCountersUrl icon { publicUrl } previewPicture { publicUrl } name ${COMMON_FIELDS} }`
const B2BAppNewsSharingConfig = generateGqlQueries('B2BAppNewsSharingConfig', B2B_APP_NEWS_SHARING_CONFIG_FIELDS)

Expand Down Expand Up @@ -135,5 +141,6 @@ module.exports = {
B2BAppRoleWithoutEmployeeRole,
B2BAppPosIntegrationConfig,
B2CAppAccessRightSet,
SEND_VOIP_START_MESSAGE_MUTATION,
/* AUTOGENERATE MARKER <EXPORTS> */
}
62 changes: 58 additions & 4 deletions apps/condo/domains/miniapp/schema/B2CAppAccessRightSet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@

const { faker } = require('@faker-js/faker')

const { makeLoggedInAdminClient, makeClient, UUID_RE } = require('@open-condo/keystone/test.utils')
const { makeLoggedInAdminClient, makeClient, UUID_RE, expectToThrowAccessDeniedErrorToResult } = require('@open-condo/keystone/test.utils')
const {
expectToThrowAuthenticationErrorToObj, expectToThrowAuthenticationErrorToObjects,
expectToThrowAccessDeniedErrorToObj, expectToThrowAccessDeniedErrorToObjects,
} = require('@open-condo/keystone/test.utils')



const { B2CAppAccessRightSet, createTestB2CAppAccessRightSet, updateTestB2CAppAccessRightSet, createTestB2CAppProperty, updateTestB2CAppProperty, B2CAppProperty } = require('@condo/domains/miniapp/utils/testSchema')
const { B2CAppAccessRightSet, createTestB2CAppAccessRightSet, updateTestB2CAppAccessRightSet, createTestB2CAppProperty, updateTestB2CAppProperty, B2CAppProperty, sendVoIPStartMessageByTestClient, updateTestB2CAppAccessRight } = require('@condo/domains/miniapp/utils/testSchema')
const { createTestB2CApp, createTestB2CAppAccessRight } = require('@condo/domains/miniapp/utils/testSchema')
const { FLAT_UNIT_TYPE } = require('@condo/domains/property/constants/common')
const { buildFakeAddressAndMeta } = require('@condo/domains/property/utils/testSchema/factories')
const { makeClientWithNewRegisteredAndLoggedInUser, makeClientWithSupportUser } = require('@condo/domains/user/utils/testSchema')
const { makeClientWithServiceUser } = require('@condo/domains/user/utils/testSchema')


describe('B2CAppAccessRightSet', () => {
let admin

Expand Down Expand Up @@ -304,13 +306,14 @@ describe('B2CAppAccessRightSet', () => {
let user
let b2cApp
let serviceUser
let b2cAccessRight

beforeEach(async () => {
support = await makeClientWithSupportUser()
user = await makeClientWithNewRegisteredAndLoggedInUser()
serviceUser = await makeClientWithServiceUser();
[b2cApp] = await createTestB2CApp(admin)
await createTestB2CAppAccessRight(admin, serviceUser.user, b2cApp)
[b2cApp] = await createTestB2CApp(admin);
Comment on lines 314 to +315
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove semicolons from the changed setup lines.

These two lines violate the repo’s JavaScript style rule.

Style fix
-            serviceUser = await makeClientWithServiceUser();
-            [b2cApp] = await createTestB2CApp(admin);
+            serviceUser = await makeClientWithServiceUser()
+            [b2cApp] = await createTestB2CApp(admin)

As per coding guidelines, Never use semicolons in JavaScript/TypeScript code.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
serviceUser = await makeClientWithServiceUser();
[b2cApp] = await createTestB2CApp(admin)
await createTestB2CAppAccessRight(admin, serviceUser.user, b2cApp)
[b2cApp] = await createTestB2CApp(admin);
serviceUser = await makeClientWithServiceUser()
[b2cApp] = await createTestB2CApp(admin)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/condo/domains/miniapp/schema/B2CAppAccessRightSet.test.js` around lines
314 - 315, Remove trailing semicolons from the two setup statements: the call
that assigns serviceUser from makeClientWithServiceUser() and the array
destructure that assigns b2cApp from createTestB2CApp(admin); update the lines
with serviceUser = await makeClientWithServiceUser() and [b2cApp] = await
createTestB2CApp(admin) to omit the semicolons to comply with the repo's
no-semicolon JS/TS style rule.

[b2cAccessRight] = await createTestB2CAppAccessRight(admin, serviceUser.user, b2cApp)
})

test('B2CAppAccessRightSet', async () => {
Expand Down Expand Up @@ -418,6 +421,57 @@ describe('B2CAppAccessRightSet', () => {
expect(foundB2CAppProperty.id).toEqual(createdB2CAppProperty.id)

})

test('SendVoIPStartMessageService', async () => {
const args = {
app: { id: b2cApp.id },
addressKey: faker.datatype.uuid(),
unitName: faker.random.alphaNumeric(8),
unitType: FLAT_UNIT_TYPE,
callData: {
callId: faker.random.alphaNumeric(8),
b2cAppCallData: {
B2CAppContext: faker.random.alphaNumeric(8),
},
},
}

// Can't without access right set
await expectToThrowAccessDeniedErrorToResult(async () => {
await sendVoIPStartMessageByTestClient(serviceUser, args)
})

// Can't with access right set and without b2c app property
const [rightSet] = await createTestB2CAppAccessRightSet(support, b2cApp, { canExecuteSendVoIPStartMessage: true })
await updateTestB2CAppAccessRight(support, b2cAccessRight.id, { accessRightSet: { connect: { id: rightSet.id } } })
await expectToThrowAccessDeniedErrorToResult(async () => {
await sendVoIPStartMessageByTestClient(serviceUser, args)
})

// Can with access right set and b2c app property
const [b2cAppProperty] = await createTestB2CAppProperty(serviceUser, b2cApp)
args.addressKey = b2cAppProperty.addressKey
const [result] = await sendVoIPStartMessageByTestClient(serviceUser, args)
expect(result).toEqual(expect.objectContaining({
verifiedContactsCount: expect.any(Number),
createdMessagesCount: expect.any(Number),
erroredMessagesCount: expect.any(Number),
}))

// Can't with access right and another b2c app proeprty
const [anotherB2CApp] = await createTestB2CApp(admin)
const [anotherB2CAppProperty] = await createTestB2CAppProperty(admin, anotherB2CApp)
args.addressKey = anotherB2CAppProperty.addressKey
await expectToThrowAccessDeniedErrorToResult(async () => {
await sendVoIPStartMessageByTestClient(serviceUser, args)
})

// Can't for another app
args.app.id = anotherB2CApp.id
await expectToThrowAccessDeniedErrorToResult(async () => {
await sendVoIPStartMessageByTestClient(serviceUser, args)
})
})
})

})
Expand Down
Loading
Loading