* sqlstore: Run tests as integration tests
* Truncate database instead of re-creating it on each test
* Fix test description
See https://github.com/grafana/grafana/pull/12129
* Fix lint issues
* Fix postgres dialect after review suggestion
* Rename and document functions after review suggestion
* Add periods
* Fix auto-increment value for mysql dialect
Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
* API: Improve error handling (#26934)
* New ErrUserAlreadyExists error has been introduced
* Create user endpoint returns 412 Precondition Failed on ErrUserAlreadyExists errors
* Make ErrUserAlreadyExists error message clearer
Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
* Use errors.Is instead of equality comparator on AdminCreateUser handler
* Improve sqlstore/user test definition
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
* Improve sqlstore/user tests for ErrUserAlreadyExists cases
* Remove no needed string fmt and err declaration on sqlstore/user tests
* Code improvements for sqlstore/user tests
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
* Use err.Error() instead of sentinel error value on AdminCreateUser
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
* Add ErrUserAlreadyExists handling for signup & org invite use cases
Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
* Allow API to assign new user to a specific organization
* Add defer block to test
* Add API tests and return 400 instead of 500 for bad orgId
* Minor test improvements
* Add support for `is_disabled` to `CreateUser()`
* Add support for `is_disabled` to `SearchUsers()`
Had to add it as a `string` type not as `bool`, since if that's property
is omitted, we would have add it to SQL request, which might be dangerous
* Restructure desctructive tests and add more
* batch disable users
* batch revoke users tokens
* split batch disable user and revoke token
* API: get users with auth info and isExternal flag
* fix tests for batch disable users
* Users: refactor /api/users/search endpoint
* Users: use alias for "user" table
* Chore: add BatchDisableUsers() to the bus
* Users: order user list by id explicitly
* Users: return AuthModule from /api/users/:id endpoint
* Users: do not return unused fields
* Users: fix SearchUsers method after last changes
* User: return auth module as array for future purposes
* User: tests for SearchUsers()
* User: return only latest auth module in SearchUsers()
* User: fix JOIN, get only most recent auth module
To not get into a situation where a user has a current organization assign which he is
not a member of we try to always make sure that a user has a valid current organization
assigned.
Currently there is a limit of 1000 users in the global
user list. This change introduces paging so that an
admin can see all users and not just the first 1000.
Adds a new route to the api - /api/users/search that
returns a list of users and a total count. It takes
two parameters perpage and page that enable paging.
Fixes#7469