Commit Graph

418 Commits

Author SHA1 Message Date
Douwe Maan b7c8f7d76d Update specs for sudo behavior 2017-11-02 11:39:03 +01:00
Douwe Maan 3f24f9ed18 Add sudo API scope 2017-11-02 11:39:03 +01:00
Travis Miller 8d1ab256bf Add pages domains API implementation 2017-10-22 08:04:43 -05:00
Douwe Maan 025c6eeaa1 Move all API authentication code to APIGuard 2017-10-12 11:13:37 +02:00
Alejandro Rodríguez 60a35e4230 Send API parameters as extra data for sentry errors 2017-10-05 18:31:34 -03:00
Rémy Coutable 3040b994df
Ensure no exception is raised when Raven tries to get the current user in API context
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-09-29 18:57:22 +02:00
Douwe Maan b6c5a73c0b Make sure API responds with 401 when invalid authentication info is provided 2017-09-28 14:17:52 +02:00
Lin Jen-Shin 6a4ee9aa71 Allow simple ivar ||= form. Update accordingly 2017-09-19 01:29:32 +08:00
Lin Jen-Shin 9ae92b8caa Add cop to make sure we don't use ivar in a module 2017-09-18 21:23:45 +08:00
Ruben Davila 62bb6235c2 Make Members with Owner and Master roles always able to create subgroups 2017-09-07 13:47:58 -05:00
Grzegorz Bizon 8ed0a05107 Merge branch 'wiki_api' into 'master'
Add API support for wiki pages

Closes #12747

See merge request !13372
2017-09-07 10:38:03 +00:00
blackst0ne 2915bb2707 Add API support for wiki pages 2017-09-07 09:21:52 +11:00
Grzegorz Bizon c922fb4b68 Respond with a bad request if artifact path is invalid 2017-09-06 11:31:08 +02:00
Grzegorz Bizon 80b3dcc777 Extract job artifacts API code to a separate file 2017-09-06 11:20:12 +02:00
Grzegorz Bizon dfb8fcbb65 Use API helper to send artifact file through Workhorse 2017-09-05 11:16:49 +02:00
Sean McGivern b9d8946395 Don't use public_send in destroy_conditionally! helper
As we only override in two places, we could just ask for the value rather than
the method name.
2017-08-30 14:32:02 +01:00
Robert Schilling dcd4ea473c Update remaining endpoints 2017-08-28 17:10:30 +02:00
Robert Schilling e80313f9ee Conditionally destroy a ressource 2017-08-28 16:40:25 +02:00
Robert Schilling 998afa5f74 API: Respect the 'If-Unmodified-Since' for delete endpoints 2017-08-28 16:40:25 +02:00
Zeger-Jan van de Weg dc8e1676cd
Upgrade grape to 1.0
Main feature was the deprication of the Hashie stuff, so the access by
calling keys as method is gone now.
2017-08-16 22:06:31 +02:00
Lin Jen-Shin 4f0fa13eb8 Show error message for API 500 error in tests, and
document have_gitlab_http_status
2017-08-11 20:50:35 +08:00
Douwe Maan 14644d40e0 Do not validate CSRF token in API unless needed 2017-08-02 18:20:31 +02:00
Douwe Maan dcf4a2e83c Rescue only from ActionController::InvalidAuthenticityToken 2017-07-26 11:25:10 +02:00
blackst0ne cc3a82bc8b Add `rescue false`. 2017-07-26 11:05:44 +02:00
blackst0ne 8ce8b21f67 Refactor CSRF protection 2017-07-26 11:05:44 +02:00
blackst0ne 2902235099 Add CSRF token verification to API 2017-07-26 11:05:44 +02:00
Felipe Artur c5c9dce270 Add group milestones API endpoint 2017-07-21 11:00:00 -03:00
vanadium23 8d44d5142a Add user projects API 2017-07-06 08:04:54 +03:00
Timothy Andrew 4dbfa14e16 Implement review comments from @dbalexandre for !12300. 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
Rémy Coutable 4cfa5ce4a9
Enable the Style/PreferredHashMethods cop
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-06-02 19:11:26 +02:00
Kamil Trzcinski 6185d12c18 Add missing specs 2017-06-01 16:34:48 +02:00
Toon Claes db679788e4 Add :owned param to ProjectFinder
And use it in the API.
2017-05-30 22:45:59 +02:00
Toon Claes 0f0b9a8466 Use helper to construct Finder params
The ProjectsFinder and GroupFinder both support the same set of params. And the
`/api/v4/projects` and `/api/v4/group/:id/projects` also support the same set of
params. But they do not match the Finder params. So use a helper method to
transform them.
2017-05-30 22:45:59 +02:00
Toon Claes a1deed629e Use ProjectFinder to filter the projects
Instead of trying to do the heavy lifting in the API itself, use the existing
features of the ProjectFinder.
2017-05-30 22:45:59 +02:00
Toon Claes 07fc79e7c5 Handle `membership` in ProjectFinder
The ProjectFinder supports the `non_public` parameter. This can be used to find
only projects the user is member of.
2017-05-30 22:45:59 +02:00
Robert Speicher cb2f739d48 Merge branch '27144-enforce-rubocop-trailing_commas-no_comma-style' into 'master'
Resolve "Use consistent style for trailing commas"

Closes #27144

