From 7250bd4a65acd4f5d5064c78639c2eec048697db Mon Sep 17 00:00:00 2001 From: Nicholas Valbusa Date: Wed, 4 Sep 2019 19:13:41 +0200 Subject: [PATCH 1/4] interface to upload firebase file --- interface.html | 50 ++++++++++++++++++++++ js/interface.js | 107 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 149 insertions(+), 8 deletions(-) diff --git a/interface.html b/interface.html index 3a79e79..7a2bdf8 100644 --- a/interface.html +++ b/interface.html @@ -740,6 +740,22 @@

App version and bundle ID

+ +

Google Firebase (optional)

+
+
+ +

Register your app on Firebase and download the config file from the Firebase project settings.

+
+
+ +
+ +
+
+
@@ -1439,6 +1455,23 @@

App version and bundle ID

+ +

Google Firebase (optional)

+
+
+ +

Register your app on Firebase and download the config file from the Firebase project settings.

+
+
+ +
+ +
+
+
+ @@ -1554,6 +1587,23 @@

Google Firebase (optional)

+
+
+ +

Register your app on Firebase and download the config file from the Firebase project settings.

+
+
+ +
+ +
+
+
+ diff --git a/js/interface.js b/js/interface.js index 013f97b..bb84d85 100644 --- a/js/interface.js +++ b/js/interface.js @@ -15,6 +15,9 @@ var previousAppStoreSubmission = {}; var previousEnterpriseStoreSubmission = {}; var appStorePreviousCredential = undefined; var appStoreFileField = undefined; +var appStoreFirebaseFileField = undefined; +var enterpriseFirebaseFileField = undefined; +var unsignedFirebaseFileField = undefined; var appStoreTeamId = undefined; var enterprisePreviousCredential = undefined; var enterpriseFileField = undefined; @@ -111,6 +114,34 @@ function createBundleID(orgName, appName) { }); } +function saveFirebaseSettings(origin) { + if (origin === 'appStore' && appStoreFirebaseFileField && appStoreFirebaseFileField.files[0]) { + var formData = new FormData(); + + formData.append('firebase', appStoreFirebaseFileField.files[0]); + + return setFirebaseConfigFile(appStoreSubmission.id, formData); + } + + if (origin === 'enterprise' && enterpriseFirebaseFileField && enterpriseFirebaseFileField.files[0]) { + var formData = new FormData(); + + formData.append('firebase', enterpriseFirebaseFileField.files[0]); + + return setFirebaseConfigFile(enterpriseSubmission.id, formData); + } + + if (origin === 'unsigned' && unsignedFirebaseFileField && unsignedFirebaseFileField.files[0]) { + var formData = new FormData(); + + formData.append('firebase', unsignedFirebaseFileField.files[0]); + + return setFirebaseConfigFile(enterpriseSubmission.id, formData); + } + + return Promise.resolve(); +} + function incrementVersionNumber(versionNumber) { var splitNumber = _.compact(versionNumber.split('.')); var arrLength = splitNumber.length; @@ -249,6 +280,11 @@ function loadAppStoreData() { return; } + // Firebase + if (name === 'fl-store-firebase') { + return; + } + /* Manual release */ if (name === "fl-store-manualRelease") { if (!_.isUndefined(appStoreSubmission.data[name])) { @@ -443,6 +479,11 @@ function loadEnterpriseData() { return; } + // Firebase + if (name === 'fl-ent-firebase') { + return; + } + $('[name="' + name + '"]').val((typeof enterpriseSubmission.data[name] !== "undefined") ? enterpriseSubmission.data[name] : ''); }); @@ -571,6 +612,11 @@ function loadUnsignedData() { return; } + // Firebase + if (name === 'fl-uns-firebase') { + return; + } + $('[name="' + name + '"]').val((typeof unsignedSubmission.data[name] !== "undefined") ? unsignedSubmission.data[name] : ''); }); @@ -612,8 +658,9 @@ function loadPushNotesData() { } function submissionBuild(appSubmission, origin) { - Fliplet.App.Submissions.build(appSubmission.id).then(function (builtSubmission) { - + saveFirebaseSettings(origin).then(function () { + return Fliplet.App.Submissions.build(appSubmission.id); + }).then(function (builtSubmission) { if (origin === "appStore") { appStoreSubmission = builtSubmission.submission; // Auto increments the version number and saves the submission @@ -768,6 +815,7 @@ function requestBuild(origin, submission) { if (submission.data.hasOwnProperty('fl-credentials')) { delete submission.data['fl-credentials']; } + return Fliplet.App.Submissions.create({ platform: 'ios', data: $.extend(true, submission.data, { @@ -800,6 +848,8 @@ function requestBuild(origin, submission) { }); } + // TODO: APPEND FIREBASE FILE? + if (origin === "appStore" && appStoreSubmission.data['fl-store-distribution'] === 'upload-file') { var formData = new FormData(); var fileName = appStoreFileField.value.replace(/\\/g, '/').replace(/.*\//, ''); @@ -871,6 +921,8 @@ function requestBuild(origin, submission) { }); } + // Code for first submission of this type + setCredentials(appStoreSubmission.id, { appPassword: $('#fl-store-appPassword').val().trim() }, false).then(function () { @@ -1216,7 +1268,7 @@ function saveProgressOnClose () { "enterprise-control": saveEnterpriseData, "unsigned-control": saveUnsignedData } - + //Finding out active tab to use correct save method var activeTabId = $(".nav.nav-tabs li.active").prop("id"); @@ -1529,6 +1581,16 @@ function setCertificateP12(id, file) { }); } +function setFirebaseConfigFile(id, file) { + return Fliplet.API.request({ + method: 'PUT', + url: 'v1/organizations/' + organizationID + '/credentials/submission-' + id + '?fileName=firebase', + data: file, + contentType: false, + processData: false + }); +} + function revokeCertificate(id, certId) { return Fliplet.API.request({ method: 'DELETE', @@ -1711,7 +1773,7 @@ function checkSubmissionStatus(origin, iosSubmissions) { // Default copy for testing status for different users if (submission.status === 'ready-for-testing') { - if (userInfo.user && (userInfo.user.isAdmin || userInfo.user.isImpersonating)) { + if (userInfo && userInfo.user && (userInfo.user.isAdmin || userInfo.user.isImpersonating)) { // Fliplet users build.testingStatus = 'Ready for testing'; build.testingMessage = 'App is ready for testing'; @@ -1756,7 +1818,7 @@ function checkSubmissionStatus(origin, iosSubmissions) { build.message = submission.result.message; } - if (userInfo.user && (userInfo.user.isAdmin || userInfo.user.isImpersonating)) { + if (userInfo && userInfo.user && (userInfo.user.isAdmin || userInfo.user.isImpersonating)) { build.debugFileUrl = debugHtmlPage ? debugHtmlPage.url : ''; } @@ -2387,7 +2449,7 @@ $('.redirectToSettings, [data-change-settings]').on('click', function (event) { Fliplet.Studio.emit('close-overlay', { name: 'publish-apple' }); - + Fliplet.Studio.emit('overlay', { name: 'app-settings', options: { @@ -2412,7 +2474,7 @@ $(document).on('click', '[data-change-assets]', function (event) { Fliplet.Studio.emit('close-overlay', { name: 'publish-apple' }); - + Fliplet.Studio.emit('overlay', { name: 'app-settings', options: { @@ -2427,7 +2489,7 @@ $(document).on('click', '[data-change-assets]', function (event) { message: Fliplet.parseError(err) }) }); - + }); $('#appStoreConfiguration, #enterpriseConfiguration, #unsignedConfiguration').on('validated.bs.validator', function () { @@ -2887,6 +2949,35 @@ $('#fl-store-certificate').on('change', function () { } }); +// Firebase + +$('#fl-store-firebase').on('change', function () { + appStoreFirebaseFileField = this; + var fileName = this.value.replace(/\\/g, '/').replace(/.*\//, ''); + + if (this.files && this.files[0]) { + $('#fl-store-firebase-uploaded').html('File uploaded: ' + fileName + '').removeClass('hidden'); + } +}); + +$('#fl-ent-firebase').on('change', function () { + enterpriseFirebaseFileField = this; + var fileName = this.value.replace(/\\/g, '/').replace(/.*\//, ''); + + if (this.files && this.files[0]) { + $('#fl-ent-firebase-uploaded').html('File uploaded: ' + fileName + '').removeClass('hidden'); + } +}); + +$('#fl-uns-firebase').on('change', function () { + unsignedFirebaseFileField = this; + var fileName = this.value.replace(/\\/g, '/').replace(/.*\//, ''); + + if (this.files && this.files[0]) { + $('#fl-uns-firebase-uploaded').html('File uploaded: ' + fileName + '').removeClass('hidden'); + } +}); + $('.appStore-replace-cert').on('click', function () { var $this = $(this); $(this).html('Replacing ' + spinner); From 9b57831eede33de2c752e7b51f463e98ddd8d5ca Mon Sep 17 00:00:00 2001 From: Nicholas Valbusa Date: Wed, 4 Sep 2019 19:16:39 +0200 Subject: [PATCH 2/4] tweaks --- js/interface.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/js/interface.js b/js/interface.js index bb84d85..bf8dcff 100644 --- a/js/interface.js +++ b/js/interface.js @@ -1027,8 +1027,8 @@ function saveAppStoreData(request) { value = value.trim(); } - if (name === 'fl-store-appPassword') { - // Skip saving app-specific password + if (name === 'fl-store-appPassword' || name === 'fl-store-firebase') { + // Skip saving app-specific password and Firebase config file // This will be saved in credentials return; } @@ -1112,6 +1112,10 @@ function saveEnterpriseData(request) { return; } + if (name === 'fl-ent-firebase') { + return; // saved in credentials + } + if (name === 'fl-ent-teamId') { if (enterpriseManual) { data[name] = value; @@ -1196,6 +1200,11 @@ function saveUnsignedData(request) { $('#unsignedConfiguration [name]').each(function (i, el) { var name = $(el).attr("name"); + + if (name === 'fl-uns-firebase') { + return; // saved in credentials + } + var value = $(el).val(); if (typeof value === 'string') { From 58b4df26761cb45a42a32364fd98eaf47033e0b0 Mon Sep 17 00:00:00 2001 From: Nicholas Valbusa Date: Wed, 4 Sep 2019 19:19:53 +0200 Subject: [PATCH 3/4] typo --- js/interface.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/interface.js b/js/interface.js index bf8dcff..52c0665 100644 --- a/js/interface.js +++ b/js/interface.js @@ -136,7 +136,7 @@ function saveFirebaseSettings(origin) { formData.append('firebase', unsignedFirebaseFileField.files[0]); - return setFirebaseConfigFile(enterpriseSubmission.id, formData); + return setFirebaseConfigFile(unsignedSubmission.id, formData); } return Promise.resolve(); From 1968c7e4989448f9f8a8e5d0f4e3711a31c9007e Mon Sep 17 00:00:00 2001 From: Nicholas Valbusa Date: Wed, 4 Sep 2019 19:25:48 +0200 Subject: [PATCH 4/4] save unsigned credentials --- js/interface.js | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/js/interface.js b/js/interface.js index 52c0665..46f991b 100644 --- a/js/interface.js +++ b/js/interface.js @@ -741,19 +741,19 @@ function save(origin, submission) { .then(function (newSubmission) { var cloneCredentialsPromise = Promise.resolve(); + newSubmission.data['fl-credentials'] = 'submission-' + newSubmission.id; + if (origin === "appStore") { - newSubmission.data['fl-credentials'] = 'submission-' + newSubmission.id; appStoreSubmission = newSubmission; cloneCredentialsPromise = cloneCredentials(previousCredentials, appStoreSubmission); - } - if (origin === "enterprise") { - newSubmission.data['fl-credentials'] = 'submission-' + newSubmission.id; + } else if (origin === "enterprise") { enterpriseSubmission = newSubmission; cloneCredentialsPromise = cloneCredentials(previousCredentials, enterpriseSubmission); - } - if (origin === "unsigned") { + } else if (origin === "unsigned") { unsignedSubmission = newSubmission; + cloneCredentialsPromise = cloneCredentials(previousCredentials, unsignedSubmission); } + return cloneCredentialsPromise.then(function () { return Fliplet.App.Submissions.update(newSubmission.id, newSubmission.data); }).then(function () { @@ -1214,6 +1214,8 @@ function saveUnsignedData(request) { data[name] = value; }); + data['fl-credentials'] = 'submission-' + unsignedSubmission.id; + unsignedSubmission.data = data; if (request) { @@ -1930,6 +1932,24 @@ function submissionChecker(submissions) { } } + var cloneUnsignedCredentialsPromise = Promise.resolve(); + if (unsignedSubmission.data && !unsignedSubmission.data['fl-credentials']) { + + var prevSubCred = _.filter(esub, function (submission) { + return submission.data && submission.data['fl-credentials']; + }); + + var previousSubWithCredentials = _.maxBy(prevSubCred, function (el) { + return new Date(el.createdAt).getTime(); + }); + + unsignedSubmission.data['fl-credentials'] = 'submission-' + unsignedSubmission.id; + + if (previousSubWithCredentials) { + cloneUnsignedCredentialsPromise = cloneCredentials(previousSubWithCredentials.data['fl-credentials'], unsignedSubmission, true); + } + } + var usub = _.filter(submissions, function (submission) { return submission.data.submissionType === "unsigned" && submission.platform === "ios"; }); @@ -1946,6 +1966,8 @@ function submissionChecker(submissions) { return cloneAppStoreCredentialsPromise.then(function () { return cloneEnterpriseCredentialsPromise; + }).then(function () { + return cloneUnsignedCredentialsPromise; }).then(function () { if (_.isEmpty(appStoreSubmission)) { return Fliplet.App.Submissions.create({