Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Add output to Google Drive option #67

Merged
merged 65 commits into from
Aug 8, 2020
Merged

Add output to Google Drive option #67

merged 65 commits into from
Aug 8, 2020

Conversation

aguilerapy
Copy link
Contributor

In #42 we consider adding two input/output options, in this pull request we have the output to google drive option, I will create a different one for the URL input option.

For this to work it's necessary to create credentials for the Google Drive API with an OCP account. Here we have a guide.

Then just configure the environment variable: OCDS_TOUCAN_CREDENTIALS_DRIVE in settings.py to point to a JSON file that contains the credentials.

We can get this JSON file from here:
Screenshot_Google Cloud Platform

@aguilerapy aguilerapy self-assigned this Jan 10, 2020
@aguilerapy aguilerapy changed the title 42 in out options Add output to Google Drive option Jan 10, 2020
@jpmckinney
Copy link
Member

What's the Google integration look like? I figured Toucan would use OAuth to be able to create a spreadsheet in the user's Google account.

@aguilerapy
Copy link
Contributor Author

aguilerapy commented Jan 24, 2020

Yes, Toucan needs OAuth and some other libraries. I add those libraries in requirements.in and I still have the same problem, what can I do? @jpmckinney

@jpmckinney
Copy link
Member

@aguilerapy You need to run:

pip-compile
pip-compile requirements_dev.in

To update the requirements*.txt files.

https://ocds-standard-development-handbook.readthedocs.io/en/latest/coding/index.html#id1

Copy link
Contributor

@romifz romifz left a comment

Choose a reason for hiding this comment

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

There are a few things to improve, but in general looks good!

default/templates/default/base-uploader.html Outdated Show resolved Hide resolved
default/templates/default/base-uploader.html Outdated Show resolved Hide resolved
default/drive_options.py Outdated Show resolved Hide resolved
default/drive_options.py Outdated Show resolved Hide resolved
default/drive_options.py Outdated Show resolved Hide resolved
default/drive_options.py Outdated Show resolved Hide resolved
default/urls.py Outdated Show resolved Hide resolved
@aguilerapy aguilerapy requested review from romifz and removed request for romifz February 28, 2020 17:11
@aguilerapy aguilerapy mentioned this pull request Jun 18, 2020
3 tasks
@romifz
Copy link
Contributor

romifz commented Jul 9, 2020

Regarding credentials, I've created an OAuth2 Client ID selecting the "Web application" type. I'm including here a screenshot for the configuration I used:

screenshot-console developers google com-2020 07 08-22_15_08

The redirect URI must work over https.

Once the user has identified themselves, the credentials are saved for the session.

@romifz romifz dismissed stale reviews from jpmckinney and themself July 9, 2020 02:27

the code needs to be reviewed again

@romifz
Copy link
Contributor

romifz commented Jul 9, 2020

@aguilerapy can you please have a look at the code, and test it locally? I'll send you the test credentials

def upload_to_drive(request):

datafile = DataFile(**request.session['google_drive_file'])
credentials = get_credentials_from_session(request)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once a credential is entered into toucan, it cannot be changed, we could create an issue to add an option in which the user can change accounts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we can leave that for another issue.


try:
if credentials:
if credentials.expired:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the credentials expire, it automatically restarts, then the user never enters the credentials again, it's okay?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the credentials are refreshed. The user does not need to give explicit approval again (as long as their credentials are stored in the session).

})

except Exception as e:
print(e)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This print is correct here?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, this should return some kind of error message, I'll fix it.

.content-wrap.ocp-content {
padding-bottom: 2.5rem;
}
.link-disabled {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this class is no longer used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok! I'll remove it.

<ul class="list-unstyled">
<li>
<strong>{% trans "Upload a file:" %}</strong>
{% trans "Upload no more than one file by dragging and dropping in the box below or using the <strong>Add a file</strong> link." %}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This message is shown in all tools, in some functions we can upload more than one file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll check.

</li>
<li>
<strong>{% trans "Provide a URL:" %}</strong>
{% trans "Provide a single URL to a file." %}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here, in some functions we can provide more than one URL.

prefix = 'flatten-csv'
ext = '.zip'
filename = 'result-csv.zip'
filename = 'result.csv.zip'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We must update the file name 'result-csv.zip' in the message box.

image

"There was an authorization issue when saving the file to Google Drive, "
"please try again."
msgstr "Se encontró un problema de autorización al guardar el archivo en Google Drive, "
"favor intente de nuevo más tarde"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Debemos sacar "mas tarde" o agregar "later" en la traducción?

Copy link
Contributor

Choose a reason for hiding this comment

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

Creo que hay que decir "please try again later"

#: default/templates/default/mapping_sheet.html:53
#: default/templates/default/to-spreadsheet.html:25
#: default/templates/default/to-spreadsheet.html:38
msgid "File saved on Google Drive"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's better to say "in"?

Copy link
Contributor

Choose a reason for hiding this comment

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

La verdad no estaba segura, así que le pregunté a Teté y me dijo que es "on".

@aguilerapy
Copy link
Contributor Author

I reviewed the code and tried the new features and I have no further comments.

Do you want to look at it? @jpmckinney

It's convenient to install the sslserver package.

@jpmckinney
Copy link
Member

I'm happy to trust that it works, given the attention paid to this feature!

For deployment, please provide specific, step-by-step instructions for anything needed from Google.

@romifz
Copy link
Contributor

romifz commented Jul 27, 2020

Hi @jpmckinney, I've followed the instructions here to create the credentials ("Enable APIs for your project" and "Create authorization credentials" sections).

After downloading the client_secret.json file, save it in the root directory for the project with the name "googleapi_credentials.json", or set the OCDS_TOUCAN_GOOGLE_API_CREDENTIALS_FILE envvar with the path to the file.

Let me know if you need anything else.

I think we want to follow the verification process since unverified apps have a limit of 100 new users. The only scope we use is https://www.googleapis.com/auth/drive.file.

@jpmckinney jpmckinney merged commit dba699e into master Aug 8, 2020
CDS 2020-05/2021-02 automation moved this from In progress [6 max] to Done Aug 8, 2020
@jpmckinney jpmckinney deleted the 42-in_out_options branch August 8, 2020 01:57
@jpmckinney
Copy link
Member

It works! 🎉 🎊

@jpmckinney
Copy link
Member

I think we want to follow the verification process since unverified apps have a limit of 100 new users. The only scope we use is https://www.googleapis.com/auth/drive.file.

I was able to use the same OAuth secret I had created earlier around May 20, for which I had requested verification. On https://console.cloud.google.com/apis/credentials/consent?project=toucan-277800 it says:

Verification Status: Being verified
The Trust and Safety team has received your form. They will reach out to you via your contact email if needed. The review process can take up to 4-6 weeks. Your last approved consent screen is still in use.

@jpmckinney jpmckinney removed this from Done in CDS 2020-05/2021-02 Dec 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants