Set user rights with UID, not workspace ID.

#3481
Search using correct KEY_EMAIL const.

Make code similar to that of Orion, to ease future
maintainability.
Fix warnings.