Commit Graph

2835 Commits

Author SHA1 Message Date
Johan H ae95118a4f Convert UTF-8 Emoji to Gitlab emoji 2016-10-13 13:18:30 +02:00
henrik 8caf097a16 Convert unicode emojis to images. 2016-10-11 15:41:10 +02:00
Robert Speicher 1659c3b871 Merge branch 'explain-0600' into 'master'
Explain the extra chmod

There is confusion about what passing `0600` to File.open does.

```
$ touch /tmp/foobar
$ ls -l /tmp/foobar
-rw-r--r--  1 jacobvosmaer  wheel  0 Sep 26 14:20 /tmp/foobar
$ ruby -e 'File.open("/tmp/foobar", "w", 0600)'
$ ls -l /tmp/foobar
-rw-r--r--  1 jacobvosmaer  wheel  0 Sep 26 14:20 /tmp/foobar
$ 
$ 
$ rm /tmp/foobar
$ ruby -e 'File.open("/tmp/foobar", "w", 0600)'
$ ls -l /tmp/foobar
-rw-------  1 jacobvosmaer  wheel  0 Sep 26 14:21 /tmp/foobar
```

See merge request !6523
2016-10-10 15:18:46 +00:00
Will Starms 4f1de5faac Correct namespace validation to forbid bad names #21077
Adds .git and .atom to the master namespace regex
Updates existing group tests and adds two new ones
Updates path cleaning to also forbid .atom
2016-10-07 13:46:59 -05: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
Rémy Coutable 0a7678b58a Merge branch 'fix/github-importer-client' into 'master'
Fix broken handling of certain calls in GitHub importer client

## What does this MR do?
It changes/fixes the behavior of request handling in GH client. Now it returns the response directly if it's not a collection of resources. Otherwise, it checks for a passed block, if true, then it yield each page to said block, if not, it collects all response in a single array then returns it.

Closes #22998

See merge request !6703
2016-10-06 13:29:08 +00:00
Ahmad Sherif 333c02a8c8 Fix broken handling of certain calls in GitHub importer client
Closes #22998
2016-10-06 11:14:25 +02:00
Paco Guzman 640a4c8834 Use higher size on Gitlab::Redis connection pool on Sidekiq servers 2016-10-06 10:50:03 +02:00
Rémy Coutable 67aabcc764 Merge remote-tracking branch 'dev/master' 2016-10-06 08:34:39 +02:00
Rémy Coutable d51bb99a7e
Merge commit 'dev/security' into 'master'
Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-10-06 08:33:11 +02:00
Rémy Coutable c9396bc7c5 Merge branch 'test-improve-gitlab-identifier' into 'master'
Refactor Gitlab::Identifier

## What does this MR do?

This refactors `Gitlab::Identifier` so that it:

1. Has tests
2. Caches output in an instance variable to reduce queries
3. Uses only a single query to find a user by an SSH key, instead of 2

## Why was this MR needed?

This code was untested and would execute more SQL queries than needed.

See merge request !6680
2016-10-05 11:38:58 +00:00
Yorick Peterse 16ed9b6129
Refactor Gitlab::Identifier
This refactors Gitlab::Identifier so it uses fewer queries and is
actually tested. Queries are reduced by caching the output as well as
using 1 query (instead of 2) to find a user using an SSH key.
2016-10-05 12:40:17 +02:00
Douglas Barbosa Alexandre b5f9541778 Skip wiki creation when GitHub project has wiki enabled
If the GitHub project repository has wiki, we should not create
the default wiki. Otherwise the GitHub importer will fail because
the wiki repository already exist.

This bug was introduced here
https://gitlab.com/gitlab-org/gitlab-ce/commit/892dea67717c0efbd6a28f763
9f34535ec0a8747
2016-10-04 13:06:45 -03:00
Rémy Coutable 8d333c87f1 Merge branch 'aiionx_sidekiq_log_patch' into 'master'
Log sidekiq arguments as json

Logging the sidekiq job arguments as a ruby literal structure 
is akward. Specially when parsing the logs.

JSON is a standar format.



See merge request !3735
2016-10-03 14:20:18 +00:00
Robert Speicher e64594ac44 Merge branch '21983-member-add_user-doesn-t-detect-existing-members-that-have-requested-access' into 'master'
Resolve "`Member.add_user`doesn't detect existing members that have requested access"

## What does this MR do?

This merge request handle the case when an access requester is added to a group or project (via the members page or the API).

In `Member.add_user`, if an access requester already exists, we simply accept their request (and set the `created_by`, `access_level` and `expires_at` attributes if given).

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

I've taken the opportunity to cleanup the whole `{Group,Project}Member.add_user*` methods since it was quite a mess.

