2022-04-18 (C) Questetra, Inc. (MIT License) 2 Create a shared link for the specified file or folder on Google Drive. An error occurs when the file/folder is already shared with anyone or within the domain. Google ドライブ の指定ファイルやフォルダの共有リンクを作成します。すでにリンクを知っている全員、もしくはドメインで共有されているファイル/フォルダを指定した場合はエラーになります。 https://support.questetra.com/bpmn-icons/googledrive-permissioncreate/ https://support.questetra.com/ja/bpmn-icons/googledrive-permissioncreate/ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADLUlEQVRYR2NkYGBgZBhAALJ81AFE hUBmYabNj19/dglzM7ERirGerpkshNTA5ImOgvTClGu/fjEq5AfeYdeX+YrT0cv2S3y69kjgVGv7 IjdiHEGUAzKK0nKf8X9peyz5ntv5jty/7qTzTPgML51n+O/rbyaH6f3TjxByBFEOSMxO/XZB/wnH d6k/DGpnRb82WT/nwhcKF59w/5++VfnmzP45WhQ7IL0wdfZzga8Rt4xfc4MM43zGwkBMKICi4vBt idoZfbMm43ME3hAAJbx/DL9nHXR+qAEzBOQA2eeCBEMBpD5psv6P+VNnc5HtgOrKuF2XOf5YwnyP 7oiN4XfAoYILEJMgcYYAyPdPBT5uR7ccFg2gUAgX+/I3yvEFHyUJEqcDQNnulOZTDVDCQwegaAAB g4syPwhlS1CCXL1Xdi+ubInVAbBsh833yNEAcgAb2/8HM9IvwdMIttDAlyAxHIAt4WEzFJQdJT9w rwDJ2am9DMUXFfiyJYYD0LMdNstBUQDyPSyFg8qJebkXOQglyEO3xFfP7J+diqwOxQGk+F7qI08V LI+DosxW9UUzoQQJypYcbCxuyCUkigPwJTzkuDe7Ln0DvZQD6c30vqtOqIRET5BwBxCT8ECOsN8r f4OJgTUNvZyHhR6pCRLuAOTyHldcwhIeejzC1IPSDyhBBuvu42MXwV4NoGdLsAOISXj4fA9zACwU JgavwJktQQ4DZUtYgoQ6AHehAzMc5HvhV9zM/xkl/uFL7SA5xv8vmAg1XD7//nsLlI7ADiAm/i23 K/y48ywQnNXY9S0ZePlx1zGfP37D60aZN33fONheVoJyETwN4MsBIN+/vxADrngIWU4odDjeH/vP 93kpvK0AdwCszXfc8wFKgQKyXOi1MuPdp5ZclFoOchz/3ZZvnKxvPGC5CK0cwGx8gEo8UNBTw3KI 75fNQ85FGEUxLDvCajtqWQ5KF8ofSzEKMAwHwBIkyAGgoH8iUsSFL8ERinOYPCjoYQkPZ12AKFBS rj0X+Cb77f9UbmpYjp7wCDoAlCC//xbZQazviFGHnPAIOoAYA6mlhqh+AbUsw2bOgDsAAHEO2FDM 6/Q2AAAAAElFTkSuQmCC { const quser = engine.createQuser(3, 'サウスポール', 'SouthPole@questetra.com'); configs.putObject('conf_UserID', quser); // 共有するファイル/フォルダの ID を保存する文字型データ項目(単一行)を準備 const fileIdDef = engine.createDataDefinition('共有するファイル/フォルダの ID', 1, 'q_fileId', 'STRING_TEXTFIELD'); engine.setData(fileIdDef, fileId); configs.putObject('conf_FileIdsItem', fileIdDef); configs.put('conf_SharedRange', sharedRange); configs.put('conf_Role', role); configs.put('conf_Domain', domain); configs.putObject('conf_AllowFileDiscovery', allowFileDiscovery); // 共有したファイル/フォルダの表示 URL を保存する文字型データ項目(単一行)を準備 const sharedUrlItemDef = engine.createDataDefinition('共有したファイル/フォルダの表示 URL', 2, 'q_fileUrl', 'STRING_TEXTFIELD'); engine.setData(sharedUrlItemDef, '事前文字列'); configs.putObject('conf_SharedUrlItem', sharedUrlItemDef); return sharedUrlItemDef; }; /** * UserID に対応する QuserView がない場合 */ test('User not found', () => { prepareConfigs('abc123', ANYONE, VIEWER, '', false); configs.put('conf_UserID', ''); expect(execute).toThrow('User not found'); }); /** * 共有範囲がドメインなのにドメインが空でエラーになる場合 */ test('domain is blank', () => { prepareConfigs('abc456', DOMAIN, VIEWER, '', false); expect(execute).toThrow("Domain to share isn't set."); }); /** * 共有するファイル/フォルダの ID が空でエラーになる場合 */ test('File / Folder ID is blank', () => { prepareConfigs(null, ANYONE, VIEWER, '', true); expect(execute).toThrow("File / Folder ID isn't set."); }); /** * 1つ目の API リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param fileId */ const assert1stRequest = ({url, method}, fileId) => { const fields = encodeURIComponent('permissions/type'); expect(url).toEqual(`https://www.googleapis.com/drive/v3/files/${fileId}/permissions?fields=${fields}&supportsAllDrives=true`); expect(method).toEqual('GET'); }; /** * 1つ目の API リクエストでエラー */ test('1st API Request Failed', () => { prepareConfigs('def789', ANYONE, VIEWER, '', false); httpClient.setRequestHandler((request) => { assert1stRequest(request, 'def789'); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); expect(execute).toThrow('Failed to get permission list. File:def789, Status:400'); }); /** * すでにドメイン内で共有されていてエラー */ test('The file is already shared - domain', () => { prepareConfigs('def789', ANYONE, VIEWER, '', false); const res = { permissions: [ { "type": "user" }, { "type": "domain" } ] }; httpClient.setRequestHandler((request) => { assert1stRequest(request, 'def789'); return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(res)); }); expect(execute).toThrow('The item (ID: def789) is already shared.'); }); /** * すでにリンクを知っている全員に共有されていてエラー */ test('The file is already shared - anyone', () => { prepareConfigs('def789', ANYONE, VIEWER, '', false); const res = { permissions: [ { "type": "anyone" }, { "type": "group" } ] }; httpClient.setRequestHandler((request) => { assert1stRequest(request, 'def789'); return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(res)); }); expect(execute).toThrow('The item (ID: def789) is already shared.'); }); /** * 2つ目の API リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param request.contentType * @param request.body * @param fileId * @param type * @param role * @param domain * @param allowFileDiscovery */ const assert2ndRequest = ({url, method, contentType, body}, fileId, type, role, domain, allowFileDiscovery) => { expect(url).toEqual(`https://www.googleapis.com/drive/v3/files/${fileId}/permissions?supportsAllDrives=true`); expect(method).toEqual('POST'); expect(contentType).toEqual('application/json; charset=UTF-8'); const bodyObj = JSON.parse(body); expect(bodyObj.type).toEqual(type); expect(bodyObj.role).toEqual(role); if (type === "domain"){ expect(bodyObj.domain).toEqual(domain); expect(bodyObj.allowFileDiscovery).toEqual(allowFileDiscovery); } else { expect(bodyObj.domain).toEqual(undefined); expect(bodyObj.allowFileDiscovery).toEqual(undefined); } }; const SAMPLE_PERMISSION_LIST = { permissions: [ { "type": "user" }, { "type": "group" } ] }; /** * 2つ目の API リクエストでエラー */ test('2nd API Request Failed', () => { prepareConfigs('abc789', DOMAIN, EDITOR, 'test1.example.com', true); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assert1stRequest(request, 'abc789'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_PERMISSION_LIST)); } assert2ndRequest(request, 'abc789', DOMAIN, EDITOR, 'test1.example.com', true); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); expect(execute).toThrow('Failed to create permission. File:abc789, Status:400'); }); /** * 3つ目の API リクエストのテスト * @param {Object} request * @param request.url * @param request.method * @param fileId */ const assert3rdRequest = ({url, method}, fileId) => { expect(url).toEqual(`https://www.googleapis.com/drive/v3/files/${fileId}?fields=webViewLink&supportsAllDrives=true`); expect(method).toEqual('GET'); }; /** * 3つ目の API リクエストでエラー */ test('3rd API Request Failed', () => { prepareConfigs('abc789', ANYONE, VIEWER, '', false); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assert1stRequest(request, 'abc789'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_PERMISSION_LIST)); } if (reqCount === 1) { assert2ndRequest(request, 'abc789', ANYONE, VIEWER, '', false); reqCount++; return httpClient.createHttpResponse(200, 'application/json', '{}'); } assert3rdRequest(request, 'abc789'); return httpClient.createHttpResponse(400, 'application/json', '{}'); }); expect(execute).toThrow('Failed to get item info. File:abc789, Status:400'); }); const SAMPLE_FILE_1 = { "webViewLink": "https://docs.google.com/spreadsheets/d/def123/edit?usp=drivesdk" }; const SAMPLE_FILE_2 = { "webViewLink": "https://docs.google.com/spreadsheets/d/abc789/edit?usp=drivesdk" }; /** * 共有成功 - ドメイン */ test('Succeed - domain', () => { const sharedUrlItemDef = prepareConfigs('def123', DOMAIN, VIEWER, 'test1.example.com', true); let reqCount = 0; httpClient.setRequestHandler((request) => { if (reqCount === 0) { assert1stRequest(request, 'def123'); reqCount++; return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_PERMISSION_LIST)); } if (reqCount === 1) { assert2ndRequest(request, 'def123', DOMAIN, VIEWER, 'test1.example.com', true); reqCount++; return httpClient.createHttpResponse(200, 'application/json', '{}'); } assert3rdRequest(request, 'def123'); return httpClient.createHttpResponse(200, 'application/json', JSON.stringify(SAMPLE_FILE_1)); }); //