camptocamp/c2cgeoportal — pull request #815 by kalbermattenm (2013-12-16 13:27:30+00:00)
Title: Check first that user exists

At SITN, we will soon be using the "remote user" policy (see `c2cgeoportal` doc)

The problem with the current implemented solution is that all users have to exist in the `c2cgeoportal` database, otherwise the application throws an error 500, because of line https://github.com/camptocamp/c2cgeoportal/blob/master/c2cgeoportal/__init__.py#L103.

In SQLAlchemy:
* `one()`: Return exactly one result or raise an exception.

So I would like to propose something to first check if a user exists in the DB, if yes continue to get his role, if no return `None` (thus unconnected user)

Moreover: is there a specific purpose to use `one()` and raise an error ? Or could we use `first()` (and return `None` instead of raising an error...)

The solution proposed in this PR actually checks first if the user exists, and then uses the already implemented join which uses `one`.

@elemoine, could I have your opinion on this ?