## What are the relevant issue numbers?

Closes #21983

See merge request !6393
2016-10-02 11:42:57 +00:00
James Lopez 958d9f11e8 fix export project file permissions issue 2016-09-30 16:10:48 +02:00
Yorick Peterse b9daced7a2 Merge branch 'initialize-redis' into 'master'
Initialize Redis pool in single-threaded context

See merge request !6613
2016-09-30 12:32:18 +00:00
Jacob Vosmaer 52ee85e7bf Initialize Redis pool in single-threaded context
This side-steps the need for mutexes and whatnot.
2016-09-30 12:27:43 +02:00
Douwe Maan 8a866bfce3 Merge branch 'fix/id-claim-import-issue' into 'master'
Prevent claiming associated model IDs via import

On the import side, we should be careful not to use any IDs as part of the JSON file that could have been manipulated.

Part of https://gitlab.com/gitlab-org/gitlab-ce/issues/20821


Things we already do (__before__ this fix):

1. Remove all primary keys
1. **Always** reassign some of the foreign keys, such as ALL project IDs and user IDs (so it would be difficult to impersonate or try to gain access to another project)
1. Ignore/reject attributes that do not exist in the model
1. If someone reassigns a foreign key `submodel_id`, and that object has another json as the submodel, the new submodel will reassign the `submodel_id` to the newly created submodel ID.

Things we should do:

1. Remove/nullify any other foreign keys that we don't reassign (checked this, and there aren't many, fortunately. In fact, I don't think much harm can be done at all - at the moment).

See merge request !1985
2016-09-30 07:31:02 +00:00
Patricio Cano 26678d8ea3 Fix race condition that can be triggered if the token expires right after we retrieve it, but before we can set the new expiry time. 2016-09-29 10:25:26 -05:00
Douwe Maan 029c0d79af Merge branch 'lfs-ssh-authorization-fix' into 'master'
Do not regenerate the `lfs_token` every time `git-lfs-authenticate` is called

## What does this MR do?

 Do not regenerate the `lfs_token` every time `git-lfs-authenticate` is called, instead return the saved token if one is present.

This was causing a lot of 401s, leading to 403s, as state in #22527

As it turns out, when pushing a lot of LFS objects, the LFS client was calling `git-lfs-authenticate` in the middle of the request again. This caused the `lfs_token` to be regenerated. The problem lies in that the LFS client was not aware of this change, and was still using the old token. This caused all subsequent requests to fail with a 401 error.

Since HTTP Auth is protected by Rack Attack, this 401s where immediately flagged and resulted in the IP of the user being banned. 

With this change, GitLab returns the value stored in Redis, if one is present, thus if the LFS client calls `git-lfs-authenticate` again during the request, the auth header will remain unchanged, allowing all subsequent requests to continue without issues.

## What are the relevant issue numbers?

Fixes #22527

cc @SeanPackham @jacobvosmaer-gitlab

See merge request !6551
2016-09-28 18:13:34 +00:00
Patricio Cano 2772109ac1 Handle LFS token creation and retrieval in the same method, and in the same Redis connection.
Reset expiry time of token, if token is retrieved again before it expires.
2016-09-28 12:13:48 -05:00
Rémy Coutable ec0061a95c Allow Member.add_user to handle access requesters
Changes include:

- Ensure Member.add_user is not called directly when not necessary
- New GroupMember.add_users_to_group to have the same abstraction level as for Project
- Refactor Member.add_user to take a source instead of an array of members
- Fix Rubocop offenses
- Always use Project#add_user instead of project.team.add_user
- Factorize users addition as members in Member.add_users_to_source
- Make access_level a keyword argument in GroupMember.add_users_to_group and ProjectMember.add_users_to_projects
- Destroy any requester before adding them as a member
- Improve the way we handle access requesters in Member.add_user
  Instead of removing the requester and creating a new member,
  we now simply accepts their access request. This way, they will
  receive a "access request granted" email.
- Fix error that was previously silently ignored
- Stop raising when access level is invalid in Member, let Rails validation do their work

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-09-28 09:43:00 +02:00
Markus Koller 68364fe2f0
Log LDAP lookup errors and don't swallow unrelated exceptions
Signed-off-by: Roger Meier <r.meier@siemens.com>
2016-09-28 07:44:58 +02:00
Ahmad Sherif dca1acd6a6 Call after_remove_branch only once after importing all GitHub PRs 2016-09-27 20:45:07 +02:00
Ahmad Sherif e30bfb809a Import all GitHub comments after importing issues and PRs 2016-09-27 20:45:07 +02:00
Ahmad Sherif dbcbbf262b Speed up label-applying process for GitHub importing
* No need to re-fetch issues from GH to read their labels, the labels
  are already there from the index request.
* No need to look up labels on the database for every application, so we
  cache them.
2016-09-27 20:45:07 +02:00
Ahmad Sherif 395a9301b2 Process each page of GitHub resources instead of concating them then processing
This should avoid having large memory growth when importing GitHub repos
with lots of resources.
2016-09-27 20:45:07 +02:00
Patricio Cano a4944fb715 Do not regenerate the `lfs_token` every time `git-lfs-authenticate` is called, instead return the saved token if one is present. 2016-09-27 13:23:51 -05:00
James Lopez 9e0b7c630f updated attribute cleaner to use allowed keyword and reject attributes 2016-09-27 16:12:08 +02:00
James Lopez 4c480be39b Prevent claiming associated model IDs via import and added relevant specs 2016-09-27 15:48:10 +02:00
James Lopez fc548207d5 fix model order in import/export config and 1to1 relation issue. Added relevant specs. 2016-09-27 14:56:33 +02:00
Jacob Vosmaer 05745737c6 Explain the extra chmod 2016-09-26 14:21:39 +02:00
James Lopez a9f1e972ec Fixes issue with rails reserved keyword type exporting/importing services. Also fixed CustomIssueTrackerService title setter and added relevant specs. 2016-09-26 09:49:05 +02:00
Robert Speicher 0a9f9c10e4 Merge branch '22229-use-base-sha-when-downloading-merge-requests' into 'master'
Use base SHA for patches and diffs

## What does this MR do?

Switch from using 'start SHA' to 'base SHA' for patches and diffs

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

## Why was this MR needed?

Makes the downloaded patches and diffs on the merge request page match the frontend-rendered "changes" in these scenarios:

