Browse Source

6.8.0 release

Former-commit-id: b473b4b6e636b44b8bdc5a2ccdaae54c5746ed70
Gaudenz Alder 8 years ago
parent
commit
4b24bc928a

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+14-JUN-2017: 6.8.0
+
+- Adds support for OneDrive for Business
+
 13-JUN-2017: 6.7.11
 
 - Fixes possible NPE in DriveFile

+ 1 - 1
VERSION

@@ -1 +1 @@
-6.7.11
+6.8.0

+ 1 - 1
war/cache.manifest

@@ -1,7 +1,7 @@
 CACHE MANIFEST
 
 # THIS FILE WAS GENERATED. DO NOT MODIFY!
-# 06/13/2017 03:41 PM
+# 06/14/2017 01:41 PM
 
 app.html
 index.html?offline=1

File diff suppressed because it is too large
+ 24 - 24
war/js/app.min.js


File diff suppressed because it is too large
+ 2 - 2
war/js/atlas.min.js


+ 1 - 1
war/js/diagramly/App.js

@@ -169,7 +169,7 @@ App.DROPINS_URL = 'https://www.dropbox.com/static/api/2/dropins.js';
 /**
  * Sets the delay for autosave in milliseconds. Default is 2000.
  */
-App.ONEDRIVE_URL = 'https://js.live.net/v7.0/OneDrive.js';
+App.ONEDRIVE_URL = 'https://js.live.net/v7.2/OneDrive.js';
 
 /**
  * Defines plugin IDs for loading via p URL parameter. Update the table at

+ 57 - 45
war/js/diagramly/OneDriveClient.js

@@ -17,41 +17,45 @@ mxUtils.extend(OneDriveClient, DrawioClient);
  * LATER: If thumbnails are disabled, make sure to replace the
  * existing thumbnail with the placeholder only once.
  */
-OneDriveClient.prototype.clientId = (window.location.hostname == 'test.draw.io') ? '0000000048148130' :
-	((window.location.hostname == 'drive.draw.io') ? '000000004413EC37' : '0000000040145A19');
-
-/**
- * Specifies if thumbnails should be enabled. Default is true.
- * LATER: If thumbnails are disabled, make sure to replace the
- * existing thumbnail with the placeholder only once.
- */
-OneDriveClient.prototype.clientId2 = (window.location.hostname == 'test.draw.io') ?
+OneDriveClient.prototype.clientId = (window.location.hostname == 'test.draw.io') ?
 	'2e598409-107f-4b59-89ca-d7723c8e00a4' : '45c10911-200f-4e27-a666-9e9fca147395';
 
 /**
  * OAuth 2.0 scopes for installing Drive Apps.
  */
-OneDriveClient.prototype.scopes = 'wl.skydrive_update wl.signin';
+OneDriveClient.prototype.scopes = 'user.read';
 
 /**
  * OAuth 2.0 scopes for installing Drive Apps.
  */
-OneDriveClient.prototype.redirectUri = 'https://' + window.location.hostname + '/onedrive.html';
+OneDriveClient.prototype.redirectUri = 'https://' + window.location.hostname + '/onedrive3.html';
 
 /**
- * OAuth 2.0 scopes for installing Drive Apps.
+ * Executes the first step for connecting to Google Drive.
  */
-OneDriveClient.prototype.redirectUri2 = 'https://' + window.location.hostname + '/onedrive2.html';
+OneDriveClient.prototype.extension = '.html';
 
 /**
  * Executes the first step for connecting to Google Drive.
  */
-OneDriveClient.prototype.extension = '.html';
+OneDriveClient.prototype.baseUrl = 'https://graph.microsoft.com/v1.0';
 
 /**
- * Executes the first step for connecting to Google Drive.
+ * Checks if the client is authorized and calls the next step.
  */
