Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] fix multi gdrive external storage bug #34987

Merged
merged 1 commit into from
Apr 12, 2019
Merged

Conversation

karakayasemi
Copy link
Contributor

@karakayasemi karakayasemi commented Apr 8, 2019

Description

  • Fixes bug on multiple gdrive account addition
  • As @Lirein explained in Google Drive external js fix #31497 (comment). currently oauth2_step1 and oauth_step2 handlers are always registering for the first container in gdrive.js. I moved them inside of whenSelectBackend event and registered each of them separately.

@op6sie, @Lirein please test if you available.

Related Issue

fixes #31154 , fixes #31497

Motivation and Context

Fixing bugs.

How Has This Been Tested?

Try to add multiple gdrive external storage. It should work.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Open Tasks:

  • Port to files_external_gdrive app

@karakayasemi karakayasemi self-assigned this Apr 8, 2019
@karakayasemi karakayasemi changed the title fix multi gdrive external storage bug [stable10] fix multi gdrive external storage bug Apr 8, 2019
@karakayasemi
Copy link
Contributor Author

something failed in js tests. I will look at it.

@codecov
Copy link

codecov bot commented Apr 9, 2019

Codecov Report

Merging #34987 into stable10 will decrease coverage by 19.32%.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff               @@
##             stable10   #34987       +/-   ##
===============================================
- Coverage       64.29%   44.97%   -19.33%     
===============================================
  Files            1285      116     -1169     
  Lines           76824    11565    -65259     
  Branches         1307     1307               
===============================================
- Hits            49394     5201    -44193     
+ Misses          27049     5983    -21066     
  Partials          381      381
Flag Coverage Δ Complexity Δ
#javascript 53.01% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 30.71% <ø> (-34.79%) 0 <ø> (-20040)
Impacted Files Coverage Δ Complexity Δ
lib/private/Files/Storage/DAV.php 59.45% <0%> (-21.64%) 0% <0%> (ø)
apps/updatenotification/templates/admin.php
lib/private/Encryption/Keys/Storage.php
lib/private/App/CodeChecker/NodeVisitor.php
lib/private/RedisFactory.php
apps/dav/lib/Avatars/AvatarNode.php
...s/dav/appinfo/Migrations/Version20170202213905.php
apps/dav/lib/Upload/ChunkLocationProvider.php
apps/files/lib/AppInfo/Application.php
apps/systemtags/list.php
... and 1161 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 443bf44...3a01edd. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 9, 2019

Codecov Report

Merging #34987 into stable10 will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff               @@
##             stable10   #34987      +/-   ##
==============================================
- Coverage       64.29%   64.29%   -0.01%     
  Complexity      20040    20040              
==============================================
  Files            1285     1285              
  Lines           76824    76824              
  Branches         1307     1307              
==============================================
- Hits            49394    49393       -1     
- Misses          27049    27050       +1     
  Partials          381      381
Flag Coverage Δ Complexity Δ
#javascript 53.01% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 65.49% <ø> (-0.01%) 20040 <ø> (ø)
Impacted Files Coverage Δ Complexity Δ
lib/private/Server.php 86.54% <0%> (-0.12%) 253% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 443bf44...3a01edd. Read the comment docs.

@jvillafanez
Copy link
Member

This requires careful testing and I don't think I have the environment to test this PR.
I'm particularly worried about when the events are triggered and whether the listeners will be ready to run. It might be possible that the events are triggered but the listeners aren't registered yet, and this will cause problems.

I'll skip my worries about optimization since they're probably quite small (we might be assigning different function instances for each storage, increasing memory usage), and I'm not a js expert, so we can ignore those.

The code looks fine, but I don't know if it works in all the possible scenarios.

@karakayasemi
Copy link
Contributor Author

Since I only changed gdrive.js, I do not expect any regression in the other external storage providers.
I tested changes manually with the following scenarios, all of that worked;

  • Add single gdrive account. (no regression, working with current stable10 also)
  • Add multiple gdrive accounts. (Not working with current stable10)
  • Firstly, add an external owncloud storage and secondly add a gdrive account (Not working with current stable10)
  • Firstly, add a gdrive account and secondly add an external owncloud storage. (no regression, working with current stable10 also)

@jvillafanez
Copy link
Member

Any guarantee about the loading order of the gdrive.js and settings.js files? If there is no guarantee that the files will be loaded in a specific order, I'm not sure if there could be problems.

@jvillafanez
Copy link
Member

I'm not sure 100% about this, but I guess the process goes as described below:

  1. setting.js from files_external are always loaded first, then each custom js file added by the backend and then the ones added by the authentication mechanism.
  2. As consequence, I expect the "document ready" function from the settings.js is executed before the ones from the backends (it has been registered first).
  3. This means that the loadStorages function is called before the backends have given a chance to register their callbacks.

The reason this is working is because the "selectBackend" event, which is the one the backend is registering for with the "whenSelectBackend", is triggered in the "newStorage" function which is called as a success callback for an ajax call during the "loadStorage".
I suspect this callback (and probably any other) won't be executed until all the registered "document ready" functions finish, which means that the "whenSelectBackend" callbacks will be registered by that time.

Quite a difficult explanation to answer my question on #34987 (comment)

@jvillafanez
Copy link
Member

@karakayasemi in case of multiple gdrive accounts, could you doble-check that there is only one request being made to the backend for the oauth events?

* abstract away the details of sending the request to backend for getting the AuthURL or
* verifying the code, mounting the storage config etc
*/
$('.configuration').on('oauth_step1', function (event, data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the old code is registering listeners when document.ready() for all .configuration class elements. Whenever oauth_step1 event triggered, all .configuration class elements are receiving this event and the below line (backend_id check) is preventing multiple ouath requests.
The problem here is new elements are not listening oauth_step1 event, because of that grant access button is only working for elements that rendered before document.ready()

* abstract away the details of sending the request to backend for getting the AuthURL or
* verifying the code, mounting the storage config etc
*/
$tr.find('.configuration').on('oauth_step1', function (event, data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR, we are registering oauth_step events for only related<tr> element when user select backend. IMHO, this way is safer than previous.

@karakayasemi
Copy link
Contributor Author

Yes, I tried one more time with adding 5 gdrive accounts, oauth events only triggered for related <tr> element. I added comments on the code to explain details from my perspective.
I have not much experience with jquery also. I may be wrong.

@phil-davis
Copy link
Contributor

I do not see this in 10.2 or 10.2.1. I think it got merged to stable10 just after the release-10.2 branch was created, and so it is not yet in any release. So it will end up in 10.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants