diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-05-14 23:26:44 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-05-14 23:26:44 +0300 |
commit | e54ff51aca26469c143644a536c1825b63db5e45 (patch) | |
tree | 41eb7073e1ca6e8bbc3c50efead3138b8a80f24e | |
parent | e1982c32889399ff50881b00636f01d36dc7d9d1 (diff) | |
parent | 740dc412506f80699cb9f82930d948fa961c6c05 (diff) | |
download | gitlab-ce-e54ff51aca26469c143644a536c1825b63db5e45.tar.gz |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 2 | ||||
-rw-r--r-- | app/controllers/concerns/authenticates_with_two_factor.rb | 30 | ||||
-rw-r--r-- | app/controllers/sessions_controller.rb | 12 | ||||
-rw-r--r-- | doc/api/projects.md | 3 | ||||
-rw-r--r-- | lib/api/projects.rb | 7 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 9 |
8 files changed, 54 insertions, 12 deletions
diff --git a/CHANGELOG b/CHANGELOG index db3ffb3fb13..e70f28f7fef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.11.0 (unreleased) + - Fix broken view when viewing history of a file that includes a path that used to be another file (Stan Hu) - Don't show duplicate deploy keys - Fix commit time being displayed in the wrong timezone in some cases (Hannes Rosenögger) - Make the first branch pushed to an empty repository the default HEAD (Stan Hu) @@ -44,7 +44,7 @@ gem "browser" # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", '~> 7.1.11' +gem "gitlab_git", '~> 7.1.12' # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 2.0.2', require: 'grack' diff --git a/Gemfile.lock b/Gemfile.lock index ef7487ae5bc..ce1c8cf513d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -225,7 +225,7 @@ GEM mime-types (~> 1.19) gitlab_emoji (0.1.0) gemojione (~> 2.0) - gitlab_git (7.1.11) + gitlab_git (7.1.12) activesupport (~> 4.0) charlock_holmes (~> 0.6) gitlab-linguist (~> 3.0) diff --git a/app/controllers/concerns/authenticates_with_two_factor.rb b/app/controllers/concerns/authenticates_with_two_factor.rb new file mode 100644 index 00000000000..d5918a7af3b --- /dev/null +++ b/app/controllers/concerns/authenticates_with_two_factor.rb @@ -0,0 +1,30 @@ +# == AuthenticatesWithTwoFactor +# +# Controller concern to handle two-factor authentication +# +# Upon inclusion, skips `require_no_authentication` on `:create`. +module AuthenticatesWithTwoFactor + extend ActiveSupport::Concern + + included do + # This action comes from DeviseController, but because we call `sign_in` + # manually, not skipping this action would cause a "You are already signed + # in." error message to be shown upon successful login. + skip_before_action :require_no_authentication, only: [:create] + end + + # Store the user's ID in the session for later retrieval and render the + # two factor code prompt + # + # The user must have been authenticated with a valid login and password + # before calling this method! + # + # user - User record + # + # Returns nil + def prompt_for_two_factor(user) + session[:otp_user_id] = user.id + + render 'devise/sessions/two_factor' and return + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index d4ff0d97561..b89b4c27350 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,11 +1,7 @@ class SessionsController < Devise::SessionsController - prepend_before_action :authenticate_with_two_factor, only: [:create] + include AuthenticatesWithTwoFactor - # This action comes from DeviseController, but because we call `sign_in` - # manually inside `authenticate_with_two_factor`, not skipping this action - # would cause a "You are already signed in." error message to be shown upon - # successful login. - skip_before_action :require_no_authentication, only: [:create] + prepend_before_action :authenticate_with_two_factor, only: [:create] def new redirect_path = @@ -74,9 +70,7 @@ class SessionsController < Devise::SessionsController end else if user && user.valid_password?(user_params[:password]) - # Save the user's ID to session so we can ask for a one-time password - session[:otp_user_id] = user.id - render :two_factor and return + prompt_for_two_factor(user) end end end diff --git a/doc/api/projects.md b/doc/api/projects.md index 971fe96fb8e..17c014019ea 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -32,6 +32,7 @@ Parameters: - `order_by` (optional) - Return requests ordered by `id`, `name`, `path`, `created_at`, `updated_at` or `last_activity_at` fields. Default is `created_at` - `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` - `search` (optional) - Return list of authorized projects according to a search criteria +- `ci_enabled_first` - Return projects ordered by ci_enabled flag. Projects with enabled GitLab CI go first ```json [ @@ -134,6 +135,7 @@ Parameters: - `order_by` (optional) - Return requests ordered by `id`, `name`, `path`, `created_at`, `updated_at` or `last_activity_at` fields. Default is `created_at` - `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` - `search` (optional) - Return list of authorized projects according to a search criteria +- `ci_enabled_first` - Return projects ordered by ci_enabled flag. Projects with enabled GitLab CI go first ### List ALL projects @@ -149,6 +151,7 @@ Parameters: - `order_by` (optional) - Return requests ordered by `id`, `name`, `path`, `created_at`, `updated_at` or `last_activity_at` fields. Default is `created_at` - `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` - `search` (optional) - Return list of authorized projects according to a search criteria +- `ci_enabled_first` - Return projects ordered by ci_enabled flag. Projects with enabled GitLab CI go first ### Get single project diff --git a/lib/api/projects.rb b/lib/api/projects.rb index e3fff79d68f..1f2251c9b9c 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -22,7 +22,12 @@ module API projects = projects.search(params[:search]) end - projects.reorder(project_order_by => project_sort) + if params[:ci_enabled_first].present? + projects.includes(:gitlab_ci_service). + reorder("services.active DESC, projects.#{project_order_by} #{project_sort}") + else + projects.reorder(project_order_by => project_sort) + end end def project_order_by diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index cc387378d3a..aada7febf6c 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -86,6 +86,15 @@ describe API::API, api: true do expect(json_response).to be_an Array expect(json_response.first['id']).to eq(project3.id) end + + it 'returns projects in the correct order when ci_enabled_first parameter is passed' do + [project, project2, project3].each{ |project| project.build_missing_services } + project2.gitlab_ci_service.update(active: true, token: "token", project_url: "url") + get api('/projects', user), { ci_enabled_first: 'true'} + expect(response.status).to eq(200) + expect(json_response).to be_an Array + expect(json_response.first['id']).to eq(project2.id) + end end end end |