See merge request !11063
2017-05-10 21:43:34 +00:00
Rémy Coutable 3db37e0562 Enable the Style/TrailingCommaInArguments cop
Use the EnforcedStyleForMultiline: no_comma option.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-05-10 18:25:45 +02:00
Bob Van Landuyt ebd8b7f60f Use new SnippetsFinder signature in API 2017-05-10 16:48:18 +02:00
Timothy Andrew 4dfdef2ddf Allow admins to sudo to blocked users.
- Currently, (for example) admins can't delete snippets for blocked users, which
  is an unexpected limitation.

- We modify `authenticate!` to conduct the `access_api` policy check against the
  `initial_current_user`, instead of the user being impersonated.

- Update CHANGELOG for !10842
2017-04-26 08:00:19 +00:00
blackst0ne 11aff97d88 Remove the User#is_admin? method 2017-04-09 13:20:57 +11:00
Toon Claes add5cd996f API: Make the /notes endpoint work with noteable iid instead of id
In API V4 all endpoints were changed so Merge Requests and Issues
should be referred by iid, instead of id. Except the /notes endpoint
was forgotten. So change the endpoints from:

- /projects/:id/issues/:issue_id/notes
- /projects/:id/merge_requests/:merge_request_id/notes

To:

- /projects/:id/issues/:issue_iid/notes
- /projects/:id/merge_requests/:merge_request_iid/notes

For Project Snippets nothing changes.
2017-03-27 15:29:37 +02:00
http://jneen.net/ 0ea04cc5bf use the policy stack to protect logins 2017-03-09 11:49:52 -08:00
http://jneen.net/ 846e581732 use a magic default :global symbol instead of nil
to make sure we mean the global permissions
2017-03-09 11:49:52 -08:00
Timothy Andrew 719327112c
API routes referencing a specific merge request should use the MR `iid`
- As opposed to the `id` that was previously being used.
- This brings the API routes closer to the web interface's routes.
- This is specific to API v4.
2017-03-07 13:06:42 +05:30
Timothy Andrew dd99622347
API routes referencing a specific issue should use the issue `iid`
- As opposed to the issue `id` that was previously being used.
- This brings the API routes closer to the web interface's routes.
- This is specific to API v4.
2017-03-07 13:06:42 +05:30
Pawel Chojnacki 8993801f0c Test various login scenarios if the limit gets enforced 2017-03-06 15:41:25 +01:00
Adam Niedzielski c727d4328f Remove "subscribed" field from API responses returning list of issues or merge requests 2017-03-06 14:17:07 +01:00
Toon Claes 6357635686 Rename query parameter to `membership`
The query parameter `membership` should be more self-explaining.
2017-03-03 13:42:39 +01:00
Oswaldo Ferreira 06e96907ee Add filter param for authorized projects for current_user for V4 2017-03-03 12:02:41 +01:00
Mark Fletcher 61baf3528d Enable filtering milestones by search criteria in the API
- Also remove a redundant test
2017-03-02 10:07:57 +05:30
Oswaldo 2b001d9e7a Return 202 with JSON body on async removals on V4 API 2017-02-23 19:55:13 -03:00
Douwe Maan b7d8df503c Enable Style/MutableConstant 2017-02-23 09:31:56 -06:00
Sean McGivern 7e8a6a63af Merge branch '28093-snippet-and-issue-spam-check-on-edit' into 'master'
Spam check and reCAPTCHA improvements

Closes #28093

See merge request !9248
2017-02-22 10:13:20 +00:00
Douwe Maan f40716f48a No more and/or 2017-02-21 16:31:14 -06:00
Oswaldo Ferreira 2ace39f242 Spam check and reCAPTCHA improvements 2017-02-21 13:32:49 -03:00
Robert Schilling 612e61f4c4 Use grape validation for dates 2017-02-20 14:24:09 +01:00
Toon Claes 4e9e29d295 API: Consolidate /projects endpoint
It consolidates these endpoints:
 - /projects
 - /projects/owned
 - /projects/visible
 - /projects/starred
 - /projects/all

Into the /projects endpoint using query parameters.
2017-02-14 16:41:57 +01:00
Robert Schilling 6e1d675de9 API: Fix file downloading 2017-02-03 12:42:11 +01:00
Adam Pahlevi a0586dbc16 replace `find_with_namespace` with `find_by_full_path`
add complete changelog for !8949
2017-02-03 07:14:04 +07:00
Robert Speicher 3a5df1d8fc Merge branch 'fix-api-mr-permissions' into 'security'
Ensure that only privileged users can access merge requests in the API

See merge request !2053
2017-01-23 13:54:35 -05:00
Kamil Trzcinski d8e440c8e0
Fix specs 2017-01-19 23:41:12 +01:00
Kamil Trzcinski 31af6be076
Fix specs 2017-01-19 23:31:03 +01:00
Kamil Trzcinski 8171a1932b
Merge remote-tracking branch 'origin/master' into 21698-redis-runner-last-build 2017-01-19 15:31:04 +01:00
Sean McGivern cc1e43da39 Merge branch 'time-tracking-api' into 'master'
Time tracking API

Closes #25861

See merge request !8483
2017-01-18 18:18:13 +00:00
Ruben Davila 0f3c9355c1 Add some API endpoints for time tracking.
New endpoints are:

POST :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/time_estimate"

POST :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/reset_time_estimate"

POST :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/add_spent_time"

POST :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/reset_spent_time"

GET  :project_id/(issues|merge_requests)/(:issue_id|:merge_request_id)/time_stats"
2017-01-18 10:48:16 -06:00
Robert Schilling 1cccb37831 Fix a API deprecation warning 2017-01-16 00:38:25 +01:00
Lin Jen-Shin 8c9a4ed373 WIP: Add tests and make sure that headers are set
* We realized that headers were not set whenever we give 204
  because `render_api_error!` doesn't preserve the headers.

