Commit Graph

2154 Commits

Author SHA1 Message Date
Douwe Maan fe13f11041 Create and use project path helpers that only need a project, no namespace 2017-07-05 11:11:59 -05: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
Rémy Coutable 52862754ab Merge branch '34141-allow-unauthenticated-access-to-the-users-api' into 'master'
Allow unauthenticated access to the `/api/v4/users` API

Closes #34141

See merge request !12445
2017-07-04 14:45:40 +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
Stan Hu 2a9c2fec4e Optimize creation of commit API by using Repository#commit instead of Repository#commits
Repository#commits is expensive because it has to use Rugged to walk the Git
tree as opposed to doing a direct ref lookup.

Improves performance in #34533
2017-07-03 15:48:13 -07: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 afbc7520c2 `AccessTokenValidationService` accepts `String` or `API::Scope` scopes.
- There's no need to use `API::Scope` for scopes that don't have `if`
  conditions, such as in `lib/gitlab/auth.rb`.
2017-06-30 07:32:25 +00:00
http://jneen.net/ 7765dd6a1d bugfix: use `require_dependency` to bring in DeclarativePolicy 2017-06-29 11:57:59 -07:00
Robert Speicher 066a6c8ba8 Merge branch '34078-allow-to-enable-feature-flags-with-more-granularity' into 'master'
Allow the feature flags to be enabled/disabled with more granularity

Closes #34078

See merge request !12357
2017-06-29 16:36:22 +00:00
Sean McGivern 8c5538be40 Merge branch 'refactor/declarative-policy' into 'master'
Refactor/declarative policy

See merge request !10515
2017-06-29 13:20:24 +00:00
Douwe Maan 46def2045e Merge branch 'add-members-count-and-parent-id-data-on-namespaces-api' into 'master'
Add group members counting related data on namespaces API

See merge request !12497
2017-06-29 13:04:13 +00:00
Timothy Andrew b8ec1f4201 Extract a `Gitlab::Scope` class.
- To represent an authorization scope, such as `api` or `read_user`
- This is a better abstraction than the hash we were previously using.
2017-06-29 06:15:57 +00:00
Oswaldo Ferreira bd4c2847f4 Rename members_count to members_count_with_descendants and expose only to group admins 2017-06-28 17:27:01 -03:00
Oswaldo Ferreira da3e4f4128 Add "members_count" and "parent_id" data on namespaces API 2017-06-28 15:50:29 -03:00
Rémy Coutable 289fae78e9
Rename flipper_group to feature_group
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-06-28 19:29:56 +02:00
Tiago Botelho 34f57b462b Fix current feature related specs 2017-06-28 11:32:34 +01:00
Timothy Andrew c1fcd730cc Implement review comments from @DouweM for !12300.
- Use a struct for scopes, so we can call `scope.if` instead of `scope[:if]`

- Refactor the "remove scopes whose :if condition returns false" logic to use a
  `select` rather than a `reject`.
2017-06-28 07:17:13 +00:00
Timothy Andrew 4dbfa14e16 Implement review comments from @dbalexandre for !12300. 2017-06-28 07:17:13 +00:00
Timothy Andrew 1b8223dd51 Fix remaining spec failures for !12300.
1. Get the spec for `lib/gitlab/auth.rb` passing.

  - Make the `request` argument to `AccessTokenValidationService` optional -
  `auth.rb` doesn't need to pass in a request.

  - Pass in scopes in the format `[{ name: 'api' }]` rather than `['api']`, which
  is what `AccessTokenValidationService` now expects.

2. Get the spec for `API::V3::Users` passing

2. Get the spec for `AccessTokenValidationService` passing
2017-06-28 07:17:13 +00:00
Timothy Andrew d774825f98 When verifying scopes, manually include scopes from `API::API`.
- They are not included automatically since `API::Users` does not inherit from
  `API::API`, as I initially assumed.

- Scopes declared in `API::API` are considered global (to the API), and need to
  be included in all cases.
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
http://jneen.net/ 59e7c39f4c use subject scope in :id/users
since we're loading all the members anyways
2017-06-27 12:44:38 -07:00
Kamil Trzcinski 6afff7c607 Fix head pipeline stored in merge request for external pipelines 2017-06-27 21:08:31 +02:00
Rémy Coutable 5fa9d6a17d Rename FLippable to FeatureGate and make `flipper_group` and `user` mutually exclusive
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-06-27 18:59:51 +02:00
Rémy Coutable b4d325c80c Allow the feature flags to be enabled/disabled with more granularity
This allows to enable/disable a feature flag for a given user, or a
given Flipper group (must be declared statically in the `flipper.rb`
initializer beforehand).

Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-06-27 18:59:51 +02:00
Lin Jen-Shin 01960fce25 Fix optional args for POST :id/variables
Always use declared_params(include_missing: false)
so that we don't give nils for optional arguments
2017-06-27 15:20:11 +08: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 ae95310523 fix spec failures 2017-06-24 10:00:23 +02:00
James Lopez 859858c7e6 fix spec failures 2017-06-23 21:13:46 +02:00
James Lopez b33c638483 update code based on feedback 2017-06-23 17:11:31 +02:00
James Lopez b804db2648 refactor update user service not to do auth checks 2017-06-23 11:41:43 +02:00
James Lopez 12dc3992ea fix spec failures 2017-06-23 11:41:42 +02:00
James Lopez c9fd3dc42c more refactoring based on feedback 2017-06-23 11:41:42 +02:00
James Lopez 785cbb79e2 refactor emails service 2017-06-23 11:41:42 +02:00
James Lopez 831b2fccf9 update missing email actions 2017-06-23 11:41:42 +02:00
James Lopez 87bf08c96c fix specs 2017-06-23 11:41:42 +02:00
James Lopez 3bab585bec update to use emails destroy service 2017-06-23 11:41:42 +02:00
James Lopez ad44af2faa fixed specs 2017-06-23 11:41:42 +02:00
James Lopez 158550cf37 added service in the rest of controllers and classes 2017-06-23 11:41:42 +02:00
James Lopez bf3a3f3652 fix api and controller issues 2017-06-23 11:41:41 +02:00
James Lopez ef6a4240e5 update notification settings, fix api specs 2017-06-23 11:41:41 +02:00
vanadium23 eda30f3104 Filter archived project in API v3 only if param present 2017-06-21 20:04:25 +03:00
Grzegorz Bizon 0430b76441 Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
Rémy Coutable 6a3da45a22 Merge branch '33878-fix-edit-deploy-key' into 'master'
Fix edit button for deploy keys available from other projects

Closes #33878

See merge request !12301
2017-06-21 10:08:16 +00:00
Rémy Coutable 18ef5be6c4 Merge branch 'dt/printing-to-api' into 'master'
add printing_merge_request_link_enabled to API

See merge request !12240
2017-06-21 09:00:57 +00:00
Douwe Maan 026455cf3a Merge branch '28517-discover-by-userid' into 'master'
Allow discover by userid - issue 28517

Closes #28517

See merge request !12314
2017-06-20 17:07:25 +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
Matt Walsh 02ad2841d8 Allow discover by userid - issue 28517 2017-06-20 08:53:28 -06:00