-OneDriveClient.prototype.baseUrl = 'https://api.onedrive.com/v1.0';
+OneDriveClient.prototype.get = function(url, onload, onerror)
+{
+	var req = new mxXmlRequest(url, null, 'GET');
+	
+	req.setRequestHeaders = mxUtils.bind(this, function(request, params)
+	{
+		request.setRequestHeader('Authorization', 'Bearer ' + this.token);
+	});
+	
+	req.send(onload, onerror);
+	
+	return req;
+};
 
 /**
  * Checks if the client is authorized and calls the next step.
@@ -66,7 +70,7 @@ OneDriveClient.prototype.updateUser = function(success, error, failOnAuth)
 		error({code: App.ERROR_TIMEOUT});
 	}), this.ui.timeout);
 	
-	mxUtils.get(this.baseUrl + '/drive?access_token=' + this.token, mxUtils.bind(this, function(req)
+	this.get(this.baseUrl + '/me', mxUtils.bind(this, function(req)
 	{
 		window.clearTimeout(timeoutThread);
 		
@@ -91,7 +95,7 @@ OneDriveClient.prototype.updateUser = function(success, error, failOnAuth)
 			else
 			{
 				var data = JSON.parse(req.getText());
-				this.setUser(new DrawioUser(data.owner.user.id, null, data.owner.user.displayName));
+				this.setUser(new DrawioUser(data.id, null, data.displayName));
 				success();
 			}
 		}
@@ -111,10 +115,12 @@ OneDriveClient.prototype.authenticate = function(success, error)
 			
 			this.ui.showAuthDialog(this, true, mxUtils.bind(this, function(remember, authSuccess)
 			{
-				var url = 'https://login.live.com/oauth20_authorize.srf?client_id=' + this.clientId +
-					'&scope=' + encodeURIComponent(this.scopes) + '&response_type=token' +
-					'&redirect_uri=' + encodeURIComponent(this.redirectUri);
-			
+				var url = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize' +
+					'?client_id=' + this.clientId + '&response_type=token' +
+					'&redirect_uri=' + encodeURIComponent(this.redirectUri) +
+					'&scope=' + encodeURIComponent(this.scopes) + 
+					'&response_mode=fragment';
+
 				var width = 525,
 					height = 525,
 					screenX = window.screenX,
@@ -219,7 +225,7 @@ OneDriveClient.prototype.executeRequest = function(url, success, error)
 			error({code: App.ERROR_TIMEOUT, retry: fn});
 		}), this.ui.timeout);
 
-		mxUtils.get(url + '?access_token=' + this.token, mxUtils.bind(this, function(req)
+		this.get(url, mxUtils.bind(this, function(req)
 		{
 			window.clearTimeout(timeoutThread);
 			
@@ -230,7 +236,8 @@ OneDriveClient.prototype.executeRequest = function(url, success, error)
 				{
 					success(req);
 				}
-				else if (req.getStatus() === 401)
+				// 400 is returns if wrong user for this file
+				else if (req.getStatus() === 401 || req.getStatus() === 400)
 				{
 					this.clearPersistentToken();
 					this.setUser(null);
@@ -305,7 +312,7 @@ OneDriveClient.prototype.getFile = function(id, success, error, denyConvert, asL
 {
 	asLibrary = (asLibrary != null) ? asLibrary : false;
 
-	this.executeRequest(this.baseUrl + '/drive/items/' + id, mxUtils.bind(this, function(req)
+	this.executeRequest(this.baseUrl + '/me/drive/items/' + id, mxUtils.bind(this, function(req)
 	{
 		if (req.getStatus() >= 200 && req.getStatus() <= 299)
 		{
@@ -315,7 +322,7 @@ OneDriveClient.prototype.getFile = function(id, success, error, denyConvert, asL
 			if ((/\.vsdx$/i.test(meta.name) || /\.gliffy$/i.test(meta.name) || /\.png$/i.test(meta.name)))
 			{
 				var mimeType = (meta.file != null) ? meta.file.mimeType : null;
-				this.ui.convertFile(meta['@content.downloadUrl'], meta.name, mimeType,
+				this.ui.convertFile(meta['@microsoft.graph.downloadUrl'], meta.name, mimeType,
 					this.extension, success, error);
 			}
 			else
@@ -328,7 +335,7 @@ OneDriveClient.prototype.getFile = function(id, success, error, denyConvert, asL
 					error({code: App.ERROR_TIMEOUT})
 				}), this.ui.timeout);
 				
-				this.ui.loadUrl(meta['@content.downloadUrl'], mxUtils.bind(this, function(data)
+				this.ui.loadUrl(meta['@microsoft.graph.downloadUrl'], mxUtils.bind(this, function(data)
 	    		{
 					window.clearTimeout(timeoutThread);
 		    	
@@ -377,7 +384,7 @@ OneDriveClient.prototype.renameFile = function(file, filename, success, error)
 		{
 			if (checked)
 			{
-				var url = this.baseUrl + '/drive/items/' + file.meta.id;
+				var url = this.baseUrl + '/me/drive/items/' + file.meta.id;
 				this.writeFile(url, JSON.stringify({name: filename}), 'PATCH', 'application/json', success, error);
 			}
 			else
@@ -396,7 +403,7 @@ OneDriveClient.prototype.renameFile = function(file, filename, success, error)
  */
 OneDriveClient.prototype.moveFile = function(id, folderId, success, error)
 {
-	var url = this.baseUrl + '/drive/items/' + id;
+	var url = this.baseUrl + '/me/drive/items/' + id;
 	this.writeFile(url, JSON.stringify({parentReference: {id: folderId}}), 'PATCH', 'application/json', success, error);
 };
 
