Skip to content

Commit c2d9562

Browse files
committed
Add a logic to check whether the user belongs to the organization which is the target keyboard.
1 parent 04d35b6 commit c2d9562

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

functions/src/keyboards/create-keyboard-statistics-command.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,27 @@ export class CreateKeyboardStatisticsCommand extends AbstractCommand<ICreateKeyb
132132
};
133133
}
134134
const keyboardDefinition = keyboardDefinitionSnapshot.data()!;
135-
if (keyboardDefinition.author_uid !== uid) {
136-
return {
137-
success: false,
138-
errorCode: ERROR_KEYBOARD_DEFINITION_NOT_FOUND,
139-
errorMessage: `The user is not an owner of the keyboard definition ${keyboardDefinitionId}.`,
140-
};
135+
if (keyboardDefinition.author_type === 'organization') {
136+
const organizationId = keyboardDefinition.organization_id;
137+
const result = await this.checkUserIsOrganizationMember(
138+
uid,
139+
organizationId
140+
);
141+
if (!result) {
142+
return {
143+
success: false,
144+
errorCode: ERROR_KEYBOARD_DEFINITION_NOT_FOUND,
145+
errorMessage: `The user is not a member of the organization ${organizationId}.`,
146+
};
147+
}
148+
} else {
149+
if (keyboardDefinition.author_uid !== uid) {
150+
return {
151+
success: false,
152+
errorCode: ERROR_KEYBOARD_DEFINITION_NOT_FOUND,
153+
errorMessage: `The user is not an owner of the keyboard definition ${keyboardDefinitionId}.`,
154+
};
155+
}
141156
}
142157
return {
143158
success: true,

0 commit comments

Comments
 (0)