Wed, 07 Jul 2010

Improving the usability of launchpadlib-using code

Normally when you write some code using launchpadlib you end up with Launchpad showing your users something like this:

/images/lplib-before.png

This isn't great, how is the user supposed to know which option to click? What do you do if they don't choose the option you want?

Instead it's possible to limit the choices that the user has to make to only those that your application can use, plus the option to deny all access, by changing the way you create your Launchpad object.

from launchpadlib.launchpad import Launchpad

lp = Launchpad.get_token_and_login("testing", allow_access_levels=["WRITE_PUBLIC"])

This will present your users with something like this:

/images/lplib-after.png

which is easier to understand. There could be further improvements, but they would happen on the Launchpad side.

This approach works for both Launchpad.get_token_and_login and Launchpad.login_with.

The values that you can pass here aren't documented, and should probably be constants in launchpadlib, rather than hardcoded in every application, but for now you can use:

Posted at: 21:17 | category: /tech | Comments (8)


Is there a bug report for this opened so that I can complain in a moderately "helpful" forum? :) At this point I've simply rage quit the app that wanted help with their testing.

Posted by emmajane at Wed Jul 7 21:04:47 2010

There's no one bug report, as this in an app-specific problem.

For individual apps where this is a problem, I would encourage you to file bugs and feel free to point to this as explanation.

For the particular app in question, I've just reported the bug at https://bugs.launchpad.net/lp-bug-form/+bug/602882

Posted by James Westby at Wed Jul 7 21:28:00 2010

Was this prompted by the just-announced http://fonttest.design.canonical.com/?

Posted by Marius Gedminas at Thu Jul 8 00:48:31 2010

Marius, indeed it was, but it was the straw that broke the camel's back. This topic has come up several times over the last few weeks, and so I wanted to research the exact way to do this.

I'm also fed up of apps not telling me what access they need and so having to guess.

Posted by James Westby at Thu Jul 8 00:59:38 2010

It's possible one of the reasons why apps don't do this is because the get_token_and_login() routine is not documented in the API reference docs.  Indeed, none of the login routines are specified there.

As a result of this, I suspect a lot of people cargo-cult the launchpad login using code snipped from tutorials, examples, or other people's code.

Like you, I finally got fed up, and have mocked up apidocs with documentation for these functions added:

  http://people.canonical.com/~bryce/apidoc/devel.html

I'm handwaving the fact that these docs mostly are already available in the launchpadlib pydocs.  There doesn't seem to be an online version of them (at least, not that's locatable from the launchpad api docs).  Plus, I'm pretty strongly opinionated that the docs for these routines should be included in the API docs since that's where people are apt to be looking.

Posted by Bryce Harrington at Fri Jul 9 21:07:46 2010

Hi Bryce,

Nice work on the docs.

I think it would be great if your version became docs of the Python interface, rather than the HTTP interface.

What I mean is that the default docs are for the more general interface, not what you can get through launchpadlib. For instance, in the HTTP docs is says that a "bug", has "attachments_collection_link", but if you are using the Python interface you have the much more useful attribute "attachments". This trips up a lot of people first time.

It should be possible with some XSL or similar to produce the python docs from the HTTP ones, making  the few tweaks that are needed.

Posted by James Westby at Fri Jul 9 22:11:34 2010

Hi James,

I am the author of lp-bug-form / fonttest.design.canonical.com

Thanks for bringing this issue to my attention. Sorry for the delay in looking in this problem.

I've written this in Rails so I am not using launchpadlib.
Is there anyway I can do this via the https://edge.launchpad.net/+request-token post method?

Richard

Posted by Richard H Lee at Mon Sep 20 14:52:13 2010

Hi Richard,

You can encode it in the URL with

  allow_permission=<permission>

where the permissions are the constants
noted at the bottom of the post.

You do this to the URL that you direct the
user to to grant access, i.e. +authorize-token.

Thanks,

James

Posted by James Westby at Mon Sep 20 15:26:36 2010