Commit Graph

143 Commits

Author SHA1 Message Date
Rémy Coutable 09a348eb13
Include the `is_admin` field in the `GET /users/:id` API when current user is an admin
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-08-11 15:14:32 +02:00
Lin Jen-Shin (godfat) 0d35b08180 Allow logged in users to read user list under public restriction 2017-08-01 07:46:13 +00:00
Lin Jen-Shin 25e44edc30 Allow admin to read_users_list even if it's restricted 2017-07-25 16:49:26 +08:00
Rémy Coutable 91f63820a5
Return `is_admin` attribute in the GET /user endpoint for admins
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-07-12 12:45:46 +02:00
Paul Charlton cb3b4a15e6 Support multiple Redis instances based on queue type 2017-07-11 03:35:47 +00:00
James Lopez 5e66c6568b fix specs 2017-07-07 16:09:30 +02:00
James Lopez 377244dd45 refactor filters 2017-07-07 11:38:01 +02:00
James Lopez b08df253ef add finder and users API spec 2017-07-07 10:38:57 +02:00
Timothy Andrew 94258a6500 Fix build for !12300.
- The `/users` and `/users/:id` APIs are now accessible without
  authentication (!12445), and so scopes are not relevant for these endpoints.

- Previously, we were testing our scope declaration against these two methods.
  This commit moves these tests to other `GET` user endpoints which still
  require authentication.
2017-07-05 03:44:40 +00:00
Douwe Maan 5e2f7f25eb Merge branch 'master' into '33580-fix-api-scoping'
# Conflicts:
#   lib/api/users.rb
2017-07-04 15:00:01 +00:00
Timothy Andrew d1488268b2 Simplify authentication logic in the v4 users API for !12445.
- Rather than using an explicit check to turn off authentication for the
  `/users` endpoint, simply call `authenticate_non_get!`.

- All `GET` endpoints we wish to restrict already call
  `authenticated_as_admin!`, and so remain inacessible to anonymous users.

- This _does_ open up the `/users/:id` endpoint to anonymous access. It contains
  the same access check that `/users` users, and so is safe for use here.

- More context: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12445#note_34031323
2017-07-04 12:19:48 +00:00
Timothy Andrew 5dedea358d Merge remote-tracking branch 'origin/master' into 34141-allow-unauthenticated-access-to-the-users-api
- Modify policy code to work with the `DeclarativePolicy` refactor
  in 37c401433b.
2017-06-30 13:45:51 +00:00
Timothy Andrew 3c88a7869b Implement review comments for !12445 from @godfat and @rymai.
- Use `GlobalPolicy` to authorize the users that a non-authenticated user can
  fetch from `/api/v4/users`. We allow access if the `Gitlab::VisibilityLevel::PUBLIC`
  visibility level is not restricted.

- Further, as before, `/api/v4/users` is only accessible to unauthenticated users if
  the `username` parameter is passed.

- Turn off `authenticate!` for the `/api/v4/users` endpoint by matching on the actual
  route + method, rather than the description.

- Change the type of `current_user` check in `UsersFinder` to be more
  compatible with EE.
2017-06-30 13:06:03 +00:00
Timothy Andrew 157c05f49d Test `/users` endpoints for the `read_user` scope.
- Test `GET` endpoints to check that the scope is allowed.
- Test `POST` endpoints to check that the scope is disallowed.
- Test both `v3` and `v4` endpoints.
2017-06-28 07:17:13 +00:00
Timothy Andrew 80c1ebaa83 Allow API scope declarations to be applied conditionally.
- Scope declarations of the form:

    allow_access_with_scope :read_user, if: -> (request) { request.get? }

  will only apply for `GET` requests

- Add a negative test to a `POST` endpoint in the `users` API to test this. Also
  test for this case in the `AccessTokenValidationService` unit tests.
2017-06-28 07:17:13 +00:00
Timothy Andrew 6f1922500b Initial attempt at refactoring API scope declarations.
- Declaring an endpoint's scopes in a `before` block has proved to be
  unreliable. For example, if we're accessing the `API::Users` endpoint - code
  in a `before` block in `API::API` wouldn't be able to see the scopes set in
  `API::Users` since the `API::API` `before` block runs first.

- This commit moves these declarations to the class level, since they don't need
  to change once set.
2017-06-28 07:17:13 +00:00
Timothy Andrew 20f679d620 Allow unauthenticated access to the `/api/v4/users` API.
- The issue filtering frontend code needs access to this API for non-logged-in
  users + public projects. It uses the API to fetch information for a user by
  username.

- We don't authenticate this API anymore, but instead - if the `current_user` is
  not present:

  - Verify that the `username` parameter has been passed. This disallows an
    unauthenticated user from grabbing a list of all users on the instance. The
    `UsersFinder` class performs an exact match on the `username`, so we are
    guaranteed to get 0 or 1 users.
  - Verify that the resulting user (if any) is accessible to be viewed publicly
    by calling `can?(current_user, :read_user, user)`