* We also realized that `update_runner_info` would be called in
  POST /builds/register every time therefore runner is updated
  every time, ticking the queue, making this last_update didn't
  work very well, and the test would be failing due to that.
2017-01-04 17:46:56 +08:00
Regis 0a074f2e09 fix pipelines/index.html.haml merge conflict 2017-01-02 16:24:37 -07:00
Robert Schilling 465700ddc2 Merge branch 'fix-api-deprecation' into 'master'
Fix a Grape deprecation, use `#request_method` instead of `#route_method`

See merge request !8297
2016-12-28 11:36:28 +00:00
Rémy Coutable 1b109c99a4
Fix a Grape deprecation, use `#request_method` instead of `#route_method`
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-12-23 19:07:23 +01:00
Markus Koller 3ef4f74b1a
Add more storage statistics
This adds counters for build artifacts and LFS objects, and moves
the preexisting repository_size and commit_count from the projects
table into a new project_statistics table.

The counters are displayed in the administration area for projects
and groups, and also available through the API for admins (on */all)
and normal users (on */owned)

The statistics are updated through ProjectCacheWorker, which can now
do more granular updates with the new :statistics argument.
2016-12-21 16:39:49 +01:00
Grzegorz Bizon 468b47d47c Remove redundant pagination helpers after a bad merge
[ci skip]
2016-12-21 15:19:00 +01:00
Grzegorz Bizon 3deaf1342e Merge branch 'master' into auto-pipelines-vue
* master: (367 commits)
  Set “Remove branch” button to default size
  remove unused helper method
  reduce common code even further to satisfy rake flay
  remove button class size alteration from revert and cherry pick links
  factor out common code to satisfy rake flay
  homogenize revert and cherry-pick button styles generated by commits_helper
  apply margin on alert banners only when there is one or more alerts
  Rename MattermostNotificationService back to MattermostService
  Rename SlackNotificationService back to SlackService
  Fix stage and pipeline specs and rubocop offenses
  Added QueryRecorder to test N+1 fix on Milestone#show
  Use gitlab-workhorse 1.2.1
  Make 'unmarked as WIP' message more consistent
  Improve specs for Files API
  Allow unauthenticated access to Repositories Files API GET endpoints
  Add isolated view spec for pipeline stage partial
  Move test for HTML stage endpoint to controller specs
  Fix sizing of avatar circles; add border
  Fix broken test
  Fix broken test Changes after review
  ...

Conflicts:
	app/assets/stylesheets/pages/pipelines.scss
	app/controllers/projects/pipelines_controller.rb
	app/views/projects/pipelines/index.html.haml
	spec/features/projects/pipelines/pipelines_spec.rb
2016-12-21 12:09:06 +01:00
Timothy Andrew 7fa06ed55d Calls to the API are checked for scope.
- Move the `Oauth2::AccessTokenValidationService` class to
  `AccessTokenValidationService`, since it is now being used for
  personal access token validation as well.

- Each API endpoint declares the scopes it accepts (if any). Currently,
  the top level API module declares the `api` scope, and the `Users` API
  module declares the `read_user` scope (for GET requests).

- Move the `find_user_by_private_token` from the API `Helpers` module to
  the `APIGuard` module, to avoid littering `Helpers` with more
  auth-related methods to support `find_user_by_private_token`
2016-12-16 16:29:31 +05:30
Regis 77daed05ca merge master 2016-12-13 13:03:49 -07:00
Sean McGivern e3231cc297 Merge branch '25482-fix-api-sudo' into 'master'
API: Memoize the current_user so that the sudo can work properly

Closes #25482

See merge request !8017
2016-12-13 18:58:23 +00:00
Rémy Coutable d95b709a66
Be smarter when finding a sudoed user in API::Helpers
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-12-13 15:53:00 +01:00
Rémy Coutable 927a75567a Merge branch 'grapify-service-api' into 'master'
Grapify the service API

Related to #22928 

See merge request !7970
2016-12-12 17:54:00 +00:00
Rémy Coutable 2f45d3bcf0 API: Memoize the current_user so that the sudo can work properly
The issue was arising when `#current_user` was called a second time
after a user was impersonated: the `User#is_admin?` check would be
performed on it and it would fail.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-12-12 13:50:31 +01:00
Grzegorz Bizon 0f40ae5f18 Merge branch 'master' into auto-pipelines-vue
* master: (76 commits)
  Update "Installation from source" guide for 8.15.0
  Group links spec update
  Updates the font weight of button styles because of the change to system fonts
  Refactor SSH keys docs
  Improvements to setting up ssh
  Do not reload diff for merge request made from fork when target branch in fork is updated
  Add 8.12.10, 8.12.11, and 8.12.12 CHANGELOG.md items
  Changes after review
  Fix broken test
  Adds CHANGELOG entry
  Adds tests
  Uniformize props name format
  Replace commit icon svg logic
  Replace play icon svg logic
  Updated JS based on review Fixed group links dropdown to match
  Update docs to reflect new defaults on omnibus
  Merge branch 'jej-23867-use-mr-finder-instead-of-access-check' into 'security'
  Merge branch 'html-safe-diff-line-content' into 'security'
  Merge branch 'rs-filter-authentication_token' into 'security'
  Merge branch 'destroy-session' into 'security'
  ...

