Commit Graph

2293 Commits

Author SHA1 Message Date
Sean McGivern 5883ce95ef `current_application_settings` belongs on `Gitlab::CurrentSettings`
The initializers including this were doing so at the top level, so every object
loaded after them had a `current_application_settings` method. However, if
someone had rack-attack enabled (which was loaded before these initializers), it
would try to load the API, and fail, because `Gitlab::CurrentSettings` didn't
have that method.

To fix this:

1. Don't include `Gitlab::CurrentSettings` at the top level. We do not need
   `Object.new.current_application_settings` to work.
2. Make `Gitlab::CurrentSettings` explicitly `extend self`, as we already use it
   like that in several places.
3. Change the initializers to use that new form.
2017-08-31 13:38:33 +01:00
Robert Speicher 966b635221 Merge branch '28453-add-time-estimate-time-spent-to-api-issue-output' into 'master'
Add time stats to Issue and Merge Request API

Closes #28453

See merge request !13335
2017-08-30 17:35:14 +00: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
Sean McGivern 2f1ef2be6f Merge branch '37198-api-doesn-t-respect-default-group-visibility' into 'master'
Respect the default visibility level when creating a group via the API

Closes #37198

See merge request !13903
2017-08-30 10:04:00 +00:00
Sean McGivern f11049ab91 Merge branch 'api-delete-respect-headers' into 'master'
API: Respect the 'If-Unmodified-Since' for delete endpoints

See merge request !9621
2017-08-30 09:56:17 +00:00
Robert Schilling 9edaff0d35 Make rubocop happy 2017-08-30 10:11:24 +02:00
Robert Schilling 67c042e4a5 Respect the default visibility level when creating a group 2017-08-29 16:49:43 +02:00
Travis Miller 749c389345 Add time stats to issue and merge request API end points 2017-08-29 08:31:36 -05:00
Travis Miller ce1ce82045 Resolve new N+1 by adding preloads and metadata to issues end points 2017-08-29 08:31:36 -05:00
Maxim Rydkin 9226804bf3 replace `is_runner_queue_value_latest?` with `runner_queue_value_latest?` 2017-08-29 11:14:41 +03:00
Robert Schilling ee4820a526 Add a spec when ressource is not modified 2017-08-29 10:12:10 +02:00
Robert Schilling dcd4ea473c Update remaining endpoints 2017-08-28 17:10:30 +02:00
Robert Schilling f0f3f38576 Use commit date for branches and tags 2017-08-28 16:40:25 +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
Nick Thomas 2adff699ce Refactor complicated API group finding rules into GroupsFinder 2017-08-24 11:33:09 +01:00
Nick Thomas 502d6464b0 Allow v4 API GET requests for groups to be unauthenticated 2017-08-23 18:30:53 +01:00
Toon Claes e17d9529fa Total Pages should be at least one
And the link to the last page cannot be `page=0`.
2017-08-17 21:47:01 +02:00
Jordan Patterson fdf4f0fc08 don't add next page link if current page is out of range 2017-08-17 21:47:01 +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
Rémy Coutable fcce6c3168 Merge branch 'rs-more-public-send-whitelists' into 'master'
Whitelist or fix additional `Gitlab/PublicSend` cop violations

See merge request !13467
2017-08-16 11:25:26 +00:00
Robert Speicher 4edfad9678 Enable Layout/TrailingWhitespace cop and auto-correct offenses 2017-08-15 13:44:37 -04:00
Felipe Artur b7e9862004 Fix API responses when dealing with txt files 2017-08-15 11:32:48 -03:00
Robert Speicher 260c8da060 Whitelist or fix additional `Gitlab/PublicSend` cop violations
An upcoming update to rubocop-gitlab-security added additional
violations.
2017-08-14 12:14:11 -04:00
Yorick Peterse aef9f1eb94
Cache the number of forks of a project
The number of forks of a project doesn't change very frequently and
running a COUNT(*) every time this information is requested can be quite
expensive. We also end up running such a COUNT(*) query at least twice
on the homepage of a project.

