Login with option to agree to terms of service and human friendly errors #866

Merged
merged 16 commits into from Nov 14, 2016

Conversation

Projects
None yet
4 participants
Contributor

psivaa commented Oct 13, 2016

Storeside changes to introduce graceful failure messages and an option to sign developer agreement via snapcraft CLI. Also includes some refactoring in the surrounding area to move messages/errors/warnings into 'storeapi/constants.py'

LP: #1619193

psivaa added some commits Oct 12, 2016

Contributor

psivaa commented Oct 14, 2016

The static checks and the tests have passed now. The relevant change needed in the server side has also landed. So if the review is OK, this can land.

Hi, thanks for the PR, looks generally good. I did a first pass of this already and have some changes requested

+ return None
+
+
+def _check_dev_agreement_and_namespace_statuses(store):
@sergiusens

sergiusens Oct 25, 2016

Collaborator

Can we just raise exceptions if the conditions are not met. The exception would carry a friendly error message we would raise to the user just like we do for all others

@psivaa

psivaa Nov 1, 2016

Contributor

This has been taken on board. Added an exception type for this, with a human friendly error message.

snapcraft/_store.py
+ storeapi.constants.NAMESPACE_ERROR.format(url))
+ else:
+ raise
+ return True
@sergiusens

sergiusens Oct 25, 2016

Collaborator

let's use exeptions instead

@psivaa

psivaa Nov 1, 2016

Contributor

Agreed and only use exception here.

snapcraft/_store.py
+ raise
+ return True
+
+
def _login(store, acls=None, save=True):
@sergiusens

sergiusens Oct 25, 2016

Collaborator

I don't mind if this just raises an exception that is friendly enough and this return _login(store) is refactored a bit.

This may not be a task for you and you may not want to do it, but we have a lot of double logic with exceptions and if True/False around.

@psivaa

psivaa Nov 1, 2016

Contributor

I personally don't mind doing this. But moving the exception handling to login() for refactoring return _login(store) will imho shift the complexity to login. So i don't feel there is much gain here. But if you still insist on it, i can happily do that :)

snapcraft/_store.py
- return False
+
+ # Continue if agreement and namespace conditions are met.
+ if not _check_dev_agreement_and_namespace_statuses(store):
@sergiusens

sergiusens Oct 25, 2016

Collaborator

just deal with the exception in the exception catching logic a couple lines below

snapcraft/storeapi/__init__.py
+
+ if not response.ok:
+ raise errors.DeveloperAgreementSignError(
+ 'Failed to sign developer ToS.')
@sergiusens

sergiusens Oct 25, 2016

Collaborator

Hmm, response.ok not being ok may not be an indication of failing to sign the developer agreement and a 503 instead

@psivaa

psivaa Nov 1, 2016

Contributor

Right. The error message was just an indicator. Now use an exception to use the response itself.

snapcraft/storeapi/errors.py
@@ -87,20 +87,32 @@ class StoreMacaroonNeedsRefreshError(StoreError):
fmt = 'Authentication macaroon needs to be refreshed.'
+class DeveloperAgreementSignError(StoreError):
+
+ fmt = 'Developer agreement sign error: {message}'
@sergiusens

sergiusens Oct 25, 2016

Collaborator

This sentence needs to be more human friendly

@psivaa

psivaa Nov 1, 2016

Contributor

Fixed

snapcraft/tests/fake_servers.py
+ int(self.headers['Content-Length'])).decode('utf8')
+ data = json.loads(string_data)
+ if data['latest_tos_accepted'] is not True:
+ self.send_response(400)
@sergiusens

sergiusens Oct 25, 2016

Collaborator

Can we add a 500 case?

@psivaa

psivaa Nov 1, 2016

Contributor

done.

Member

kyrofa commented Oct 25, 2016

Would you mind please updating the PR title to be more descriptive? The bug reference should be in the PR description and the commit, not the title.

@psivaa psivaa changed the title from Bug/1619193 to login_with_transparent_terms_signing_errors Nov 1, 2016