@@ -425,8 +432,8 @@ OneDriveClient.prototype.insertFile = function(filename, data, success, error, a
 	{
 		if (checked)
 		{
-			var folder = (folderId != null) ? 'items/' + folderId : 'special/documents';
-			var url = this.baseUrl + '/drive/' + folder + '/children/' + filename + '/content';
+			var folder = (folderId != null) ? '/me/drive/items/' + folderId : '/me/drive/root';
+			var url = this.baseUrl + folder + '/children/' + filename + '/content';
 			
 			this.writeFile(url, data, 'PUT', null, mxUtils.bind(this, function(meta)
 			{
@@ -455,9 +462,9 @@ OneDriveClient.prototype.insertFile = function(filename, data, success, error, a
  */
 OneDriveClient.prototype.checkExists = function(parentId, filename, askReplace, fn)
 {
-	var path = (parentId != null) ? 'items/' + parentId : 'special/documents';
+	var folder = (parentId != null) ? '/me/drive/items/' + parentId : '/me/drive/root';
 	
-	this.executeRequest(this.baseUrl + '/drive/' + path + '/children/' + filename, mxUtils.bind(this, function(req)
+	this.executeRequest(this.baseUrl + folder + '/children/' + filename, mxUtils.bind(this, function(req)
 	{
 		if (req.getStatus() == 404)
 		{
@@ -501,7 +508,7 @@ OneDriveClient.prototype.checkExists = function(parentId, filename, askReplace,
  */
 OneDriveClient.prototype.saveFile = function(file, success, error)
 {
-	var url = this.baseUrl + '/drive/items/' + file.meta.id + '/content/';
+	var url = this.baseUrl + '/me/drive/items/' + file.meta.id + '/content/';
 	this.writeFile(url, file.getData(), 'PUT', null, success, error);
 };
 
@@ -525,14 +532,15 @@ OneDriveClient.prototype.writeFile = function(url, data, method, contentType, su
 				error({code: App.ERROR_TIMEOUT, retry: fn});
 			}), this.ui.timeout);
 
-			var req = new mxXmlRequest(url + '?access_token=' + this.token, data, method);
+			var req = new mxXmlRequest(url, data, method);
 	
-			req.setRequestHeaders = function(request, params)
+			req.setRequestHeaders = mxUtils.bind(this, function(request, params)
 			{
 				// Space deletes content type header. Specification says "text/plain"
 				// should work but returns an 415 Unsupported Media Type error
 				request.setRequestHeader('Content-Type', contentType || ' ');
-			};
+				request.setRequestHeader('Authorization', 'Bearer ' + this.token);
+			});
 			
 			req.send(mxUtils.bind(this, function(req)
 			{
@@ -651,17 +659,19 @@ OneDriveClient.prototype.pickFolder = function(fn)
 {
 	OneDrive.save(
 	{
-		clientId: this.clientId2,
+		clientId: this.clientId,
 		action: 'query',
 		openInNewWindow: true,
 		advanced:
 		{
-			'redirectUri': this.redirectUri2
+			'redirectUri': this.redirectUri
 		},
-		success: function(files)
+		success: mxUtils.bind(this, function(files)
 		{
+			// KNOWN: Token should be per I/O operation
+			this.token = files.accessToken;
 			fn(files);
-		},
+		}),
 		cancel: function()
 		{
 			// do nothing
@@ -685,20 +695,22 @@ OneDriveClient.prototype.pickFile = function(fn, returnObject)
 	
 	OneDrive.open(
 	{
-		clientId: this.clientId2,
+		clientId: this.clientId,
 		action: 'query',
 		multiSelect: false,
 		advanced:
 		{
-			'redirectUri': this.redirectUri2
+			'redirectUri': this.redirectUri
 		},
-		success: function(files)
+		success: mxUtils.bind(this, function(files)
 		{
 			if (files != null && files.value != null && files.value.length > 0)
 			{
+				// KNOWN: Token should be per I/O operation
+				this.token = files.accessToken;
 				fn((returnObject) ? files : files.value[0].id);
 			}
-		},
+		}),
 		cancel: function()
 		{
 			// do nothing

File diff suppressed because it is too large
+ 1 - 1
war/js/embed-static.min.js


File diff suppressed because it is too large
+ 1 - 1
war/js/reader.min.js


+ 58 - 0
war/onedrive3.html

@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<title></title>
+		<script type="text/javascript" src="https://js.live.net/v7.2/OneDrive.js"></script>
+		<script>
+			// Extract authentication info from redirect URL in popup window
+			function getAuthInfoFromUrl()
+			{
+				if (window.location.hash != null)
+				{
+					try
+					{
+						var result = new Object();
+						var authResponse = window.location.hash.substring(1);
+						var params = authResponse.split('&');
+						
+						for (var i = 0; i < params.length; i++)
+						{
+							idx = params[i].indexOf('=');
+							
+							if (idx > 0)
+							{
+								result[params[i].substring(0, idx)] = params[i].substring(idx + 1);
+							}
+						}
+						
+						return result;
+					}
+					catch (e)
+					{
+						// ignores parsing errors
+					}
+				}
+
+				return null;
+			};
+
+			// Main
+			if (window.opener != null && window.opener.onOneDriveCallback != null)
+			{
+				try
+				{
+					var authInfo = getAuthInfoFromUrl();
+					var token = authInfo['access_token'];		
+					window.opener.onOneDriveCallback(token, window);
+				}
+				catch (e)
+				{
+					alert('OneDrive: ' + e.toString());
+					window.close();
+				}
+			}
+		</script>
+	</head>
+	<body>
+	</body>
+</html>