By caching this data and refreshing it when necessary we can reduce
project homepage loading times by around 60 milliseconds (based on the
timings of https://gitlab.com/gitlab-org/gitlab-ce).
2017-08-14 18:00:28 +02:00
Rémy Coutable 455dc74e65 Merge branch 'disable-project-export' into 'master'
Add option to disable project export on instance

See merge request !13211
2017-08-11 17:33:45 +00:00
Robin Bobbitt 649d042dbc Add option to disable project export on instance 2017-08-11 12:22:37 -04:00
Sean McGivern 0887a2bd10 Merge branch '36213-return-is_admin-in-users-api-when-current_user-is-admin' into 'master'
Include the `is_admin` field in the `GET /users/:id` API when current user is an admin

Closes #36213

See merge request !13501
2017-08-11 15:46:17 +00:00
Sean McGivern e80a893ff0 Merge branch 'split-events-into-push-events' into 'master'
Use a separate table for storing push events

See merge request !12463
2017-08-11 14:40:03 +00:00
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 4f0fa13eb8 Show error message for API 500 error in tests, and
document have_gitlab_http_status
2017-08-11 20:50:35 +08:00
Yorick Peterse 0395c47193
Migrate events into a new format
This commit migrates events data in such a way that push events are
stored much more efficiently. This is done by creating a shadow table
called "events_for_migration", and a table called "push_event_payloads"
which is used for storing push data of push events. The background
migration in this commit will copy events from the "events" table into
the "events_for_migration" table, push events in will also have a row
created in "push_event_payloads".

This approach allows us to reclaim space in the next release by simply
swapping the "events" and "events_for_migration" tables, then dropping
the old events (now "events_for_migration") table.

The new table structure is also optimised for storage space, and does
not include the unused "title" column nor the "data" column (since this
data is moved to "push_event_payloads").

== Newly Created Events

Newly created events are inserted into both "events" and
"events_for_migration", both using the exact same primary key value. The
table "push_event_payloads" in turn has a foreign key to the _shadow_
table. This removes the need for recreating and validating the foreign
key after swapping the tables. Since the shadow table also has a foreign
key to "projects.id" we also don't have to worry about orphaned rows.

This approach however does require some additional storage as we're
duplicating a portion of the events data for at least 1 release. The
exact amount is hard to estimate, but for GitLab.com this is expected to
be between 10 and 20 GB at most. The background migration in this commit
deliberately does _not_ update the "events" table as doing so would put
a lot of pressure on PostgreSQL's auto vacuuming system.

== Supporting Both Old And New Events

Application code has also been adjusted to support push events using
both the old and new data formats. This is done by creating a PushEvent
class which extends the regular Event class. Using Rails' Single Table
Inheritance system we can ensure the right class is used for the right
data, which in this case is based on the value of `events.action`. To
support displaying old and new data at the same time the PushEvent class
re-defines a few methods of the Event class, falling back to their
original implementations for push events in the old format.

Once all existing events have been migrated the various push event
related methods can be removed from the Event model, and the calls to
`super` can be removed from the methods in the PushEvent model.

The UI and event atom feed have also been slightly changed to better
handle this new setup, fortunately only a few changes were necessary to
make this work.

== API Changes

The API only displays push data of events in the new format. Supporting
both formats in the API is a bit more difficult compared to the UI.
Since the old push data was not really well documented (apart from one
example that used an incorrect "action" nmae) I decided that supporting
both was not worth the effort, especially since events will be migrated
in a few days _and_ new events are created in the correct format.
2017-08-10 17:45:44 +02:00
Rémy Coutable c946ee1282
Enable the Layout/SpaceBeforeBlockBraces cop
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-08-09 11:52:22 +02:00
Brian Neel 9770c57fab Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
Sean McGivern 5b08d59f07 Merge branch 'rc/fix-commits-api' into 'master'
Fix the /projects/:id/repository/commits endpoint to handle dots in the ref name…

Closes #15651

See merge request !13370
2017-08-08 12:54:55 +00:00
sue445 7bc0486162 Expose noteable_iid in Note 2017-08-08 11:31:55 +00:00
Rémy Coutable 023a3f7a3b
Fix the /projects/:id/repository/commits endpoint to handle dots in the ref name when the project full path contains a `/`
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-08-08 12:54:07 +02:00
Rémy Coutable 10fe62ec80
Fix the /projects/:id/repository/tags endpoint to handle dots in the tag name when the project full path contains a `/`
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-08-08 11:50:58 +02:00
Mike Greiling 7767ceef47 Merge branch 'master' into ide
* master: (177 commits)
  Add changelog
  Bump gitlab-shell version to 5.8.0 to fix Git for Windows 2.14
  Make contextual sidebar collapsible
  Fixed sidebar context header hover colors
  Use correct `Environment`-class within `Gitlab` namespace
  Remove gl.Activities from Commits page
  Move `let` calls inside the `describe` block using them
  Add `/assign me` alias support for assigning issuables to oneself
  GRPC::Unavailable (< GRPC::BadStatus) is wrapped in a CommandError
  Use `broken_storage` in the fs_shards_spec.
  Eager load project creators for project dashboards
  Memoize a user's personal projects count
  Remove redundant query from User#recent_push
  Improve checking if projects would be returned
  Change spelling of gitlab-shell
  Remove unused #tree-holder
  Add custom linter for inline JavaScript to haml_lint
  Rename user_can_admin? because it's more accurate
  Synchronous zanata community contribution translation
  Add Korean translation to i18n
  ...
2017-08-07 15:20:09 -05:00
Sean McGivern 5bf65c9306 Merge branch 'bvl-nfs-circuitbreaker' into 'master'
Circuitbreaker for storage paths

Closes #32207, #33117, gitlab-com/infrastructure#1946, and gitlab-com/infrastructure#1775

See merge request !11449
2017-08-07 14:56:15 +00:00
Rémy Coutable 81933cfdd3 Merge branch '32300__expose_more_attributes' into 'master'
Expose more attributes to unauthenticated GET /projects/:id

See merge request !13283
2017-08-07 09:52:37 +00:00
Douwe Maan 9c7602d104 Fix batch commit API 2017-08-04 19:25:35 +02:00
Douwe Maan d41479266d Add start_branch to files and commits APIs 2017-08-04 19:18:07 +02:00
Bob Van Landuyt 3598e60bf2 Add a Circuitbreaker for storage paths 2017-08-04 15:38:48 +02:00
Toon Claes a723cba574 Avoid plucking Todo ids and use sub-queries instead
TodoService should not call `.select(&:id)` on todos, because this is
bad performance. So instead use sub-queries, which will result in a
single SQL query to the database.

https://docs.gitlab.com/ee/development/sql.html#plucking-ids
2017-08-03 16:31:05 +02:00
Tony 3c8b2ae168 Expose more attributes to unauthenticated GET /projects/:id 2017-08-03 16:42:11 +03:00
Sean McGivern 1018ab0516 Merge branch 'dm-api-current-user' into 'master'
Do not validate CSRF token in API unless needed

Closes #35705

See merge request !13256
2017-08-03 10:47:03 +00:00
Douwe Maan 14644d40e0 Do not validate CSRF token in API unless needed 2017-08-02 18:20:31 +02:00
Rémy Coutable 1b117e7f2d Merge branch 'api_project_events_target_iid' into 'master'
Expose target_iid in Events API

See merge request !13247
2017-08-02 10:34:35 +00:00
Eric fb5b2d8d0e Extending API for protected branches 2017-08-02 10:16:17 +00:00