@psivaa psivaa changed the title from login_with_transparent_terms_signing_errors to Login with option to agree to terms of service and human friendly errors Nov 1, 2016

Contributor

psivaa commented Nov 1, 2016

Thanks for the reviews. I've addressed them and replied inline. Would appreciate a re-review please.
Thanks

A few minor things. Otherwise looks good.

+ except storeapi.errors.StoreAccountInformationError:
+ return _fail_login(storeapi.constants.ACCOUNT_INFORMATION_ERROR)
+ except storeapi.errors.NeedTermsSignedError as e:
+ return _fail_login(e.message)
@josepht

josepht Nov 3, 2016

Contributor

Any reason to not include this in storeapi.constants as well?

@psivaa

psivaa Nov 3, 2016

Contributor

The NeedTermsSignedError will contain different messages based on the error in _check_dev_agreement_and_namespace_statuses.

+ 'alongside the other details for your snap. Please visit {} and login '
+ 'again.')
+AGREEMENT_INPUT_MSG = (
+ 'Do you agree to the developer terms and conditions. ({})? [y/N]')
@josepht

josepht Nov 3, 2016

Contributor

I'm not a fan of mixing formatting in the constants. It's not a blocker for me just an opinion.

@psivaa

psivaa Nov 3, 2016

Contributor

Yea, I agree that its not perfect. But I think keeping them here will make the actual logic more readable.

snapcraft/storeapi/errors.py
+class DeveloperAgreementSignError(StoreError):
+
+ fmt = (
+ 'There was an error whilst signing developer agreement.\n'
@josepht

josepht Nov 3, 2016

Contributor

s/whilst/while/

@psivaa

psivaa Nov 3, 2016

Contributor

Fixed. Thanks

psivaa and others added some commits Nov 3, 2016

Looks good in general, thanks!

snapcraft/storeapi/__init__.py
@@ -286,6 +286,9 @@ def push_validation(self, snap_id, assertion):
def get_validations(self, snap_id):
return self.sca.get_validations(snap_id)
+ def sign_developer_agreement(self, latest_tos_accepted=True):
@sergiusens

sergiusens Nov 14, 2016

Collaborator

shouldn't latest_tos_accepted be False by default?

@psivaa

psivaa Nov 14, 2016

Contributor

Yes, fair point. Thanks. Changed.

snapcraft/storeapi/__init__.py
@@ -618,6 +621,19 @@ def close_channels(self, snap_id, channel_names):
response.content))
raise errors.StoreChannelClosingError(response)
+ def sign_developer_agreement(self, latest_tos_accepted=True):
@sergiusens

sergiusens Nov 14, 2016

Collaborator

ditto on latest_tos_accepted

@psivaa

psivaa Nov 14, 2016

Contributor

Changed. Thanks

psivaa added some commits Nov 14, 2016

Contributor

psivaa commented Nov 14, 2016

Thanks for the comments. Pushed the fix for them.

+1 from me.

@sergiusens sergiusens merged commit 36d7765 into snapcore:master Nov 14, 2016

3 of 5 checks passed

xenial-amd64 autopkgtest finished (failure)
Details
zesty-amd64 autopkgtest finished (failure)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.03%) to 98.244%
Details
yakkety-amd64 autopkgtest finished (success)
Details

@psivaa psivaa deleted the psivaa:bug/1619193 branch Nov 15, 2016

@psivaa psivaa restored the psivaa:bug/1619193 branch Nov 15, 2016

@psivaa psivaa deleted the psivaa:bug/1619193 branch Nov 15, 2016

kalikiana pushed a commit to kalikiana/snapcraft that referenced this pull request Apr 6, 2017

store: login with option to agree to terms of service and human frien…
…dly errors (#866)

Storeside changes to introduce graceful failure messages and an option to sign developer agreement via snapcraft CLI. Also includes some refactoring in the surrounding area to move messages/errors/warnings into `storeapi/constants.py`

LP: #1619193
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment