2023-10-16
(C) Questetra, Inc. (MIT License)
3
2
This item deletes the specified Sharing Link from the file/folder in OneDrive.
この工程は、OneDrive 内のファイル / フォルダから、指定された共有リンクを削除します。
https://support.questetra.com/bpmn-icons/service-task-onedrive-file-link-delete/
https://support.questetra.com/ja/bpmn-icons/service-task-onedrive-file-link-delete/
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADXUlEQVRYR8WXW0hUURSG/33GbC5e
8pJJF6nM6YKUmsFAIAZSONOM4FtqL/mQVg9GhXR5iCIiEAqF9KEMsvKpi06OZoRPGaRmVoSGU4om
aqaMzeXYOLPjTJ7R41w8k8bZLwNn1r/Wt9dee+29CSQeRHR8vVEpd7vzGTAHKKXpADYDiJnTTwEY
IIR0u+FuYxnmCYx6uxjfSwKotE2JbuoqB0EJALkYpwBYUNQwRHbDZtKNBtMEBVBqG0ooSAUAlcjA
i81sBPSs3ZRXE0gfEECuM94mlJb+Y2CBjBJSzTbpT/jz5RdAoTU+BGjBSgSf90EeOUz6wsU+fQBW
cuaLg/nLhABgbs2rV3bmQm8EtHRhTXgBPNUOV/8yCk4st42BbBu/O7wAitzGmyAoE+tlWXYUtxzN
htOcj78AeqNS4aI/Q9jneH5Ng0x1DCLkMlhZFz59m0ZZ9UfPr4jBOmQkjmtWHgC5rqGIUFIXTHih
QI3UzVHoH7HhsCYROzZF+JgPjNqxq/iViPgAJfQo25T3wAOg1BnvUkqP+VNGKsLQXpmF5PXCXmR1
zKJvyAqL3Yn4qHCoN0ZCHs6gvm0YxRXdS0IQQmrtTfpiD4BC2/gOANfffUbjVQ1yMtYKvnNZGJlg
kZESDeVqGSy2WbzoHPdkpdtswcnKniUBAHQ7TIYMHmBywcEiEPfey0FSgsL7zWJzosc8jazdcQI7
l5tiwvIbUaowTE47UfXMjMqnX4OBTDlMhlgegC62TNmgwp0z6UhLjsaqMMbzN5f25o4x5O5bhwhF
WNBZ2mdcyDn3Gu/NloB2DpOBBAToqs7GzqRIr/j7BIu+4V9I2xqN2KhwMSlGbcsgTlV9EAXgswSW
Bp135pQCrV3jOJSZICowb2RjXWjtHEfh9U5/OsES+BThj8daqOQyb+q/DFuRkbImJADOmKuNg+Xt
ePOZm6NgzBehv21YfzETek0iGIZgxun2OMjeEx8yACfIv/wWLR1jAq1gGwZqROePqLE/NRZjUzOo
ezmE++V7ER8tbv35aFzm0o63+YALGlEorfhS0XZsSVSKysTgmANX6nr92QpbMWch7WHEncFSH8dc
FiS9kPALJemVjIeQ9FL6PzIR8rWch5D0YcJDSPo0E3QQqR6nolreMoz+ACVfiTBvFfnjAAAAAElF
TkSuQmCC
{
const oauth2 = httpClient.createAuthSettingOAuth2(
'OneDrive',
'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize',
'https://login.microsoftonline.com/organizations/oauth2/v2.0/token',
'https://graph.microsoft.com/Files.ReadWrite.All offline_access',
'client_id',
'client_secret',
'access_token'
);
configs.putObject('conf_OAuth2', oauth2);
if (isFixed) {
configs.put('conf_DriveItemUrl', driveItemUrl);
} else {
const driveItemUrlDef = engine.createDataDefinition('ファイル / フォルダ URL', 1, 'q_driveItemUrl', 'STRING_TEXTFIELD');
engine.setData(driveItemUrlDef, driveItemUrl);
configs.putObject('conf_DriveItemUrl', driveItemUrlDef);
}
const sharingLinkIdDef = engine.createDataDefinition('共有リンクの ID', 2, 'q_sharingLinkId', 'STRING_TEXTFIELD');
engine.setData(sharingLinkIdDef, sharingLinkId);
configs.putObject('conf_SharingLinkId', sharingLinkIdDef);
};
/**
* 異常系のテスト
* @param func
* @param errorMsg
*/
const assertError = (func, errorMsg) => {
try {
func();
fail();
} catch (e) {
expect(e.toString()).toEqual(errorMsg);
}
};
/**
* ファイル / フォルダ URL を文字型データ項目で指定し、値が空でエラー
*/
test('File / Folder URL is blank', () => {
prepareConfigs(null, false, '1234567890');
assertError(main, 'File / Folder URL is blank.');
});
/**
* ファイル / フォルダ URL を文字型データ項目で指定し、値が空でエラー
*/
test('Sharing Link ID is blank', () => {
const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt';
prepareConfigs(fileUrl, false, null);
assertError(main, 'Sharing Link ID is blank.');
});
/**
* ドライブアイテム取得の GET リクエストのテスト
* @param {Object} request
* @param request.url
* @param request.method
* @param sharingUrl
*/
const assertGetDriveItemRequest = ({ url, method }, sharingUrl) => {
const encodedUrl = encodeSharingUrl(sharingUrl);
const expectedUrl = `${GRAPH_URI}shares/${encodedUrl}/driveItem`
+ `?select=${encodeURIComponent('id,parentReference')}`
+ `&expand=${encodeURIComponent('permissions(select=id,link)')}`.replace(/\(/g, '%28').replace(/\)/g, '%29');
expect(url).toEqual(expectedUrl);
expect(method).toEqual('GET');
};
/**
* ドライブアイテム取得の GET リクエストでエラー
*/
test('Fail in GET request', () => {
const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt';
prepareConfigs(fileUrl, false, '1234567890');
httpClient.setRequestHandler((request) => {
assertGetDriveItemRequest(request, fileUrl);
return httpClient.createHttpResponse(400, 'application/json', '{}');
});
assertError(main, 'Failed to get drive item. status: 400');
});
/**
* ドライブアイテム取得の GET リクエストのレスポンスを準備
* @param driveId
* @param id
* @param permissions
* @return {Object} responseObj
*/
const prepareDriveItemResponse = (driveId, id, permissions) => {
return JSON.stringify(
{
id,
parentReference: { driveId },
permissions
}
);
};
/**
* 指定したドライブアイテムに指定した共有リンクがない場合のテスト
* 共有設定が 1 つもない場合
*/
test('The specified sharing link not found - No permissions', () => {
const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt';
prepareConfigs(fileUrl, false, '1234567890');
const driveId = 'driveId-1';
const driveItemId = 'fileId-1';
const permissions = [];
httpClient.setRequestHandler((request) => {
assertGetDriveItemRequest(request, fileUrl);
return httpClient
.createHttpResponse(200, 'application/json', prepareDriveItemResponse(driveId, driveItemId, permissions));
});
assertError(main, 'The specified sharing link not found in the file/folder.');
});
/**
* 指定したドライブアイテムに指定した共有リンクがない場合のテスト
* 共有設定はあるが、ID が一致しない場合
*/
test('The specified sharing link not found - Permission ID not found', () => {
const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt';
prepareConfigs(fileUrl, false, '1234567890');
const driveId = 'driveId-1';
const driveItemId = 'fileId-1';
const permissions = [];
const perm1 = {
id: '2345678901',
link: {
type: 'view',
scope: 'anonymous',
webUrl: 'https://test-my.sharepoint.com/:i:/g/personal/aaa/abcdef'
}
};
permissions.push(perm1);
httpClient.setRequestHandler((request) => {
assertGetDriveItemRequest(request, fileUrl);
return httpClient
.createHttpResponse(200, 'application/json', prepareDriveItemResponse(driveId, driveItemId, permissions));
});
assertError(main, 'The specified sharing link not found in the file/folder.');
});
/**
* 指定したドライブアイテムに指定した共有リンクがない場合のテスト
* ID の一致する共有設定はあるが、共有リンクでない場合
*/
test('The specified sharing link not found - Permission is not a sharing link', () => {
const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt';
prepareConfigs(fileUrl, false, '1234567890');
const driveId = 'driveId-1';
const driveItemId = 'fileId-1';
const permissions = [];
const perm1 = {
id: '1234567890'
};
permissions.push(perm1);
httpClient.setRequestHandler((request) => {
assertGetDriveItemRequest(request, fileUrl);
return httpClient
.createHttpResponse(200, 'application/json', prepareDriveItemResponse(driveId, driveItemId, permissions));
});
assertError(main, 'The specified sharing link not found in the file/folder.');
});
/**
* 共有リンク削除の DELETE リクエストのテスト
* @param {Object} request
* @param request.url
* @param request.method
* @param driveId
* @param id
* @param sharingLinkId
*/
const assertDeleteLinkRequest = ({ url, method }, driveId, id, sharingLinkId) => {
expect(url).toEqual(`${GRAPH_URI}drives/${driveId}/items/${id}/permissions/${encodeURIComponent(sharingLinkId)}`);
expect(method).toEqual('DELETE');
};
/**
* 共有リンク削除の DELETE リクエストでエラー
*/
test('Fail in DELETE request', () => {
const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt';
const sharingLinkId = '1234567890';
prepareConfigs(fileUrl, false, sharingLinkId);
let reqCount = 0;
const driveId = 'driveId-1';
const driveItemId = 'fileId-1';
const permissions = [];
const perm1 = {
id: sharingLinkId,
link: {
type: 'view',
scope: 'anonymous',
webUrl: 'https://test-my.sharepoint.com/:i:/g/personal/aaa/abcdef'
}
};
permissions.push(perm1);
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetDriveItemRequest(request, fileUrl);
reqCount++;
return httpClient
.createHttpResponse(200, 'application/json', prepareDriveItemResponse(driveId, driveItemId, permissions));
}
assertDeleteLinkRequest(request, driveId, driveItemId, sharingLinkId);
return httpClient.createHttpResponse(400, 'application/json', '{}');
});
assertError(main, 'Failed to delete sharing link. status: 400');
});
/**
* 成功
* URL は文字型データ項目で指定
*/
test('Succeed - set URL by data item', () => {
const fileUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/test1.txt';
const sharingLinkId = '1234567890';
prepareConfigs(fileUrl, false, sharingLinkId);
let reqCount = 0;
const driveId = 'driveId-1';
const driveItemId = 'fileId-1';
const permissions = [];
const perm1 = {
id: sharingLinkId,
link: {
type: 'view',
scope: 'anonymous',
webUrl: 'https://test-my.sharepoint.com/:i:/g/personal/aaa/abcdef'
}
};
permissions.push(perm1);
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetDriveItemRequest(request, fileUrl);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse(driveId, driveItemId, permissions));
}
assertDeleteLinkRequest(request, driveId, driveItemId, sharingLinkId);
return httpClient.createHttpResponse(204, 'application/json', '{}');
});
expect(main()).toEqual(undefined);
});
/**
* 成功
* URL は固定値で指定
*/
test('Succeed - set URL as fixed value', () => {
const folderUrl = 'https://test-my.sharepoint.com/personal/aaa/Documents/TestFolder';
const sharingLinkId = '2345678901';
prepareConfigs(folderUrl, true, sharingLinkId);
let reqCount = 0;
const driveId = 'driveId-1';
const driveItemId = 'folderId-1';
const permissions = [];
const perm1 = {
id: '1234567890',
link: {
type: 'view',
scope: 'organization',
webUrl: 'https://test-my.sharepoint.com/:i:/g/personal/aaa/abcdef'
}
};
const perm2 = {
id: sharingLinkId,
link: {
type: 'view',
scope: 'anonymous',
webUrl: 'https://test-my.sharepoint.com/:i:/g/personal/aaa/defghi'
}
};
permissions.push(perm1);
permissions.push(perm2);
httpClient.setRequestHandler((request) => {
if (reqCount === 0) {
assertGetDriveItemRequest(request, folderUrl);
reqCount++;
return httpClient.createHttpResponse(200, 'application/json', prepareDriveItemResponse(driveId, driveItemId, permissions));
}
assertDeleteLinkRequest(request, driveId, driveItemId, sharingLinkId);
return httpClient.createHttpResponse(204, 'application/json', '{}');
});
expect(main()).toEqual(undefined);
});
]]>