* Unpatched gitlab-workhorse, downloading patchsets of open MRs (https://gitlab.com/gitlab-org/gitlab-workhorse/merge_requests/68)
* Unpatched gitlab-workhorse, downloading diffs of open and merged MRs
* Patched gitlab-workhorse, downloading patchsets of merged merge requests

## What are the relevant issue numbers?

Closes #22229

See merge request !6435
2016-09-25 10:30:37 +00:00
Rémy Coutable c2b8063fda Merge branch 'fix/database-seeds' into 'master'
Fix database seeds for development environment

## What does this MR do?

This MR fixes database seeds for development environment and adds CI test for it.

## Why was this MR needed?

Database seeds for development environment are often broken, and we are not able to catch that when someone modified `db/fixtures` and forgets to reseed database.

Closes #22422

See merge request !6475
2016-09-23 14:50:36 +00:00
Grzegorz Bizon cee66810f8 Remove use of `USE_DB` environment variable in code 2016-09-23 10:50:46 +02:00
Nick Thomas a8829f25d3 Use base SHA for patches and diffs
This commit changes the revisions used for diffs. The current behaviour is
to show all changes between current tip of master and tip of the MR, rather
than matching the output of the web frontend (which just shows the changes
in the MR). Switching from start_sha to base_sha fixes this.
2016-09-22 18:49:31 +01:00
Grzegorz Bizon 52e897dd14 Update `CurrentSettings` class that uses ENV 2016-09-22 17:25:52 +02:00
Jacob Vosmaer b228b86b3e Make Gitlab::Redis.params safe for mutation 2016-09-22 15:58:40 +02:00
James Lopez ad62a25e0f fix import/export security specs after merge 2016-09-21 15:47:11 -05:00
Rémy Coutable a25ac8a89b Merge branch 'add_spec_for_committer_hash' into 'master'
Add spec covering 'committer_hash'

Adds a missing spec from changes added in !5822

See merge request !6433
2016-09-21 10:15:00 +00:00
Dmitriy Zaporozhets c2a7e7b8ac Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce 2016-09-21 12:22:02 +03:00
Stan Hu 5416ab8a0d Merge branch '21170-cycle-analytics' into 'master'
Cycle Analytics: first iteration

## What does this MR do?

- Implement the first iteration of the "Cycle Analytics" feature.

## What are the relevant issue numbers?

- Closes #21170 

## Screenshots

![cycle_analytics_screencast.gif](/uploads/d23c3c912caa6935fd47b53ca3a56b97/cycle_analytics.gif)

## Backend Tasks

- [x]  Implementation
    - [x]  Phases
        - [x]  Issue (Tracker)
        - [x]  Plan (Board)
        - [x]  Code (IDE)
        - [x]  Test (CI)
        - [x]  Review (MR)
        - [x]  Staging (CD)
        - [x]  Production (Total)
    - [x]  Make heuristics more modular
    - [x]  Scope to project
    - [x]  Date range (30 days, 90 days)
    - [x]  Access restriction
- [x]  Test
    - [x]  Find a better way to test these phases
    - [x]  Phases
        - [x]  Issue (Tracker)
        - [x]  Plan (Board)
        - [x]  Code (IDE)
        - [x]  Test (CI)
        - [x]  Review (MR)
        - [x]  Staging (CD)
        - [x]  Production (Total)
    - [x]  Test for "end case happens before start case"
    - [x]  Consolidate helper
- [x]  Miniboss review
- [x]  Performance testing with mock data
- [x]  Improve performance
    - [x]  Pre-calculate "merge requests closing issues
    - [x]  Pre-calculate everything else
- [x]  Test performance against 10k issues
- [x]  Test all pre-calculation code
    - [x]  Ci::Pipeline -> build start/finish
    - [x]  Ci::Pipeline#merge_requests
    - [x]  Issue -> record default metrics after save
    - [x]  MergeRequest -> record default metrics after save
    - [x]  Deployment -> Update "first_deployed_to_production_at" for MR metrics
    - [x]  Git Push -> Update "first commit mention" for issue metrics
    - [x]  Merge request create/update/refresh -> Update "merge requests closing issues"
- [x]  Remove `MergeRequestsClosingIssues` when necessary
- [x]  Changes to unblock Fatih
    - [x]  Add summary data
    - [x]  `stats` should be array
    - [x]  Let `stats` be `null` if all `stats` are null
- [x]  Indexes for "merge requests closing issues"
- [x]  Test summary data
- [x]  Scope everything to project
    - [x]  Find out why tests were passing
- [x]  Filter should include issues/MRs which have made it to production within the range
- [x]  Don't create duplicate `MergeRequestsClosingIssues`
- [x]  Fix tests
- [x]  MySQL median
- [x]  Assign to Douwe for review
- [x]  Fix conflicts
- [x]  Implement suggestions from Yorick's review
    - [x]  Test on PG
    - [x]  Test on MySQL
- [x]  Refactor
    - [x]  Cleanup
        - [x]  What happens if we have no data at all?
        - [x]  Extract common queries to methods / scopes
    - [x]  Remove unused queries
    - [x]  Downtime for foreign key migrations
    - [x]  Find a way around "if issue.metrics.present?" all over the place
    - [x]  Find a way around "if merge_request.metrics.present?" all over the place
    - [x]  Test migrations on a fresh database
        - [x]  MySQL
        - [x]  Pg
- [x]  Access issues
    - While the project is public and the visibility is set to "Everyone with access", you cannot visit the cycle analytics page when signed out.
- [x]  CHANGELOG
- [x]  Implement suggestions from Douwe's review
    - [x]  First set of comments
    - [x]  Second set of comments
    - [x]  Third set of comments
    - [x]  Fourth set of comments
- [x]  Make sure build is green
- [ ]  Make issue for "polish"
- [ ]  EE MR


See merge request !5986
2016-09-21 05:05:02 +00:00
Timothy Andrew 244ec0a84c Implement fourth round of comments from @DouweM.
- Pluralize summary titles
- Remove the `run_query` method - always return sql strings from the
  `date_time_sql` methods
2016-09-21 09:57:14 +05:30
Timothy Andrew 6df2d57394 Improve indentation in `Gitlab::Database::Median` 2016-09-21 02:18:57 +05:30
Timothy Andrew 918e589c2b Implement a second round of review comments from @DouweM.
- Don't use `TableReferences` - using `.arel_table` is shorter!
- Move some database-related code to `Gitlab::Database`
- Remove the `MergeRequest#issues_closed` and
  `Issue#closed_by_merge_requests`  associations. They were either
  shadowing or were too similar to existing methods. They are not being
  used anywhere, so it's better to remove them to reduce confusion.
- Use Rails 3-style validations
- Index for `MergeRequest::Metrics#first_deployed_to_production_at`
- Only include `CycleAnalyticsHelpers::TestGeneration` for specs that
  need it.
- Other minor refactorings.
2016-09-21 00:47:37 +05:30
Dan Dunckel 02d69091bc Add spec covering 'committer_hash' 2016-09-20 10:15:43 -07:00
Rémy Coutable f0bda348bb Merge branch 'add_optional_author_for_commits' into 'master'
Add optional 'author' param when making commits

This fulfills https://gitlab.com/gitlab-org/gitlab-ce/issues/20789 by adding the ability to specify a user's ID to be used as the author of a commit.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/20789

See merge request !5822
2016-09-20 15:30:00 +00:00
Timothy Andrew 231a9f5b87 Fix rubocop spec.
And `scss_lint`
2016-09-20 18:26:31 +05:30