Conflicts:
	app/models/ci/pipeline.rb
	app/models/commit_status.rb
	app/views/projects/ci/pipelines/_pipeline.html.haml
	app/views/projects/commit/_pipeline.html.haml
	app/views/projects/pipelines/_with_tabs.html.haml
	app/views/projects/pipelines/index.html.haml
	lib/api/helpers.rb
2016-12-09 20:30:39 +01:00
Robert Schilling 593c912151 Grapify the service API 2016-12-09 17:20:12 +01:00
Douwe Maan 05efd19e89 Merge branch 'dz-nested-groups' into 'master'
Add nested groups support on data level

## What does this MR do?

- [x] Add  `parent_id` field to `Namespace`model. 
- [x] Create new database table `routes` that keeps information about full path to each group or project
- [x] Remove uniq index from `namespaces.path`
- [x] Add uniq index on `routes.path`
- [x] Fill routes table with path data from namespaces and projects
- [x] Change Namespace/Project URL lookup by routes table
- [x] Rename related routes (nested groups, projects) when parent path changes

This is solely backend preparation. UI, Permissions and API support will be added in separate merge request.   
 
## Are there points in the code the reviewer needs to double check?

migrations, Route model, Routable concern

Will require downtime. See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7121#note_19490281 discussion

## Why was this MR needed?

One step further to full nested groups support

## Screenshots (if relevant)

No UI changes in this merge request so far

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG.md) entry added~~
- ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
- ~~API support added~~
- Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

https://gitlab.com/gitlab-org/gitlab-ce/issues/2772

See merge request !7121
2016-12-09 01:52:36 +00:00
Dmitriy Zaporozhets 83232be0e1
Add nested groups support on data level
* add parent_id field to namespaces table to store relation with nested groups
* create routes table to keep information about full path of every group and project
* project/group lookup by full path from routes table

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2016-12-08 11:47:16 +02:00
Douwe Maan cf2206eb2b Merge branch '24537-reenable-private-token-with-sudo' into 'master'
Reenables /user API request to return private-token if user is admin and requested with sudo

## What does this MR do?

Reenables the API /users to return `private-token` when sudo is either a parameter or passed as a header and the user is admin.

## Screenshots (if relevant)

Without **sudo**:

![Screen_Shot_2016-11-21_at_11.44.49](/uploads/ebecf95dbadaf4a159b80c61c75771d9/Screen_Shot_2016-11-21_at_11.44.49.png)

With **sudo**:
![Screen_Shot_2016-11-21_at_11.45.52](/uploads/f25f9ddffcf2b921e9694e5a250191d3/Screen_Shot_2016-11-21_at_11.45.52.png)

## Does this MR meet the acceptance criteria?

- [x] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- [x] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [x] API support added
- Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?


Closes #24537

See merge request !7615
2016-12-08 00:17:44 +00:00
tiagonbotelho 3ed96afc47 adds impersonator variable and makes sudo usage overall more clear 2016-12-07 14:42:51 +00:00
Grzegorz Bizon 7870614fb9 Extract API pagination code to a separete module 2016-12-07 15:23:07 +01:00
Robert Schilling 3e7818e93a Grapify the issues API 2016-12-07 10:19:28 +01:00
Rémy Coutable d757247247
Allow public access to some Project API endpoints
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-12-01 16:39:42 +01:00
Rémy Coutable 43c8788e7b Merge branch 'grapify-projects-api' into 'master'
Grapify the projects API

Related to #22928 

See merge request !7456
2016-11-30 11:32:32 +00:00
Douwe Maan 3bf34face4 Merge branch 'jej-use-issuable-finder-instead-of-access-check' into 'security'
Replace issue access checks with use of IssuableFinder

Split from !2024 to partially solve https://gitlab.com/gitlab-org/gitlab-ce/issues/23867

## Which fixes are in this MR?

⚠️ - Potentially untested  
💣 - No test coverage  
🚥 - Test coverage of some sort exists (a test failed when error raised)  
🚦 - Test coverage of return value (a test failed when nil used)  
 - Permissions check tested

### Issue lookup with access check