2017-06-26 07:20:30 +00:00
James Lopez c9fd3dc42c more refactoring based on feedback 2017-06-23 11:41:42 +02:00
James Lopez ef6a4240e5 update notification settings, fix api specs 2017-06-23 11:41:41 +02:00
James Lopez 5f0e7873ae ported EE user service to CE 2017-06-23 11:41:41 +02:00
Grzegorz Bizon 0430b76441 Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
Mike Ricketts 0e7478064f Re-instate is_admin flag in users API is current user is an admin 2017-06-20 14:54:29 +00:00
vanadium23 83a9a472b3 Accept image for avatar in user API 2017-06-16 23:52:15 +03:00
Robert Speicher a6ec5121f0 Correct RSpec/SingleLineHook cop offenses 2017-06-14 13:18:56 -05:00
Grzegorz Bizon eebd18c3ac Merge branch '2563-backport-ee1942' into 'master'
Backport some EE changes from adding shared_runners_minutes_limit to the API

Closes gitlab-ee#2563

See merge request !11936
2017-06-07 07:04:21 +00:00
Lin Jen-Shin d919f924bf Backport https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1942 2017-06-06 21:42:45 +08:00
Mark Fletcher ad3e180ed3 Introduce an Events API
* Meld the following disparate endpoints:
 * `/projects/:id/events`
 * `/events`
 * `/users/:id/events`
+ Add result filtering to the above endpoints:
 * action
 * target_type
 * before and after dates
2017-06-06 20:16:41 +08:00
Nick Thomas c890c6aaf2 Allow users to be hard-deleted from the API 2017-06-02 18:28:12 +01:00
Douwe Maan 43b1750892 Revert "Remove changes that are not absolutely necessary"
This reverts commit b0498c176f
2017-05-24 20:59:26 +00:00
Sean McGivern 6dc424c949 Merge branch '29903-remove-user-is-admin-flag-from-api' into 'master'
Don't display the `is_admin?` flag for user API responses

Closes #29903

See merge request !10846
2017-04-25 10:57:32 +00:00
Timothy Andrew 34b71e734b Don't display the `is_admin?` flag for user API responses.
- To prevent an attacker from enumerating the `/users` API to get a list of all
  the admins.

- Display the `is_admin?` flag wherever we display the `private_token` - at the
  moment, there are two instances:

  - When an admin uses `sudo` to view the `/user` endpoint
  - When logging in using the `/session` endpoint
2017-04-25 09:46:05 +00:00
Jacopo ff76adb547 Unnecessary "include WaitForAjax" and "include ApiHelpers"
Removed all the unnecessary include of `WaitForAjax` and `ApiHelpers` in the specs.
Removed unnecessary usage of `api:true`
2017-04-21 22:32:02 +02:00
Robert Speicher 93e23a5d71 Merge branch 'query-users-by-extern-uid' into 'master'
Implement search by extern_uid in Users API

See merge request !10509
2017-04-19 19:50:38 +00:00
Robin Bobbitt ddf7e6ae78 Implement search by extern_uid in Users API 2017-04-18 14:55:32 -04:00
Rémy Coutable 814212621f Expose `last_activity_on` in the User API
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-04-14 15:20:55 +02:00
Sean McGivern 91ac0e038a Port 'Add user activities API' to CE
CE port of https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/962
2017-04-14 15:20:55 +02:00
Stan Hu 6a2d022d1d Delete users asynchronously 2017-04-02 05:37:05 -07:00
Douwe Maan 6a52cda31d Merge remote-tracking branch 'origin/personal_access_token_api_and_impersonation_token' 2017-03-07 09:29:55 -06:00
Tiago Botelho 005749a616 apply codestyle and implementation changes to the respective feature code 2017-03-06 19:18:26 +00:00
Adam Niedzielski 5753acfabc Move schema definitions for our public API to a separate directory 2017-03-06 14:17:07 +01:00
Tiago Botelho 2b474dc2b2 refactors finder and correlated code 2017-03-01 13:11:11 +00:00
Tiago Botelho 9f2e4742e3 applies relevant changes to the code and code structure 2017-02-28 22:15:40 +00:00
Tiago Botelho f0ea7130f7 refactors documentation and personal access tokens form to not allow admins to generate non impersionation tokens 2017-02-28 22:15:40 +00:00
Simon Vocella a3dfb58e7f add impersonation token 2017-02-28 22:15:39 +00:00
Simon Vocella 81246e5649 manage personal_access_tokens through api 2017-02-28 22:15:39 +00:00
Robert Schilling 86c58687b2 Return 204 for delete endpoints 2017-02-28 08:32:38 +01:00
Rémy Coutable 6f5bf9fcbb Merge branch 'remove-paginated-ressource' into 'master'
Remove shared example for pagination

See merge request !9377
2017-02-20 17:06:46 +00:00
Robert Schilling 993c3d14d5 Remove shared example for pagination 2017-02-20 15:39:16 +01:00
Robert Schilling 8f690604a5 API: Use POST to (un)block a user 2017-02-20 15:18:40 +01:00
Robert Schilling c70dfbc686 Add a custom pagination matcher 2017-02-16 15:38:40 +01:00