Skip to content

Commit 38e328c

Browse files
authored
Merge pull request #273 from scratchfoundation/UEPR-289
feat: [UEPR-289] disconnect project from cloud
2 parents 8dfd7f8 + b7ad4c1 commit 38e328c

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

packages/scratch-gui/src/lib/cloud-manager-hoc.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ const cloudManagerHOC = function (WrappedComponent) {
101101
handleExtensionAdded (categoryInfo) {
102102
// Note that props.vm.extensionManager.isExtensionLoaded('videoSensing') is still false
103103
// at the point of this callback, so it is difficult to reuse the canModifyCloudData logic.
104-
if (categoryInfo.id === 'videoSensing' && this.isConnected()) {
104+
if (
105+
(categoryInfo.id === 'videoSensing' ||
106+
categoryInfo.id === 'faceSensing') &&
107+
this.isConnected()
108+
) {
105109
this.disconnectFromCloud();
106110
}
107111
}
@@ -157,9 +161,18 @@ const cloudManagerHOC = function (WrappedComponent) {
157161
isShowingWithId: getIsShowingWithId(loadingState),
158162
projectId: state.scratchGui.projectState.projectId,
159163
// if you're editing someone else's project, you can't modify cloud data
160-
canModifyCloudData: (!state.scratchGui.mode.hasEverEnteredEditor || ownProps.canSave) &&
164+
canModifyCloudData:
165+
(!state.scratchGui.mode.hasEverEnteredEditor ||
166+
ownProps.canSave) &&
161167
// possible security concern if the program attempts to encode webcam data over cloud variables
162-
!ownProps.vm.extensionManager.isExtensionLoaded('videoSensing')
168+
!(
169+
ownProps.vm.extensionManager.isExtensionLoaded(
170+
'videoSensing'
171+
) ||
172+
ownProps.vm.extensionManager.isExtensionLoaded(
173+
'faceSensing'
174+
)
175+
)
163176
};
164177
};
165178

packages/scratch-gui/test/unit/util/cloud-manager-hoc.test.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,25 @@ describe('CloudManagerHOC', () => {
162162
expect(CloudProvider).not.toHaveBeenCalled();
163163
});
164164

165+
test('when faceSensing extension is active, the cloud provider is not set on the vm', () => {
166+
const Component = () => <div />;
167+
const WrappedComponent = cloudManagerHOC(Component);
168+
vm.extensionManager.isExtensionLoaded = jest.fn(extension => extension === 'faceSensing');
169+
170+
mount(
171+
<WrappedComponent
172+
hasCloudPermission
173+
cloudHost="nonEmpty"
174+
store={store}
175+
username="user"
176+
vm={vm}
177+
/>
178+
);
179+
180+
expect(vm.setCloudProvider.mock.calls.length).toBe(0);
181+
expect(CloudProvider).not.toHaveBeenCalled();
182+
});
183+
165184
test('if the isShowingWithId prop becomes true, it sets the cloud provider on the vm', () => {
166185
const Component = () => <div />;
167186
const WrappedComponent = cloudManagerHOC(Component);

0 commit comments

Comments
 (0)