Using `visible_to_user` likely makes these security issues too. See [Code smells](#code-smells).

- [x] 🚦 app/finders/notes_finder.rb:15 [`visible_to_user`]
- [x] 🚥 app/views/layouts/nav/_project.html.haml:73 [`visible_to_user`] [`.count`]
- [x]  app/services/merge_requests/build_service.rb:84 [`issue.try(:confidential?)`]
- [x]  lib/api/issues.rb:112 [`visible_to_user`]
  - CHANGELOG: Prevented API returning issues set to 'Only team members' to everyone
- [x]  lib/api/helpers.rb:126 [`can?(current_user, :read_issue, issue)`] Maybe here too?
- [x]  lib/gitlab/search_results.rb:53 [`visible_to_user`]

### Previous discussions
- [ ] https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2024/diffs#b2ff264eddf9819d7693c14ae213d941494fe2b3_128_126
- [ ] https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2024/diffs#7b6375270d22f880bdcb085e47b519b426a5c6c7_87_87

See merge request !2031
2016-11-28 21:26:23 -03:00
Douwe Maan 3d7704ae5f Merge branch 'zj-fix-label-creation-non-members' into 'security'
Fix label creation non members

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/23416

See merge request !2006
2016-11-28 21:24:19 -03:00
Robert Schilling 7c607a55ab Grapify the projects API 2016-11-28 21:01:43 +01:00
Rémy Coutable 81ba3f9177
API: Introduce `#find_group!` which also check access permission
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-11-24 16:58:32 +01:00
Rémy Coutable 4f5ed81232
API: Introduce `#find_project!` which also check access permission
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-11-24 14:40:35 +01:00
Rémy Coutable 4d2e7894ef
Make API::Helpers find a project with only one query
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-11-24 10:19:36 +01:00
Z.J. van de Weg f749fb7fe0 Improve style, add more tests 2016-11-18 11:38:54 +01:00
Z.J. van de Weg 0d04724fa1 More coverage on service level 2016-11-18 10:00:40 +01:00
Douwe Maan 4e63411daa Merge branch 'adam-build-missing-services-when-necessary' into 'master'
Defer saving project services to the database if there are no user changes

## What does this MR do?

It defers saving project services to the database as long as it is possible. It creates a project service when creating a project only if this project service has an active template. After that project services are saved on the first edit.

## Are there points in the code the reviewer needs to double check?

- tests that used `build_missing_services` before the change
- number of queries executed

## Why was this MR needed?

Motivation in #22281

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

Fixes #22281

See merge request !6958
2016-11-16 16:27:54 +00:00
Adam Niedzielski ef3be00a02 Defer saving project services to the database if there are no user changes 2016-11-16 12:46:07 +01:00
Robert Schilling 510092c83a Use #to_h to convert params to a hash 2016-11-14 11:17:51 +01:00
Felipe Artur f4e31b820e Fix project features default values 2016-11-01 11:03:56 -02:00
Rémy Coutable cae27eae3f
API: Fix booleans not recognized as such when using the `to_boolean` helper
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-10-27 18:21:09 +02:00
Douglas Barbosa Alexandre bf710b5119 Validate label params against all labels available to project on the API 2016-10-19 14:58:26 -02:00
Rémy Coutable 0876b46024 Merge branch 'memoize_shell_secret_token' into 'master'
Memoize Github::Shell's secret token

## What does this MR do?

`API::Helpers#secret_token` was reading the secret file on every invocation. This MR reads the file in the `gitlab_shell_secret_token.rb` initializer and saves it as a class variable at `Gitlab::Shell.secret_token`

## Are there points in the code the reviewer needs to double check?

 - I'm not sure if the use of `cattr_accessor` is the best approach, or if should be moved into the `class << self` block?
 - Should `API::Helpers#secret_token` be removed in favor of using `Gitlab::Shell.secret_token`?

## Why was this MR needed?

Performance optimization.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/22510

See merge request !6599
2016-10-07 10:35:03 +00:00
Justin DiPierro fe46e4eb35 Load Github::Shell's secret token from file on initialization instead of every request. 2016-10-06 11:22:37 -04:00
Nick Thomas 86c0c0869d Switch from request to env in ::API::Helpers
Per https://gitlab.com/gitlab-org/gitlab-ce/issues/22820, this helper is mixed
in to classes that lack a `request` method. They do include `env`, so use it
instead.
2016-10-06 15:07:25 +01:00
Nick Thomas fd51f19c97 API: disable rails session auth for non-GET/HEAD requests 2016-09-23 12:21:47 +01:00
Nick Thomas 10c072263b Enable Warden for the Grape API
The practical effect of this commit is to make the API check the Rails session
cookie for authentication details. If the cookie is present and valid, it will
be used to authenticate.

The API now has several authentication options for users. They follow in this
order of precedence:

* Authentication token
* Personal access token
* OAuth2 Bearer token (Doorkeeper - application access)
* Rails session cookie
2016-09-19 12:27:37 +01:00
Tomasz Maczukin 940f900f1c
Change response for /ci/api/v1/builds/register.json from 404 to 204 2016-09-13 17:44:18 +02:00
http://jneen.net/ 2bdcef4d67 use a nil subject when we want to check global abilities 2016-08-30 11:39:22 -07:00
http://jneen.net/ 5853c96b49 remove Ability.abilities 2016-08-30 11:35:06 -07:00
http://jneen.net/ 99ee86206e remove six, and use a Set instead 2016-08-30 11:32:55 -07:00
Stan Hu 170885edd6 Add Sentry logging to API calls
Closes #21043
2016-08-24 12:09:51 -07:00
Rémy Coutable 7c1b33b48f Restore back-compatibility for current members API endpoints
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-08-10 19:07:05 +02:00
Rémy Coutable 29850364ec New AccessRequests API endpoints for Group & Project
Also, mutualize AccessRequests and Members endpoints for Group &
Project.
New API documentation for the AccessRequests endpoints.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-08-10 19:07:05 +02:00
Robert Schilling 839aec1a61 Replace parse_boolean with to_boolean 2016-07-20 08:55:44 +02:00
Robert Schilling 54d26c89f6 API: Expose 'developers_can_push' for branches 2016-07-19 11:11:56 +02:00
Rémy Coutable 2cf7f09b1e
Revert "Revert "Merge branch '18193-developers-can-merge' into 'master' ""
This reverts commit 530f5158e2.

See !4892.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-07-18 10:16:56 +02:00
Robert Speicher 530f5158e2 Revert "Merge branch '18193-developers-can-merge' into 'master' "
This reverts commit 9ca633eb4c, reversing
changes made to fb229bbf79.
2016-07-13 13:57:30 -05:00
Timothy Andrew 60245bbe22 Refactor `Gitlab::GitAccess`
1. Don't use case statements for dispatch anymore. This leads to a lot
   of duplication, and makes the logic harder to follow.

2. Remove duplicated logic.

    - For example, the `can_push_to_branch?` exists, but we also have a
      different way of checking the same condition within `change_access_check`.

    - This kind of duplication is removed, and the `can_push_to_branch?`
      method is used in both places.

3. Move checks returning true/false to `UserAccess`.

    - All public methods in `GitAccess` now return an instance of
      `GitAccessStatus`. Previously, some methods would return
      true/false as well, which was confusing.

    - It makes sense for these kinds of checks to be at the level of a
      user, so the `UserAccess` class was repurposed for this. The prior
      `UserAccess.allowed?` classmethod is converted into an instance
      method.

    - All external uses of these checks have been migrated to use the
      `UserAccess` class

4. Move the "change_access_check" into a separate class.

    - Create the `GitAccess::ChangeAccessCheck` class to run these
      checks, which are quite substantial.

    - `ChangeAccessCheck` returns an instance of `GitAccessStatus` as
      well.

5. Break out the boolean logic in `ChangeAccessCheck` into `if/else`
   chains - this seems more readable.

6. I can understand that this might look like overkill for !4892, but I
   think this is a good opportunity to clean it up.

    - http://martinfowler.com/bliki/OpportunisticRefactoring.html
2016-07-13 13:24:56 +05:30
Timothy Andrew 7ee0898a9e Implement @DouweM's feedback.
- Extract a duplicated `redirect_to`
- Fix a typo: "token", not "certificate"
- Have the "Expires at" datepicker be attached to a text field, not inline
- Have both private tokens and personal access tokens verified in a
  single "authenticate_from_private_token" method, both in the
  application and API. Move relevant logic to
  `User#find_by_personal_access_token`
- Remove unnecessary constants relating to API auth. We don't need a
  separate constant for personal access tokens since the param is the
  same as for private tokens.
2016-06-16 08:24:13 +05:30
Timothy Andrew d0bcba1105 Merge remote-tracking branch 'origin/master' into 2979-personal-access-tokens 2016-06-14 09:06:53 +05:30
Stan Hu a85dde9182 Fix Error 500 when using closes_issues API with an external issue tracker
Closes #18484
2016-06-11 19:50:08 -07:00
Douwe Maan 701e2df7e5 Satisfy Rubocop 2016-06-10 12:29:15 +02:00
Douwe Maan 8c3ba8d6c9 Add workhorse controller and API helpers 2016-06-06 13:16:30 +02:00
Timothy Andrew ae0d8222af Merge remote-tracking branch 'origin/master' into 2979-personal-access-tokens 2016-06-03 09:31:16 +05:30
Robert Speicher 013bccbd93 Enable Style/DefWithParentheses cop and fix single offense 2016-05-23 13:06:36 -04:00
Gabriel Mazetto f5a0ac0fc1 Codestyle: make sure we have space around operators 2016-05-13 04:46:56 -03:00
Ahmad Sherif 0c22698bd4 Add API endpoints for un/subscribing from/to a label
Closes #15638
2016-05-12 22:48:09 +02:00
Timothy Andrew d915e7d5ca Reuse the private token param and header for personal access tokens.
- https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3749#note_11626427
- Personal access tokens are still a separate entity as far as the
  codebase is concerned - they just happen to use the same entry point
  as private tokens.
- Update tests and documentation to reflect this change
2016-05-11 10:16:23 +05:30
Timothy Andrew 2e9742997d Merge remote-tracking branch 'origin/master' into 2979-personal-access-tokens 2016-05-11 09:52:58 +05:30
Paco Guzman c4b9bd0413 API support for the 'since' and 'until' operators on commit requests
- Parameter validation as ISO8601 format
2016-04-29 09:26:52 +02:00
Timothy Andrew b22a47c62e Combine `API::Helpers::Core` and `API::Helpers::Authentication` back into `API::Helpers`
- Makes the MR easier to read; this can go in a separate MR
- This is a (sort of) revert of 99bea01
2016-04-28 22:28:36 +05:30
Timothy Andrew e8314ccca5 Refactor `API::Helpers` into `API::Helpers::Core` and `API::Helpers::Authentication` 2016-04-28 22:28:36 +05:30
Rémy Coutable 94e130cec3 Merge branch 'api-star-project' into 'master'
API: Star and unstar a project

Add two new endpoints `POST /projects/:id/star` and `POST /projects/:id/unstar` to star and unstar a project.

* Closes #12739


See merge request !3578
2016-04-13 15:05:21 +00:00
Robert Schilling 54231aa4e0 Styling changes to code and docs 2016-04-13 16:25:24 +02:00
Robert Schilling ea2193aaeb API: Star and unstar a project 2016-04-13 14:26:40 +02:00
Robert Schilling b2f48d8c46 API: Return 404 if user does not have access to group 2016-04-13 11:11:09 +02:00
Zeger-Jan van de Weg 1d77822816 minor improvements and fixed specs 2016-03-19 21:24:05 +01:00
Michi302 c41a8be8d2 Fix add_pagination_headers to keep request parameters in Link header 2016-02-02 15:26:29 +01:00
Kamil Trzcinski 95d2f0fb51 Fix CI runner version not being properly updated when asking for a build
Due to broken implementation of attribute_for_keys the runner information was not updated correctly.

This MR adds test to check that such scenario will never happen again.
2016-01-27 12:04:54 +01:00
Josh Frye 11797df1af Change 'public' flag to more robust 'visibility' query. 2016-01-19 09:57:00 -05:00
Josh Frye 10669097fa Add public params to GET /projects api. Closes #3788 2016-01-19 09:57:00 -05:00
Rémy Coutable 1b08cd811a Merge branch 'master' of https://gitlab.com/gitlab-org/gitlab-ce into add-pagination-headers-to-api 2016-01-14 14:23:42 +01:00
Grzegorz Bizon 154b8ceba4 Refactor build artifacts upload API endpoint 2016-01-14 12:48:17 +01:00
Rémy Coutable 3183092ca9 Add pagination headers to already paginated API resources 2016-01-14 12:10:27 +01:00
Kamil Trzcinski e80e3f5372 Migrate CI::Project to Project 2015-12-11 18:02:09 +01:00
Kamil Trzcinski db3213fc1c Use normal file upload mechanism to upload artifacts 2015-11-10 12:51:51 +01:00
Kamil Trzcinski 445cdb7579 Move tmp artifacts to shared/artifacts/tmp/. Check for GitLab-Workhorse now 2015-11-10 12:51:51 +01:00
Kamil Trzcinski d0e3e823a2 Implement Build Artifacts
- Offloads uploading to GitLab Workhorse
- Use /authorize request for fast uploading
- Added backup recipes for artifacts
- Support download acceleration using X-Sendfile
2015-11-10 12:51:50 +01:00
Jason Lee 3d613fe1e8 Fix API::APIHelpers -> API::Helpers;
Rails Autoload find file to require is use , APIHelpers -> api_helpers.rb, not helpers.rb;
2015-10-23 11:42:57 +08:00
Guilherme Garnier 59d0263bc8 Fix rubocop warnings in lib 2015-10-03 01:29:58 -05:00
Valery Sizov 22bf844869 fix specs. Stage 3 2015-09-15 13:50:24 +03:00
Valery Sizov 910bf96ec3 fix specs. Stage 2 2015-09-14 18:14:17 +03:00
Kirilll Zaitsev 263abda3fd Drone CI service 2015-09-02 05:52:16 +03:00
Jakub Jirutka ed3298fc01 Allow to configure gitlab_shell_secret location 2015-05-16 21:46:06 +02:00
jubianchi 2c544d43c8 Query issues, merge requests and milestones with their IID through API 2015-05-02 10:44:52 +02:00
Dmitriy Zaporozhets 6ec8ff069c Enable more rubocop style checks 2015-03-24 18:28:10 -07:00
Vinnie Okada ad0ca0499a Merge branch 'master' into fix-restricted-visibility
Conflicts:
	db/schema.rb
2015-03-14 10:49:11 -06:00
Vinnie Okada 285c534185 Allow admins to override restricted visibility
Allow admins to use restricted visibility levels when creating or
updating projects.
2015-03-08 16:10:05 -06:00
Jörg Thalheim 9f089ac48c use constant-time string compare for internal api authentication
Ruby str_equal uses memcmp internally to compare String.
Memcmp is vunerable to timing attacks because it returns early
on mismatch (on most x32 platforms memcmp uses a bytewise comparision).
Devise.secure_compare implements a constant time comparision instead.
2015-03-06 20:06:26 +01:00
Dmitriy Zaporozhets 558dd81197 Improve broadcast message API 2015-02-18 14:58:20 -08:00
Vinnie Okada b0dacc8eb0 Edit group members via API
Add an API endpoint to update the access level of an existing group
member.
2015-02-11 18:53:07 -07:00
Dmitriy Zaporozhets bdfb349ff7 Refactor and improve sorting objects in API for projects, issues and merge requests 2015-02-05 22:00:54 -08:00
Dmitriy Zaporozhets dc9bf32420 Merge pull request #8723 from jubianchi/api-groups-path
Access groups using path
2015-02-03 10:57:27 -08:00
jubianchi 4e97f26649 Acces groups with their path in API 2015-02-03 13:42:38 +01:00
Dmitriy Zaporozhets e890582681 Rubocop enabled for: Use spaces inside hash literal braces 2015-02-02 20:36:54 -08:00
Marin Jankovski 7fa80b5bd0 Update branch api not found messages to 'Branch not found'. 2014-12-30 13:37:14 +01:00
Valery Sizov e41dadcb33 Doorkeeper integration 2014-12-24 15:38:07 +02:00
Valery Sizov b5763e91cd add gitlab-shell identification 2014-10-15 20:03:25 +03:00
Ciro Santilli 2e9f5de868 Add parenthesis to function def with arguments. 2014-10-03 09:18:46 +02:00
jubianchi 998cd3cb63 Improve error reporting on users API
* users (#6878, #3526, #4209): Validation error messages are now exposed through 400 responses, 409 response are sent in case of duplicate email or username
* MRs (#5335): 409 responses are sent in case of duplicate merge request (source/target branches), 422 responses are sent when submiting MR fo/from unrelated forks
* issues
* labels
* projects
2014-09-16 01:25:24 +02:00
jubianchi 7ad93ab250 Improve labels validation and expose error messages 2014-08-20 12:09:19 +02:00
Robert Schilling cbc90565b5 Do label validation for issues/merge requests API 2014-08-14 10:17:52 +02:00
Sasha Joseph 37c4ba6f8d Add an option to GET /projects in the GitLab API to exclude archived projects 2014-07-28 12:48:13 -04:00
Dmitriy Zaporozhets 8fee5a0572
Make app works with strong params
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-06-26 23:24:17 +03:00
Dmitriy Zaporozhets a7be3dfa30
Remove set of thread variables
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-06-10 17:51:49 +03:00
Jacob Vosmaer 02b85fd236 Check user access status in API for current_user 2014-05-15 10:22:59 +02:00
Dmitriy Zaporozhets 33a00ceeea
Create branch via API
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-04-01 10:39:53 +03:00
Dmitriy Zaporozhets 046fa9bdb1 Merge pull request #5469 from NARKOZ/api-pagination-headers
add 'Link' header for API response
2014-03-31 13:46:57 +03:00
Dmitriy Zaporozhets a9f2903e86
Change project lookup order for api
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-03-14 15:58:52 +02:00
skv a3f645ef51 Remove deprecated finders 2014-01-19 23:39:56 +04:00
Dmitriy Zaporozhets 9d79d6e152
Make sure private_token for API is a string
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2013-11-08 18:49:38 +02:00
Nihad Abbasov 0678b8a426 add 'Link' header for API response 2013-10-29 13:41:20 +04:00
Dmitriy Zaporozhets 03dba1fd42 Merge pull request #5344 from amacarthur/thread-variable-fix
Fixing unsafe use of Thread.current variable :current_user
2013-10-16 23:30:44 -07:00
Nihad Abbasov 12420a2256 refactor by_username_or_id 2013-10-16 22:31:46 +05:00
Nihad Abbasov e09cc195a7 fix variable name 2013-10-16 22:28:39 +05:00
Angus MacArthur aefe2e952f Fixing unsafe use of Thread.current variable :current_user 2013-10-16 01:20:53 -04:00
Dmitriy Zaporozhets 836104b41a Merge pull request #5213 from bladealslayer/feature/user_api_extended
Extended User API to expose admin and can_create_group for user creation...
2013-09-29 23:03:46 -07:00
Dmitriy Zaporozhets 726fa6c76a Respect authorization in Repository API
* dont allow protect/unprotect branches for users without master permissions
* dont allow access to Repository api for guests
2013-09-29 16:04:57 +03:00
Boyan Tabakov 479631aafc Extended User API to expose admin and can_create_group for user creation/updating.
Also, is_admin and can_create_group are exposed in the user information.
Fixed attributes_for_keys to process properly keys with boolean values (since false.present? is false).
2013-09-29 11:47:29 +03:00
Izaak Alpert 7a56075efa Some of the requested updates, rebase on master
Change-Id: I305266fe9acbbb5136adeeb52e7e4e1d6629a30a
2013-09-09 12:04:38 -04:00
Izaak Alpert e86e881832 API: admin users can sudo commands as other users
-Specifying a header of SUDO or adding a :sudo with either user id, or username of the user will set the current_user to be that user if your identifying private_token/PRIVATE_TOKEN is an administrator token
2013-09-09 12:04:38 -04:00
Angus MacArthur ea5a006f27 Additon of apis for fork administration.
Added ability to add and remove the forked from/to relatioinship
between existing repos.
2013-07-08 17:34:00 -04:00
Dmitriy Zaporozhets 634cbd7138 Refactor API classes. So api classes like Gitlab::Issues become API::Issues 2013-05-14 15:33:31 +03:00
Sebastian Ziebell 7499f65014 API: extracted helper method to validate required parameters, code clean up
Added a helper method to check if required parameters are given in an API call. Can be used
to return a `400 Bad Request` return code if a required attribute is missing.
Code clean up and fixed tests.
2013-02-27 17:50:30 +01:00
Sebastian Ziebell 6fc3263e15 API: extracted helper method to provide 400 bad request error with description
Extracted a method for 400 error (Bad request) and adjusted code accordingly. The name of
the missing attribute is used to show which one was missing from the request. It is used to
give an appropriate message in the json response.
2013-02-13 15:48:52 +01:00
Dmitriy Zaporozhets 439d03bbed Fix namespace api autocomplete 2012-12-12 12:54:28 +02:00
Dmitriy Zaporozhets c50ec72b52 Deprecate code for Project. Use title and path 2012-11-23 21:11:09 +03:00
Valeriy Sizov e7608cd6f9 API: private token via header 2012-10-02 18:43:35 +03:00
Valeriy Sizov 2e1c3c52bc #1606 Fixes 2012-10-02 18:08:04 +03:00
Valeriy Sizov e9c356092b #1606 API private token via the header 2012-10-02 18:02:21 +03:00
Valeriy Sizov 825081174a #1585 Api for user creation: base implementation 2012-10-02 12:46:01 +03:00
Dmitriy Zaporozhets 10d3a30b25 APi for commits. Better api docs 2012-09-21 13:22:30 +03:00
Alex Denisov b896880eb4 Method name changed 2012-09-16 20:08:57 +03:00
Alex Denisov 549c4c2202 API attributes refactored 2012-09-16 19:51:04 +03:00
Alex Denisov a065557208 Common errors method added 2012-09-10 13:49:00 +03:00
Alex Denisov 915dac0055 Error throwing moved to api_helper 2012-09-10 10:41:46 +03:00
randx b565f33472 Auth for API 2012-09-10 09:06:11 +03:00
Nihad Abbasov 76e4d94d43 add pagination to API 2012-09-03 04:46:29 -07:00
Nihad Abbasov cb32e0320a return 404 if project not found 2012-07-25 05:24:28 -07:00
Nihad Abbasov 1b95c8bff3 API: ability to get project by id 2012-07-25 02:18:30 -07:00
Nihad Abbasov 0f604e62fb refactor projects API 2012-07-06 06:36:43 -07:00
Nihad Abbasov 1d2c981860 return errors in json format 2012-06-29 03:52:20 -07:00
Nihad Abbasov 4ad91d3c11 add users API 2012-06-28 03:43:41 -07:00