From b69f8a62b2078fbd43413c670dea76871b74d0d5 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Wed, 30 Mar 2016 15:04:58 -0300 Subject: [PATCH 001/212] Add specific markdown_preview route for Wikis --- app/controllers/projects/wikis_controller.rb | 14 ++++++++++++++ app/views/layouts/project.html.haml | 6 +++++- config/routes.rb | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb index 02ceb8f433..9f3a4a6972 100644 --- a/app/controllers/projects/wikis_controller.rb +++ b/app/controllers/projects/wikis_controller.rb @@ -88,6 +88,20 @@ class Projects::WikisController < Projects::ApplicationController ) end + def markdown_preview + text = params[:text] + + ext = Gitlab::ReferenceExtractor.new(@project, current_user, current_user) + ext.analyze(text) + + render json: { + body: view_context.markdown(text, pipeline: :wiki, project_wiki: @project_wiki), + references: { + users: ext.users.map(&:username) + } + } + end + def git_access end diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml index ab527e8e43..a7ef31acd3 100644 --- a/app/views/layouts/project.html.haml +++ b/app/views/layouts/project.html.haml @@ -5,10 +5,14 @@ - content_for :scripts_body_top do - project = @target_project || @project + - if @project_wiki + - markdown_preview_path = namespace_project_wikis_markdown_preview_path(project.namespace, project) + - else + - markdown_preview_path = markdown_preview_namespace_project_path(project.namespace, project) - if current_user :javascript window.project_uploads_path = "#{namespace_project_uploads_path project.namespace,project}"; - window.markdown_preview_path = "#{markdown_preview_namespace_project_path(project.namespace, project)}"; + window.markdown_preview_path = "#{markdown_preview_path}"; - content_for :scripts_body do = render "layouts/init_auto_complete" if current_user diff --git a/config/routes.rb b/config/routes.rb index 6bf22fb445..e57c04595f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -575,6 +575,7 @@ Rails.application.routes.draw do # Order matters to give priority to these matches get '/wikis/git_access', to: 'wikis#git_access' get '/wikis/pages', to: 'wikis#pages', as: 'wiki_pages' + post '/wikis/markdown_preview', to:'wikis#markdown_preview' post '/wikis', to: 'wikis#create' get '/wikis/*id/history', to: 'wikis#history', as: 'wiki_history', constraints: WIKI_SLUG_ID From 7d56d592cd7d1df718d59981af1ced9d0be8eaac Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Wed, 30 Mar 2016 15:30:36 -0300 Subject: [PATCH 002/212] Fixed Gollum pages link url expansion to render correctly in preview --- lib/banzai/filter/gollum_tags_filter.rb | 12 +++++++++--- spec/lib/banzai/filter/gollum_tags_filter_spec.rb | 8 +++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/banzai/filter/gollum_tags_filter.rb b/lib/banzai/filter/gollum_tags_filter.rb index 7ce26db1b9..cfd3e28ed0 100644 --- a/lib/banzai/filter/gollum_tags_filter.rb +++ b/lib/banzai/filter/gollum_tags_filter.rb @@ -144,12 +144,18 @@ module Banzai # if it is not. def process_page_link_tag(parts) if parts.size == 1 - url = parts[0].strip + reference = parts[0].strip else - name, url = *parts.compact.map(&:strip) + name, reference = *parts.compact.map(&:strip) end - content_tag(:a, name || url, href: url) + if url?(reference) + href = reference + else + href = ::File.join(project_wiki_base_path, reference) + end + + content_tag(:a, name || reference, href: href) end def project_wiki diff --git a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb index 5e23c5c319..ad777fe4b9 100644 --- a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb +++ b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb @@ -70,20 +70,22 @@ describe Banzai::Filter::GollumTagsFilter, lib: true do end context 'linking internal resources' do - it "the created link's text will be equal to the resource's text" do + it "the created link's text will include the resource's text and project_wiki_base_path" do tag = '[[wiki-slug]]' doc = filter("See #{tag}", project_wiki: project_wiki) + expected_path = ::File.join(project_wiki.wiki_base_path, 'wiki-slug') expect(doc.at_css('a').text).to eq 'wiki-slug' - expect(doc.at_css('a')['href']).to eq 'wiki-slug' + expect(doc.at_css('a')['href']).to eq expected_path end it "the created link's text will be link-text" do tag = '[[link-text|wiki-slug]]' doc = filter("See #{tag}", project_wiki: project_wiki) + expected_path = ::File.join(project_wiki.wiki_base_path, 'wiki-slug') expect(doc.at_css('a').text).to eq 'link-text' - expect(doc.at_css('a')['href']).to eq 'wiki-slug' + expect(doc.at_css('a')['href']).to eq expected_path end end From ccc929d75d1f34accc4c7a6604c26cac6113a18c Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 31 Mar 2016 11:50:00 -0500 Subject: [PATCH 003/212] CSS tweaks - Use colors according to design - Fix search input' width --- app/assets/stylesheets/framework/variables.scss | 8 ++++---- app/assets/stylesheets/pages/search.scss | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index bb49ae396c..b86dbcb04b 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -199,11 +199,11 @@ $award-emoji-new-btn-icon-color: #dcdcdc; /* * Search Box */ -$search-input-border-color: $dropdown-input-focus-border; +$search-input-border-color: rgba(#4688f1, .8); $search-input-focus-shadow-color: $dropdown-input-focus-shadow; -$search-input-width: $dropdown-width; +$search-input-width: 244px; $location-badge-color: #aaa; $location-badge-bg: $gray-normal; +$location-badge-active-bg: #4f91f8; $location-icon-color: #e7e9ed; -$location-active-color: $gl-text-color; -$location-active-bg: $search-input-border-color; +$location-icon-active-color: #807e7e; diff --git a/app/assets/stylesheets/pages/search.scss b/app/assets/stylesheets/pages/search.scss index 3c74d25beb..9274796233 100644 --- a/app/assets/stylesheets/pages/search.scss +++ b/app/assets/stylesheets/pages/search.scss @@ -135,13 +135,13 @@ .location-badge { @include transition(all .15s); - background-color: $location-active-bg; + background-color: $location-badge-active-bg; color: $white-light; } .search-input-wrap { i { - color: $location-active-color; + color: $location-icon-active-color; } } From e3a983050714aa54a3c7911666cdd0abbc36e57a Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 31 Mar 2016 15:28:45 -0500 Subject: [PATCH 004/212] Skip default behaviour if we are clicking a result for the same location --- app/assets/javascripts/gl_dropdown.js.coffee | 2 +- app/assets/javascripts/search_autocomplete.js.coffee | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index 0fea2a69cb..e4df7d46d5 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -174,7 +174,7 @@ class GitLabDropdown selected = self.rowClicked $(@) if self.options.clicked - self.options.clicked(selected) + self.options.clicked(selected, e) # Finds an element inside wrapper element getElement: (selector) -> diff --git a/app/assets/javascripts/search_autocomplete.js.coffee b/app/assets/javascripts/search_autocomplete.js.coffee index 030655491b..2656c6e30a 100644 --- a/app/assets/javascripts/search_autocomplete.js.coffee +++ b/app/assets/javascripts/search_autocomplete.js.coffee @@ -62,6 +62,8 @@ class @SearchAutocomplete search: fields: ['text'] data: @getData.bind(@) + selectable: true + clicked: @onClick.bind(@) getData: (term, callback) -> _this = @ @@ -268,3 +270,9 @@ class @SearchAutocomplete
  • Loading...
  • " @dropdownContent.html(html) + + onClick: (item, e) -> + if location.pathname.indexOf(item.url) isnt -1 + e.preventDefault() + @disableAutocomplete() + @searchInput.val('') From ff676333d0d257869a917a5e48e9717d219b8311 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 31 Mar 2016 19:28:17 -0500 Subject: [PATCH 005/212] Add current element and event as params to clicked callback --- app/assets/javascripts/gl_dropdown.js.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index e4df7d46d5..d447013f63 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -171,10 +171,11 @@ class GitLabDropdown selector = ".dropdown-page-one .dropdown-content a" @dropdown.on "click", selector, (e) -> - selected = self.rowClicked $(@) + $el = $(@) + selected = self.rowClicked $el if self.options.clicked - self.options.clicked(selected, e) + self.options.clicked(selected, $el, e) # Finds an element inside wrapper element getElement: (selector) -> From ab42560ea6c2fade09b8436a893bf4a269e67c39 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 31 Mar 2016 19:28:41 -0500 Subject: [PATCH 006/212] Return selected object if toggleLabel option is not defined --- app/assets/javascripts/gl_dropdown.js.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index d447013f63..ca8d9a1694 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -352,6 +352,8 @@ class GitLabDropdown # Toggle the dropdown label if @options.toggleLabel $(@el).find(".dropdown-toggle-text").text @options.toggleLabel + else + selectedObject else if !value? field.remove() From 824fecb728ae7534b8ef56aaa6679814f3924cd5 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 31 Mar 2016 19:31:01 -0500 Subject: [PATCH 007/212] Bring back search context when chosing the same project/group --- .../javascripts/search_autocomplete.js.coffee | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/search_autocomplete.js.coffee b/app/assets/javascripts/search_autocomplete.js.coffee index 2656c6e30a..564fb265b9 100644 --- a/app/assets/javascripts/search_autocomplete.js.coffee +++ b/app/assets/javascripts/search_autocomplete.js.coffee @@ -104,6 +104,8 @@ class @SearchAutocomplete lastCategory = suggestion.category data.push + id: "#{suggestion.category.toLowerCase()}-#{suggestion.id}" + category: suggestion.category text: suggestion.label url: suggestion.url @@ -271,8 +273,27 @@ class @SearchAutocomplete " @dropdownContent.html(html) - onClick: (item, e) -> + onClick: (item, $el, e) -> if location.pathname.indexOf(item.url) isnt -1 e.preventDefault() + if not @badgePresent + if item.category is 'Projects' + @projectInputEl.val(item.id) + @addLocationBadge( + value: 'This project' + ) + + if item.category is 'Groups' + @groupInputEl.val(item.id) + @addLocationBadge( + value: 'This group' + ) + + $el.removeClass('is-active') @disableAutocomplete() - @searchInput.val('') + @searchInput.val('').focus() + + # We need to wait because of @skipBlurEvent + setTimeout( => + @onSearchInputFocus() + , 200) From 28266d9d610123d20333c6b05fcf83d1fb3e336a Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Fri, 1 Apr 2016 00:17:37 -0300 Subject: [PATCH 008/212] Added WikiLinkFilter --- lib/banzai/filter/wiki_link_filter.rb | 52 +++++++++++++++++++++++++++ lib/banzai/pipeline/wiki_pipeline.rb | 6 ++-- 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 lib/banzai/filter/wiki_link_filter.rb diff --git a/lib/banzai/filter/wiki_link_filter.rb b/lib/banzai/filter/wiki_link_filter.rb new file mode 100644 index 0000000000..7a585eff65 --- /dev/null +++ b/lib/banzai/filter/wiki_link_filter.rb @@ -0,0 +1,52 @@ +require 'uri' + +module Banzai + module Filter + # HTML filter that "fixes" relative links to files in a repository. + # + # Context options: + # :project_wiki + class WikiLinkFilter < HTML::Pipeline::Filter + + def call + return doc unless project_wiki? + + doc.search('a:not(.gfm)').each do |el| + process_link_attr el.attribute('href') + end + + doc + end + + protected + + def project_wiki? + !context[:project_wiki].nil? + end + + def process_link_attr(html_attr) + return if html_attr.blank? + + uri = URI(html_attr.value) + if uri.relative? && uri.path.present? && uri.path + html_attr.value = rebuild_wiki_uri(uri).to_s + end + rescue URI::Error + # noop + end + + def rebuild_wiki_uri(uri) + uri.path = ::File.join(project_wiki_base_path, uri.path) + uri + end + + def project_wiki + context[:project_wiki] + end + + def project_wiki_base_path + project_wiki && project_wiki.wiki_base_path + end + end + end +end diff --git a/lib/banzai/pipeline/wiki_pipeline.rb b/lib/banzai/pipeline/wiki_pipeline.rb index 0b5a9e0b2b..1cdb380896 100644 --- a/lib/banzai/pipeline/wiki_pipeline.rb +++ b/lib/banzai/pipeline/wiki_pipeline.rb @@ -2,8 +2,10 @@ module Banzai module Pipeline class WikiPipeline < FullPipeline def self.filters - @filters ||= super.insert_after(Filter::TableOfContentsFilter, - Filter::GollumTagsFilter) + @filters ||= begin + super.insert_after(Filter::TableOfContentsFilter, Filter::GollumTagsFilter) + .insert_after(Filter::GollumTagsFilter, Filter::WikiLinkFilter) + end end end end From fb8b0041d86080f0f8d53f13be1016b0b199a47f Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 30 Mar 2016 18:53:30 -0400 Subject: [PATCH 009/212] First pass at a Testing styleguide [ci skip] --- CONTRIBUTING.md | 2 +- doc/development/README.md | 1 + doc/development/testing.md | 105 +++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 doc/development/testing.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 511336f384..1f26a5d7ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -448,7 +448,7 @@ merge request: - multi-line method chaining style **Option B**: dot `.` on previous line - string literal quoting style **Option A**: single quoted by default 1. [Rails](https://github.com/bbatsov/rails-style-guide) -1. [Testing](https://github.com/thoughtbot/guides/tree/master/style/testing) +1. [Testing](doc/development/testing.md) 1. [CoffeeScript](https://github.com/thoughtbot/guides/tree/master/style/coffeescript) 1. [SCSS styleguide][scss-styleguide] 1. [Shell commands](doc/development/shell_commands.md) created by GitLab diff --git a/doc/development/README.md b/doc/development/README.md index 1b281809af..a8bc4fe5ab 100644 --- a/doc/development/README.md +++ b/doc/development/README.md @@ -9,4 +9,5 @@ - [Shell commands](shell_commands.md) in the GitLab codebase - [Sidekiq debugging](sidekiq_debugging.md) - [SQL guidelines](sql.md) for SQL guidelines +- [Testing standards and style guidelines](testing.md) - [UI guide](ui_guide.md) for building GitLab with existing css styles and elements diff --git a/doc/development/testing.md b/doc/development/testing.md new file mode 100644 index 0000000000..d37ef5d878 --- /dev/null +++ b/doc/development/testing.md @@ -0,0 +1,105 @@ +# Testing Standards and Style Guidelines + +This guide outlines standards and best practices for automated testing of GitLab +CE and EE. + +It is meant to be an _extension_ of the [thoughtbot testing +styleguide](https://github.com/thoughtbot/guides/tree/master/style/testing). If +this guide defines a rule that contradicts the thoughtbot guide, this guide +takes precedence. Some guidelines may be repeated verbatim to stress their +importance. + +## Factories + +GitLab uses [factory_girl] as a test +fixture replacement. + +- Factory definitions live in `spec/factories/`, named using the pluralization + of their corresponding model (`User` factories are defined in `users.rb`). +- There should be only one top-level factory definition per file. +- Make use of [Traits] to clean up definitions and usages. +- When defining a factory, don't define attributes that are not required for the + resulting record to pass validation. +- When instantiating from a factory, don't supply extraneous attributes that + aren't required by the test. + +[factory_girl]: https://github.com/thoughtbot/factory_girl +[Traits]: http://www.rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md#Traits + +## JavaScript + +GitLab uses [Teaspoon] to run its [Jasmine] JavaScript specs. They can be run on +the command line via `bundle exec teaspoon`, or via a web browser at +`http://localhost:3000/teaspoon` when the Rails server is running. + +- JavaScript tests live in `spec/javascripts/`, matching the folder structure of + `app/assets/javascripts/`: `app/assets/javascripts/behaviors/autosize.js.coffee` has a corresponding + `spec/javascripts/behaviors/autosize_spec.js.coffee` file. +- Haml fixtures required for JavaScript tests live in + `spec/javascripts/fixtures`. They should contain the bare minimum amount of + markup necessary for the test. + + > **Warning:** Keep in mind that a Rails view may change and + invalidate your test, but everything will still pass because your fixture + doesn't reflect the latest view. + +- Keep in mind that in a CI environment, these tests are run in a headless + browser and you will not have access to certain APIs, such as + [`Notification`](https://developer.mozilla.org/en-US/docs/Web/API/notification), + which will have to be stubbed. + +[Teaspoon]: https://github.com/modeset/teaspoon +[Jasmine]: https://github.com/jasmine/jasmine + +## RSpec + +### General Guidelines + +- Use a single, top-level `describe ClassName` block. +- Use `described_class` instead of repeating the class name being described. +- Use `.method` to describe class methods and `#method` to describe instance + methods. +- Use `context` to test branching logic. +- Don't `describe` symbols (see [Gotchas](gotchas.md#dont-describe-symbols)). +- Prefer `not_to` to `to_not`. +- Try to match the ordering of tests to the ordering within the class. + +### Test speed + +GitLab has a massive test suite that, without parallelization, can take more +than an hour to run. It's important that we make an effort to write tests that +are accurate and effective _as well as_ fast. + +Here are some things to keep in mind regarding test performance: + +- `double` and `spy` are faster than `FactoryGirl.build(...)` +- `FactoryGirl.build(...)` and `.build_stubbed` are faster than `.create`. +- Don't `create` an object when `build`, `build_stubbed`, `attributes_for`, + `spy`, or `double` will do. Database persistence is slow! +- Use `create(:empty_project)` instead of `create(:project)` when you don't need + the underlying repository. Filesystem operations are slow! +- Don't mark a feature as requiring JavaScript (through `@javascript` in + Spinach or `js: true` in RSpec) unless it's _actually_ required for the test + to be valid. Headless browser testing is slow! + +### Features / Integration + +- Feature specs live in `spec/features/` and should be named + `ROLE_ACTION_spec.rb`, such as `user_changes_password_spec.rb`. +- Use only one `feature` block per feature spec file. +- Use scenario titles that describe the success and failure paths. +- Avoid scenario titles that add no information, such as "successfully." +- Avoid scenario titles that repeat the feature title. + +## Spinach (feature) tests + +GitLab [moved from Cucumber to Spinach](https://github.com/gitlabhq/gitlabhq/pull/1426) +for its feature/integration tests in September 2012. + +As of March 2016, we are [trying to avoid adding new Spinach +tests](https://gitlab.com/gitlab-org/gitlab-ce/issues/14121) going forward, +opting for [RSpec feature](#features-integration) specs. + +Adding new Spinach scenarios is acceptable _only if_ the new scenario requires +no more than one new `step` definition. If more than that is required, the +test should be re-implemented using RSpec instead. From 0b9d9816f8ef1d871a050cea5d8bc3d9203c3d18 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 30 Mar 2016 19:11:02 -0400 Subject: [PATCH 010/212] Add a note about Four-Phase Test to Testing guide [ci skip] --- doc/development/testing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/development/testing.md b/doc/development/testing.md index d37ef5d878..a7e85ecebe 100644 --- a/doc/development/testing.md +++ b/doc/development/testing.md @@ -63,6 +63,8 @@ the command line via `bundle exec teaspoon`, or via a web browser at - Don't `describe` symbols (see [Gotchas](gotchas.md#dont-describe-symbols)). - Prefer `not_to` to `to_not`. - Try to match the ordering of tests to the ordering within the class. +- Try to follow the [Four-Phase Test](https://robots.thoughtbot.com/four-phase-test) + pattern, using newlines to separate phases. ### Test speed From 60f4081e135bdcd893d60192e652c4b829c656dd Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 1 Apr 2016 20:29:48 -0400 Subject: [PATCH 011/212] Factories don't have to be limited to `ActiveRecord` objects [ci skip] --- doc/development/testing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/development/testing.md b/doc/development/testing.md index a7e85ecebe..3d1c4ccab4 100644 --- a/doc/development/testing.md +++ b/doc/development/testing.md @@ -22,6 +22,8 @@ fixture replacement. resulting record to pass validation. - When instantiating from a factory, don't supply extraneous attributes that aren't required by the test. +- Factories don't have to be limited to `ActiveRecord` objects. + [See example](https://gitlab.com/gitlab-org/gitlab-ce/commit/0b8cefd3b2385a21cfed779bd659978c0402766d). [factory_girl]: https://github.com/thoughtbot/factory_girl [Traits]: http://www.rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md#Traits From 2e83b562030e078ce6d37f81915590426a57c820 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 1 Apr 2016 20:30:24 -0400 Subject: [PATCH 012/212] Add a section about `let` to the Testing guide [ci skip] --- doc/development/testing.md | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/development/testing.md b/doc/development/testing.md index 3d1c4ccab4..187d852e53 100644 --- a/doc/development/testing.md +++ b/doc/development/testing.md @@ -11,8 +11,7 @@ importance. ## Factories -GitLab uses [factory_girl] as a test -fixture replacement. +GitLab uses [factory_girl] as a test fixture replacement. - Factory definitions live in `spec/factories/`, named using the pluralization of their corresponding model (`User` factories are defined in `users.rb`). @@ -65,8 +64,30 @@ the command line via `bundle exec teaspoon`, or via a web browser at - Don't `describe` symbols (see [Gotchas](gotchas.md#dont-describe-symbols)). - Prefer `not_to` to `to_not`. - Try to match the ordering of tests to the ordering within the class. -- Try to follow the [Four-Phase Test](https://robots.thoughtbot.com/four-phase-test) - pattern, using newlines to separate phases. +- Try to follow the [Four-Phase Test][four-phase-test] pattern, using newlines + to separate phases. + +[four-phase-test]: https://robots.thoughtbot.com/four-phase-test + +### `let` variables + +GitLab's RSpec suite has made extensive use of `let` variables to reduce +duplication. However, this sometimes [comes at the cost of clarity][lets-not], +so we need to set some guidelines for their use going forward: + +- `let` variables are preferable to instance variables. Local variables are + preferable to `let` variables. +- Use `let` to reduce duplication throughout an entire spec file. +- Don't use `let` to define variables used by a single test; define them as + local variables inside the test's `it` block. +- Don't define a `let` variable inside the top-level `describe` block that's + only used in a more deeply-nested `context` or `describe` block. Keep the + definition as close as possible to where it's used. +- Try to avoid overriding the definition of one `let` variable with another. +- Don't define a `let` variable that's only used by the definition of another. + Use a helper method instead. + +[lets-not]: https://robots.thoughtbot.com/lets-not ### Test speed From 6ffda88c973ce9be263d0e9142a3105f2cccf000 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 1 Apr 2016 20:36:44 -0400 Subject: [PATCH 013/212] Add a link back to Development documentation to Testing guide [ci skip] --- doc/development/testing.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/development/testing.md b/doc/development/testing.md index 187d852e53..23417845f1 100644 --- a/doc/development/testing.md +++ b/doc/development/testing.md @@ -128,3 +128,7 @@ opting for [RSpec feature](#features-integration) specs. Adding new Spinach scenarios is acceptable _only if_ the new scenario requires no more than one new `step` definition. If more than that is required, the test should be re-implemented using RSpec instead. + +--- + +[Return to Development documentation](README.md) From 261c8e765f5b13dd627fcda5ca1ae263ecfad0c8 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Thu, 31 Mar 2016 23:33:32 +0100 Subject: [PATCH 014/212] fix missing filters on status tab when user swithches to another state --- app/assets/javascripts/issues.js.coffee | 15 +++++++++++ app/assets/javascripts/lib/url_utility.js | 33 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 app/assets/javascripts/lib/url_utility.js diff --git a/app/assets/javascripts/issues.js.coffee b/app/assets/javascripts/issues.js.coffee index b1479bfb44..8d069a209d 100644 --- a/app/assets/javascripts/issues.js.coffee +++ b/app/assets/javascripts/issues.js.coffee @@ -26,6 +26,20 @@ $(".selected_issue").bind "change", Issues.checkChanged + # Update state filters if present in page + updateStateFilters: -> + stateFilters = $('.issues-state-filters') + newParams = {} + paramKeys = ['author_id', 'label_name', 'milestone_title', 'assignee_id', 'issue_search'] + + for paramKey in paramKeys + newParams[paramKey] = getUrlParameter(paramKey) or '' + + if stateFilters.length + stateFilters.find('a').each -> + initialUrl = $(this).attr 'href' + $(this).attr 'href', mergeUrlParams(newParams, initialUrl) + # Make sure we trigger ajax request only after user stop typing initSearch: -> @timer = null @@ -54,6 +68,7 @@ # Change url so if user reload a page - search results are saved history.replaceState {page: issuesUrl}, document.title, issuesUrl Issues.reload() + Issues.updateStateFilters() dataType: "json" checkChanged: -> diff --git a/app/assets/javascripts/lib/url_utility.js b/app/assets/javascripts/lib/url_utility.js new file mode 100644 index 0000000000..5fa3a4c69d --- /dev/null +++ b/app/assets/javascripts/lib/url_utility.js @@ -0,0 +1,33 @@ +function getUrlParameter(sParam) { + var sPageURL = decodeURIComponent(window.location.search.substring(1)), + sURLVariables = sPageURL.split('&'), + sParameterName, + i; + + for (i = 0; i < sURLVariables.length; i++) { + sParameterName = sURLVariables[i].split('='); + + if (sParameterName[0] === sParam) { + return sParameterName[1] === undefined ? true : sParameterName[1]; + } + } +} + +/** + * @param {Object} params - url keys and value to merge + * @param {String} url + */ +function mergeUrlParams(params, url){ + var newUrl = decodeURIComponent(url); + + Object.keys(params).forEach(function(paramName) { + var pattern = new RegExp('\\b('+paramName+'=).*?(&|$)') + if (url.search(pattern) >= 0){ + newUrl = newUrl.replace(pattern,'$1' + params[paramName] + '$2'); + } else { + newUrl = newUrl + (newUrl.indexOf('?') > 0 ? '&' : '?') + paramName + '=' + params[paramName] + } + }); + + return newUrl; +} \ No newline at end of file From db8836ca84ab86dc39b4d8b3282603c724a78e67 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Sat, 2 Apr 2016 16:56:31 +0100 Subject: [PATCH 015/212] attach the utitlity function to the global scope with some changes --- app/assets/javascripts/issues.js.coffee | 4 +-- app/assets/javascripts/lib/url_utility.js | 33 ------------------- .../javascripts/lib/url_utility.js.coffee | 31 +++++++++++++++++ 3 files changed, 33 insertions(+), 35 deletions(-) delete mode 100644 app/assets/javascripts/lib/url_utility.js create mode 100644 app/assets/javascripts/lib/url_utility.js.coffee diff --git a/app/assets/javascripts/issues.js.coffee b/app/assets/javascripts/issues.js.coffee index 8d069a209d..0d9f2094c2 100644 --- a/app/assets/javascripts/issues.js.coffee +++ b/app/assets/javascripts/issues.js.coffee @@ -33,12 +33,12 @@ paramKeys = ['author_id', 'label_name', 'milestone_title', 'assignee_id', 'issue_search'] for paramKey in paramKeys - newParams[paramKey] = getUrlParameter(paramKey) or '' + newParams[paramKey] = gl.utils.getUrlParameter(paramKey) or '' if stateFilters.length stateFilters.find('a').each -> initialUrl = $(this).attr 'href' - $(this).attr 'href', mergeUrlParams(newParams, initialUrl) + $(this).attr 'href', gl.utils.mergeUrlParams(newParams, initialUrl) # Make sure we trigger ajax request only after user stop typing initSearch: -> diff --git a/app/assets/javascripts/lib/url_utility.js b/app/assets/javascripts/lib/url_utility.js deleted file mode 100644 index 5fa3a4c69d..0000000000 --- a/app/assets/javascripts/lib/url_utility.js +++ /dev/null @@ -1,33 +0,0 @@ -function getUrlParameter(sParam) { - var sPageURL = decodeURIComponent(window.location.search.substring(1)), - sURLVariables = sPageURL.split('&'), - sParameterName, - i; - - for (i = 0; i < sURLVariables.length; i++) { - sParameterName = sURLVariables[i].split('='); - - if (sParameterName[0] === sParam) { - return sParameterName[1] === undefined ? true : sParameterName[1]; - } - } -} - -/** - * @param {Object} params - url keys and value to merge - * @param {String} url - */ -function mergeUrlParams(params, url){ - var newUrl = decodeURIComponent(url); - - Object.keys(params).forEach(function(paramName) { - var pattern = new RegExp('\\b('+paramName+'=).*?(&|$)') - if (url.search(pattern) >= 0){ - newUrl = newUrl.replace(pattern,'$1' + params[paramName] + '$2'); - } else { - newUrl = newUrl + (newUrl.indexOf('?') > 0 ? '&' : '?') + paramName + '=' + params[paramName] - } - }); - - return newUrl; -} \ No newline at end of file diff --git a/app/assets/javascripts/lib/url_utility.js.coffee b/app/assets/javascripts/lib/url_utility.js.coffee new file mode 100644 index 0000000000..abd556e0b4 --- /dev/null +++ b/app/assets/javascripts/lib/url_utility.js.coffee @@ -0,0 +1,31 @@ +((w) -> + + w.gl ?= {} + w.gl.utils ?= {} + + w.gl.utils.getUrlParameter = (sParam) -> + sPageURL = decodeURIComponent(window.location.search.substring(1)) + sURLVariables = sPageURL.split('&') + sParameterName = undefined + i = 0 + while i < sURLVariables.length + sParameterName = sURLVariables[i].split('=') + if sParameterName[0] is sParam + return if sParameterName[1] is undefined then true else sParameterName[1] + i++ + + # # + # @param {Object} params - url keys and value to merge + # @param {String} url + # # + w.gl.utils.mergeUrlParams = (params, url) -> + newUrl = decodeURIComponent(url) + for paramName, paramValue of params + pattern = new RegExp "\\b(#{paramName}=).*?(&|$)" + if url.search(pattern) >= 0 + newUrl = newUrl.replace pattern, "$1#{paramValue}$2" + else + newUrl = "#{newUrl}#{(if newUrl.indexOf('?') > 0 then '&' else '?')}#{paramName}=#{paramValue}" + newUrl + +) window From 0163e27631fb993bd3541c09a95f0ef5e2026455 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 16 Mar 2016 18:10:03 +0100 Subject: [PATCH 016/212] Add Gitlab::Redis connection pool --- config/application.rb | 4 ++-- config/initializers/session_store.rb | 2 +- config/initializers/sidekiq.rb | 4 ++-- config/mail_room.yml | 4 ++-- lib/gitlab/exclusive_lease.rb | 4 +++- lib/gitlab/{redis_config.rb => redis.rb} | 11 ++++++++--- lib/tasks/cache.rake | 25 ++++++++++++------------ 7 files changed, 31 insertions(+), 23 deletions(-) rename lib/gitlab/{redis_config.rb => redis.rb} (72%) diff --git a/config/application.rb b/config/application.rb index 5a0ac70aa2..9633084d60 100644 --- a/config/application.rb +++ b/config/application.rb @@ -4,7 +4,7 @@ require 'rails/all' require 'devise' I18n.config.enforce_available_locales = false Bundler.require(:default, Rails.env) -require_relative '../lib/gitlab/redis_config' +require_relative '../lib/gitlab/redis' module Gitlab REDIS_CACHE_NAMESPACE = 'cache:gitlab' @@ -69,7 +69,7 @@ module Gitlab end end - redis_config_hash = Gitlab::RedisConfig.redis_store_options + redis_config_hash = Gitlab::Redis.redis_store_options redis_config_hash[:namespace] = REDIS_CACHE_NAMESPACE redis_config_hash[:expires_in] = 2.weeks # Cache should not grow forever config.cache_store = :redis_store, redis_config_hash diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 3da5d46be9..7028525587 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -13,7 +13,7 @@ end if Rails.env.test? Gitlab::Application.config.session_store :cookie_store, key: "_gitlab_session" else - redis_config = Gitlab::RedisConfig.redis_store_options + redis_config = Gitlab::Redis.redis_store_options redis_config[:namespace] = 'session:gitlab' Gitlab::Application.config.session_store( diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index cc83137745..9182d92980 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -2,7 +2,7 @@ SIDEKIQ_REDIS_NAMESPACE = 'resque:gitlab' Sidekiq.configure_server do |config| config.redis = { - url: Gitlab::RedisConfig.url, + url: Gitlab::Redis.url, namespace: SIDEKIQ_REDIS_NAMESPACE } @@ -29,7 +29,7 @@ end Sidekiq.configure_client do |config| config.redis = { - url: Gitlab::RedisConfig.url, + url: Gitlab::Redis.url, namespace: SIDEKIQ_REDIS_NAMESPACE } end diff --git a/config/mail_room.yml b/config/mail_room.yml index 60257329f3..761a32adb9 100644 --- a/config/mail_room.yml +++ b/config/mail_room.yml @@ -2,7 +2,7 @@ <% require "yaml" require "json" -require_relative "lib/gitlab/redis_config" +require_relative "lib/gitlab/redis" rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" @@ -18,7 +18,7 @@ if File.exists?(config_file) config['mailbox'] = "inbox" if config['mailbox'].nil? if config['enabled'] && config['address'] - redis_url = Gitlab::RedisConfig.new(rails_env).url + redis_url = Gitlab::Redis.new(rails_env).url %> - :host: <%= config['host'].to_json %> diff --git a/lib/gitlab/exclusive_lease.rb b/lib/gitlab/exclusive_lease.rb index c73eca832d..c2260a5f7a 100644 --- a/lib/gitlab/exclusive_lease.rb +++ b/lib/gitlab/exclusive_lease.rb @@ -43,7 +43,9 @@ module Gitlab # false if the lease is already taken. def try_obtain # Performing a single SET is atomic - !!redis.set(redis_key, '1', nx: true, ex: @timeout) + Gitlab::Redis.with do |redis| + !!redis.set(redis_key, '1', nx: true, ex: @timeout) + end end # No #cancel method. See comments above! diff --git a/lib/gitlab/redis_config.rb b/lib/gitlab/redis.rb similarity index 72% rename from lib/gitlab/redis_config.rb rename to lib/gitlab/redis.rb index 4949c6db53..d03e6e4cd9 100644 --- a/lib/gitlab/redis_config.rb +++ b/lib/gitlab/redis.rb @@ -1,14 +1,19 @@ module Gitlab - class RedisConfig + class Redis attr_reader :url def self.url - new.url + @url ||= new.url + end + + def self.with + @pool ||= ConnectionPool.new { ::Redis.new(url: url) } + @pool.with { |redis| yield redis } end def self.redis_store_options url = new.url - redis_config_hash = Redis::Store::Factory.extract_host_options_from_uri(url) + redis_config_hash = ::Redis::Store::Factory.extract_host_options_from_uri(url) # Redis::Store does not handle Unix sockets well, so let's do it for them redis_uri = URI.parse(url) if redis_uri.scheme == 'unix' diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake index 51e746ef92..6c2e2e9149 100644 --- a/lib/tasks/cache.rake +++ b/lib/tasks/cache.rake @@ -4,18 +4,19 @@ namespace :cache do desc "GitLab | Clear redis cache" task :clear => :environment do - redis = Redis.new(url: Gitlab::RedisConfig.url) - cursor = REDIS_SCAN_START_STOP - loop do - cursor, keys = redis.scan( - cursor, - match: "#{Gitlab::REDIS_CACHE_NAMESPACE}*", - count: CLEAR_BATCH_SIZE - ) - - redis.del(*keys) if keys.any? - - break if cursor == REDIS_SCAN_START_STOP + Gitlab::Redis.with do |redis| + cursor = REDIS_SCAN_START_STOP + loop do + cursor, keys = redis.scan( + cursor, + match: "#{Gitlab::REDIS_CACHE_NAMESPACE}*", + count: CLEAR_BATCH_SIZE + ) + + redis.del(*keys) if keys.any? + + break if cursor == REDIS_SCAN_START_STOP + end end end end From 213ee62469c6518af8423f00fb902b7665d61204 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 18 Mar 2016 15:31:53 +0100 Subject: [PATCH 017/212] Be careful when setting class instance vars --- lib/gitlab/redis.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/redis.rb b/lib/gitlab/redis.rb index d03e6e4cd9..8c3aea2627 100644 --- a/lib/gitlab/redis.rb +++ b/lib/gitlab/redis.rb @@ -2,12 +2,23 @@ module Gitlab class Redis attr_reader :url + # To be thread-safe we must be careful when writing the class instance + # variables @url and @pool. Because @pool depends on @url we need two + # mutexes to prevent deadlock. + URL_MUTEX = Mutex.new + POOL_MUTEX = Mutex.new + private_constant :URL_MUTEX, :POOL_MUTEX + def self.url - @url ||= new.url + @url || URL_MUTEX.synchronize { @url = new.url } end def self.with - @pool ||= ConnectionPool.new { ::Redis.new(url: url) } + if @pool.nil? + POOL_MUTEX.synchronize do + @pool = ConnectionPool.new { ::Redis.new(url: url) } + end + end @pool.with { |redis| yield redis } end From 1a168279fa3eb87c2061917707397af21e7b26ea Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 4 Apr 2016 19:09:12 -0500 Subject: [PATCH 018/212] Prepare SAML for group retrieval --- lib/gitlab/saml/auth_hash.rb | 17 ++++++++++++++ lib/gitlab/saml/config.rb | 22 ++++++++++++++++++ lib/gitlab/saml/user.rb | 43 ++++++++++++++++++++++++++++++++++-- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 lib/gitlab/saml/auth_hash.rb create mode 100644 lib/gitlab/saml/config.rb diff --git a/lib/gitlab/saml/auth_hash.rb b/lib/gitlab/saml/auth_hash.rb new file mode 100644 index 0000000000..5ffccc0e10 --- /dev/null +++ b/lib/gitlab/saml/auth_hash.rb @@ -0,0 +1,17 @@ +module Gitlab + module Saml + class AuthHash < Gitlab::OAuth::AuthHash + + def groups + get_raw(Gitlab::Saml::Config.groups) + end + + private + + def get_raw(key) + auth_hash.extra[:raw_info][key] + end + + end + end +end diff --git a/lib/gitlab/saml/config.rb b/lib/gitlab/saml/config.rb new file mode 100644 index 0000000000..dade4c0fa6 --- /dev/null +++ b/lib/gitlab/saml/config.rb @@ -0,0 +1,22 @@ +# Load a specific server configuration +module Gitlab + module Saml + class Config + + class << self + def options + Gitlab.config.omniauth.providers.find { |provider| provider.name == 'saml' } + end + + def groups + options['groups_attribute'] + end + + def external_groups + options['external_groups'] + end + end + + end + end +end diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index b1e30110ef..14eda337d9 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -7,6 +7,11 @@ module Gitlab module Saml class User < Gitlab::OAuth::User + def initialize(auth_hash) + super + update_user_attributes + end + def save super('SAML') end @@ -18,7 +23,7 @@ module Gitlab @user ||= find_or_create_ldap_user end - if auto_link_saml_enabled? + if auto_link_saml_user? @user ||= find_by_email end @@ -37,11 +42,45 @@ module Gitlab end end + def changed? + gl_user.changed? || gl_user.identities.any?(&:changed?) + end + protected - def auto_link_saml_enabled? + def build_new_user + user = super + if external_users_enabled? + unless (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? + user.external = true + end + end + user + end + + def auto_link_saml_user? Gitlab.config.omniauth.auto_link_saml_user end + + def external_users_enabled? + !Gitlab::Saml::Config.external_groups.nil? + end + + def auth_hash=(auth_hash) + @auth_hash = Gitlab::Saml::AuthHash.new(auth_hash) + end + + def update_user_attributes + if persisted? + if external_users_enabled? + if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? + gl_user.external = false + else + gl_user.external = true + end + end + end + end end end end From d14f080c0a7e4cfb2893a9fb2462a650f02a6ef9 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 4 Apr 2016 19:09:46 -0500 Subject: [PATCH 019/212] Remove unnecessary LDAP tests from SAML tests --- spec/lib/gitlab/saml/user_spec.rb | 66 ++++--------------------------- 1 file changed, 7 insertions(+), 59 deletions(-) diff --git a/spec/lib/gitlab/saml/user_spec.rb b/spec/lib/gitlab/saml/user_spec.rb index de7cd99d49..6f5cf3a1cf 100644 --- a/spec/lib/gitlab/saml/user_spec.rb +++ b/spec/lib/gitlab/saml/user_spec.rb @@ -23,6 +23,12 @@ describe Gitlab::Saml::User, lib: true do allow(Gitlab::LDAP::Config).to receive_messages(messages) end + def stub_saml_config(messages) + allow(Gitlab::Saml::Config).to receive_messages(messages) + end + + before { stub_saml_config({ options: { name: 'saml', args: {} } }) } + describe 'account exists on server' do before { stub_omniauth_config({ allow_single_sign_on: ['saml'], auto_link_saml_user: true }) } context 'and should bind with SAML' do @@ -138,7 +144,7 @@ describe Gitlab::Saml::User, lib: true do end describe 'blocking' do - before { stub_omniauth_config({ allow_saml_sign_up: true, auto_link_saml_user: true }) } + before { stub_omniauth_config({ allow_single_sign_on: ['saml'], auto_link_saml_user: true }) } context 'signup with SAML only' do context 'dont block on create' do @@ -162,64 +168,6 @@ describe Gitlab::Saml::User, lib: true do end end - context 'signup with linked omniauth and LDAP account' do - before do - stub_omniauth_config(auto_link_ldap_user: true) - allow(ldap_user).to receive(:uid) { uid } - allow(ldap_user).to receive(:username) { uid } - allow(ldap_user).to receive(:email) { ['johndoe@example.com','john2@example.com'] } - allow(ldap_user).to receive(:dn) { 'uid=user1,ou=People,dc=example' } - allow(saml_user).to receive(:ldap_person).and_return(ldap_user) - end - - context "and no account for the LDAP user" do - context 'dont block on create (LDAP)' do - before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false) } - - it do - saml_user.save - expect(gl_user).to be_valid - expect(gl_user).not_to be_blocked - end - end - - context 'block on create (LDAP)' do - before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true) } - - it do - saml_user.save - expect(gl_user).to be_valid - expect(gl_user).to be_blocked - end - end - end - - context 'and LDAP user has an account already' do - let!(:existing_user) { create(:omniauth_user, email: 'john@example.com', extern_uid: 'uid=user1,ou=People,dc=example', provider: 'ldapmain', username: 'john') } - - context 'dont block on create (LDAP)' do - before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false) } - - it do - saml_user.save - expect(gl_user).to be_valid - expect(gl_user).not_to be_blocked - end - end - - context 'block on create (LDAP)' do - before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true) } - - it do - saml_user.save - expect(gl_user).to be_valid - expect(gl_user).not_to be_blocked - end - end - end - end - - context 'sign-in' do before do saml_user.save From 943d8d4b90fbdc4f68d548c0566343903f895138 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 4 Apr 2016 19:10:17 -0500 Subject: [PATCH 020/212] Config examples --- config/gitlab.yml.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index fb1c3476f6..c607e32a05 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -345,6 +345,8 @@ production: &base # # - { name: 'saml', # label: 'Our SAML Provider', + # groups_attribute: 'Groups', + # external_groups: ['Contractors', 'Freelancers'], # args: { # assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback', # idp_cert_fingerprint: '43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8', From e99855bfe4b4741d33d5575fdf1f0bc2edd85844 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 4 Apr 2016 19:10:59 -0500 Subject: [PATCH 021/212] Avoid saving again if the user attributes haven't changed --- app/controllers/omniauth_callbacks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index 21135f7d60..d28e96c3f1 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -55,7 +55,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController end else saml_user = Gitlab::Saml::User.new(oauth) - saml_user.save + saml_user.save if saml_user.changed? @user = saml_user.gl_user continue_login_process From 7a2370f74060b2f065e3602700fe1b33fda4685c Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 4 Apr 2016 21:25:38 -0400 Subject: [PATCH 022/212] Standardize the way we check for and display form errors - Some views had a "Close" button. We've removed this, because we don't want users accidentally hiding the validation errors and not knowing what needs to be fixed. - Some views used `li`, some used `p`, some used `span`. We've standardized on `li`. - Some views only showed the first error. We've standardized on showing all of them. - Some views added an `#error_explanation` div, which we've made standard. --- app/helpers/form_helper.rb | 18 ++++++++ app/views/abuse_reports/new.html.haml | 6 +-- app/views/admin/appearances/_form.html.haml | 5 +- .../application_settings/_form.html.haml | 6 +-- app/views/admin/applications/_form.html.haml | 7 +-- .../admin/broadcast_messages/_form.html.haml | 6 +-- app/views/admin/deploy_keys/new.html.haml | 6 +-- app/views/admin/groups/_form.html.haml | 5 +- app/views/admin/hooks/index.html.haml | 6 +-- app/views/admin/identities/_form.html.haml | 6 +-- app/views/admin/labels/_form.html.haml | 8 +--- app/views/admin/users/_form.html.haml | 6 +-- .../doorkeeper/applications/_form.html.haml | 6 +-- app/views/groups/edit.html.haml | 4 +- app/views/groups/new.html.haml | 5 +- app/views/profiles/keys/_form.html.haml | 6 +-- .../profiles/notifications/show.html.haml | 6 +-- app/views/profiles/passwords/edit.html.haml | 7 +-- app/views/profiles/passwords/new.html.haml | 7 +-- app/views/profiles/show.html.haml | 7 +-- app/views/projects/_errors.html.haml | 5 +- .../projects/deploy_keys/_form.html.haml | 6 +-- app/views/projects/hooks/index.html.haml | 6 +-- app/views/projects/labels/_form.html.haml | 8 +--- .../merge_requests/_new_compare.html.haml | 5 +- app/views/projects/milestones/_form.html.haml | 7 +-- .../protected_branches/index.html.haml | 6 +-- app/views/projects/variables/show.html.haml | 8 +--- app/views/projects/wikis/_form.html.haml | 6 +-- app/views/shared/_service_settings.html.haml | 7 +-- app/views/shared/issuable/_form.html.haml | 9 +--- app/views/shared/snippets/_form.html.haml | 6 +-- spec/helpers/form_helper_spec.rb | 46 +++++++++++++++++++ 33 files changed, 105 insertions(+), 153 deletions(-) create mode 100644 app/helpers/form_helper.rb create mode 100644 spec/helpers/form_helper_spec.rb diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb new file mode 100644 index 0000000000..6a43be2cf3 --- /dev/null +++ b/app/helpers/form_helper.rb @@ -0,0 +1,18 @@ +module FormHelper + def form_errors(model) + return unless model.errors.any? + + pluralized = 'error'.pluralize(model.errors.count) + headline = "The form contains the following #{pluralized}:" + + content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do + content_tag(:h4, headline) << + content_tag(:ul) do + model.errors.full_messages. + map { |msg| content_tag(:li, msg) }. + join. + html_safe + end + end + end +end diff --git a/app/views/abuse_reports/new.html.haml b/app/views/abuse_reports/new.html.haml index 3bc1b24b5e..06be1a5331 100644 --- a/app/views/abuse_reports/new.html.haml +++ b/app/views/abuse_reports/new.html.haml @@ -3,11 +3,9 @@ %p Please use this form to report users who create spam issues, comments or behave inappropriately. %hr = form_for @abuse_report, html: { class: 'form-horizontal js-quick-submit js-requires-input'} do |f| + = form_errors(@abuse_report) + = f.hidden_field :user_id - - if @abuse_report.errors.any? - .alert.alert-danger - - @abuse_report.errors.full_messages.each do |msg| - %p= msg .form-group = f.label :user_id, class: 'control-label' .col-sm-10 diff --git a/app/views/admin/appearances/_form.html.haml b/app/views/admin/appearances/_form.html.haml index 6f325914d1..d88f3ad314 100644 --- a/app/views/admin/appearances/_form.html.haml +++ b/app/views/admin/appearances/_form.html.haml @@ -1,8 +1,5 @@ = form_for @appearance, url: admin_appearances_path, html: { class: 'form-horizontal'} do |f| - - if @appearance.errors.any? - .alert.alert-danger - - @appearance.errors.full_messages.each do |msg| - %p= msg + = form_errors(@appearance) %fieldset.sign-in %legend diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index de86dacbb1..a8cca1a81c 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -1,9 +1,5 @@ = form_for @application_setting, url: admin_application_settings_path, html: { class: 'form-horizontal fieldset-form' } do |f| - - if @application_setting.errors.any? - #error_explanation - .alert.alert-danger - - @application_setting.errors.full_messages.each do |msg| - %p= msg + = form_errors(@application_setting) %fieldset %legend Visibility and Access Controls diff --git a/app/views/admin/applications/_form.html.haml b/app/views/admin/applications/_form.html.haml index e18f7b499d..4aacbb8cd7 100644 --- a/app/views/admin/applications/_form.html.haml +++ b/app/views/admin/applications/_form.html.haml @@ -1,9 +1,6 @@ = form_for [:admin, @application], url: @url, html: {class: 'form-horizontal', role: 'form'} do |f| - - if application.errors.any? - .alert.alert-danger - %button{ type: "button", class: "close", "data-dismiss" => "alert"} × - - application.errors.full_messages.each do |msg| - %p= msg + = form_errors(application) + = content_tag :div, class: 'form-group' do = f.label :name, class: 'col-sm-2 control-label' .col-sm-10 diff --git a/app/views/admin/broadcast_messages/_form.html.haml b/app/views/admin/broadcast_messages/_form.html.haml index b748460a9f..6b157abf84 100644 --- a/app/views/admin/broadcast_messages/_form.html.haml +++ b/app/views/admin/broadcast_messages/_form.html.haml @@ -4,10 +4,8 @@ = render_broadcast_message(@broadcast_message.message.presence || "Your message here") = form_for [:admin, @broadcast_message], html: { class: 'broadcast-message-form form-horizontal js-quick-submit js-requires-input'} do |f| - -if @broadcast_message.errors.any? - .alert.alert-danger - - @broadcast_message.errors.full_messages.each do |msg| - %p= msg + = form_errors(@broadcast_message) + .form-group = f.label :message, class: 'control-label' .col-sm-10 diff --git a/app/views/admin/deploy_keys/new.html.haml b/app/views/admin/deploy_keys/new.html.haml index 5b46b3222a..15aa059c93 100644 --- a/app/views/admin/deploy_keys/new.html.haml +++ b/app/views/admin/deploy_keys/new.html.haml @@ -4,11 +4,7 @@ %div = form_for [:admin, @deploy_key], html: { class: 'deploy-key-form form-horizontal' } do |f| - -if @deploy_key.errors.any? - .alert.alert-danger - %ul - - @deploy_key.errors.full_messages.each do |msg| - %li= msg + = form_errors(@deploy_key) .form-group = f.label :title, class: "control-label" diff --git a/app/views/admin/groups/_form.html.haml b/app/views/admin/groups/_form.html.haml index 7f2b1cd235..0cc405401c 100644 --- a/app/views/admin/groups/_form.html.haml +++ b/app/views/admin/groups/_form.html.haml @@ -1,8 +1,5 @@ = form_for [:admin, @group], html: { class: "form-horizontal" } do |f| - - if @group.errors.any? - .alert.alert-danger - %span= @group.errors.full_messages.first - + = form_errors(@group) = render 'shared/group_form', f: f .form-group.group-description-holder diff --git a/app/views/admin/hooks/index.html.haml b/app/views/admin/hooks/index.html.haml index 53b3cd04c6..ad952052f2 100644 --- a/app/views/admin/hooks/index.html.haml +++ b/app/views/admin/hooks/index.html.haml @@ -10,10 +10,8 @@ = form_for @hook, as: :hook, url: admin_hooks_path, html: { class: 'form-horizontal' } do |f| - -if @hook.errors.any? - .alert.alert-danger - - @hook.errors.full_messages.each do |msg| - %p= msg + = form_errors(@hook) + .form-group = f.label :url, "URL:", class: 'control-label' .col-sm-10 diff --git a/app/views/admin/identities/_form.html.haml b/app/views/admin/identities/_form.html.haml index 3a78855822..112a201faf 100644 --- a/app/views/admin/identities/_form.html.haml +++ b/app/views/admin/identities/_form.html.haml @@ -1,9 +1,5 @@ = form_for [:admin, @user, @identity], html: { class: 'form-horizontal fieldset-form' } do |f| - - if @identity.errors.any? - #error_explanation - .alert.alert-danger - - @identity.errors.full_messages.each do |msg| - %p= msg + = form_errors(@identity) .form-group = f.label :provider, class: 'control-label' diff --git a/app/views/admin/labels/_form.html.haml b/app/views/admin/labels/_form.html.haml index 8c6b389bf1..448aa95354 100644 --- a/app/views/admin/labels/_form.html.haml +++ b/app/views/admin/labels/_form.html.haml @@ -1,11 +1,5 @@ = form_for [:admin, @label], html: { class: 'form-horizontal label-form js-requires-input' } do |f| - -if @label.errors.any? - .row - .col-sm-offset-2.col-sm-10 - .alert.alert-danger - - @label.errors.full_messages.each do |msg| - %span= msg - %br + = form_errors(@label) .form-group = f.label :title, class: 'control-label' diff --git a/app/views/admin/users/_form.html.haml b/app/views/admin/users/_form.html.haml index d2527ede99..b05fdbd555 100644 --- a/app/views/admin/users/_form.html.haml +++ b/app/views/admin/users/_form.html.haml @@ -1,10 +1,6 @@ .user_new = form_for [:admin, @user], html: { class: 'form-horizontal fieldset-form' } do |f| - -if @user.errors.any? - #error_explanation - .alert.alert-danger - - @user.errors.full_messages.each do |msg| - %p= msg + = form_errors(@user) %fieldset %legend Account diff --git a/app/views/doorkeeper/applications/_form.html.haml b/app/views/doorkeeper/applications/_form.html.haml index 906b067615..5c98265727 100644 --- a/app/views/doorkeeper/applications/_form.html.haml +++ b/app/views/doorkeeper/applications/_form.html.haml @@ -1,9 +1,5 @@ = form_for application, url: doorkeeper_submit_path(application), html: {role: 'form'} do |f| - - if application.errors.any? - .alert.alert-danger - %ul - - application.errors.full_messages.each do |msg| - %li= msg + = form_errors(application) .form-group = f.label :name, class: 'label-light' diff --git a/app/views/groups/edit.html.haml b/app/views/groups/edit.html.haml index ea5a035839..a698cbbe9d 100644 --- a/app/views/groups/edit.html.haml +++ b/app/views/groups/edit.html.haml @@ -5,9 +5,7 @@ Group settings .panel-body = form_for @group, html: { multipart: true, class: "form-horizontal" }, authenticity_token: true do |f| - - if @group.errors.any? - .alert.alert-danger - %span= @group.errors.full_messages.first + = form_errors(@group) = render 'shared/group_form', f: f .form-group diff --git a/app/views/groups/new.html.haml b/app/views/groups/new.html.haml index 30ab8aeba1..2b8bc269e6 100644 --- a/app/views/groups/new.html.haml +++ b/app/views/groups/new.html.haml @@ -6,10 +6,7 @@ %hr = form_for @group, html: { class: 'group-form form-horizontal' } do |f| - - if @group.errors.any? - .alert.alert-danger - %span= @group.errors.full_messages.first - + = form_errors(@group) = render 'shared/group_form', f: f, autofocus: true .form-group.group-description-holder diff --git a/app/views/profiles/keys/_form.html.haml b/app/views/profiles/keys/_form.html.haml index 4d78215ed3..b3ed59a1a4 100644 --- a/app/views/profiles/keys/_form.html.haml +++ b/app/views/profiles/keys/_form.html.haml @@ -1,10 +1,6 @@ %div = form_for [:profile, @key], html: { class: 'js-requires-input' } do |f| - - if @key.errors.any? - .alert.alert-danger - %ul - - @key.errors.full_messages.each do |msg| - %li= msg + = form_errors(@key) .form-group = f.label :key, class: 'label-light' diff --git a/app/views/profiles/notifications/show.html.haml b/app/views/profiles/notifications/show.html.haml index 3d15c0d932..6609295a2a 100644 --- a/app/views/profiles/notifications/show.html.haml +++ b/app/views/profiles/notifications/show.html.haml @@ -2,11 +2,7 @@ - header_title page_title, profile_notifications_path = form_for @user, url: profile_notifications_path, method: :put, html: { class: 'update-notifications prepend-top-default' } do |f| - -if @user.errors.any? - %div.alert.alert-danger - %ul - - @user.errors.full_messages.each do |msg| - %li= msg + = form_errors(@user) = hidden_field_tag :notification_type, 'global' .row diff --git a/app/views/profiles/passwords/edit.html.haml b/app/views/profiles/passwords/edit.html.haml index 44d758dceb..5ac8a8b9d0 100644 --- a/app/views/profiles/passwords/edit.html.haml +++ b/app/views/profiles/passwords/edit.html.haml @@ -13,11 +13,8 @@ - unless @user.password_automatically_set? or recover your current one = form_for @user, url: profile_password_path, method: :put, html: {class: "update-password"} do |f| - -if @user.errors.any? - .alert.alert-danger - %ul - - @user.errors.full_messages.each do |msg| - %li= msg + = form_errors(@user) + - unless @user.password_automatically_set? .form-group = f.label :current_password, class: 'label-light' diff --git a/app/views/profiles/passwords/new.html.haml b/app/views/profiles/passwords/new.html.haml index d165f758c8..2eb9fac57c 100644 --- a/app/views/profiles/passwords/new.html.haml +++ b/app/views/profiles/passwords/new.html.haml @@ -7,11 +7,8 @@ Please set a new password before proceeding. %br After a successful password update you will be redirected to login screen. - -if @user.errors.any? - .alert.alert-danger - %ul - - @user.errors.full_messages.each do |msg| - %li= msg + + = form_errors(@user) - unless @user.password_automatically_set? .form-group diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml index dcb3be9585..f59d27f7ed 100644 --- a/app/views/profiles/show.html.haml +++ b/app/views/profiles/show.html.haml @@ -1,9 +1,6 @@ = form_for @user, url: profile_path, method: :put, html: { multipart: true, class: "edit-user prepend-top-default" }, authenticity_token: true do |f| - -if @user.errors.any? - %div.alert.alert-danger - %ul - - @user.errors.full_messages.each do |msg| - %li= msg + = form_errors(@user) + .row .col-lg-3.profile-settings-sidebar %h4.prepend-top-0 diff --git a/app/views/projects/_errors.html.haml b/app/views/projects/_errors.html.haml index 7c8bb33ed7..2dba22d3be 100644 --- a/app/views/projects/_errors.html.haml +++ b/app/views/projects/_errors.html.haml @@ -1,4 +1 @@ -- if @project.errors.any? - .alert.alert-danger - %button{ type: "button", class: "close", "data-dismiss" => "alert"} × - = @project.errors.full_messages.first += form_errors(@project) diff --git a/app/views/projects/deploy_keys/_form.html.haml b/app/views/projects/deploy_keys/_form.html.haml index 5e182af266..f6565f8583 100644 --- a/app/views/projects/deploy_keys/_form.html.haml +++ b/app/views/projects/deploy_keys/_form.html.haml @@ -1,10 +1,6 @@ %div = form_for [@project.namespace.becomes(Namespace), @project, @key], url: namespace_project_deploy_keys_path, html: { class: 'deploy-key-form form-horizontal js-requires-input' } do |f| - -if @key.errors.any? - .alert.alert-danger - %ul - - @key.errors.full_messages.each do |msg| - %li= msg + = form_errors(@key) .form-group = f.label :title, class: "control-label" diff --git a/app/views/projects/hooks/index.html.haml b/app/views/projects/hooks/index.html.haml index 67d016bd87..e39224d86c 100644 --- a/app/views/projects/hooks/index.html.haml +++ b/app/views/projects/hooks/index.html.haml @@ -9,10 +9,8 @@ %hr.clearfix = form_for [@project.namespace.becomes(Namespace), @project, @hook], as: :hook, url: namespace_project_hooks_path(@project.namespace, @project), html: { class: 'form-horizontal' } do |f| - -if @hook.errors.any? - .alert.alert-danger - - @hook.errors.full_messages.each do |msg| - %p= msg + = form_errors(@hook) + .form-group = f.label :url, "URL", class: 'control-label' .col-sm-10 diff --git a/app/views/projects/labels/_form.html.haml b/app/views/projects/labels/_form.html.haml index be7a0bb562..aa143e54ff 100644 --- a/app/views/projects/labels/_form.html.haml +++ b/app/views/projects/labels/_form.html.haml @@ -1,11 +1,5 @@ = form_for [@project.namespace.becomes(Namespace), @project, @label], html: { class: 'form-horizontal label-form js-quick-submit js-requires-input' } do |f| - -if @label.errors.any? - .row - .col-sm-offset-2.col-sm-10 - .alert.alert-danger - - @label.errors.full_messages.each do |msg| - %span= msg - %br + = form_errors(@label) .form-group = f.label :title, class: 'control-label' diff --git a/app/views/projects/merge_requests/_new_compare.html.haml b/app/views/projects/merge_requests/_new_compare.html.haml index 01dc7519be..0931f743a3 100644 --- a/app/views/projects/merge_requests/_new_compare.html.haml +++ b/app/views/projects/merge_requests/_new_compare.html.haml @@ -28,10 +28,7 @@ .mr_target_commit - if @merge_request.errors.any? - .alert.alert-danger - - @merge_request.errors.full_messages.each do |msg| - %div= msg - + = form_errors(@merge_request) - elsif @merge_request.source_branch.present? && @merge_request.target_branch.present? .light-well.append-bottom-default .center diff --git a/app/views/projects/milestones/_form.html.haml b/app/views/projects/milestones/_form.html.haml index 23f2bca7ba..b2dae1c70e 100644 --- a/app/views/projects/milestones/_form.html.haml +++ b/app/views/projects/milestones/_form.html.haml @@ -1,9 +1,6 @@ = form_for [@project.namespace.becomes(Namespace), @project, @milestone], html: {class: 'form-horizontal milestone-form gfm-form js-quick-submit js-requires-input'} do |f| - -if @milestone.errors.any? - .alert.alert-danger - %ul - - @milestone.errors.full_messages.each do |msg| - %li= msg + = form_errors(@milestone) + .row .col-md-6 .form-group diff --git a/app/views/projects/protected_branches/index.html.haml b/app/views/projects/protected_branches/index.html.haml index cfd7e1534c..653b02da4d 100644 --- a/app/views/projects/protected_branches/index.html.haml +++ b/app/views/projects/protected_branches/index.html.haml @@ -13,11 +13,7 @@ - if can? current_user, :admin_project, @project = form_for [@project.namespace.becomes(Namespace), @project, @protected_branch], html: { class: 'form-horizontal' } do |f| - -if @protected_branch.errors.any? - .alert.alert-danger - %ul - - @protected_branch.errors.full_messages.each do |msg| - %li= msg + = form_errors(@protected_branch) .form-group = f.label :name, "Branch", class: 'control-label' diff --git a/app/views/projects/variables/show.html.haml b/app/views/projects/variables/show.html.haml index efe1e6f24c..ca284b84d3 100644 --- a/app/views/projects/variables/show.html.haml +++ b/app/views/projects/variables/show.html.haml @@ -13,13 +13,7 @@ = nested_form_for @project, url: url_for(controller: 'projects/variables', action: 'update'), html: { class: 'form-horizontal' } do |f| - - if @project.errors.any? - #error_explanation - %p.lead= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:" - .alert.alert-error - %ul - - @project.errors.full_messages.each do |msg| - %li= msg + = form_errors(@project) = f.fields_for :variables do |variable_form| .form-group diff --git a/app/views/projects/wikis/_form.html.haml b/app/views/projects/wikis/_form.html.haml index f0d1932e23..812876e283 100644 --- a/app/views/projects/wikis/_form.html.haml +++ b/app/views/projects/wikis/_form.html.haml @@ -1,9 +1,5 @@ = form_for [@project.namespace.becomes(Namespace), @project, @page], method: @page.persisted? ? :put : :post, html: { class: 'form-horizontal wiki-form gfm-form prepend-top-default js-quick-submit' } do |f| - -if @page.errors.any? - #error_explanation - .alert.alert-danger - - @page.errors.full_messages.each do |msg| - %p= msg + = form_errors(@page) = f.hidden_field :title, value: @page.title .form-group diff --git a/app/views/shared/_service_settings.html.haml b/app/views/shared/_service_settings.html.haml index 5a60ff5a5d..fc935166bf 100644 --- a/app/views/shared/_service_settings.html.haml +++ b/app/views/shared/_service_settings.html.haml @@ -1,9 +1,4 @@ -- if @service.errors.any? - #error_explanation - .alert.alert-danger - %ul - - @service.errors.full_messages.each do |msg| - %li= msg += form_errors(@service) - if @service.help.present? .well diff --git a/app/views/shared/issuable/_form.html.haml b/app/views/shared/issuable/_form.html.haml index e2a9e5bfb9..0cda785f91 100644 --- a/app/views/shared/issuable/_form.html.haml +++ b/app/views/shared/issuable/_form.html.haml @@ -1,10 +1,5 @@ -- if issuable.errors.any? - .row - .col-sm-offset-2.col-sm-10 - .alert.alert-danger - - issuable.errors.full_messages.each do |msg| - %span= msg - %br += form_errors(issuable) + .form-group = f.label :title, class: 'control-label' .col-sm-10 diff --git a/app/views/shared/snippets/_form.html.haml b/app/views/shared/snippets/_form.html.haml index 1041eccd1d..47ec09f62c 100644 --- a/app/views/shared/snippets/_form.html.haml +++ b/app/views/shared/snippets/_form.html.haml @@ -1,10 +1,6 @@ .snippet-form-holder = form_for @snippet, url: url, html: { class: "form-horizontal snippet-form js-requires-input" } do |f| - - if @snippet.errors.any? - .alert.alert-danger - %ul - - @snippet.errors.full_messages.each do |msg| - %li= msg + = form_errors(@snippet) .form-group = f.label :title, class: 'control-label' diff --git a/spec/helpers/form_helper_spec.rb b/spec/helpers/form_helper_spec.rb new file mode 100644 index 0000000000..b20373a96f --- /dev/null +++ b/spec/helpers/form_helper_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' + +describe FormHelper do + describe 'form_errors' do + it 'returns nil when model has no errors' do + model = double(errors: []) + + expect(helper.form_errors(model)).to be_nil + end + + it 'renders an alert div' do + model = double(errors: errors_stub('Error 1')) + + expect(helper.form_errors(model)). + to include('
    ') + end + + it 'contains a summary message' do + single_error = double(errors: errors_stub('A')) + multi_errors = double(errors: errors_stub('A', 'B', 'C')) + + expect(helper.form_errors(single_error)). + to include('

    The form contains the following error:') + expect(helper.form_errors(multi_errors)). + to include('

    The form contains the following errors:') + end + + it 'renders each message' do + model = double(errors: errors_stub('Error 1', 'Error 2', 'Error 3')) + + errors = helper.form_errors(model) + + aggregate_failures do + expect(errors).to include('
  • Error 1
  • ') + expect(errors).to include('
  • Error 2
  • ') + expect(errors).to include('
  • Error 3
  • ') + end + end + + def errors_stub(*messages) + ActiveModel::Errors.new(double).tap do |errors| + messages.each { |msg| errors.add(:base, msg) } + end + end + end +end From 831d1807df6d1d9f8213898614a24bea78208114 Mon Sep 17 00:00:00 2001 From: "P.S.V.R" Date: Tue, 5 Apr 2016 16:20:08 +0800 Subject: [PATCH 023/212] Eliminate ugly scroll bars shown in modal boxes --- app/assets/stylesheets/pages/help.scss | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/assets/stylesheets/pages/help.scss b/app/assets/stylesheets/pages/help.scss index bd224705f0..604f1700cf 100644 --- a/app/assets/stylesheets/pages/help.scss +++ b/app/assets/stylesheets/pages/help.scss @@ -59,6 +59,9 @@ position: relative; overflow-y: auto; padding: 15px; + .form-actions { + margin: -$gl-padding+1; + } } body.modal-open { From 1ba9a91c6d3b98e1825e173fe281ba065d35890c Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Thu, 31 Mar 2016 16:11:49 -0300 Subject: [PATCH 024/212] Fix problem when creating milestones in groups without projects --- .../groups/milestones_controller.rb | 28 +++++++++++++++---- .../groups/milestones_controller_spec.rb | 6 ++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/controllers/groups/milestones_controller.rb b/app/controllers/groups/milestones_controller.rb index b23c3022fb..2c05d9e0fe 100644 --- a/app/controllers/groups/milestones_controller.rb +++ b/app/controllers/groups/milestones_controller.rb @@ -18,14 +18,14 @@ class Groups::MilestonesController < Groups::ApplicationController end def create - project_ids = params[:milestone][:project_ids] + project_ids = params[:milestone][:project_ids].reject(&:blank?) title = milestone_params[:title] - @projects.where(id: project_ids).each do |project| - Milestones::CreateService.new(project, current_user, milestone_params).execute + if project_ids.present? + create_milestones(project_ids, title) + else + render_new_with_error("Select a project(s).") end - - redirect_to milestone_path(title) end def show @@ -41,6 +41,24 @@ class Groups::MilestonesController < Groups::ApplicationController private + def create_milestones(project_ids, title) + begin + @projects.where(id: project_ids).each do |project| + ActiveRecord::Base.transaction { Milestones::CreateService.new(project, current_user, milestone_params).execute } + end + + redirect_to milestone_path(title) + rescue => e + render_new_with_error("Error creating milestones: #{e.message}") + end + end + + def render_new_with_error(error) + @milestone = Milestone.new(milestone_params) + flash[:alert] = error + render :new + end + def authorize_admin_milestones! return render_404 unless can?(current_user, :admin_milestones, group) end diff --git a/spec/controllers/groups/milestones_controller_spec.rb b/spec/controllers/groups/milestones_controller_spec.rb index eb0c6ac6d8..f258d6fa0c 100644 --- a/spec/controllers/groups/milestones_controller_spec.rb +++ b/spec/controllers/groups/milestones_controller_spec.rb @@ -23,5 +23,11 @@ describe Groups::MilestonesController do expect(response).to redirect_to(group_milestone_path(group, title.to_slug.to_s, title: title)) expect(Milestone.where(title: title).count).to eq(2) end + + it "redirects to new when there are no project ids" do + post :create, group_id: group.id, milestone: { title: title, project_ids: [""] } + expect(response).to render_template :new + expect(flash[:alert]).to_not be_nil + end end end From 5d428030451b1fa2bac89f798c40d2f91ac65bac Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Fri, 1 Apr 2016 15:50:17 -0300 Subject: [PATCH 025/212] Improve code --- .../groups/milestones_controller.rb | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/controllers/groups/milestones_controller.rb b/app/controllers/groups/milestones_controller.rb index 2c05d9e0fe..21fc329f23 100644 --- a/app/controllers/groups/milestones_controller.rb +++ b/app/controllers/groups/milestones_controller.rb @@ -21,10 +21,10 @@ class Groups::MilestonesController < Groups::ApplicationController project_ids = params[:milestone][:project_ids].reject(&:blank?) title = milestone_params[:title] - if project_ids.present? - create_milestones(project_ids, title) + if create_milestones(project_ids, title) + redirect_to milestone_path(title) else - render_new_with_error("Select a project(s).") + render_new_with_error(@error) end end @@ -42,14 +42,22 @@ class Groups::MilestonesController < Groups::ApplicationController private def create_milestones(project_ids, title) + unless project_ids.present? + @error = "Please select at least one project." + return false + end + begin - @projects.where(id: project_ids).each do |project| - ActiveRecord::Base.transaction { Milestones::CreateService.new(project, current_user, milestone_params).execute } + ActiveRecord::Base.transaction do + @projects.where(id: project_ids).each do |project| + Milestones::CreateService.new(project, current_user, milestone_params).execute + end end - redirect_to milestone_path(title) + true rescue => e - render_new_with_error("Error creating milestones: #{e.message}") + @error = "Error creating milestone: #{e.message}." + false end end From 32c7e42b612bdda43eeef55d8c8afdc9eeb33785 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Mon, 4 Apr 2016 17:04:35 -0300 Subject: [PATCH 026/212] Improve code --- .../groups/milestones_controller.rb | 31 +++++++++---------- app/views/groups/milestones/new.html.haml | 8 +++++ .../groups/milestones_controller_spec.rb | 2 +- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/app/controllers/groups/milestones_controller.rb b/app/controllers/groups/milestones_controller.rb index 21fc329f23..fcf19e8066 100644 --- a/app/controllers/groups/milestones_controller.rb +++ b/app/controllers/groups/milestones_controller.rb @@ -24,7 +24,7 @@ class Groups::MilestonesController < Groups::ApplicationController if create_milestones(project_ids, title) redirect_to milestone_path(title) else - render_new_with_error(@error) + render_new_with_error(project_ids.empty?) end end @@ -42,28 +42,25 @@ class Groups::MilestonesController < Groups::ApplicationController private def create_milestones(project_ids, title) - unless project_ids.present? - @error = "Please select at least one project." - return false - end + return false unless project_ids.present? - begin - ActiveRecord::Base.transaction do - @projects.where(id: project_ids).each do |project| - Milestones::CreateService.new(project, current_user, milestone_params).execute - end + ActiveRecord::Base.transaction do + @projects.where(id: project_ids).each do |project| + Milestones::CreateService.new(project, current_user, milestone_params).execute end - - true - rescue => e - @error = "Error creating milestone: #{e.message}." - false end + + true + + rescue => e + + flash.now[:alert] = "An error occurred while creating the milestone: #{e.message}" + false end - def render_new_with_error(error) + def render_new_with_error(empty_project_ids) @milestone = Milestone.new(milestone_params) - flash[:alert] = error + @milestone.errors.add(:project_id, "Please select at least one project.") if empty_project_ids render :new end diff --git a/app/views/groups/milestones/new.html.haml b/app/views/groups/milestones/new.html.haml index a8e1ed77da..4290e0bf72 100644 --- a/app/views/groups/milestones/new.html.haml +++ b/app/views/groups/milestones/new.html.haml @@ -10,6 +10,14 @@ = form_for @milestone, url: group_milestones_path(@group), html: { class: 'form-horizontal milestone-form gfm-form js-quick-submit js-requires-input' } do |f| .row + - if @milestone.errors.any? + #error_explanation + .alert.alert-danger + %ul + - @milestone.errors.full_messages.each do |msg| + %li + = msg + .col-md-6 .form-group = f.label :title, "Title", class: "control-label" diff --git a/spec/controllers/groups/milestones_controller_spec.rb b/spec/controllers/groups/milestones_controller_spec.rb index f258d6fa0c..9c7b5c74b8 100644 --- a/spec/controllers/groups/milestones_controller_spec.rb +++ b/spec/controllers/groups/milestones_controller_spec.rb @@ -27,7 +27,7 @@ describe Groups::MilestonesController do it "redirects to new when there are no project ids" do post :create, group_id: group.id, milestone: { title: title, project_ids: [""] } expect(response).to render_template :new - expect(flash[:alert]).to_not be_nil + expect(assigns(:milestone).errors).to_not be_nil end end end From 5ff9d2a1821ef0413a349388bcdc0fab84a17086 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 28 Mar 2016 15:37:53 -0400 Subject: [PATCH 027/212] Bump rails to 4.2.6 --- Gemfile | 2 +- Gemfile.lock | 72 ++++++++++++++++++------------------- config/environments/test.rb | 1 + 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/Gemfile b/Gemfile index 6327227282..5eaaf0cfb1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem 'rails', '4.2.5.2' +gem 'rails', '4.2.6' gem 'rails-deprecated_sanitizer', '~> 1.0.3' # Responders respond_to and respond_with diff --git a/Gemfile.lock b/Gemfile.lock index 229089f431..df18410ece 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,41 +4,41 @@ GEM CFPropertyList (2.3.2) RedCloth (4.2.9) ace-rails-ap (2.0.1) - actionmailer (4.2.5.2) - actionpack (= 4.2.5.2) - actionview (= 4.2.5.2) - activejob (= 4.2.5.2) + actionmailer (4.2.6) + actionpack (= 4.2.6) + actionview (= 4.2.6) + activejob (= 4.2.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.5.2) - actionview (= 4.2.5.2) - activesupport (= 4.2.5.2) + actionpack (4.2.6) + actionview (= 4.2.6) + activesupport (= 4.2.6) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.5.2) - activesupport (= 4.2.5.2) + actionview (4.2.6) + activesupport (= 4.2.6) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.5.2) - activesupport (= 4.2.5.2) + activejob (4.2.6) + activesupport (= 4.2.6) globalid (>= 0.3.0) - activemodel (4.2.5.2) - activesupport (= 4.2.5.2) + activemodel (4.2.6) + activesupport (= 4.2.6) builder (~> 3.1) - activerecord (4.2.5.2) - activemodel (= 4.2.5.2) - activesupport (= 4.2.5.2) + activerecord (4.2.6) + activemodel (= 4.2.6) + activesupport (= 4.2.6) arel (~> 6.0) activerecord-deprecated_finders (1.0.4) activerecord-session_store (0.1.2) actionpack (>= 4.0.0, < 5) activerecord (>= 4.0.0, < 5) railties (>= 4.0.0, < 5) - activesupport (4.2.5.2) + activesupport (4.2.6) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) @@ -464,8 +464,8 @@ GEM nokogiri (>= 1.5.9) macaddr (1.7.1) systemu (~> 2.6.2) - mail (2.6.3) - mime-types (>= 1.16, < 3) + mail (2.6.4) + mime-types (>= 1.16, < 4) mail_room (0.6.1) method_source (0.8.2) mime-types (1.25.1) @@ -595,16 +595,16 @@ GEM rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.5.2) - actionmailer (= 4.2.5.2) - actionpack (= 4.2.5.2) - actionview (= 4.2.5.2) - activejob (= 4.2.5.2) - activemodel (= 4.2.5.2) - activerecord (= 4.2.5.2) - activesupport (= 4.2.5.2) + rails (4.2.6) + actionmailer (= 4.2.6) + actionpack (= 4.2.6) + actionview (= 4.2.6) + activejob (= 4.2.6) + activemodel (= 4.2.6) + activerecord (= 4.2.6) + activesupport (= 4.2.6) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.5.2) + railties (= 4.2.6) sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) @@ -614,9 +614,9 @@ GEM rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - railties (4.2.5.2) - actionpack (= 4.2.5.2) - activesupport (= 4.2.5.2) + railties (4.2.6) + actionpack (= 4.2.6) + activesupport (= 4.2.6) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.1.0) @@ -788,10 +788,10 @@ GEM spring (>= 0.9.1) sprockets (3.3.5) rack (> 1, < 3) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) + sprockets-rails (3.0.4) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) state_machines (0.4.0) state_machines-activemodel (0.3.0) activemodel (~> 4.1) @@ -1002,7 +1002,7 @@ DEPENDENCIES rack-attack (~> 4.3.1) rack-cors (~> 0.4.0) rack-oauth2 (~> 1.2.1) - rails (= 4.2.5.2) + rails (= 4.2.6) rails-deprecated_sanitizer (~> 1.0.3) raphael-rails (~> 2.1.2) rblineprof diff --git a/config/environments/test.rb b/config/environments/test.rb index f96ac6f975..a703c0934f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -8,6 +8,7 @@ Rails.application.configure do config.cache_classes = false # Configure static asset server for tests with Cache-Control for performance + config.assets.digest = false config.serve_static_files = true config.static_cache_control = "public, max-age=3600" From 0ab6b82a234f6dcc208591724036f152eca0e1c4 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Tue, 5 Apr 2016 12:09:19 -0700 Subject: [PATCH 028/212] Update shades of red --- app/assets/stylesheets/framework/variables.scss | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index 98fe794d36..dd189a2cb7 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -104,9 +104,9 @@ $orange-light: rgba(252, 109, 38, 0.80); $orange-normal: #e75e40; $orange-dark: #ce5237; -$red-light: #f06559; -$red-normal: #e52c5a; -$red-dark: #d22852; +$red-light: #e52c5a; +$red-normal: #d22852; +$red-dark: darken($red-normal, 5%); $border-white-light: #f1f2f4; $border-white-normal: #d6dae2; @@ -128,9 +128,9 @@ $border-orange-light: #fc6d26; $border-orange-normal: #ce5237; $border-orange-dark: #c14e35; -$border-red-light: #f24f41; -$border-red-normal: #d22852; -$border-red-dark: #ca264f; +$border-red-light: #d22852; +$border-red-normal: #ca264f; +$border-red-dark: darken($border-red-normal, 5%); $help-well-bg: #fafafa; $help-well-border: #e5e5e5; From 5ee6badade3c453c7090e9c1f1f4d636c5bb068e Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Tue, 5 Apr 2016 16:33:37 -0300 Subject: [PATCH 029/212] Unblocks user when active_directory is disabled and it can be found --- lib/gitlab/ldap/access.rb | 5 ++++- spec/lib/gitlab/ldap/access_spec.rb | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/ldap/access.rb b/lib/gitlab/ldap/access.rb index da4435c730..f2b649e50a 100644 --- a/lib/gitlab/ldap/access.rb +++ b/lib/gitlab/ldap/access.rb @@ -33,7 +33,10 @@ module Gitlab def allowed? if ldap_user - return true unless ldap_config.active_directory + unless ldap_config.active_directory + user.activate if user.ldap_blocked? + return true + end # Block user in GitLab if he/she was blocked in AD if Gitlab::LDAP::Person.disabled_via_active_directory?(user.ldap_identity.extern_uid, adapter) diff --git a/spec/lib/gitlab/ldap/access_spec.rb b/spec/lib/gitlab/ldap/access_spec.rb index 32a19bf344..f5b66b8156 100644 --- a/spec/lib/gitlab/ldap/access_spec.rb +++ b/spec/lib/gitlab/ldap/access_spec.rb @@ -33,7 +33,7 @@ describe Gitlab::LDAP::Access, lib: true do it { is_expected.to be_falsey } - it 'should block user in GitLab' do + it 'blocks user in GitLab' do access.allowed? expect(user).to be_blocked expect(user).to be_ldap_blocked @@ -78,6 +78,31 @@ describe Gitlab::LDAP::Access, lib: true do end it { is_expected.to be_truthy } + + context 'when user cannot be found' do + before do + allow(Gitlab::LDAP::Person).to receive(:find_by_dn).and_return(nil) + end + + it { is_expected.to be_falsey } + + it 'blocks user in GitLab' do + access.allowed? + expect(user).to be_blocked + expect(user).to be_ldap_blocked + end + end + + context 'when user was previously ldap_blocked' do + before do + user.ldap_block + end + + it 'unblocks the user if it exists' do + access.allowed? + expect(user).not_to be_blocked + end + end end end end From 3911e77eb4244f010af4050c140bc2d08e3c34df Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 5 Apr 2016 23:08:22 +0200 Subject: [PATCH 030/212] Remove TODO for not documented stuff --- doc/development/ui_guide.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/development/ui_guide.md b/doc/development/ui_guide.md index 2f01defc11..a3e260a5f8 100644 --- a/doc/development/ui_guide.md +++ b/doc/development/ui_guide.md @@ -1,9 +1,5 @@ # UI Guide for building GitLab -## Best practices for creating new pages in GitLab - -TODO: write some best practices when develop GitLab features. - ## GitLab UI development kit We created a page inside GitLab where you can check commonly used html and css elements. From d2afeb8dde7837688bdaaf8575d6621a8b42ba7f Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Tue, 5 Apr 2016 17:29:40 -0500 Subject: [PATCH 031/212] Do not add location badge when creating a group or project --- app/views/layouts/_search.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_search.html.haml b/app/views/layouts/_search.html.haml index 9d4ab9847a..ce9df1566d 100644 --- a/app/views/layouts/_search.html.haml +++ b/app/views/layouts/_search.html.haml @@ -1,6 +1,6 @@ -- if controller.controller_path =~ /^groups/ +- if controller.controller_path =~ /^groups/ && !@group.new_record? - label = 'This group' -- if controller.controller_path =~ /^projects/ +- if controller.controller_path =~ /^projects/ && !@project.new_record? - label = 'This project' .search.search-form{class: "#{'has-location-badge' if label.present?}"} From 7baebd322008e0ca912c447792f1d7cffd74f8e2 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Tue, 5 Apr 2016 19:18:34 -0500 Subject: [PATCH 032/212] Do not create input if fieldName is not defined --- app/assets/javascripts/gl_dropdown.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index 6b55917ec8..362ddda359 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -369,7 +369,7 @@ class GitLabDropdown if @options.toggleLabel $(@el).find(".dropdown-toggle-text").text @options.toggleLabel(selectedObject) if value? - if !field.length + if !field.length and fieldName # Create hidden input for form input = "" if @options.inputId? From 518ec6b2660c55beba2833ce71b93774ed0a6c2a Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Tue, 5 Apr 2016 19:20:18 -0500 Subject: [PATCH 033/212] Changed config syntax and improved how chaanges in group memberships are handled when external groups is set up --- lib/gitlab/saml/config.rb | 4 ++-- lib/gitlab/saml/user.rb | 39 ++++++++++++--------------------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/lib/gitlab/saml/config.rb b/lib/gitlab/saml/config.rb index dade4c0fa6..2b3cf840f6 100644 --- a/lib/gitlab/saml/config.rb +++ b/lib/gitlab/saml/config.rb @@ -9,11 +9,11 @@ module Gitlab end def groups - options['groups_attribute'] + options[:groups_attribute] end def external_groups - options['external_groups'] + options[:external_groups] end end diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index 14eda337d9..6ab165cf51 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -7,11 +7,6 @@ module Gitlab module Saml class User < Gitlab::OAuth::User - def initialize(auth_hash) - super - update_user_attributes - end - def save super('SAML') end @@ -31,6 +26,18 @@ module Gitlab @user ||= build_new_user end + if external_users_enabled? + # Check if there is overlap between the user's groups and the external groups + # setting and set user as external or internal. + if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? + # Avoid an unnecessary change of values and the subsequent save + @user.external = false if @user.external + else + # Avoid an unnecessary change of values and the subsequent save + @user.external = true unless @user.external + end + end + @user end @@ -48,16 +55,6 @@ module Gitlab protected - def build_new_user - user = super - if external_users_enabled? - unless (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? - user.external = true - end - end - user - end - def auto_link_saml_user? Gitlab.config.omniauth.auto_link_saml_user end @@ -69,18 +66,6 @@ module Gitlab def auth_hash=(auth_hash) @auth_hash = Gitlab::Saml::AuthHash.new(auth_hash) end - - def update_user_attributes - if persisted? - if external_users_enabled? - if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? - gl_user.external = false - else - gl_user.external = true - end - end - end - end end end end From 7efaf22bccb16b381f7e76054d084e741006fc5f Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Tue, 5 Apr 2016 19:22:58 -0500 Subject: [PATCH 034/212] Removed extra LDAP tests and added tests for the external groups feature --- spec/lib/gitlab/saml/user_spec.rb | 68 +++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/spec/lib/gitlab/saml/user_spec.rb b/spec/lib/gitlab/saml/user_spec.rb index 6f5cf3a1cf..84a26af940 100644 --- a/spec/lib/gitlab/saml/user_spec.rb +++ b/spec/lib/gitlab/saml/user_spec.rb @@ -5,7 +5,7 @@ describe Gitlab::Saml::User, lib: true do let(:gl_user) { saml_user.gl_user } let(:uid) { 'my-uid' } let(:provider) { 'saml' } - let(:auth_hash) { OmniAuth::AuthHash.new(uid: uid, provider: provider, info: info_hash) } + let(:auth_hash) { OmniAuth::AuthHash.new(uid: uid, provider: provider, info: info_hash, extra: { raw_info: { groups: %w(Developers Freelancers Designers) } }) } let(:info_hash) do { name: 'John', @@ -31,8 +31,8 @@ describe Gitlab::Saml::User, lib: true do describe 'account exists on server' do before { stub_omniauth_config({ allow_single_sign_on: ['saml'], auto_link_saml_user: true }) } + let!(:existing_user) { create(:user, email: 'john@mail.com', username: 'john') } context 'and should bind with SAML' do - let!(:existing_user) { create(:user, email: 'john@mail.com', username: 'john') } it 'adds the SAML identity to the existing user' do saml_user.save expect(gl_user).to be_valid @@ -42,6 +42,32 @@ describe Gitlab::Saml::User, lib: true do expect(identity.provider).to eql 'saml' end end + + context 'external groups' do + context 'are defined' do + before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Freelancers), args: {} } }) } + it 'marks the user as external' do + saml_user.save + expect(gl_user.external).to be_truthy + end + end + + before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Interns), args: {} } }) } + context 'are defined but the user does not belong there' do + it 'does not mark the user as external' do + saml_user.save + expect(gl_user.external).to be_falsey + end + end + + context 'user was external, now should not be' do + it 'should make user internal' do + existing_user.update_attribute('external', true) + saml_user.save + expect(gl_user.external).to be_falsey + end + end + end end describe 'no account exists on server' do @@ -74,6 +100,24 @@ describe Gitlab::Saml::User, lib: true do end end + context 'external groups' do + context 'are defined' do + before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Freelancers), args: {} } }) } + it 'marks the user as external' do + saml_user.save + expect(gl_user.external).to be_truthy + end + end + + before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Interns), args: {} } }) } + context 'are defined but the user does not belong there' do + it 'does not mark the user as external' do + saml_user.save + expect(gl_user.external).to be_falsey + end + end + end + context 'with auto_link_ldap_user disabled (default)' do before { stub_omniauth_config({ auto_link_ldap_user: false, auto_link_saml_user: false, allow_single_sign_on: ['saml'] }) } include_examples 'to verify compliance with allow_single_sign_on' @@ -193,26 +237,6 @@ describe Gitlab::Saml::User, lib: true do expect(gl_user).not_to be_blocked end end - - context 'dont block on create (LDAP)' do - before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: false) } - - it do - saml_user.save - expect(gl_user).to be_valid - expect(gl_user).not_to be_blocked - end - end - - context 'block on create (LDAP)' do - before { allow_any_instance_of(Gitlab::LDAP::Config).to receive_messages(block_auto_created_users: true) } - - it do - saml_user.save - expect(gl_user).to be_valid - expect(gl_user).not_to be_blocked - end - end end end end From 55b2fae327854be6ab0789dbdf92f4265207680f Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Wed, 6 Apr 2016 02:50:01 +0100 Subject: [PATCH 035/212] set up test for preventing this issue from reoccuring --- spec/features/issues/filter_issues_spec.rb | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 spec/features/issues/filter_issues_spec.rb diff --git a/spec/features/issues/filter_issues_spec.rb b/spec/features/issues/filter_issues_spec.rb new file mode 100644 index 0000000000..7884121353 --- /dev/null +++ b/spec/features/issues/filter_issues_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +describe 'Filter issues', feature: true do + + let!(:project) { create(:project) } + let!(:issue) { create(:issue, project: project) } + let!(:user) { create(:user)} + + before do + project.team << [user, :master] + login_as(user) + end + + describe 'Filter issues for assignee from issues#index' do + + before do + visit namespace_project_issues_path(project.namespace, project) + + find('.js-assignee-search').click + + find('.dropdown-menu-user-link', text: user.username).click + + sleep 2 + end + + context 'assignee', js: true do + it 'should update to current user' do + expect(find('.js-assignee-search .dropdown-toggle-text')).to have_content(user.name) + end + + it 'should not change when closed link is clicked' do + find('.issues-state-filters a', text: "Closed").click + + expect(find('.js-assignee-search .dropdown-toggle-text')).to have_content(user.name) + end + + + it 'should not change when all link is clicked' do + find('.issues-state-filters a', text: "All").click + + expect(find('.js-assignee-search .dropdown-toggle-text')).to have_content(user.name) + end + end + end +end From 1e87679702d57a0c01f6352851fd144fd213ea56 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Wed, 6 Apr 2016 03:42:27 +0100 Subject: [PATCH 036/212] complete the tests --- spec/features/issues/filter_issues_spec.rb | 76 +++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/spec/features/issues/filter_issues_spec.rb b/spec/features/issues/filter_issues_spec.rb index 7884121353..90822a8c12 100644 --- a/spec/features/issues/filter_issues_spec.rb +++ b/spec/features/issues/filter_issues_spec.rb @@ -3,8 +3,9 @@ require 'rails_helper' describe 'Filter issues', feature: true do let!(:project) { create(:project) } - let!(:issue) { create(:issue, project: project) } let!(:user) { create(:user)} + let!(:milestone) { create(:milestone, project: project) } + let!(:label) { create(:label, project: project) } before do project.team << [user, :master] @@ -42,4 +43,77 @@ describe 'Filter issues', feature: true do end end end + + describe 'Filter issues for milestone from issues#index' do + + before do + visit namespace_project_issues_path(project.namespace, project) + + find('.js-milestone-select').click + + find('.milestone-filter .dropdown-content a', text: milestone.title).click + + sleep 2 + end + + context 'milestone', js: true do + it 'should update to current milestone' do + expect(find('.js-milestone-select .dropdown-toggle-text')).to have_content(milestone.title) + end + + it 'should not change when closed link is clicked' do + find('.issues-state-filters a', text: "Closed").click + + expect(find('.js-milestone-select .dropdown-toggle-text')).to have_content(milestone.title) + end + + + it 'should not change when all link is clicked' do + find('.issues-state-filters a', text: "All").click + + expect(find('.js-milestone-select .dropdown-toggle-text')).to have_content(milestone.title) + end + end + end + + describe 'Filter issues for assignee and label from issues#index' do + + before do + visit namespace_project_issues_path(project.namespace, project) + + find('.js-assignee-search').click + + find('.dropdown-menu-user-link', text: user.username).click + + sleep 2 + + find('.js-label-select').click + + find('.dropdown-menu-labels .dropdown-content a', text: label.title).click + + sleep 2 + end + + context 'assignee and label', js: true do + it 'should update to current assignee and label' do + expect(find('.js-assignee-search .dropdown-toggle-text')).to have_content(user.name) + expect(find('.js-label-select .dropdown-toggle-text')).to have_content(label.title) + end + + it 'should not change when closed link is clicked' do + find('.issues-state-filters a', text: "Closed").click + + expect(find('.js-assignee-search .dropdown-toggle-text')).to have_content(user.name) + expect(find('.js-label-select .dropdown-toggle-text')).to have_content(label.title) + end + + + it 'should not change when all link is clicked' do + find('.issues-state-filters a', text: "All").click + + expect(find('.js-assignee-search .dropdown-toggle-text')).to have_content(user.name) + expect(find('.js-label-select .dropdown-toggle-text')).to have_content(label.title) + end + end + end end From 61fe0a23977749b0a5dba41ca26101b4a03de720 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Fri, 1 Apr 2016 04:03:08 -0300 Subject: [PATCH 037/212] Fixed WikiPipeline and specs --- lib/banzai/pipeline/wiki_pipeline.rb | 2 +- spec/lib/banzai/pipeline/wiki_pipeline_spec.rb | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/banzai/pipeline/wiki_pipeline.rb b/lib/banzai/pipeline/wiki_pipeline.rb index 1cdb380896..bcb89485de 100644 --- a/lib/banzai/pipeline/wiki_pipeline.rb +++ b/lib/banzai/pipeline/wiki_pipeline.rb @@ -4,7 +4,7 @@ module Banzai def self.filters @filters ||= begin super.insert_after(Filter::TableOfContentsFilter, Filter::GollumTagsFilter) - .insert_after(Filter::GollumTagsFilter, Filter::WikiLinkFilter) + .insert_after(Filter::TableOfContentsFilter, Filter::WikiLinkFilter) end end end diff --git a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb index 3e25406e49..4f86b1d87e 100644 --- a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb @@ -1,6 +1,9 @@ require 'rails_helper' describe Banzai::Pipeline::WikiPipeline do + let(:project_wiki) { double } + before(:each) { allow(project_wiki).to receive(:wiki_base_path) { '/some/repo/wikis' } } + describe 'TableOfContents' do it 'replaces the tag with the TableOfContentsFilter result' do markdown = <<-MD.strip_heredoc @@ -11,7 +14,7 @@ describe Banzai::Pipeline::WikiPipeline do Foo MD - result = described_class.call(markdown, project: spy, project_wiki: double) + result = described_class.call(markdown, project: spy, project_wiki: project_wiki) aggregate_failures do expect(result[:output].text).not_to include '[[' @@ -29,7 +32,7 @@ describe Banzai::Pipeline::WikiPipeline do Foo MD - output = described_class.to_html(markdown, project: spy, project_wiki: double) + output = described_class.to_html(markdown, project: spy, project_wiki: project_wiki) expect(output).to include('[[toc]]') end @@ -42,7 +45,7 @@ describe Banzai::Pipeline::WikiPipeline do Foo MD - output = described_class.to_html(markdown, project: spy, project_wiki: double) + output = described_class.to_html(markdown, project: spy, project_wiki: project_wiki) aggregate_failures do expect(output).not_to include('
      ') From 22055e10580ae93c2cb87956eefba0a06e9b50d0 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Fri, 1 Apr 2016 05:22:22 -0300 Subject: [PATCH 038/212] Fix a few edited references from WikiLinkFilter and specs --- lib/banzai/filter/wiki_link_filter.rb | 8 ++++++-- spec/features/markdown_spec.rb | 1 + spec/support/matchers/markdown_matchers.rb | 9 +++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/banzai/filter/wiki_link_filter.rb b/lib/banzai/filter/wiki_link_filter.rb index 7a585eff65..06d10c9850 100644 --- a/lib/banzai/filter/wiki_link_filter.rb +++ b/lib/banzai/filter/wiki_link_filter.rb @@ -25,10 +25,10 @@ module Banzai end def process_link_attr(html_attr) - return if html_attr.blank? + return if html_attr.blank? || file_reference?(html_attr) uri = URI(html_attr.value) - if uri.relative? && uri.path.present? && uri.path + if uri.relative? && uri.path.present? html_attr.value = rebuild_wiki_uri(uri).to_s end rescue URI::Error @@ -40,6 +40,10 @@ module Banzai uri end + def file_reference?(html_attr) + !File.extname(html_attr.value).blank? + end + def project_wiki context[:project_wiki] end diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb index 12fd8d3721..5149ce9cf2 100644 --- a/spec/features/markdown_spec.rb +++ b/spec/features/markdown_spec.rb @@ -230,6 +230,7 @@ describe 'GitLab Markdown', feature: true do file = Gollum::File.new(@project_wiki.wiki) expect(file).to receive(:path).and_return('images/example.jpg') expect(@project_wiki).to receive(:find_file).with('images/example.jpg').and_return(file) + allow(@project_wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' } @html = markdown(@feat.raw_markdown, { pipeline: :wiki, project_wiki: @project_wiki }) end diff --git a/spec/support/matchers/markdown_matchers.rb b/spec/support/matchers/markdown_matchers.rb index 1d52489e80..43cb6ef43f 100644 --- a/spec/support/matchers/markdown_matchers.rb +++ b/spec/support/matchers/markdown_matchers.rb @@ -13,7 +13,7 @@ module MarkdownMatchers set_default_markdown_messages match do |actual| - link = actual.at_css('a:contains("Relative Link")') + link = actual.at_css('a:contains("Relative Link")') image = actual.at_css('img[alt="Relative Image"]') expect(link['href']).to end_with('master/doc/README.md') @@ -72,14 +72,15 @@ module MarkdownMatchers have_css("img[src$='#{src}']") end + prefix = '/namespace1/gitlabhq/wikis' set_default_markdown_messages match do |actual| - expect(actual).to have_link('linked-resource', href: 'linked-resource') - expect(actual).to have_link('link-text', href: 'linked-resource') + expect(actual).to have_link('linked-resource', href: "#{prefix}/linked-resource") + expect(actual).to have_link('link-text', href: "#{prefix}/linked-resource") expect(actual).to have_link('http://example.com', href: 'http://example.com') expect(actual).to have_link('link-text', href: 'http://example.com/pdfs/gollum.pdf') - expect(actual).to have_image('/gitlabhq/wikis/images/example.jpg') + expect(actual).to have_image("#{prefix}/images/example.jpg") expect(actual).to have_image('http://example.com/images/example.jpg') end end From 207b7218aa4394dc24c68041eade04474ff41537 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Fri, 1 Apr 2016 15:03:39 -0300 Subject: [PATCH 039/212] Ensure correct filter order to validate with our markdown spec --- lib/banzai/filter/gollum_tags_filter.rb | 8 ++++++-- lib/banzai/pipeline/wiki_pipeline.rb | 2 +- spec/features/markdown_spec.rb | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/banzai/filter/gollum_tags_filter.rb b/lib/banzai/filter/gollum_tags_filter.rb index cfd3e28ed0..f710a4971b 100644 --- a/lib/banzai/filter/gollum_tags_filter.rb +++ b/lib/banzai/filter/gollum_tags_filter.rb @@ -118,7 +118,7 @@ module Banzai end if path - content_tag(:img, nil, src: path) + content_tag(:img, nil, src: path, class: tag_class('image')) end end @@ -155,7 +155,7 @@ module Banzai href = ::File.join(project_wiki_base_path, reference) end - content_tag(:a, name || reference, href: href) + content_tag(:a, name || reference, href: href, class: tag_class('page')) end def project_wiki @@ -172,6 +172,10 @@ module Banzai def validate needs :project_wiki end + + def tag_class(type) + "gfm gollum gollum-#{type}" + end end end end diff --git a/lib/banzai/pipeline/wiki_pipeline.rb b/lib/banzai/pipeline/wiki_pipeline.rb index bcb89485de..c37b8e71cb 100644 --- a/lib/banzai/pipeline/wiki_pipeline.rb +++ b/lib/banzai/pipeline/wiki_pipeline.rb @@ -4,7 +4,7 @@ module Banzai def self.filters @filters ||= begin super.insert_after(Filter::TableOfContentsFilter, Filter::GollumTagsFilter) - .insert_after(Filter::TableOfContentsFilter, Filter::WikiLinkFilter) + .insert_before(Filter::TaskListFilter, Filter::WikiLinkFilter) end end end diff --git a/spec/features/markdown_spec.rb b/spec/features/markdown_spec.rb index 5149ce9cf2..3d0d0e59fd 100644 --- a/spec/features/markdown_spec.rb +++ b/spec/features/markdown_spec.rb @@ -39,7 +39,7 @@ describe 'GitLab Markdown', feature: true do end def doc(html = @html) - Nokogiri::HTML::DocumentFragment.parse(html) + @doc ||= Nokogiri::HTML::DocumentFragment.parse(html) end # Shared behavior that all pipelines should exhibit From 3137f61a5558d1b38dd9f607263d5a21b61deb2d Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 6 Apr 2016 10:49:57 +0200 Subject: [PATCH 040/212] Make redis an explicit Gemfile dependency --- Gemfile | 5 ++++- Gemfile.lock | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 6327227282..eebaae320e 100644 --- a/Gemfile +++ b/Gemfile @@ -149,6 +149,10 @@ gem 'version_sorter', '~> 2.0.0' # Cache gem "redis-rails", '~> 4.0.0' +# Redis +gem 'redis', '~> 3.2' +gem 'connection_pool', '~> 2.0' + # Campfire integration gem 'tinder', '~> 1.10.0' @@ -229,7 +233,6 @@ group :metrics do gem 'allocations', '~> 1.0', require: false, platform: :mri gem 'method_source', '~> 0.8', require: false gem 'influxdb', '~> 0.2', require: false - gem 'connection_pool', '~> 2.0', require: false end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 229089f431..3be9ed0afc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1009,6 +1009,7 @@ DEPENDENCIES rdoc (~> 3.6) recaptcha redcarpet (~> 3.3.3) + redis (~> 3.2) redis-namespace redis-rails (~> 4.0.0) request_store (~> 1.3.0) From 4d463c3b0f05fa8873b76afce621eaaf44c19836 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 09:54:49 +0100 Subject: [PATCH 041/212] Fixed delete comment button color --- app/views/projects/notes/_note.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/notes/_note.html.haml b/app/views/projects/notes/_note.html.haml index 34fe1743f4..a681d6dece 100644 --- a/app/views/projects/notes/_note.html.haml +++ b/app/views/projects/notes/_note.html.haml @@ -18,7 +18,7 @@ = access = link_to '#', title: 'Edit comment', class: 'note-action-button js-note-edit' do = icon('pencil-square-o') - = link_to namespace_project_note_path(note.project.namespace, note.project, note), title: 'Remove comment', method: :delete, data: { confirm: 'Are you sure you want to remove this comment?' }, remote: true, class: 'note-action-button js-note-delete danger' do + = link_to namespace_project_note_path(note.project.namespace, note.project, note), title: 'Remove comment', method: :delete, data: { confirm: 'Are you sure you want to remove this comment?' }, remote: true, class: 'note-action-button js-note-delete' do = icon('trash-o') .note-body{class: note_editable?(note) ? 'js-task-list-container' : ''} .note-text From d6f276eacfdb7e8287df69dfc1dbf756288bade8 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 10:05:39 +0100 Subject: [PATCH 042/212] Fixed issue with enter key not selecting correct value in dropdown --- app/assets/javascripts/gl_dropdown.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index 2a4811b876..33c5126087 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -394,7 +394,7 @@ class GitLabDropdown selector = ".dropdown-page-one #{selector}" # simulate a click on the first link - $(selector).trigger "click" + $(selector, @dropdown).trigger "click" addArrowKeyEvent: -> ARROW_KEY_CODES = [38, 40] From d023a8528713ab9ffd8a9fc034f752ab91442b24 Mon Sep 17 00:00:00 2001 From: Yasser Hussain Date: Wed, 6 Apr 2016 15:07:31 +0530 Subject: [PATCH 043/212] Changed the argument of not_found for 'unprotect' not_found appends string "Not Found" to the argument causing the resulting message to be "Branch does not exist Not Found" which is an incorrect error message. Changed the argument of not_found! for 'unprotect' command to "Branch" from "Branch does not exist". This makes the final error message to appear as "Branch Not Found" which is correct and same as error messages for other commands like 'protect'. --- lib/api/branches.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 592100a704..231840148d 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -64,7 +64,7 @@ module API authorize_admin_project @branch = user_project.repository.find_branch(params[:branch]) - not_found!("Branch does not exist") unless @branch + not_found!("Branch") unless @branch protected_branch = user_project.protected_branches.find_by(name: @branch.name) protected_branch.destroy if protected_branch From c5c05f6a04ab3c791bc7c34dc74925731cf2ff94 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 15 Mar 2016 14:43:40 +0000 Subject: [PATCH 044/212] Updated UI for new merge request Closes #2540 --- app/assets/javascripts/compare.js.coffee | 61 ++++++++++++++++ .../stylesheets/pages/merge_requests.scss | 51 +++++++++++-- .../projects/merge_requests_controller.rb | 2 + app/helpers/commits_helper.rb | 4 +- app/views/projects/commits/_commit.html.haml | 2 +- .../merge_requests/_new_compare.html.haml | 71 ++++++------------- .../merge_requests/branch_from.html.haml | 1 + .../merge_requests/branch_from.js.haml | 3 - .../merge_requests/branch_to.html.haml | 1 + .../projects/merge_requests/branch_to.js.haml | 3 - 10 files changed, 138 insertions(+), 61 deletions(-) create mode 100644 app/assets/javascripts/compare.js.coffee create mode 100644 app/views/projects/merge_requests/branch_from.html.haml delete mode 100644 app/views/projects/merge_requests/branch_from.js.haml create mode 100644 app/views/projects/merge_requests/branch_to.html.haml delete mode 100644 app/views/projects/merge_requests/branch_to.js.haml diff --git a/app/assets/javascripts/compare.js.coffee b/app/assets/javascripts/compare.js.coffee new file mode 100644 index 0000000000..c13744ebc6 --- /dev/null +++ b/app/assets/javascripts/compare.js.coffee @@ -0,0 +1,61 @@ +class @Compare + constructor: (@opts) -> + @source_loading = $ ".js-source-loading" + @target_loading = $ ".js-target-loading" + @source_branch = $ "#merge_request_source_branch" + @target_branch = $ "#merge_request_target_branch" + @target_project = $ "#merge_request_target_project_id" + + @initialState() + @cleanBinding() + @addBinding() + + cleanBinding: -> + @source_branch.off "change" + @target_branch.off "change" + @target_project.off "change" + + addBinding: -> + @source_branch.on "change", => + @getSourceHtml() + @target_branch.on "change", => + @getTargetHtml() + @target_project.on "change", => + @getTargetProject() + + initialState: -> + @getSourceHtml() + @getTargetHtml() + + getTargetProject: -> + $.get @opts.targetProjectUrl, + target_project_id: @target_project.val() + + getSourceHtml: -> + $.ajax( + url: @opts.sourceBranchUrl + data: + ref: @source_branch.val() + beforeSend: => + @source_loading.show() + $(".mr_source_commit").html "" + success: (html) => + @source_loading.hide() + $(".mr_source_commit").html html + $(".mr_source_commit .js-timeago").timeago() + ) + + getTargetHtml: -> + $.ajax( + url: @opts.targetBranchUrl + data: + target_project_id: @target_project.val() + ref: @target_branch.val() + beforeSend: => + @target_loading.show() + $(".mr_target_commit").html "" + success: (html) => + @target_loading.hide() + $(".mr_target_commit").html html + $(".mr_target_commit .js-timeago").timeago() + ) diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index 1c6a420897..7bc1f58471 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -123,6 +123,8 @@ .mr_source_commit, .mr_target_commit { + margin-bottom: 0; + .commit { margin: 0; padding: 2px 0; @@ -174,10 +176,6 @@ display: none; } -.merge-request-form .select2-container { - width: 250px !important; -} - #modal_merge_info .modal-dialog { width: 600px; @@ -200,3 +198,48 @@ overflow-x: scroll; } } + +.panel-new-merge-request { + .panel-heading { + padding: 5px 10px; + font-weight: 600; + line-height: 25px; + } + + .panel-body { + padding: 10px 5px; + } + + .panel-footer { + padding: 10px 10px; + } + + .commit { + .commit-row-title { + margin-bottom: 4px; + } + + .avatar { + width: 20px; + height: 20px; + margin-right: 5px; + } + + .commit-row-info { + line-height: 20px; + } + } + + .btn-clipboard { + margin-right: 5px; + padding: 0; + background: transparent; + } +} + +.merge-request-select { + float: left; + width: 50%; + padding-left: 5px; + padding-right: 5px; +} diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 49064f5d50..ca6cfc9914 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -207,11 +207,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController #This is always source @source_project = @merge_request.nil? ? @project : @merge_request.source_project @commit = @repository.commit(params[:ref]) if params[:ref].present? + render layout: false end def branch_to @target_project = selected_target_project @commit = @target_project.commit(params[:ref]) if params[:ref].present? + render layout: false end def update_branches diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index bde0799f3d..a65e2e5cb8 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -28,7 +28,7 @@ module CommitsHelper def commit_to_html(commit, project, inline = true) template = inline ? "inline_commit" : "commit" - escape_javascript(render "projects/commits/#{template}", commit: commit, project: project) unless commit.nil? + render "projects/commits/#{template}", commit: commit, project: project unless commit.nil? end # Breadcrumb links for a Project and, if applicable, a tree path @@ -117,7 +117,7 @@ module CommitsHelper end end link_to( - "Browse Files »", + "Browse Files", namespace_project_tree_path(project.namespace, project, commit), class: "pull-right" ) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 7f2903589a..b55fe510f7 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -35,8 +35,8 @@ = preserve(markdown(escape_once(commit.description), pipeline: :single_line)) .commit-row-info + by = commit_author_link(commit, avatar: true, size: 24) - authored .committed_ago #{time_ago_with_tooltip(commit.committed_date, skip_js: true)}   = link_to_browse_code(project, commit) diff --git a/app/views/projects/merge_requests/_new_compare.html.haml b/app/views/projects/merge_requests/_new_compare.html.haml index 01dc7519be..4fc74dfcf4 100644 --- a/app/views/projects/merge_requests/_new_compare.html.haml +++ b/app/views/projects/merge_requests/_new_compare.html.haml @@ -5,27 +5,31 @@ .hide.alert.alert-danger.mr-compare-errors .merge-request-branches.row .col-md-6 - .panel.panel-default + .panel.panel-default.panel-new-merge-request .panel-heading - %strong Source branch - .panel-body - = f.select(:source_project_id, [[@merge_request.source_project_path,@merge_request.source_project.id]] , {}, { class: 'source_project select2 span3', disabled: @merge_request.persisted?, required: true }) -   - = f.select(:source_branch, @merge_request.source_branches, { include_blank: true }, { class: 'source_branch select2 span2', required: true, data: { placeholder: "Select source branch" } }) + Source branch + .panel-body.clearfix + .merge-request-select + = f.select(:source_project_id, [[@merge_request.source_project_path,@merge_request.source_project.id]] , {}, { class: 'source_project select2', disabled: @merge_request.persisted?, required: true }) + .merge-request-select + = f.select(:source_branch, @merge_request.source_branches, { include_blank: true }, { class: 'source_branch select2', required: true, data: { placeholder: "Select source branch" } }) .panel-footer - .mr_source_commit + = icon('spinner spin', class: "js-source-loading") + %ul.list-unstyled.mr_source_commit .col-md-6 - .panel.panel-default + .panel.panel-default.panel-new-merge-request .panel-heading - %strong Target branch - .panel-body + Target branch + .panel-body.clearfix - projects = @project.forked_from_project.nil? ? [@project] : [@project, @project.forked_from_project] - = f.select(:target_project_id, options_from_collection_for_select(projects, 'id', 'path_with_namespace', f.object.target_project_id), {}, { class: 'target_project select2 span3', disabled: @merge_request.persisted?, required: true }) -   - = f.select(:target_branch, @merge_request.target_branches, { include_blank: true }, { class: 'target_branch select2 span2', required: true, data: { placeholder: "Select target branch" } }) + .merge-request-select + = f.select(:target_project_id, options_from_collection_for_select(projects, 'id', 'path_with_namespace', f.object.target_project_id), {}, { class: 'target_project select2', disabled: @merge_request.persisted?, required: true }) + .merge-request-select + = f.select(:target_branch, @merge_request.target_branches, { include_blank: true }, { class: 'target_branch select2', required: true, data: { placeholder: "Select target branch" } }) .panel-footer - .mr_target_commit + = icon('spinner spin', class: "js-target-loading") + %ul.list-unstyled.mr_target_commit - if @merge_request.errors.any? .alert.alert-danger @@ -45,40 +49,11 @@ and %span.label-branch #{@merge_request.target_branch} are the same. - - - .form-actions - = f.submit 'Compare branches and continue', class: "btn btn-new mr-compare-btn" + = f.submit 'Compare branches and continue', class: "btn btn-new mr-compare-btn" :javascript - var source_branch = $("#merge_request_source_branch") - , target_branch = $("#merge_request_target_branch") - , target_project = $("#merge_request_target_project_id"); - - $.get("#{branch_from_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {ref: source_branch.val() }); - $.get("#{branch_to_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {target_project_id: target_project.val(),ref: target_branch.val() }); - - target_project.on("change", function() { - $.get("#{update_branches_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {target_project_id: $(this).val() }); - }); - source_branch.on("change", function() { - $.get("#{branch_from_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {ref: $(this).val() }); - $(".mr-compare-errors").fadeOut(); - $(".mr-compare-btn").enable(); - }); - target_branch.on("change", function() { - $.get("#{branch_to_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {target_project_id: target_project.val(),ref: $(this).val() }); - $(".mr-compare-errors").fadeOut(); - $(".mr-compare-btn").enable(); - }); - - -:javascript - $(".merge-request-form").on('submit', function () { - if ($("#merge_request_source_branch").val() === "" || $('#merge_request_target_branch').val() === "") { - $(".mr-compare-errors").html("You must select source and target branch to proceed"); - $(".mr-compare-errors").fadeIn(); - event.preventDefault(); - return; - } + new Compare({ + targetProjectUrl: "#{update_branches_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", + sourceBranchUrl: "#{branch_from_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", + targetBranchUrl: "#{branch_to_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}" }); diff --git a/app/views/projects/merge_requests/branch_from.html.haml b/app/views/projects/merge_requests/branch_from.html.haml new file mode 100644 index 0000000000..4f90dde6fa --- /dev/null +++ b/app/views/projects/merge_requests/branch_from.html.haml @@ -0,0 +1 @@ += commit_to_html(@commit, @source_project, false) diff --git a/app/views/projects/merge_requests/branch_from.js.haml b/app/views/projects/merge_requests/branch_from.js.haml deleted file mode 100644 index 9210798f39..0000000000 --- a/app/views/projects/merge_requests/branch_from.js.haml +++ /dev/null @@ -1,3 +0,0 @@ -:plain - $(".mr_source_commit").html("#{commit_to_html(@commit, @source_project, false)}"); - $('.js-timeago').timeago() diff --git a/app/views/projects/merge_requests/branch_to.html.haml b/app/views/projects/merge_requests/branch_to.html.haml new file mode 100644 index 0000000000..67a7a6bcec --- /dev/null +++ b/app/views/projects/merge_requests/branch_to.html.haml @@ -0,0 +1 @@ += commit_to_html(@commit, @target_project, false) diff --git a/app/views/projects/merge_requests/branch_to.js.haml b/app/views/projects/merge_requests/branch_to.js.haml deleted file mode 100644 index 32fe2d535f..0000000000 --- a/app/views/projects/merge_requests/branch_to.js.haml +++ /dev/null @@ -1,3 +0,0 @@ -:plain - $(".mr_target_commit").html("#{commit_to_html(@commit, @target_project, false)}"); - $('.js-timeago').timeago() From 7fe19046d6633d01f1a326a5cc0d80a24879f04d Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 29 Mar 2016 09:33:23 +0100 Subject: [PATCH 045/212] Fixed failing tests --- features/steps/project/source/browse_files.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/steps/project/source/browse_files.rb b/features/steps/project/source/browse_files.rb index 243469b8e7..5beb2cc6d7 100644 --- a/features/steps/project/source/browse_files.rb +++ b/features/steps/project/source/browse_files.rb @@ -213,8 +213,8 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps end step 'I see Browse file link' do - expect(page).to have_link 'Browse File »' - expect(page).not_to have_link 'Browse Files »' + expect(page).to have_link 'Browse File' + expect(page).not_to have_link 'Browse Files' end step 'I see Browse code link' do From b31005899858bb19f5de06b49621fa1d73dbe037 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 29 Mar 2016 11:11:16 +0100 Subject: [PATCH 046/212] Use new dropdowns for MR compare --- app/assets/javascripts/compare.js.coffee | 45 +++++++-------- app/assets/javascripts/gl_dropdown.js.coffee | 2 +- .../stylesheets/pages/merge_requests.scss | 10 ++++ .../merge_requests/_new_compare.html.haml | 55 ++++++++++++++++--- features/steps/project/source/browse_files.rb | 4 +- 5 files changed, 83 insertions(+), 33 deletions(-) diff --git a/app/assets/javascripts/compare.js.coffee b/app/assets/javascripts/compare.js.coffee index c13744ebc6..e5819fa91c 100644 --- a/app/assets/javascripts/compare.js.coffee +++ b/app/assets/javascripts/compare.js.coffee @@ -2,26 +2,27 @@ class @Compare constructor: (@opts) -> @source_loading = $ ".js-source-loading" @target_loading = $ ".js-target-loading" - @source_branch = $ "#merge_request_source_branch" - @target_branch = $ "#merge_request_target_branch" - @target_project = $ "#merge_request_target_project_id" + + $('.js-compare-dropdown').each (i, dropdown) => + $dropdown = $(dropdown) + + $dropdown.glDropdown( + selectable: true + fieldName: $dropdown.data 'field-name' + id: (obj, $el) -> + $el.data 'id' + toggleLabel: (obj, $el) -> + $el.text().trim() + clicked: (e, el) => + if $dropdown.is '.js-target-branch' + @getTargetHtml() + else if $dropdown.is '.js-source-branch' + @getSourceHtml() + else if $dropdown.is '.js-target-project' + @getTargetProject() + ) @initialState() - @cleanBinding() - @addBinding() - - cleanBinding: -> - @source_branch.off "change" - @target_branch.off "change" - @target_project.off "change" - - addBinding: -> - @source_branch.on "change", => - @getSourceHtml() - @target_branch.on "change", => - @getTargetHtml() - @target_project.on "change", => - @getTargetProject() initialState: -> @getSourceHtml() @@ -29,13 +30,13 @@ class @Compare getTargetProject: -> $.get @opts.targetProjectUrl, - target_project_id: @target_project.val() + target_project_id: $("input[name='merge_request[source_project]']").val() getSourceHtml: -> $.ajax( url: @opts.sourceBranchUrl data: - ref: @source_branch.val() + ref: $("input[name='merge_request[source_branch]']").val() beforeSend: => @source_loading.show() $(".mr_source_commit").html "" @@ -49,8 +50,8 @@ class @Compare $.ajax( url: @opts.targetBranchUrl data: - target_project_id: @target_project.val() - ref: @target_branch.val() + target_project_id: $("input[name='merge_request[target_project_id]']").val() + ref: $("input[name='merge_request[target_branch]']").val() beforeSend: => @target_loading.show() $(".mr_target_commit").html "" diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index 2a4811b876..38b38fc842 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -373,7 +373,7 @@ class GitLabDropdown # Toggle the dropdown label if @options.toggleLabel - $(@el).find(".dropdown-toggle-text").text @options.toggleLabel(selectedObject) + $(@el).find(".dropdown-toggle-text").text @options.toggleLabel(selectedObject, el) if value? if !field.length # Create hidden input for form diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index 7bc1f58471..5929f607fc 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -242,4 +242,14 @@ width: 50%; padding-left: 5px; padding-right: 5px; + + .dropdown-menu-toggle { + width: 100%; + } + + .dropdown-menu { + left: 5px; + right: 5px; + width: auto; + } } diff --git a/app/views/projects/merge_requests/_new_compare.html.haml b/app/views/projects/merge_requests/_new_compare.html.haml index 4fc74dfcf4..f110c5f42c 100644 --- a/app/views/projects/merge_requests/_new_compare.html.haml +++ b/app/views/projects/merge_requests/_new_compare.html.haml @@ -9,10 +9,29 @@ .panel-heading Source branch .panel-body.clearfix - .merge-request-select - = f.select(:source_project_id, [[@merge_request.source_project_path,@merge_request.source_project.id]] , {}, { class: 'source_project select2', disabled: @merge_request.persisted?, required: true }) - .merge-request-select - = f.select(:source_branch, @merge_request.source_branches, { include_blank: true }, { class: 'source_branch select2', required: true, data: { placeholder: "Select source branch" } }) + .merge-request-select.dropdown + = f.hidden_field :source_project_id + = dropdown_toggle @merge_request.source_project_path, { toggle: "dropdown", field_name: "#{f.object_name}[source_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-source-project" } + .dropdown-menu + = dropdown_title("Select source project") + = dropdown_filter("Search projects") + = dropdown_content do + %ul + %li + %a{ href: "#", data: { id: @merge_request.source_project.id } } + = @merge_request.source_project_path + .merge-request-select.dropdown + = f.hidden_field :source_branch + = dropdown_toggle "Select source branch", { toggle: "dropdown", field_name: "#{f.object_name}[source_branch]" }, { toggle_class: "js-compare-dropdown js-source-branch" } + .dropdown-menu + = dropdown_title("Select source branch") + = dropdown_filter("Search branches") + = dropdown_content do + %ul + - @merge_request.source_branches.each do |branch| + %li + %a{ href: "#", data: { id: branch } } + = branch .panel-footer = icon('spinner spin', class: "js-source-loading") %ul.list-unstyled.mr_source_commit @@ -23,10 +42,30 @@ Target branch .panel-body.clearfix - projects = @project.forked_from_project.nil? ? [@project] : [@project, @project.forked_from_project] - .merge-request-select - = f.select(:target_project_id, options_from_collection_for_select(projects, 'id', 'path_with_namespace', f.object.target_project_id), {}, { class: 'target_project select2', disabled: @merge_request.persisted?, required: true }) - .merge-request-select - = f.select(:target_branch, @merge_request.target_branches, { include_blank: true }, { class: 'target_branch select2', required: true, data: { placeholder: "Select target branch" } }) + .merge-request-select.dropdown + = f.hidden_field :target_project_id + = dropdown_toggle projects.first.path_with_namespace, { toggle: "dropdown", field_name: "#{f.object_name}[target_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-target-project" } + .dropdown-menu + = dropdown_title("Select target project") + = dropdown_filter("Search projects") + = dropdown_content do + %ul + - projects.each do |project| + %li + %a{ href: "#" } + = project.path_with_namespace + .merge-request-select.dropdown + = f.hidden_field :target_branch + = dropdown_toggle "Select target branch", { toggle: "dropdown", field_name: "#{f.object_name}[target_branch]" }, { toggle_class: "js-compare-dropdown js-target-branch" } + .dropdown-menu.dropdown-menu-selectable + = dropdown_title("Select target branch") + = dropdown_filter("Search branches") + = dropdown_content do + %ul + - @merge_request.target_branches.each do |branch| + %li + %a{ href: "#", class: "#{("is-active" if :target_branch == branch)}", data: { id: branch } } + = branch .panel-footer = icon('spinner spin', class: "js-target-loading") %ul.list-unstyled.mr_target_commit diff --git a/features/steps/project/source/browse_files.rb b/features/steps/project/source/browse_files.rb index 5beb2cc6d7..f73bb425e5 100644 --- a/features/steps/project/source/browse_files.rb +++ b/features/steps/project/source/browse_files.rb @@ -218,8 +218,8 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps end step 'I see Browse code link' do - expect(page).to have_link 'Browse Files »' - expect(page).not_to have_link 'Browse File »' + expect(page).to have_link 'Browse Files' + expect(page).not_to have_link 'Browse File' expect(page).not_to have_link 'Browse Directory »' end From 850fa65ef2ff1fb16623c591a2147d75df333c58 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 29 Mar 2016 11:28:23 +0100 Subject: [PATCH 047/212] Checkmarks in dropdowns for already selected values --- app/assets/stylesheets/pages/commits.scss | 1 + .../projects/merge_requests/_new_compare.html.haml | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/pages/commits.scss b/app/assets/stylesheets/pages/commits.scss index 8272615768..ad8e97de3b 100644 --- a/app/assets/stylesheets/pages/commits.scss +++ b/app/assets/stylesheets/pages/commits.scss @@ -47,6 +47,7 @@ li.commit { .commit_short_id { min-width: 65px; + color: $gl-dark-link-color; font-family: $monospace_font; } diff --git a/app/views/projects/merge_requests/_new_compare.html.haml b/app/views/projects/merge_requests/_new_compare.html.haml index f110c5f42c..84c2faff92 100644 --- a/app/views/projects/merge_requests/_new_compare.html.haml +++ b/app/views/projects/merge_requests/_new_compare.html.haml @@ -12,25 +12,25 @@ .merge-request-select.dropdown = f.hidden_field :source_project_id = dropdown_toggle @merge_request.source_project_path, { toggle: "dropdown", field_name: "#{f.object_name}[source_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-source-project" } - .dropdown-menu + .dropdown-menu.dropdown-menu-selectable = dropdown_title("Select source project") = dropdown_filter("Search projects") = dropdown_content do %ul %li - %a{ href: "#", data: { id: @merge_request.source_project.id } } + %a{ href: "#", class: "#{("is-active" if f.object.source_project_id == @merge_request.source_project.id)}", data: { id: @merge_request.source_project.id } } = @merge_request.source_project_path .merge-request-select.dropdown = f.hidden_field :source_branch = dropdown_toggle "Select source branch", { toggle: "dropdown", field_name: "#{f.object_name}[source_branch]" }, { toggle_class: "js-compare-dropdown js-source-branch" } - .dropdown-menu + .dropdown-menu.dropdown-menu-selectable = dropdown_title("Select source branch") = dropdown_filter("Search branches") = dropdown_content do %ul - @merge_request.source_branches.each do |branch| %li - %a{ href: "#", data: { id: branch } } + %a{ href: "#", class: "#{("is-active" if f.object.source_branch == branch)}", data: { id: branch } } = branch .panel-footer = icon('spinner spin', class: "js-source-loading") @@ -45,14 +45,14 @@ .merge-request-select.dropdown = f.hidden_field :target_project_id = dropdown_toggle projects.first.path_with_namespace, { toggle: "dropdown", field_name: "#{f.object_name}[target_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-target-project" } - .dropdown-menu + .dropdown-menu.dropdown-menu-selectable = dropdown_title("Select target project") = dropdown_filter("Search projects") = dropdown_content do %ul - projects.each do |project| %li - %a{ href: "#" } + %a{ href: "#", class: "#{("is-active" if f.object.target_project_id == project.id)}", data: { id: project.id } } = project.path_with_namespace .merge-request-select.dropdown = f.hidden_field :target_branch @@ -64,7 +64,7 @@ %ul - @merge_request.target_branches.each do |branch| %li - %a{ href: "#", class: "#{("is-active" if :target_branch == branch)}", data: { id: branch } } + %a{ href: "#", class: "#{("is-active" if f.object.target_branch == branch)}", data: { id: branch } } = branch .panel-footer = icon('spinner spin', class: "js-target-loading") From beab104da812af015eeabb0f33d203741a221aed Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 29 Mar 2016 11:51:13 +0100 Subject: [PATCH 048/212] Filters by text on element --- app/assets/javascripts/compare.js.coffee | 1 + app/assets/javascripts/gl_dropdown.js.coffee | 37 ++++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/compare.js.coffee b/app/assets/javascripts/compare.js.coffee index e5819fa91c..8b502c8f27 100644 --- a/app/assets/javascripts/compare.js.coffee +++ b/app/assets/javascripts/compare.js.coffee @@ -9,6 +9,7 @@ class @Compare $dropdown.glDropdown( selectable: true fieldName: $dropdown.data 'field-name' + filterable: true id: (obj, $el) -> $el.data 'id' toggleLabel: (obj, $el) -> diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index 38b38fc842..82a82a27cc 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -57,14 +57,30 @@ class GitLabDropdownFilter filter: (search_text) -> data = @options.data() - results = data - if search_text isnt "" - results = fuzzaldrinPlus.filter(data, search_text, - key: @options.keys - ) + if data? + results = data - @options.callback results + if search_text isnt "" + results = fuzzaldrinPlus.filter(data, search_text, + key: @options.keys + ) + + @options.callback results + else + elements = @options.elements() + + if search_text + elements.each -> + $el = $(@) + matches = fuzzaldrinPlus.match($el.text().trim(), search_text) + + if matches.length + $el.show() + else + $el.hide() + else + elements.show() class GitLabDropdownRemote constructor: (@dataEndpoint, @options) -> @@ -147,7 +163,14 @@ class GitLabDropdown filterInputBlur: @filterInputBlur remote: @options.filterRemote query: @options.data - keys: @options.search.fields + keys: search_fields + elements: => + selector = ".dropdown-content li:not(.divider)" + + if @dropdown.find(".dropdown-toggle-page").length + selector = ".dropdown-page-one #{selector}" + + return $(selector) data: => return @fullData callback: (data) => From 1af1b6c8d32599500edb8ead52666a27d53765e2 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 29 Mar 2016 12:43:33 +0100 Subject: [PATCH 049/212] Fixed target project update --- app/assets/javascripts/compare.js.coffee | 52 +++++++++++-------- app/assets/stylesheets/pages/commits.scss | 4 ++ .../projects/merge_requests_controller.rb | 4 +- .../merge_requests/_new_compare.html.haml | 6 +-- .../merge_requests/update_branches.html.haml | 5 ++ .../merge_requests/update_branches.js.haml | 9 ---- 6 files changed, 42 insertions(+), 38 deletions(-) create mode 100644 app/views/projects/merge_requests/update_branches.html.haml delete mode 100644 app/views/projects/merge_requests/update_branches.js.haml diff --git a/app/assets/javascripts/compare.js.coffee b/app/assets/javascripts/compare.js.coffee index 8b502c8f27..762fedba40 100644 --- a/app/assets/javascripts/compare.js.coffee +++ b/app/assets/javascripts/compare.js.coffee @@ -30,34 +30,40 @@ class @Compare @getTargetHtml() getTargetProject: -> + $.ajax( + url: @opts.targetProjectUrl + data: + target_project_id: $("input[name='merge_request[target_project_id]']").val() + beforeSend: -> + $('.mr_target_commit').empty() + success: (html) -> + $('.js-target-branch-dropdown .dropdown-content').html html + ) $.get @opts.targetProjectUrl, - target_project_id: $("input[name='merge_request[source_project]']").val() + target_project_id: $("input[name='merge_request[target_project_id]']").val() getSourceHtml: -> - $.ajax( - url: @opts.sourceBranchUrl - data: - ref: $("input[name='merge_request[source_branch]']").val() - beforeSend: => - @source_loading.show() - $(".mr_source_commit").html "" - success: (html) => - @source_loading.hide() - $(".mr_source_commit").html html - $(".mr_source_commit .js-timeago").timeago() + @sendAjax(@opts.sourceBranchUrl, @source_loading, '.mr_source_commit', + ref: $("input[name='merge_request[source_branch]']").val() ) getTargetHtml: -> + @sendAjax(@opts.targetBranchUrl, @target_loading, '.mr_target_commit', + target_project_id: $("input[name='merge_request[target_project_id]']").val() + ref: $("input[name='merge_request[target_branch]']").val() + ) + + sendAjax: (url, loading, target, data) -> + $target = $(target) + $.ajax( - url: @opts.targetBranchUrl - data: - target_project_id: $("input[name='merge_request[target_project_id]']").val() - ref: $("input[name='merge_request[target_branch]']").val() - beforeSend: => - @target_loading.show() - $(".mr_target_commit").html "" - success: (html) => - @target_loading.hide() - $(".mr_target_commit").html html - $(".mr_target_commit .js-timeago").timeago() + url: url + data: data + beforeSend: -> + loading.show() + $target.empty() + success: (html) -> + loading.hide() + $target.html html + $('.js-timeago', $target).timeago() ) diff --git a/app/assets/stylesheets/pages/commits.scss b/app/assets/stylesheets/pages/commits.scss index ad8e97de3b..6453c91d95 100644 --- a/app/assets/stylesheets/pages/commits.scss +++ b/app/assets/stylesheets/pages/commits.scss @@ -89,6 +89,10 @@ li.commit { padding: 0; margin: 0; } + + a { + color: $gl-dark-link-color; + } } .commit-row-info { diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index ca6cfc9914..ae613f5e09 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -220,9 +220,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController @target_project = selected_target_project @target_branches = @target_project.repository.branch_names - respond_to do |format| - format.js - end + render layout: false end def ci_status diff --git a/app/views/projects/merge_requests/_new_compare.html.haml b/app/views/projects/merge_requests/_new_compare.html.haml index 84c2faff92..35d8faf7a9 100644 --- a/app/views/projects/merge_requests/_new_compare.html.haml +++ b/app/views/projects/merge_requests/_new_compare.html.haml @@ -44,7 +44,7 @@ - projects = @project.forked_from_project.nil? ? [@project] : [@project, @project.forked_from_project] .merge-request-select.dropdown = f.hidden_field :target_project_id - = dropdown_toggle projects.first.path_with_namespace, { toggle: "dropdown", field_name: "#{f.object_name}[target_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-target-project" } + = dropdown_toggle f.object.target_project.path_with_namespace, { toggle: "dropdown", field_name: "#{f.object_name}[target_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-target-project" } .dropdown-menu.dropdown-menu-selectable = dropdown_title("Select target project") = dropdown_filter("Search projects") @@ -56,8 +56,8 @@ = project.path_with_namespace .merge-request-select.dropdown = f.hidden_field :target_branch - = dropdown_toggle "Select target branch", { toggle: "dropdown", field_name: "#{f.object_name}[target_branch]" }, { toggle_class: "js-compare-dropdown js-target-branch" } - .dropdown-menu.dropdown-menu-selectable + = dropdown_toggle f.object.target_branch, { toggle: "dropdown", field_name: "#{f.object_name}[target_branch]" }, { toggle_class: "js-compare-dropdown js-target-branch" } + .dropdown-menu.dropdown-menu-selectable.js-target-branch-dropdown = dropdown_title("Select target branch") = dropdown_filter("Search branches") = dropdown_content do diff --git a/app/views/projects/merge_requests/update_branches.html.haml b/app/views/projects/merge_requests/update_branches.html.haml new file mode 100644 index 0000000000..1b93188a10 --- /dev/null +++ b/app/views/projects/merge_requests/update_branches.html.haml @@ -0,0 +1,5 @@ +%ul + - @target_branches.each do |branch| + %li + %a{ href: "#", class: "#{("is-active" if "a" == branch)}", data: { id: branch } } + = branch diff --git a/app/views/projects/merge_requests/update_branches.js.haml b/app/views/projects/merge_requests/update_branches.js.haml deleted file mode 100644 index ca21b3bc0d..0000000000 --- a/app/views/projects/merge_requests/update_branches.js.haml +++ /dev/null @@ -1,9 +0,0 @@ -:plain - $(".target_branch").html("#{escape_javascript(options_for_select(@target_branches))}"); - - $('select.target_branch').select2({ - width: 'resolve', - dropdownAutoWidth: true - }); - - $(".mr_target_commit").html(""); From fe811a7cdba2fcd1466f25115472265910dd394d Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 29 Mar 2016 12:44:34 +0100 Subject: [PATCH 050/212] Removed un-used get request --- app/assets/javascripts/compare.js.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/assets/javascripts/compare.js.coffee b/app/assets/javascripts/compare.js.coffee index 762fedba40..f20992ead3 100644 --- a/app/assets/javascripts/compare.js.coffee +++ b/app/assets/javascripts/compare.js.coffee @@ -39,8 +39,6 @@ class @Compare success: (html) -> $('.js-target-branch-dropdown .dropdown-content').html html ) - $.get @opts.targetProjectUrl, - target_project_id: $("input[name='merge_request[target_project_id]']").val() getSourceHtml: -> @sendAjax(@opts.sourceBranchUrl, @source_loading, '.mr_source_commit', From 8cdb50587805afa4177ee6cb938a0b5846a1641f Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 11:08:24 +0100 Subject: [PATCH 051/212] Fixed spacing in MR footer --- app/assets/stylesheets/pages/merge_requests.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index 5929f607fc..2ced7e5e1d 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -211,7 +211,7 @@ } .panel-footer { - padding: 10px 10px; + padding: 5px 10px; } .commit { From 301f4074aa05f25757396182490c3ebfffe1e81c Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 6 Apr 2016 12:26:10 +0200 Subject: [PATCH 052/212] Add specs for sessions controller including 2FA This also contains specs for a bug described in #14900 --- spec/controllers/sessions_controller_spec.rb | 93 ++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 spec/controllers/sessions_controller_spec.rb diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb new file mode 100644 index 0000000000..e7dbc3bdad --- /dev/null +++ b/spec/controllers/sessions_controller_spec.rb @@ -0,0 +1,93 @@ +require 'spec_helper' + +describe SessionsController do + describe '#create' do + before do + @request.env['devise.mapping'] = Devise.mappings[:user] + end + + context 'standard authentications' do + context 'invalid password' do + it 'does not authenticate user' do + post(:create, user: { login: 'invalid', password: 'invalid' }) + + expect(response) + .to set_flash.now[:alert].to /Invalid login or password/ + end + end + + context 'valid password' do + let(:user) { create(:user) } + + it 'authenticates user correctly' do + post(:create, user: { login: user.username, password: user.password }) + + expect(response).to set_flash.to /Signed in successfully/ + expect(subject.current_user). to eq user + end + end + end + + context 'two-factor authentication' do + let(:user) { create(:user, :two_factor) } + + def authenticate_2fa(user_params) + post(:create, { user: user_params }, { otp_user_id: user.id }) + end + + ## + # See #14900 issue + # + context 'authenticating with login and OTP belonging to another user' do + let(:another_user) { create(:user, :two_factor) } + + + context 'OTP valid for another user' do + it 'does not authenticate' do + authenticate_2fa(login: another_user.username, + otp_attempt: another_user.current_otp) + + expect(subject.current_user).to_not eq another_user + end + end + + context 'OTP invalid for another user' do + before do + authenticate_2fa(login: another_user.username, + otp_attempt: 'invalid') + end + + it 'does not authenticate' do + expect(subject.current_user).to_not eq another_user + end + + it 'does not leak information about 2FA enabled' do + expect(response).to_not set_flash.now[:alert].to /Invalid two-factor code/ + end + end + + context 'authenticating with OTP' do + context 'valid OTP' do + it 'authenticates correctly' do + authenticate_2fa(otp_attempt: user.current_otp) + + expect(subject.current_user).to eq user + end + end + + context 'invalid OTP' do + before { authenticate_2fa(otp_attempt: 'invalid') } + + it 'does not authenticate' do + expect(subject.current_user).to_not eq user + end + + it 'warns about invalid OTP code' do + expect(response).to set_flash.now[:alert].to /Invalid two-factor code/ + end + end + end + end + end + end +end From 017ed4ae37474ba43cbf4f4ee7c12d8aeec70598 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 12:52:07 +0100 Subject: [PATCH 053/212] Fixed builds --- .../stylesheets/pages/merge_requests.scss | 4 ++++ app/views/projects/commits/_commit.html.haml | 9 +------- .../merge_requests/_new_compare.html.haml | 8 +++---- .../project/forked_merge_requests.feature | 1 + features/project/merge_requests.feature | 1 + .../steps/project/forked_merge_requests.rb | 22 +++++++++++-------- features/steps/project/merge_requests.rb | 8 +++++-- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index 2ced7e5e1d..1790fbaaa1 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -235,6 +235,10 @@ padding: 0; background: transparent; } + + .ci-status-link { + margin-right: 5px; + } } .merge-request-select { diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index b55fe510f7..7da8923124 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -19,23 +19,16 @@ .pull-right - if ci_commit = render_ci_status(ci_commit) -   = clipboard_button(clipboard_text: commit.id) = link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit_short_id" - .notes_count - - if note_count > 0 - %span.light - %i.fa.fa-comments - = note_count - - if commit.description? .commit-row-description.js-toggle-content %pre = preserve(markdown(escape_once(commit.description), pipeline: :single_line)) .commit-row-info - by + by = commit_author_link(commit, avatar: true, size: 24) .committed_ago #{time_ago_with_tooltip(commit.committed_date, skip_js: true)}   diff --git a/app/views/projects/merge_requests/_new_compare.html.haml b/app/views/projects/merge_requests/_new_compare.html.haml index 35d8faf7a9..036b193536 100644 --- a/app/views/projects/merge_requests/_new_compare.html.haml +++ b/app/views/projects/merge_requests/_new_compare.html.haml @@ -12,7 +12,7 @@ .merge-request-select.dropdown = f.hidden_field :source_project_id = dropdown_toggle @merge_request.source_project_path, { toggle: "dropdown", field_name: "#{f.object_name}[source_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-source-project" } - .dropdown-menu.dropdown-menu-selectable + .dropdown-menu.dropdown-menu-selectable.dropdown-source-project = dropdown_title("Select source project") = dropdown_filter("Search projects") = dropdown_content do @@ -23,7 +23,7 @@ .merge-request-select.dropdown = f.hidden_field :source_branch = dropdown_toggle "Select source branch", { toggle: "dropdown", field_name: "#{f.object_name}[source_branch]" }, { toggle_class: "js-compare-dropdown js-source-branch" } - .dropdown-menu.dropdown-menu-selectable + .dropdown-menu.dropdown-menu-selectable.dropdown-source-branch = dropdown_title("Select source branch") = dropdown_filter("Search branches") = dropdown_content do @@ -45,7 +45,7 @@ .merge-request-select.dropdown = f.hidden_field :target_project_id = dropdown_toggle f.object.target_project.path_with_namespace, { toggle: "dropdown", field_name: "#{f.object_name}[target_project_id]", disabled: @merge_request.persisted? }, { toggle_class: "js-compare-dropdown js-target-project" } - .dropdown-menu.dropdown-menu-selectable + .dropdown-menu.dropdown-menu-selectable.dropdown-target-project = dropdown_title("Select target project") = dropdown_filter("Search projects") = dropdown_content do @@ -57,7 +57,7 @@ .merge-request-select.dropdown = f.hidden_field :target_branch = dropdown_toggle f.object.target_branch, { toggle: "dropdown", field_name: "#{f.object_name}[target_branch]" }, { toggle_class: "js-compare-dropdown js-target-branch" } - .dropdown-menu.dropdown-menu-selectable.js-target-branch-dropdown + .dropdown-menu.dropdown-menu-selectable.dropdown-target-branch.js-target-branch-dropdown = dropdown_title("Select target branch") = dropdown_filter("Search branches") = dropdown_content do diff --git a/features/project/forked_merge_requests.feature b/features/project/forked_merge_requests.feature index 10bd6fec80..67f1e117f7 100644 --- a/features/project/forked_merge_requests.feature +++ b/features/project/forked_merge_requests.feature @@ -4,6 +4,7 @@ Feature: Project Forked Merge Requests And I am a member of project "Shop" And I have a project forked off of "Shop" called "Forked Shop" + @javascript Scenario: I submit new unassigned merge request to a forked project Given I visit project "Forked Shop" merge requests page And I click link "New Merge Request" diff --git a/features/project/merge_requests.feature b/features/project/merge_requests.feature index 823658b4f2..ecda4ea824 100644 --- a/features/project/merge_requests.feature +++ b/features/project/merge_requests.feature @@ -70,6 +70,7 @@ Feature: Project Merge Requests When I click link "Reopen" Then I should see reopened merge request "Bug NS-04" + @javascript Scenario: I submit new unassigned merge request Given I click link "New Merge Request" And I submit new merge request "Wiki Feature" diff --git a/features/steps/project/forked_merge_requests.rb b/features/steps/project/forked_merge_requests.rb index 7e4425ff66..612bb8fd8b 100644 --- a/features/steps/project/forked_merge_requests.rb +++ b/features/steps/project/forked_merge_requests.rb @@ -34,10 +34,14 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps end step 'I fill out a "Merge Request On Forked Project" merge request' do - select @forked_project.path_with_namespace, from: "merge_request_source_project_id" - select @project.path_with_namespace, from: "merge_request_target_project_id" - select "fix", from: "merge_request_source_branch" - select "master", from: "merge_request_target_branch" + first('.js-source-project').click + first('.dropdown-source-project a', text: @forked_project.path_with_namespace) + + first('.js-target-project').click + first('.dropdown-target-project a', text: @project.path_with_namespace) + + first('.js-source-branch').click + first('.dropdown-source-branch .dropdown-content a', text: 'fix').click click_button "Compare branches and continue" @@ -115,10 +119,10 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps end step 'I fill out an invalid "Merge Request On Forked Project" merge request' do - expect(find(:select, "merge_request_source_project_id", {}).value).to eq @forked_project.id.to_s - expect(find(:select, "merge_request_target_project_id", {}).value).to eq @project.id.to_s - expect(find(:select, "merge_request_source_branch", {}).value).to eq "" - expect(find(:select, "merge_request_target_branch", {}).value).to eq "master" + expect(find_by_id("merge_request_source_project_id", visible: false).value).to eq @forked_project.id.to_s + expect(find_by_id("merge_request_target_project_id", visible: false).value).to eq @project.id.to_s + expect(find_by_id("merge_request_source_branch", visible: false).value).to eq nil + expect(find_by_id("merge_request_target_branch", visible: false).value).to eq "master" click_button "Compare branches" end @@ -127,7 +131,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps end step 'the target repository should be the original repository' do - expect(page).to have_select("merge_request_target_project_id", selected: @project.path_with_namespace) + expect(find_by_id("merge_request_target_project_id").value).to eq "#{@project.id}" end step 'I click "Assign to" dropdown"' do diff --git a/features/steps/project/merge_requests.rb b/features/steps/project/merge_requests.rb index a4f02b590e..f0af0d097f 100644 --- a/features/steps/project/merge_requests.rb +++ b/features/steps/project/merge_requests.rb @@ -93,8 +93,12 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps end step 'I submit new merge request "Wiki Feature"' do - select "fix", from: "merge_request_source_branch" - select "feature", from: "merge_request_target_branch" + find('.js-source-branch').click + find('.dropdown-source-branch .dropdown-content a', text: 'fix').click + + find('.js-target-branch').click + first('.dropdown-target-branch .dropdown-content a', text: 'feature').click + click_button "Compare branches" fill_in "merge_request_title", with: "Wiki Feature" click_button "Submit merge request" From 507cbca339444eabdfdd5d6dff1237bd00ee636a Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 6 Apr 2016 14:24:30 +0200 Subject: [PATCH 054/212] Fix header link rendering when containing numbers This fixes the problem where Markdown such as: ### 31st Would get rendered as a link tag pointing to issue number 31 inside a header tag. See gitlab-org/gitlab-ce#14936 for more information. --- lib/banzai/filter/abstract_reference_filter.rb | 2 +- spec/lib/banzai/filter/issue_reference_filter_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/banzai/filter/abstract_reference_filter.rb b/lib/banzai/filter/abstract_reference_filter.rb index f21dbef216..b8962379cb 100644 --- a/lib/banzai/filter/abstract_reference_filter.rb +++ b/lib/banzai/filter/abstract_reference_filter.rb @@ -119,7 +119,7 @@ module Banzai elsif element_node?(node) yield_valid_link(node) do |link, text| - if ref_pattern && link =~ /\A#{ref_pattern}/ + if ref_pattern && link =~ /\A#{ref_pattern}\z/ replace_link_node_with_href(node, link) do object_link_filter(link, ref_pattern, link_text: text) end diff --git a/spec/lib/banzai/filter/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/issue_reference_filter_spec.rb index 5a0d3d577a..266ebef33d 100644 --- a/spec/lib/banzai/filter/issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/issue_reference_filter_spec.rb @@ -95,6 +95,14 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do result = reference_pipeline_result("Fixed #{reference}") expect(result[:references][:issue]).to eq [issue] end + + it 'does not process links containing issue numbers followed by text' do + href = "#{reference}st" + doc = reference_filter("") + link = doc.css('a').first.attr('href') + + expect(link).to eq(href) + end end context 'cross-project reference' do From a3cf3d19826ea1e67381592f2d91f7041cccc222 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 4 Apr 2016 12:47:10 +0200 Subject: [PATCH 055/212] Corrected some spec headers for Gitlab::Metrics --- spec/lib/gitlab/metrics_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index 0ec8a6dc5c..93dd958168 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -13,7 +13,7 @@ describe Gitlab::Metrics do end end - describe '#submit_metrics' do + describe '.submit_metrics' do it 'prepares and writes the metrics to InfluxDB' do connection = double(:connection) pool = double(:pool) @@ -26,7 +26,7 @@ describe Gitlab::Metrics do end end - describe '#prepare_metrics' do + describe '.prepare_metrics' do it 'returns a Hash with the keys as Symbols' do metrics = described_class. prepare_metrics([{ 'values' => {}, 'tags' => {} }]) @@ -51,7 +51,7 @@ describe Gitlab::Metrics do end end - describe '#escape_value' do + describe '.escape_value' do it 'escapes an equals sign' do expect(described_class.escape_value('foo=')).to eq('foo\\=') end From 1af6cf28c031cec7813d3fc090476c088de57173 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 4 Apr 2016 14:00:35 +0200 Subject: [PATCH 056/212] Measure Ruby blocks using Gitlab::Metrics This allows measuring of timings of arbitrary Ruby blocks, this allows for more fine grained performance monitoring. Custom values and tags can also be attached to a block. --- lib/gitlab/metrics.rb | 26 +++++++++++++++++++++ spec/lib/gitlab/metrics_spec.rb | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/lib/gitlab/metrics.rb b/lib/gitlab/metrics.rb index 88a265c6af..4a3f47b5a9 100644 --- a/lib/gitlab/metrics.rb +++ b/lib/gitlab/metrics.rb @@ -70,6 +70,32 @@ module Gitlab value.to_s.gsub('=', '\\=') end + # Measures the execution time of a block. + # + # Example: + # + # Gitlab::Metrics.measure(:find_by_username_timings) do + # User.find_by_username(some_username) + # end + # + # series - The name of the series to store the data in. + # values - A Hash containing extra values to add to the metric. + # tags - A Hash containing extra tags to add to the metric. + # + # Returns the value yielded by the supplied block. + def self.measure(series, values = {}, tags = {}) + return yield unless Transaction.current + + start = Time.now.to_f + retval = yield + duration = (Time.now.to_f - start) * 1000.0 + values = values.merge(duration: duration) + + Transaction.current.add_metric(series, values, tags) + + retval + end + # When enabled this should be set before being used as the usual pattern # "@foo ||= bar" is _not_ thread-safe. if enabled? diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index 93dd958168..8f63a5f204 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -60,4 +60,45 @@ describe Gitlab::Metrics do expect(described_class.escape_value(10)).to eq('10') end end + + describe '.measure' do + context 'without a transaction' do + it 'returns the return value of the block' do + val = Gitlab::Metrics.measure(:foo) { 10 } + + expect(val).to eq(10) + end + end + + context 'with a transaction' do + let(:transaction) { Gitlab::Metrics::Transaction.new } + + before do + allow(Gitlab::Metrics::Transaction).to receive(:current). + and_return(transaction) + end + + it 'adds a metric to the current transaction' do + expect(transaction).to receive(:add_metric). + with(:foo, { duration: a_kind_of(Numeric) }, { tag: 'value' }) + + Gitlab::Metrics.measure(:foo, {}, tag: 'value') { 10 } + end + + it 'supports adding of custom values' do + values = { duration: a_kind_of(Numeric), number: 10 } + + expect(transaction).to receive(:add_metric). + with(:foo, values, { tag: 'value' }) + + Gitlab::Metrics.measure(:foo, { number: 10 }, tag: 'value') { 10 } + end + + it 'returns the return value of the block' do + val = Gitlab::Metrics.measure(:foo) { 10 } + + expect(val).to eq(10) + end + end + end end From 352bc7d2b9a4ed5725e4f0e9f2e63d71678de9bc Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 5 Apr 2016 12:37:41 +0200 Subject: [PATCH 057/212] Added dev guide for measuring Ruby blocks --- doc/development/README.md | 1 + doc/development/instrumentation.md | 37 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 doc/development/instrumentation.md diff --git a/doc/development/README.md b/doc/development/README.md index 1b281809af..8940b558fb 100644 --- a/doc/development/README.md +++ b/doc/development/README.md @@ -4,6 +4,7 @@ - [CI setup](ci_setup.md) for testing GitLab - [Gotchas](gotchas.md) to avoid - [How to dump production data to staging](db_dump.md) +- [Instrumentation](instrumentation.md) - [Migration Style Guide](migration_style_guide.md) for creating safe migrations - [Rake tasks](rake_tasks.md) for development - [Shell commands](shell_commands.md) in the GitLab codebase diff --git a/doc/development/instrumentation.md b/doc/development/instrumentation.md new file mode 100644 index 0000000000..c0192bd670 --- /dev/null +++ b/doc/development/instrumentation.md @@ -0,0 +1,37 @@ +# Instrumenting Ruby Code + +GitLab Performance Monitoring allows instrumenting of custom blocks of Ruby +code. This can be used to measure the time spent in a specific part of a larger +chunk of code. The resulting data is written to a separate series. + +To start measuring a block of Ruby code you should use +`Gitlab::Metrics.measure` and give it a name for the series to store the data +in: + +```ruby +Gitlab::Metrics.measure(:user_logins) do + ... +end +``` + +The first argument of this method is the series name and should be plural. This +name will be prefixed with `rails_` or `sidekiq_` depending on whether the code +was run in the Rails application or one of the Sidekiq workers. In the +above example the final series names would be as follows: + +- rails_user_logins +- sidekiq_user_logins + +Series names should be plural as this keeps the naming style in line with the +other series names. + +By default metrics measured using a block contain a single value, "duration", +which contains the number of milliseconds it took to execute the block. Custom +values can be added by passing a Hash as the 2nd argument. Custom tags can be +added by passing a Hash as the 3rd argument. A simple example is as follows: + +```ruby +Gitlab::Metrics.measure(:example_series, { number: 10 }, { class: self.class.to_s }) do + ... +end +``` From 82e92a0900f76d208faf94629c90309201d05914 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 14:32:36 +0200 Subject: [PATCH 058/212] API: Expose open_issues_count, closed_issues_count, open_merge_requests_count on labels --- doc/api/labels.md | 40 ++++++++++++++++++++-------------------- lib/api/entities.rb | 1 + 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/doc/api/labels.md b/doc/api/labels.md index 544e898b6a..3730c07c5a 100644 --- a/doc/api/labels.md +++ b/doc/api/labels.md @@ -23,42 +23,42 @@ Example response: { "name" : "bug", "color" : "#d9534f", - "description": "Bug reported by user" + "description": "Bug reported by user", + "open_issues_count": 1, + "closed_issues_count": 0, + "open_merge_requests_count": 1 }, { "color" : "#d9534f", "name" : "confirmed", - "description": "Confirmed issue" + "description": "Confirmed issue", + "open_issues_count": 2, + "closed_issues_count": 5, + "open_merge_requests_count": 0 }, { "name" : "critical", "color" : "#d9534f", - "description": "Criticalissue. Need fix ASAP" - }, - { - "color" : "#428bca", - "name" : "discussion", - "description": "Issue that needs further discussion" + "description": "Criticalissue. Need fix ASAP", + "open_issues_count": 1, + "closed_issues_count": 3, + "open_merge_requests_count": 1 }, { "name" : "documentation", "color" : "#f0ad4e", - "description": "Issue about documentation" + "description": "Issue about documentation", + "open_issues_count": 1, + "closed_issues_count": 0, + "open_merge_requests_count": 2 }, { "color" : "#5cb85c", "name" : "enhancement", - "description": "Enhancement proposal" - }, - { - "color" : "#428bca", - "name" : "suggestion", - "description": "Suggestion" - }, - { - "color" : "#f0ad4e", - "name" : "support", - "description": "Support issue" + "description": "Enhancement proposal", + "open_issues_count": 1, + "closed_issues_count": 0, + "open_merge_requests_count": 1 } ] ``` diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 340fc5452a..cd0d16e531 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -293,6 +293,7 @@ module API class Label < Grape::Entity expose :name, :color, :description + expose :open_issues_count, :closed_issues_count, :open_merge_requests_count end class Compare < Grape::Entity From 622b2023da48a6c0229e9eff06c142431a62db36 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 6 Apr 2016 15:07:35 +0200 Subject: [PATCH 059/212] Use gitlab-workhorse 0.7.2 --- GITLAB_WORKHORSE_VERSION | 2 +- doc/install/installation.md | 2 +- doc/update/8.6-to-8.7.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/GITLAB_WORKHORSE_VERSION b/GITLAB_WORKHORSE_VERSION index 39e898a4f9..7486fdbc50 100644 --- a/GITLAB_WORKHORSE_VERSION +++ b/GITLAB_WORKHORSE_VERSION @@ -1 +1 @@ -0.7.1 +0.7.2 diff --git a/doc/install/installation.md b/doc/install/installation.md index e0a16df09c..f32b6008d4 100644 --- a/doc/install/installation.md +++ b/doc/install/installation.md @@ -348,7 +348,7 @@ GitLab Shell is an SSH access and repository management software developed speci cd /home/git sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git cd gitlab-workhorse - sudo -u git -H git checkout v0.7.1 + sudo -u git -H git checkout v0.7.2 sudo -u git -H make ### Initialize Database and Activate Advanced Features diff --git a/doc/update/8.6-to-8.7.md b/doc/update/8.6-to-8.7.md index 76eee147c7..4cbf943bb5 100644 --- a/doc/update/8.6-to-8.7.md +++ b/doc/update/8.6-to-8.7.md @@ -58,7 +58,7 @@ GitLab 8.1. ```bash cd /home/git/gitlab-workhorse sudo -u git -H git fetch --all -sudo -u git -H git checkout v0.7.1 +sudo -u git -H git checkout v0.7.2 sudo -u git -H make ``` From 9e6c61372fe0f7f2199f4e8f72b3c4e4a4219020 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Wed, 6 Apr 2016 11:02:22 -0300 Subject: [PATCH 060/212] Fix milestone removal problem when editing issues --- app/helpers/issues_helper.rb | 1 + spec/helpers/issues_helper_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 24b90fef4f..414056c809 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -52,6 +52,7 @@ module IssuesHelper def milestone_options(object) milestones = object.project.milestones.active.reorder(due_date: :asc, title: :asc).to_a + milestones.unshift(object.milestone) if object.milestone.present? && object.milestone.closed? milestones.unshift(Milestone::None) options_from_collection_for_select(milestones, 'id', 'title', object.milestone_id) diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index ffd8ebae02..df0eb22d6f 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -148,4 +148,19 @@ describe IssuesHelper do expect(awards_sort(data).keys).to eq(["thumbsup", "thumbsdown", "lifter"]) end end + + describe "#milestone options" do + let!(:closed_milestone) { create :closed_milestone, title: "closed milestone", project: project } + let!(:milestone1) { create :milestone, title: "open milestone 1", project: project } + let!(:milestone2) { create :milestone, title: "open milestone 2", project: project } + + before { issue.update_attributes(milestone_id: closed_milestone.id) } + + it "gets closed milestone from current issue" do + options = milestone_options(issue) + expect(options).to have_selector('option[selected]', text: closed_milestone.title) + expect(options).to have_selector('option', text: milestone1.title) + expect(options).to have_selector('option', text: milestone2.title) + end + end end From 2b91abbcedb46a74770c7384544b1239d0e210a5 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 6 Apr 2016 16:08:40 +0200 Subject: [PATCH 061/212] Disable git gc --auto --- doc/install/installation.md | 6 +++++- doc/update/8.6-to-8.7.md | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/install/installation.md b/doc/install/installation.md index e0a16df09c..f8f7d6a9eb 100644 --- a/doc/install/installation.md +++ b/doc/install/installation.md @@ -283,9 +283,13 @@ sudo usermod -aG redis git # Copy the example Rack attack config sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb - # Configure Git global settings for git user, used when editing via web editor + # Configure Git global settings for git user + # 'autocrlf' is needed for the web editor sudo -u git -H git config --global core.autocrlf input + # Disable 'git gc --auto' because GitLab already runs 'git gc' when needed + sudo -u git -H git config --global gc.auto 0 + # Configure Redis connection settings sudo -u git -H cp config/resque.yml.example config/resque.yml diff --git a/doc/update/8.6-to-8.7.md b/doc/update/8.6-to-8.7.md index 76eee147c7..8599133a72 100644 --- a/doc/update/8.6-to-8.7.md +++ b/doc/update/8.6-to-8.7.md @@ -86,6 +86,14 @@ sudo -u git -H bundle exec rake assets:clean assets:precompile cache:clear RAILS ### 7. Update configuration files +#### Git configuration + +Disable `git gc --auto` because GitLab runs `git gc` for us already. + +```sh +sudo -u git -H git config --global gc.auto 0 +``` + #### Nginx configuration Ensure you're still up-to-date with the latest NGINX configuration changes: From 39ecce05c7c3b5d8054b4deb61028695872acc9e Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 16:25:38 +0100 Subject: [PATCH 062/212] Build fix --- app/assets/stylesheets/pages/merge_requests.scss | 4 ++++ spec/features/merge_requests/create_new_mr_spec.rb | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index 1790fbaaa1..4269afe4c5 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -257,3 +257,7 @@ width: auto; } } + +.merge-request-form .select2-container { + width: 250px!important; +} diff --git a/spec/features/merge_requests/create_new_mr_spec.rb b/spec/features/merge_requests/create_new_mr_spec.rb index fd02d58484..00b60bd0e7 100644 --- a/spec/features/merge_requests/create_new_mr_spec.rb +++ b/spec/features/merge_requests/create_new_mr_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -feature 'Create New Merge Request', feature: true, js: false do +feature 'Create New Merge Request', feature: true, js: true do let(:user) { create(:user) } let(:project) { create(:project, :public) } @@ -13,9 +13,12 @@ feature 'Create New Merge Request', feature: true, js: false do it 'generates a diff for an orphaned branch' do click_link 'New Merge Request' - select "orphaned-branch", from: "merge_request_source_branch" - select "master", from: "merge_request_target_branch" + + first('.js-source-branch').click + first('.dropdown-source-branch .dropdown-content a', text: 'orphaned-branch').click + click_button "Compare branches" + click_link "Changes" expect(page).to have_content "README.md" expect(page).to have_content "wm.png" @@ -23,6 +26,8 @@ feature 'Create New Merge Request', feature: true, js: false do fill_in "merge_request_title", with: "Orphaned MR test" click_button "Submit merge request" + click_link "Check out branch" + expect(page).to have_content 'git checkout -b orphaned-branch origin/orphaned-branch' end end From 222e1dc59cd559f893a4565040dede300645248b Mon Sep 17 00:00:00 2001 From: PotHix Date: Wed, 6 Apr 2016 12:05:50 -0300 Subject: [PATCH 063/212] Fixes #14638. The SQL query was ambiguous and in this case we want to filter projects. --- CHANGELOG | 1 + app/controllers/admin/projects_controller.rb | 2 +- .../admin/projects_controller_spec.rb | 23 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 spec/controllers/admin/projects_controller_spec.rb diff --git a/CHANGELOG b/CHANGELOG index a23c8a54af..35c668f17b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -22,6 +22,7 @@ v 8.7.0 (unreleased) - Fall back to `In-Reply-To` and `References` headers when sub-addressing is not available (David Padilla) - Remove "Congratulations!" tweet button on newly-created project. (Connor Shea) - Improved UX of the navigation sidebar + - Fix admin/projects when using visibility levels on search (PotHix) - Build status notifications - API: Ability to retrieve a specific tag (Robert Schilling) - API: Expose user location (Robert Schilling) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 4089091d56..c6b3105544 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -5,7 +5,7 @@ class Admin::ProjectsController < Admin::ApplicationController def index @projects = Project.all @projects = @projects.in_namespace(params[:namespace_id]) if params[:namespace_id].present? - @projects = @projects.where("visibility_level IN (?)", params[:visibility_levels]) if params[:visibility_levels].present? + @projects = @projects.where("projects.visibility_level IN (?)", params[:visibility_levels]) if params[:visibility_levels].present? @projects = @projects.with_push if params[:with_push].present? @projects = @projects.abandoned if params[:abandoned].present? @projects = @projects.non_archived unless params[:with_archived].present? diff --git a/spec/controllers/admin/projects_controller_spec.rb b/spec/controllers/admin/projects_controller_spec.rb new file mode 100644 index 0000000000..2ba0d48919 --- /dev/null +++ b/spec/controllers/admin/projects_controller_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Admin::ProjectsController do + let!(:project) { create(:project, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } + + before do + sign_in(create(:admin)) + end + + describe 'GET /projects' do + render_views + + it 'retrieves the project for the given visibility level' do + get :index, visibility_levels: [Gitlab::VisibilityLevel::PUBLIC] + expect(response.body).to match(project.name) + end + + it 'does not retrieve the project' do + get :index, visibility_levels: [Gitlab::VisibilityLevel::INTERNAL] + expect(response.body).to_not match(project.name) + end + end +end From 5083e5b616d2ba9b2812920c8d6cf3e0f95389e1 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 19:07:23 +0200 Subject: [PATCH 064/212] Add changelog item --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 8db9a9b0d1..05d8270b5b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ v 8.7.0 (unreleased) - Add endpoints to archive or unarchive a project !3372 - Add links to CI setup documentation from project settings and builds pages - Handle nil descriptions in Slack issue messages (Stan Hu) + - API: Expose open_issues_count, closed_issues_count, open_merge_requests_count for labels (Robert Schilling) - Add default scope to projects to exclude projects pending deletion - Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.) - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) From ea69037831a9b607e7936cadb8078a3182d6635a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 21 Mar 2016 11:59:55 +0100 Subject: [PATCH 065/212] Improve routes for project badges --- config/routes.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 6bf22fb445..36561c31d4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -749,10 +749,11 @@ Rails.application.routes.draw do end resources :runner_projects, only: [:create, :destroy] - resources :badges, only: [], path: 'badges/*ref', - constraints: { ref: Gitlab::Regex.git_reference_regex } do + resources :badges, only: [] do collection do - get :build, constraints: { format: /svg/ } + scope '*ref', constraints: { ref: Gitlab::Regex.git_reference_regex } do + get :build, constraints: { format: /svg/ } + end end end end From 88fc7ccddaab18435bdc85021d06d9aa21d28a68 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 22 Mar 2016 10:21:45 +0100 Subject: [PATCH 066/212] Add project badges view prototype --- app/controllers/projects/badges_controller.rb | 5 ++++- app/views/projects/badges/index.html.haml | 15 +++++++++++++++ app/views/projects/show.html.haml | 3 +++ config/routes.rb | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 app/views/projects/badges/index.html.haml diff --git a/app/controllers/projects/badges_controller.rb b/app/controllers/projects/badges_controller.rb index 6d4d436098..01db85c4a8 100644 --- a/app/controllers/projects/badges_controller.rb +++ b/app/controllers/projects/badges_controller.rb @@ -1,5 +1,8 @@ class Projects::BadgesController < Projects::ApplicationController - before_action :no_cache_headers + before_action :no_cache_headers, except: [:index] + + def index + end def build badge = Gitlab::Badge::Build.new(project, params[:ref]) diff --git a/app/views/projects/badges/index.html.haml b/app/views/projects/badges/index.html.haml new file mode 100644 index 0000000000..b527df8ac9 --- /dev/null +++ b/app/views/projects/badges/index.html.haml @@ -0,0 +1,15 @@ +- page_title 'Badges' + +.prepend-top-10 + .panel.panel-default + .panel-heading + %b Builds badge · + = image_tag(build_namespace_project_badges_path(@project.namespace, @project, :master, format: :svg), alt: 'Builds badge') + .panel-body + %table.table + %tr + %td Markdown + %td= markdown("```markdown\n[![build status](url)](link)\n```") + %tr + %td HTML + %td= markdown("```html\n\n```") diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 4310f038fc..6963d657d9 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -57,6 +57,9 @@ %li.missing = link_to add_contribution_guide_path(@project) do Add Contribution guide + - if @project.builds_enabled? + %li + = link_to 'Badges', '' - if @repository.commit .content-block.second-block.white diff --git a/config/routes.rb b/config/routes.rb index 36561c31d4..3ef5931d97 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -749,7 +749,7 @@ Rails.application.routes.draw do end resources :runner_projects, only: [:create, :destroy] - resources :badges, only: [] do + resources :badges, only: [:index] do collection do scope '*ref', constraints: { ref: Gitlab::Regex.git_reference_regex } do get :build, constraints: { format: /svg/ } From b7fa7c4d59b2fbdc49db81aa2d6a2531c931a2fe Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 1 Apr 2016 13:03:14 +0200 Subject: [PATCH 067/212] Extend build status badge, add html/markdown methods --- app/controllers/projects/badges_controller.rb | 2 ++ app/views/projects/badges/index.html.haml | 6 ++-- lib/gitlab/badge/build.rb | 32 +++++++++++++++--- spec/lib/gitlab/badge/build_spec.rb | 33 ++++++++++++++++++- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/app/controllers/projects/badges_controller.rb b/app/controllers/projects/badges_controller.rb index 01db85c4a8..b96555a153 100644 --- a/app/controllers/projects/badges_controller.rb +++ b/app/controllers/projects/badges_controller.rb @@ -2,6 +2,8 @@ class Projects::BadgesController < Projects::ApplicationController before_action :no_cache_headers, except: [:index] def index + @ref = params[:ref] || 'master' + @badge = Gitlab::Badge::Build.new(@project, @ref) end def build diff --git a/app/views/projects/badges/index.html.haml b/app/views/projects/badges/index.html.haml index b527df8ac9..87c525cc1c 100644 --- a/app/views/projects/badges/index.html.haml +++ b/app/views/projects/badges/index.html.haml @@ -4,12 +4,12 @@ .panel.panel-default .panel-heading %b Builds badge · - = image_tag(build_namespace_project_badges_path(@project.namespace, @project, :master, format: :svg), alt: 'Builds badge') + = @badge.to_html .panel-body %table.table %tr %td Markdown - %td= markdown("```markdown\n[![build status](url)](link)\n```") + %td= markdown("```markdown\n#{@badge.to_markdown}\n```") %tr %td HTML - %td= markdown("```html\n\n```") + %td= markdown("```html\n#{@badge.to_html}\n```") diff --git a/lib/gitlab/badge/build.rb b/lib/gitlab/badge/build.rb index 28a2391dbf..e5e9fab3f5 100644 --- a/lib/gitlab/badge/build.rb +++ b/lib/gitlab/badge/build.rb @@ -4,12 +4,13 @@ module Gitlab # Build badge # class Build - def initialize(project, ref) - @image = ::Ci::ImageForBuildService.new.execute(project, ref: ref) - end + include Gitlab::Application.routes.url_helpers + include ActionView::Helpers::AssetTagHelper + include ActionView::Helpers::UrlHelper - def to_s - @image[:name].sub(/\.svg$/, '') + def initialize(project, ref) + @project, @ref = project, ref + @image = ::Ci::ImageForBuildService.new.execute(project, ref: ref) end def type @@ -19,6 +20,27 @@ module Gitlab def data File.read(@image[:path]) end + + def to_s + @image[:name].sub(/\.svg$/, '') + end + + def to_html + link_to(image_tag(image_url, alt: 'build status'), link_url) + end + + def to_markdown + "[![build status](#{image_url})](#{link_url})" + end + + def image_url + build_namespace_project_badges_url(@project.namespace, + @project, @ref, format: :svg) + end + + def link_url + namespace_project_commits_url(@project.namespace, @project, id: @ref) + end end end end diff --git a/spec/lib/gitlab/badge/build_spec.rb b/spec/lib/gitlab/badge/build_spec.rb index b78c2b6224..329792bb68 100644 --- a/spec/lib/gitlab/badge/build_spec.rb +++ b/spec/lib/gitlab/badge/build_spec.rb @@ -3,13 +3,44 @@ require 'spec_helper' describe Gitlab::Badge::Build do let(:project) { create(:project) } let(:sha) { project.commit.sha } - let(:badge) { described_class.new(project, 'master') } + let(:branch) { 'master' } + let(:badge) { described_class.new(project, branch) } describe '#type' do subject { badge.type } it { is_expected.to eq 'image/svg+xml' } end + describe '#to_html' do + let(:html) { Nokogiri::HTML.parse(badge.to_html) } + let(:a_href) { html.at('a') } + + it 'points to link' do + expect(a_href[:href]).to eq badge.link_url + end + + it 'contains clickable image' do + expect(a_href.children.first.name).to eq 'img' + end + end + + describe '#to_markdown' do + subject { badge.to_markdown } + + it { is_expected.to include badge.image_url } + it { is_expected.to include badge.link_url } + end + + describe '#image_url' do + subject { badge.image_url } + it { is_expected.to include "badges/#{branch}/build.svg" } + end + + describe '#link_url' do + subject { badge.link_url } + it { is_expected.to include "commits/#{branch}" } + end + context 'build exists' do let(:ci_commit) { create(:ci_commit, project: project, sha: sha) } let!(:build) { create(:ci_build, commit: ci_commit) } From 58d63a66a084fc38ffcd72972afa388110e29fc1 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 1 Apr 2016 14:54:11 +0200 Subject: [PATCH 068/212] Improve view with list of badges --- app/views/projects/badges/index.html.haml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/views/projects/badges/index.html.haml b/app/views/projects/badges/index.html.haml index 87c525cc1c..52e68ea708 100644 --- a/app/views/projects/badges/index.html.haml +++ b/app/views/projects/badges/index.html.haml @@ -6,10 +6,15 @@ %b Builds badge · = @badge.to_html .panel-body - %table.table - %tr - %td Markdown - %td= markdown("```markdown\n#{@badge.to_markdown}\n```") - %tr - %td HTML - %td= markdown("```html\n#{@badge.to_html}\n```") + .row + .col-md-2.text-center + Markdown + .col-md-10 + = markdown("```markdown\n#{@badge.to_markdown}\n```") + .row + %hr + .row + .col-md-2.text-center + HTML + .col-md-10 + = markdown("```html\n#{@badge.to_html}\n```") From dffdb0d036d037dc4b6a363aa73e581270fc7c80 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 4 Apr 2016 10:03:42 +0200 Subject: [PATCH 069/212] Use highlight helper to render badges code syntax --- app/views/projects/badges/index.html.haml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/projects/badges/index.html.haml b/app/views/projects/badges/index.html.haml index 52e68ea708..b652415370 100644 --- a/app/views/projects/badges/index.html.haml +++ b/app/views/projects/badges/index.html.haml @@ -9,12 +9,12 @@ .row .col-md-2.text-center Markdown - .col-md-10 - = markdown("```markdown\n#{@badge.to_markdown}\n```") + .col-md-10.code.js-syntax-highlight + = highlight('.md', @badge.to_markdown) .row %hr .row .col-md-2.text-center HTML - .col-md-10 - = markdown("```html\n#{@badge.to_html}\n```") + .col-md-10.code.js-syntax-highlight + = highlight('.html', @badge.to_html) From a2bbd2501a15fa60b36110e1acb3d3141586e353 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 4 Apr 2016 10:10:24 +0200 Subject: [PATCH 070/212] Add project header title in project badges view --- app/views/projects/badges/index.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/projects/badges/index.html.haml b/app/views/projects/badges/index.html.haml index b652415370..5cd2ebce09 100644 --- a/app/views/projects/badges/index.html.haml +++ b/app/views/projects/badges/index.html.haml @@ -1,4 +1,6 @@ - page_title 'Badges' +- badges_path = namespace_project_badges_path(@project.namespace, @project) +- header_title project_title(@project, 'Badges', badges_path) .prepend-top-10 .panel.panel-default From 97a2de9e03f9ad947642ded3b4f4e7761fcaa9c3 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 4 Apr 2016 10:40:40 +0200 Subject: [PATCH 071/212] Make it possible to switch ref in badges view --- app/controllers/projects/refs_controller.rb | 2 ++ app/views/projects/badges/index.html.haml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/controllers/projects/refs_controller.rb b/app/controllers/projects/refs_controller.rb index 00df1c9c96..d79f16e6a5 100644 --- a/app/controllers/projects/refs_controller.rb +++ b/app/controllers/projects/refs_controller.rb @@ -24,6 +24,8 @@ class Projects::RefsController < Projects::ApplicationController namespace_project_find_file_path(@project.namespace, @project, @id) when "graphs_commits" commits_namespace_project_graph_path(@project.namespace, @project, @id) + when "badges" + namespace_project_badges_path(@project.namespace, @project, ref: @id) else namespace_project_commits_path(@project.namespace, @project, @id) end diff --git a/app/views/projects/badges/index.html.haml b/app/views/projects/badges/index.html.haml index 5cd2ebce09..fb57bf411d 100644 --- a/app/views/projects/badges/index.html.haml +++ b/app/views/projects/badges/index.html.haml @@ -7,6 +7,8 @@ .panel-heading %b Builds badge · = @badge.to_html + .pull-right + = render 'shared/ref_switcher', destination: 'badges' .panel-body .row .col-md-2.text-center From a3a93ba4b08176b8d63ed5f6ca95dfa78e7dda0b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 4 Apr 2016 12:32:50 +0200 Subject: [PATCH 072/212] Expose project badges in project settings menu --- app/controllers/projects/badges_controller.rb | 2 ++ app/views/layouts/nav/_project_settings.html.haml | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects/badges_controller.rb b/app/controllers/projects/badges_controller.rb index b96555a153..6e442d66ad 100644 --- a/app/controllers/projects/badges_controller.rb +++ b/app/controllers/projects/badges_controller.rb @@ -1,4 +1,6 @@ class Projects::BadgesController < Projects::ApplicationController + layout 'project_settings' + before_action :authorize_admin_project!, only: [:index] before_action :no_cache_headers, except: [:index] def index diff --git a/app/views/layouts/nav/_project_settings.html.haml b/app/views/layouts/nav/_project_settings.html.haml index dc3050f02e..d429a92846 100644 --- a/app/views/layouts/nav/_project_settings.html.haml +++ b/app/views/layouts/nav/_project_settings.html.haml @@ -51,8 +51,13 @@ = icon('code fw') %span Variables - = nav_link path: 'triggers#index' do + = nav_link(controller: :triggers) do = link_to namespace_project_triggers_path(@project.namespace, @project), title: 'Triggers' do = icon('retweet fw') %span Triggers + = nav_link(controller: :badges) do + = link_to namespace_project_badges_path(@project.namespace, @project), title: 'Badges' do + = icon('star-half-empty fw') + %span + Badges From 7640b050c06e18200a09bc100d08ed48aa6c549b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 4 Apr 2016 15:05:38 +0200 Subject: [PATCH 073/212] Add feature specs for list of badges page --- spec/features/projects/badges/list_spec.rb | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/features/projects/badges/list_spec.rb diff --git a/spec/features/projects/badges/list_spec.rb b/spec/features/projects/badges/list_spec.rb new file mode 100644 index 0000000000..13c9b95b31 --- /dev/null +++ b/spec/features/projects/badges/list_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +feature 'list of badges' do + include Select2Helper + + background do + user = create(:user) + project = create(:project) + project.team << [user, :master] + login_as(user) + visit edit_namespace_project_path(project.namespace, project) + end + + scenario 'user displays list of badges' do + click_link 'Badges' + + expect(page).to have_content 'build status' + expect(page).to have_content 'Markdown' + expect(page).to have_content 'HTML' + expect(page).to have_css('.highlight', count: 2) + expect(page).to have_xpath("//img[@alt='build status']") + + page.within('.highlight', match: :first) do + expect(page).to have_content 'badges/master/build.svg' + end + end + + scenario 'user changes current ref on badges list page', js: true do + click_link 'Badges' + select2('improve/awesome', from: '#ref') + + expect(page).to have_content 'badges/improve/awesome/build.svg' + end +end From 15ea971847e0c72d99c8822afe2b1ea181479916 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 5 Apr 2016 19:40:41 +0200 Subject: [PATCH 074/212] Remove obsolete badge code from project view --- app/views/projects/show.html.haml | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 6963d657d9..4310f038fc 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -57,9 +57,6 @@ %li.missing = link_to add_contribution_guide_path(@project) do Add Contribution guide - - if @project.builds_enabled? - %li - = link_to 'Badges', '' - if @repository.commit .content-block.second-block.white From 5f32b82a80d517421889cfc89452f8d94fa09ea5 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 6 Apr 2016 10:10:29 +0200 Subject: [PATCH 075/212] Change name of badge variable in badges controller --- app/controllers/projects/badges_controller.rb | 2 +- app/views/projects/badges/index.html.haml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/projects/badges_controller.rb b/app/controllers/projects/badges_controller.rb index 6e442d66ad..9dff74c823 100644 --- a/app/controllers/projects/badges_controller.rb +++ b/app/controllers/projects/badges_controller.rb @@ -5,7 +5,7 @@ class Projects::BadgesController < Projects::ApplicationController def index @ref = params[:ref] || 'master' - @badge = Gitlab::Badge::Build.new(@project, @ref) + @build_badge = Gitlab::Badge::Build.new(@project, @ref) end def build diff --git a/app/views/projects/badges/index.html.haml b/app/views/projects/badges/index.html.haml index fb57bf411d..c22384ddf4 100644 --- a/app/views/projects/badges/index.html.haml +++ b/app/views/projects/badges/index.html.haml @@ -6,7 +6,7 @@ .panel.panel-default .panel-heading %b Builds badge · - = @badge.to_html + = @build_badge.to_html .pull-right = render 'shared/ref_switcher', destination: 'badges' .panel-body @@ -14,11 +14,11 @@ .col-md-2.text-center Markdown .col-md-10.code.js-syntax-highlight - = highlight('.md', @badge.to_markdown) + = highlight('.md', @build_badge.to_markdown) .row %hr .row .col-md-2.text-center HTML .col-md-10.code.js-syntax-highlight - = highlight('.html', @badge.to_html) + = highlight('.html', @build_badge.to_html) From 68ac8d38e24d4c63d28f874f1a40e792cfeb4296 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 6 Apr 2016 10:17:20 +0200 Subject: [PATCH 076/212] Add Changelog entry for project badges in settings --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index a23c8a54af..7b90085380 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,9 @@ v 8.7.0 (unreleased) - All images in discussions and wikis now link to their source files !3464 (Connor Shea). - Improved Markdown rendering performance !3389 (Yorick Peterse) - Don't attempt to look up an avatar in repo if repo directory does not exist (Stan Hu) + - Expose project badges in project settings + - Don't attempt to fetch any tags from a forked repo (Stan Hu) + - Don't attempt to look up an avatar in repo if repo directory does not exist (Stan hu) - Preserve time notes/comments have been updated at when moving issue - Make HTTP(s) label consistent on clone bar (Stan Hu) - Expose label description in API (Mariusz Jachimowicz) From 7689e87854980f72f41dcf6924693fb046e1919b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 6 Apr 2016 19:55:37 +0200 Subject: [PATCH 077/212] Use default branch when displaying list of badges --- app/controllers/projects/badges_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects/badges_controller.rb b/app/controllers/projects/badges_controller.rb index 9dff74c823..824aa41db5 100644 --- a/app/controllers/projects/badges_controller.rb +++ b/app/controllers/projects/badges_controller.rb @@ -4,7 +4,7 @@ class Projects::BadgesController < Projects::ApplicationController before_action :no_cache_headers, except: [:index] def index - @ref = params[:ref] || 'master' + @ref = params[:ref] || @project.default_branch || 'master' @build_badge = Gitlab::Badge::Build.new(@project, @ref) end From d0bce1470bf0eefc2734c996d99ecf97cb9d54d2 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 6 Apr 2016 20:00:58 +0200 Subject: [PATCH 078/212] Fix Changelog entries after rebase --- CHANGELOG | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7b90085380..a02357374d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,8 +5,6 @@ v 8.7.0 (unreleased) - Improved Markdown rendering performance !3389 (Yorick Peterse) - Don't attempt to look up an avatar in repo if repo directory does not exist (Stan Hu) - Expose project badges in project settings - - Don't attempt to fetch any tags from a forked repo (Stan Hu) - - Don't attempt to look up an avatar in repo if repo directory does not exist (Stan hu) - Preserve time notes/comments have been updated at when moving issue - Make HTTP(s) label consistent on clone bar (Stan Hu) - Expose label description in API (Mariusz Jachimowicz) From ee87d15cf443e66f47e20b92bb442b9e1874fee7 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Tue, 5 Apr 2016 19:19:00 -0500 Subject: [PATCH 079/212] Change approach, do not use timeouts --- .../javascripts/search_autocomplete.js.coffee | 30 ++++++++----------- app/views/layouts/_search.html.haml | 4 +-- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/search_autocomplete.js.coffee b/app/assets/javascripts/search_autocomplete.js.coffee index 564fb265b9..5a0df7817c 100644 --- a/app/assets/javascripts/search_autocomplete.js.coffee +++ b/app/assets/javascripts/search_autocomplete.js.coffee @@ -137,13 +137,17 @@ class @SearchAutocomplete } bindEvents: -> + $(document).on 'click', @onDocumentClick @searchInput.on 'keydown', @onSearchInputKeyDown @searchInput.on 'keyup', @onSearchInputKeyUp @searchInput.on 'click', @onSearchInputClick @searchInput.on 'focus', @onSearchInputFocus - @searchInput.on 'blur', @onSearchInputBlur @clearInput.on 'click', @onRemoveLocationClick + onDocumentClick: (e) => + if not $.contains(@dropdown[0], e.target) and @isFocused + @onSearchInputBlur() + enableAutocomplete: -> # No need to enable anything if user is not logged in return if !gon.current_user_id @@ -193,27 +197,21 @@ class @SearchAutocomplete e.stopImmediatePropagation() onSearchInputFocus: => + @isFocused = true @wrap.addClass('search-active') onRemoveLocationClick: (e) => e.preventDefault() @removeLocationBadge() @searchInput.val('').focus() - @skipBlurEvent = true onSearchInputBlur: (e) => - @skipBlurEvent = false + @isFocused = false + @wrap.removeClass('search-active') - # We should wait to make sure we are not clearing the input instead - setTimeout( => - return if @skipBlurEvent - - @wrap.removeClass('search-active') - - # If input is blank then restore state - if @searchInput.val() is '' - @restoreOriginalState() - , 150) + # If input is blank then restore state + if @searchInput.val() is '' + @restoreOriginalState() addLocationBadge: (item) -> category = if item.category? then "#{item.category}: " else '' @@ -291,9 +289,5 @@ class @SearchAutocomplete $el.removeClass('is-active') @disableAutocomplete() + @onSearchInputFocus() @searchInput.val('').focus() - - # We need to wait because of @skipBlurEvent - setTimeout( => - @onSearchInputFocus() - , 200) diff --git a/app/views/layouts/_search.html.haml b/app/views/layouts/_search.html.haml index 9d4ab9847a..ba04bd74b8 100644 --- a/app/views/layouts/_search.html.haml +++ b/app/views/layouts/_search.html.haml @@ -21,8 +21,8 @@ %a.is-focused.dropdown-menu-empty-link Loading... = dropdown_loading - %i.search-icon - %i.clear-icon.js-clear-input + %i.search-icon + %i.clear-icon.js-clear-input = hidden_field_tag :group_id, @group.try(:id) = hidden_field_tag :project_id, @project && @project.persisted? ? @project.id : '', id: 'search_project_id' From 0728588c3424fd7e75ca3c45ad1ea84063437311 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 13:03:07 +0200 Subject: [PATCH 080/212] API: Ability to filter milestones by state --- CHANGELOG | 1 + doc/api/milestones.md | 3 +++ lib/api/milestones.rb | 20 ++++++++++++++++++-- spec/requests/api/milestones_spec.rb | 17 +++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a23c8a54af..531f360729 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -25,6 +25,7 @@ v 8.7.0 (unreleased) - Build status notifications - API: Ability to retrieve a specific tag (Robert Schilling) - API: Expose user location (Robert Schilling) + - API: Ability to milter milestones by state `active` and `closed` (Robert Schilling) v 8.6.5 (unreleased) - Check permissions when user attempts to import members from another project diff --git a/doc/api/milestones.md b/doc/api/milestones.md index a682872826..4d94d7f3e2 100644 --- a/doc/api/milestones.md +++ b/doc/api/milestones.md @@ -7,6 +7,8 @@ Returns a list of project milestones. ``` GET /projects/:id/milestones GET /projects/:id/milestones?iid=42 +GET /projects/:id/milestones?state=active +GET /projects/:id/milestones?state=closed ``` ```json @@ -29,6 +31,7 @@ Parameters: - `id` (required) - The ID of a project - `iid` (optional) - Return the milestone having the given `iid` +- `state` (optional) - Return "active" or "closed" milestones ## Get single milestone diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index c5cd73943f..39efa1b176 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -3,17 +3,33 @@ module API class Milestones < Grape::API before { authenticate! } + helpers do + def filter_milestones_state(milestones, state) + case state + when 'active' then milestones.active + when 'closed' then milestones.closed + else milestones + end + end + end + resource :projects do # Get a list of project milestones # # Parameters: - # id (required) - The ID of a project + # id (required) - The ID of a project + # state (optional) - Return "active" or "closed" milestones # Example Request: # GET /projects/:id/milestones + # GET /projects/:id/milestones?state=active + # GET /projects/:id/milestones?state=closed get ":id/milestones" do authorize! :read_milestone, user_project - present paginate(user_project.milestones), with: Entities::Milestone + milestones = user_project.milestones + milestones = filter_milestones_state(milestones, params[:state]) unless params[:state].nil? + + present paginate(milestones), with: Entities::Milestone end # Get a single project milestone diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb index db0f6e3c0f..281d2b25bf 100644 --- a/spec/requests/api/milestones_spec.rb +++ b/spec/requests/api/milestones_spec.rb @@ -4,6 +4,7 @@ describe API::API, api: true do include ApiHelpers let(:user) { create(:user) } let!(:project) { create(:project, namespace: user.namespace ) } + let!(:closed_milestone) { create(:closed_milestone, project: project, state: :closed) } let!(:milestone) { create(:milestone, project: project) } before { project.team << [user, :developer] } @@ -20,6 +21,22 @@ describe API::API, api: true do get api("/projects/#{project.id}/milestones") expect(response.status).to eq(401) end + + it 'should return an array of active milestones' do + get api("/projects/#{project.id}/milestones?state=active", user) + expect(response.status).to eq(200) + expect(json_response).to be_an Array + expect(json_response.length).to eq(1) + expect(json_response.first['id']).to eq(milestone.id) + end + + it 'should return an array of closed milestones' do + get api("/projects/#{project.id}/milestones?state=closed", user) + expect(response.status).to eq(200) + expect(json_response).to be_an Array + expect(json_response.length).to eq(1) + expect(json_response.first['id']).to eq(closed_milestone.id) + end end describe 'GET /projects/:id/milestones/:milestone_id' do From e6215a9a8ed20354782120a7ce6368c7e8aab9a5 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 20:53:17 +0200 Subject: [PATCH 081/212] Improve coding and doc style --- CHANGELOG | 2 +- doc/api/milestones.md | 19 ++++++++++++++----- lib/api/milestones.rb | 2 +- spec/requests/api/milestones_spec.rb | 8 +++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 531f360729..ff86e66e16 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ v 8.7.0 (unreleased) - Handle nil descriptions in Slack issue messages (Stan Hu) - Add default scope to projects to exclude projects pending deletion - Ensure empty recipients are rejected in BuildsEmailService + - API: Ability to filter milestones by state `active` and `closed` (Robert Schilling) - Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.) - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) - Gracefully handle notes on deleted commits in merge requests (Stan Hu) @@ -25,7 +26,6 @@ v 8.7.0 (unreleased) - Build status notifications - API: Ability to retrieve a specific tag (Robert Schilling) - API: Expose user location (Robert Schilling) - - API: Ability to milter milestones by state `active` and `closed` (Robert Schilling) v 8.6.5 (unreleased) - Check permissions when user attempts to import members from another project diff --git a/doc/api/milestones.md b/doc/api/milestones.md index 4d94d7f3e2..e4202025f8 100644 --- a/doc/api/milestones.md +++ b/doc/api/milestones.md @@ -11,6 +11,20 @@ GET /projects/:id/milestones?state=active GET /projects/:id/milestones?state=closed ``` +Parameters: + +| Attribute | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `id` | integer | yes | The ID of a project | +| `iid` | integer | optional | Return only the milestone having the given `iid` | +| `state` | string | optional | Return only `active` or `closed` milestones` | + +```bash +curl -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/milestones +``` + +Example Response: + ```json [ { @@ -27,11 +41,6 @@ GET /projects/:id/milestones?state=closed ] ``` -Parameters: - -- `id` (required) - The ID of a project -- `iid` (optional) - Return the milestone having the given `iid` -- `state` (optional) - Return "active" or "closed" milestones ## Get single milestone diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index 39efa1b176..afb6ffa360 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -27,7 +27,7 @@ module API authorize! :read_milestone, user_project milestones = user_project.milestones - milestones = filter_milestones_state(milestones, params[:state]) unless params[:state].nil? + milestones = filter_milestones_state(milestones, params[:state]) present paginate(milestones), with: Entities::Milestone end diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb index 281d2b25bf..d97bf6d38f 100644 --- a/spec/requests/api/milestones_spec.rb +++ b/spec/requests/api/milestones_spec.rb @@ -4,7 +4,7 @@ describe API::API, api: true do include ApiHelpers let(:user) { create(:user) } let!(:project) { create(:project, namespace: user.namespace ) } - let!(:closed_milestone) { create(:closed_milestone, project: project, state: :closed) } + let!(:closed_milestone) { create(:closed_milestone, project: project) } let!(:milestone) { create(:milestone, project: project) } before { project.team << [user, :developer] } @@ -22,16 +22,18 @@ describe API::API, api: true do expect(response.status).to eq(401) end - it 'should return an array of active milestones' do + it 'returns an array of active milestones' do get api("/projects/#{project.id}/milestones?state=active", user) + expect(response.status).to eq(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(milestone.id) end - it 'should return an array of closed milestones' do + it 'returns an array of closed milestones' do get api("/projects/#{project.id}/milestones?state=closed", user) + expect(response.status).to eq(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) From 5f4ce722c0f5fbf9129dddf20de879f00db4a311 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Wed, 6 Apr 2016 13:55:49 -0500 Subject: [PATCH 082/212] Display clear button only if input has a value --- .../javascripts/search_autocomplete.js.coffee | 7 ++++--- app/assets/stylesheets/pages/search.scss | 16 ++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/search_autocomplete.js.coffee b/app/assets/javascripts/search_autocomplete.js.coffee index 5a0df7817c..9c85ce1633 100644 --- a/app/assets/javascripts/search_autocomplete.js.coffee +++ b/app/assets/javascripts/search_autocomplete.js.coffee @@ -142,7 +142,7 @@ class @SearchAutocomplete @searchInput.on 'keyup', @onSearchInputKeyUp @searchInput.on 'click', @onSearchInputClick @searchInput.on 'focus', @onSearchInputFocus - @clearInput.on 'click', @onRemoveLocationClick + @clearInput.on 'click', @onClearInputClick onDocumentClick: (e) => if not $.contains(@dropdown[0], e.target) and @isFocused @@ -189,6 +189,8 @@ class @SearchAutocomplete # We should display the menu only when input is not empty @enableAutocomplete() + @wrap.toggleClass 'has-value', !!e.target.value + # Avoid falsy value to be returned return @@ -200,9 +202,8 @@ class @SearchAutocomplete @isFocused = true @wrap.addClass('search-active') - onRemoveLocationClick: (e) => + onClearInputClick: (e) => e.preventDefault() - @removeLocationBadge() @searchInput.val('').focus() onSearchInputBlur: (e) => diff --git a/app/assets/stylesheets/pages/search.scss b/app/assets/stylesheets/pages/search.scss index 9274796233..f0f3744c6f 100644 --- a/app/assets/stylesheets/pages/search.scss +++ b/app/assets/stylesheets/pages/search.scss @@ -144,16 +144,16 @@ color: $location-icon-active-color; } } + } - &.has-location-badge { - .search-icon { - display: none; - } + &.has-value { + .search-icon { + display: none; + } - .clear-icon { - cursor: pointer; - display: block; - } + .clear-icon { + cursor: pointer; + display: block; } } From dc3272dccbf2462ad8a7ee8f677086ffabae3afb Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 21:03:24 +0200 Subject: [PATCH 083/212] Revert "API: Ability to retrieve a single tag" This reverts commit 7f287c9136d5d1cdda8df170c6e772ca82aad1e9. --- doc/api/tags.md | 34 +--------------------------------- lib/api/tags.rb | 14 -------------- spec/requests/api/tags_spec.rb | 17 ----------------- 3 files changed, 1 insertion(+), 64 deletions(-) diff --git a/doc/api/tags.md b/doc/api/tags.md index c451a42b72..17d12e9cc6 100644 --- a/doc/api/tags.md +++ b/doc/api/tags.md @@ -38,38 +38,6 @@ Parameters: ] ``` -## Get a single repository tag - -Get a specific repository tag determined by its name. It returns 200 together -with the tag information if the tag exists. It returns 404 if the tag does not -exist. - -Parameters: - -- `id` (required) - The ID of a project -- `tag_name` (required) - The name of the tag - -```json -{ - "name": "v5.0.0", - "message": null, - "commit": { - "id": "60a8ff033665e1207714d6670fcd7b65304ec02f", - "message": "v5.0.0\n", - "parent_ids": [ - "f61c062ff8bcbdb00e0a1b3317a91aed6ceee06b" - ], - "authored_date": "2015-02-01T21:56:31.000+01:00", - "author_name": "Arthur Verschaeve", - "author_email": "contact@arthurverschaeve.be", - "committed_date": "2015-02-01T21:56:31.000+01:00", - "committer_name": "Arthur Verschaeve", - "committer_email": "contact@arthurverschaeve.be" - }, - "release": null -} -``` - ## Create a new tag Creates a new tag in the repository that points to the supplied ref. @@ -180,4 +148,4 @@ Parameters: "tag_name": "1.0.0", "description": "Amazing release. Wow" } -``` +``` \ No newline at end of file diff --git a/lib/api/tags.rb b/lib/api/tags.rb index 731a68082b..2d8a9e51bb 100644 --- a/lib/api/tags.rb +++ b/lib/api/tags.rb @@ -16,20 +16,6 @@ module API with: Entities::RepoTag, project: user_project end - # Get a single repository tag - # - # Parameters: - # id (required) - The ID of a project - # tag_name (required) - The name of the tag - # Example Request: - # GET /projects/:id/repository/tags/:tag_name - get ":id/repository/tags/:tag_name", requirements: { tag_name: /.*/ } do - tag = user_project.repository.find_tag(params[:tag_name]) - not_found!('Tag') unless tag - - present tag, with: Entities::RepoTag, project: user_project - end - # Create tag # # Parameters: diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb index acbd9c3e33..a15be07ed5 100644 --- a/spec/requests/api/tags_spec.rb +++ b/spec/requests/api/tags_spec.rb @@ -40,23 +40,6 @@ describe API::API, api: true do end end - describe "GET /projects/:id/repository/tags/:tag_name" do - let(:tag_name) { project.repository.tag_names.sort.reverse.first } - - it 'should return a specific tag' do - get api("/projects/#{project.id}/repository/tags/#{tag_name}", user) - - expect(response.status).to eq(200) - expect(json_response['name']).to eq(tag_name) - end - - it 'should return 404 for an invalid tag name' do - get api("/projects/#{project.id}/repository/tags/foobar", user) - - expect(response.status).to eq(404) - end - end - describe 'POST /projects/:id/repository/tags' do context 'lightweight tags' do it 'should create a new tag' do From 0b5ff4714caeedf359ed5a2477bada693ccb24a9 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Fri, 1 Apr 2016 18:41:36 +0100 Subject: [PATCH 084/212] change the subscribe, delete and edit buttons to icons --- app/assets/stylesheets/pages/labels.scss | 30 ++++++++++++++++++++++ app/views/projects/labels/_label.html.haml | 17 +++++++----- app/views/shared/_label_row.html.haml | 3 ++- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/pages/labels.scss b/app/assets/stylesheets/pages/labels.scss index 4e02ec4e89..cce34418c5 100644 --- a/app/assets/stylesheets/pages/labels.scss +++ b/app/assets/stylesheets/pages/labels.scss @@ -49,6 +49,11 @@ } .label-row { + .label-name { + display: inline-block; + width: 200px; + } + .label { padding: 9px; font-size: 14px; @@ -69,3 +74,28 @@ background-color: $gl-danger; color: $white-light; } + +.manage-labels-list { + + .prepend-left-10 { + display: inline-block; + width: 440px; + } + + .pull-right { + .action-buttons { + border-color: transparent; + margin: 7px; + } + + i { + color: $gl-text-color; + } + + .append-right-20 { + a { + color: $gl-text-color; + } + } + } +} diff --git a/app/views/projects/labels/_label.html.haml b/app/views/projects/labels/_label.html.haml index 0612863296..5e2dd8ac61 100644 --- a/app/views/projects/labels/_label.html.haml +++ b/app/views/projects/labels/_label.html.haml @@ -2,23 +2,26 @@ = render "shared/label_row", label: label .pull-right - %strong.append-right-20 + %span.append-right-20 = link_to_label(label, type: :merge_request) do - = pluralize label.open_merge_requests_count, 'open merge request' + = pluralize label.open_merge_requests_count, 'merge request' - %strong.append-right-20 + %span.append-right-20 = link_to_label(label) do = pluralize label.open_issues_count(current_user), 'open issue' - if current_user .label-subscription{data: {url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label)}} .subscription-status{data: {status: label_subscription_status(label)}} - %button.btn.btn-sm.btn-info.subscribe-button - %span= label_subscription_toggle_button_text(label) + + %a.subscribe-button.action-buttons{data: {toggle: "tooltip", original_title: label_subscription_toggle_button_text(label)}} + %i.fa.fa-rss - if can? current_user, :admin_label, @project - = link_to 'Edit', edit_namespace_project_label_path(@project.namespace, @project, label), class: 'btn btn-sm' - = link_to 'Delete', namespace_project_label_path(@project.namespace, @project, label), class: 'btn btn-sm btn-remove remove-row', method: :delete, remote: true, data: {confirm: "Remove this label? Are you sure?"} + = link_to edit_namespace_project_label_path(@project.namespace, @project, label), class: 'action-buttons', data: {toggle: "tooltip", original_title: "Edit"} do + %i.fa.fa-pencil-square-o + = link_to namespace_project_label_path(@project.namespace, @project, label), class: 'action-buttons remove-row', method: :delete, remote: true, data: {confirm: "Remove this label? Are you sure?", toggle: "tooltip", original_title: "Delete"} do + %i.fa.fa-trash-o - if current_user :javascript diff --git a/app/views/shared/_label_row.html.haml b/app/views/shared/_label_row.html.haml index 4b47b0291b..b38c5e18ef 100644 --- a/app/views/shared/_label_row.html.haml +++ b/app/views/shared/_label_row.html.haml @@ -1,4 +1,5 @@ %span.label-row - = link_to_label(label, tooltip: false) + %span.label-name + = link_to_label(label, tooltip: false) %span.prepend-left-10 = markdown(label.description, pipeline: :single_line) From 802c6e7bba0444ec5fa4757da30c21fd28a5ccbc Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Fri, 1 Apr 2016 19:12:11 +0100 Subject: [PATCH 085/212] set the width to the elements --- app/assets/stylesheets/pages/labels.scss | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/pages/labels.scss b/app/assets/stylesheets/pages/labels.scss index cce34418c5..1d5d402ba0 100644 --- a/app/assets/stylesheets/pages/labels.scss +++ b/app/assets/stylesheets/pages/labels.scss @@ -51,7 +51,7 @@ .label-row { .label-name { display: inline-block; - width: 200px; + width: 21%; } .label { @@ -79,10 +79,11 @@ .prepend-left-10 { display: inline-block; - width: 440px; + width: 45%; } .pull-right { + .action-buttons { border-color: transparent; margin: 7px; From 02dcc4188c8816cd4363a98e60ae54309623ea6f Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Sat, 2 Apr 2016 22:54:22 +0100 Subject: [PATCH 086/212] make the view responsive for extra small device --- app/assets/stylesheets/pages/labels.scss | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/assets/stylesheets/pages/labels.scss b/app/assets/stylesheets/pages/labels.scss index 1d5d402ba0..e77d43fa29 100644 --- a/app/assets/stylesheets/pages/labels.scss +++ b/app/assets/stylesheets/pages/labels.scss @@ -52,6 +52,10 @@ .label-name { display: inline-block; width: 21%; + + @media (max-width: $screen-xs-min) { + display: block; + } } .label { @@ -80,10 +84,21 @@ .prepend-left-10 { display: inline-block; width: 45%; + + @media (max-width: $screen-xs-min) { + display: block; + width: 100%; + margin-left: 0px; + padding: 10px 0; + } } .pull-right { + @media (max-width: $screen-xs-min) { + float: none !important; + } + .action-buttons { border-color: transparent; margin: 7px; @@ -97,6 +112,11 @@ a { color: $gl-text-color; } + + @media (max-width: $screen-xs-min) { + display: block; + margin-bottom: 10px; + } } } } From 8d28f94e7bbf09ecf49ae9d7fab8c9a76abeb7ac Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Sun, 3 Apr 2016 00:55:59 +0100 Subject: [PATCH 087/212] finish up the design and add info to the changelog --- CHANGELOG | 1 + app/assets/javascripts/subscription.js.coffee | 3 +++ app/assets/stylesheets/pages/labels.scss | 11 +++++++---- app/views/projects/labels/_label.html.haml | 8 ++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a23c8a54af..ecca821cd9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -31,6 +31,7 @@ v 8.6.5 (unreleased) v 8.6.4 - Don't attempt to fetch any tags from a forked repo (Stan Hu) + - Redesign the Labels page v 8.6.3 - Mentions on confidential issues doesn't create todos for non-members. !3374 diff --git a/app/assets/javascripts/subscription.js.coffee b/app/assets/javascripts/subscription.js.coffee index 084f0e0dc6..6ebd0750ff 100644 --- a/app/assets/javascripts/subscription.js.coffee +++ b/app/assets/javascripts/subscription.js.coffee @@ -3,8 +3,10 @@ class @Subscription $container = $(container) @url = $container.attr('data-url') @subscribe_button = $container.find('.subscribe-button') + @subscribe_icon = $container.find('.subscribe-icon') @subscription_status = $container.find('.subscription-status') @subscribe_button.unbind('click').click(@toggleSubscription) + @subscribe_icon.unbind('click').click(@toggleSubscription) toggleSubscription: (event) => btn = $(event.currentTarget) @@ -16,6 +18,7 @@ class @Subscription btn.prop('disabled', false) status = if current_status == 'subscribed' then 'unsubscribed' else 'subscribed' @subscription_status.attr('data-status', status) + @subscribe_icon.attr('data-original-title', status) action = if status == 'subscribed' then 'Unsubscribe' else 'Subscribe' btn.find('span').text(action) @subscription_status.find('>div').toggleClass('hidden') diff --git a/app/assets/stylesheets/pages/labels.scss b/app/assets/stylesheets/pages/labels.scss index e77d43fa29..0e4468ad2c 100644 --- a/app/assets/stylesheets/pages/labels.scss +++ b/app/assets/stylesheets/pages/labels.scss @@ -49,9 +49,11 @@ } .label-row { + .label-name { display: inline-block; - width: 21%; + width: 200px; + vertical-align: top; @media (max-width: $screen-xs-min) { display: block; @@ -93,15 +95,16 @@ } } - .pull-right { + .pull-info-right { + float: right; @media (max-width: $screen-xs-min) { - float: none !important; + float: none; } .action-buttons { border-color: transparent; - margin: 7px; + padding: 6px } i { diff --git a/app/views/projects/labels/_label.html.haml b/app/views/projects/labels/_label.html.haml index 5e2dd8ac61..4c144c317f 100644 --- a/app/views/projects/labels/_label.html.haml +++ b/app/views/projects/labels/_label.html.haml @@ -1,7 +1,7 @@ %li{id: dom_id(label)} = render "shared/label_row", label: label - .pull-right + .pull-info-right %span.append-right-20 = link_to_label(label, type: :merge_request) do = pluralize label.open_merge_requests_count, 'merge request' @@ -14,13 +14,13 @@ .label-subscription{data: {url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label)}} .subscription-status{data: {status: label_subscription_status(label)}} - %a.subscribe-button.action-buttons{data: {toggle: "tooltip", original_title: label_subscription_toggle_button_text(label)}} + %a.subscribe-icon.btn.action-buttons{data: {toggle: "tooltip", original_title: label_subscription_status(label)}} %i.fa.fa-rss - if can? current_user, :admin_label, @project - = link_to edit_namespace_project_label_path(@project.namespace, @project, label), class: 'action-buttons', data: {toggle: "tooltip", original_title: "Edit"} do + = link_to edit_namespace_project_label_path(@project.namespace, @project, label), class: 'btn action-buttons', data: {toggle: "tooltip", original_title: "Edit"} do %i.fa.fa-pencil-square-o - = link_to namespace_project_label_path(@project.namespace, @project, label), class: 'action-buttons remove-row', method: :delete, remote: true, data: {confirm: "Remove this label? Are you sure?", toggle: "tooltip", original_title: "Delete"} do + = link_to namespace_project_label_path(@project.namespace, @project, label), class: 'btn action-buttons remove-row', method: :delete, remote: true, data: {confirm: "Remove this label? Are you sure?", toggle: "tooltip", original_title: "Delete"} do %i.fa.fa-trash-o - if current_user From ffe2f8e679f7718e5064acb0c2504b2b3cc160de Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Mon, 4 Apr 2016 18:38:16 +0100 Subject: [PATCH 088/212] fix the failing tests and some changes --- app/assets/javascripts/subscription.js.coffee | 7 ++----- app/assets/stylesheets/pages/labels.scss | 15 +++++++++++---- app/views/projects/labels/_label.html.haml | 8 ++++---- features/steps/project/issues/labels.rb | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/subscription.js.coffee b/app/assets/javascripts/subscription.js.coffee index 6ebd0750ff..e4b7a3172e 100644 --- a/app/assets/javascripts/subscription.js.coffee +++ b/app/assets/javascripts/subscription.js.coffee @@ -3,22 +3,19 @@ class @Subscription $container = $(container) @url = $container.attr('data-url') @subscribe_button = $container.find('.subscribe-button') - @subscribe_icon = $container.find('.subscribe-icon') @subscription_status = $container.find('.subscription-status') @subscribe_button.unbind('click').click(@toggleSubscription) - @subscribe_icon.unbind('click').click(@toggleSubscription) toggleSubscription: (event) => btn = $(event.currentTarget) action = btn.find('span').text() current_status = @subscription_status.attr('data-status') - btn.prop('disabled', true) + btn.addClass('disabled') $.post @url, => - btn.prop('disabled', false) + btn.removeClass('disabled') status = if current_status == 'subscribed' then 'unsubscribed' else 'subscribed' @subscription_status.attr('data-status', status) - @subscribe_icon.attr('data-original-title', status) action = if status == 'subscribed' then 'Unsubscribe' else 'Subscribe' btn.find('span').text(action) @subscription_status.find('>div').toggleClass('hidden') diff --git a/app/assets/stylesheets/pages/labels.scss b/app/assets/stylesheets/pages/labels.scss index 0e4468ad2c..5dab999905 100644 --- a/app/assets/stylesheets/pages/labels.scss +++ b/app/assets/stylesheets/pages/labels.scss @@ -53,7 +53,7 @@ .label-name { display: inline-block; width: 200px; - vertical-align: top; + vertical-align: baseline; @media (max-width: $screen-xs-min) { display: block; @@ -85,12 +85,13 @@ .prepend-left-10 { display: inline-block; - width: 45%; + width: 40%; + vertical-align: text-top; @media (max-width: $screen-xs-min) { display: block; width: 100%; - margin-left: 0px; + margin-left: 0; padding: 10px 0; } } @@ -104,7 +105,13 @@ .action-buttons { border-color: transparent; - padding: 6px + padding: 6px; + color: $gl-text-color; + vertical-align: initial; + + &.subscribe-button { + padding-left: 0; + } } i { diff --git a/app/views/projects/labels/_label.html.haml b/app/views/projects/labels/_label.html.haml index 4c144c317f..097a65969a 100644 --- a/app/views/projects/labels/_label.html.haml +++ b/app/views/projects/labels/_label.html.haml @@ -14,13 +14,13 @@ .label-subscription{data: {url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label)}} .subscription-status{data: {status: label_subscription_status(label)}} - %a.subscribe-icon.btn.action-buttons{data: {toggle: "tooltip", original_title: label_subscription_status(label)}} - %i.fa.fa-rss + %a.subscribe-button.btn.action-buttons{data: {toggle: "tooltip"}} + %span= label_subscription_toggle_button_text(label) - if can? current_user, :admin_label, @project - = link_to edit_namespace_project_label_path(@project.namespace, @project, label), class: 'btn action-buttons', data: {toggle: "tooltip", original_title: "Edit"} do + = link_to edit_namespace_project_label_path(@project.namespace, @project, label), title: "Edit", class: 'btn action-buttons', data: {toggle: "tooltip"} do %i.fa.fa-pencil-square-o - = link_to namespace_project_label_path(@project.namespace, @project, label), class: 'btn action-buttons remove-row', method: :delete, remote: true, data: {confirm: "Remove this label? Are you sure?", toggle: "tooltip", original_title: "Delete"} do + = link_to namespace_project_label_path(@project.namespace, @project, label), title: "Delete", class: 'btn action-buttons remove-row', method: :delete, remote: true, data: {confirm: "Remove this label? Are you sure?", toggle: "tooltip"} do %i.fa.fa-trash-o - if current_user diff --git a/features/steps/project/issues/labels.rb b/features/steps/project/issues/labels.rb index 2ab8956867..0ca2d6257c 100644 --- a/features/steps/project/issues/labels.rb +++ b/features/steps/project/issues/labels.rb @@ -15,7 +15,7 @@ class Spinach::Features::ProjectIssuesLabels < Spinach::FeatureSteps step 'I delete all labels' do page.within '.labels' do - page.all('.btn-remove').each do |remove| + page.all('.remove-row').each do |remove| remove.click sleep 0.05 end From fc7b5bd49cf48d87f770acb5377c85c7a034b701 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Tue, 5 Apr 2016 19:17:30 +0100 Subject: [PATCH 089/212] apply some css changes --- app/assets/stylesheets/pages/labels.scss | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/assets/stylesheets/pages/labels.scss b/app/assets/stylesheets/pages/labels.scss index 5dab999905..3e0a3140be 100644 --- a/app/assets/stylesheets/pages/labels.scss +++ b/app/assets/stylesheets/pages/labels.scss @@ -49,11 +49,9 @@ } .label-row { - .label-name { display: inline-block; width: 200px; - vertical-align: baseline; @media (max-width: $screen-xs-min) { display: block; @@ -86,7 +84,7 @@ .prepend-left-10 { display: inline-block; width: 40%; - vertical-align: text-top; + vertical-align: middle; @media (max-width: $screen-xs-min) { display: block; @@ -107,7 +105,6 @@ border-color: transparent; padding: 6px; color: $gl-text-color; - vertical-align: initial; &.subscribe-button { padding-left: 0; From d1ad639010ecb8619db08f412babc6fb9e23458e Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Wed, 6 Apr 2016 14:28:15 -0500 Subject: [PATCH 090/212] Do not fire blur event when clicking a suggestion --- app/assets/javascripts/search_autocomplete.js.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/search_autocomplete.js.coffee b/app/assets/javascripts/search_autocomplete.js.coffee index 9c85ce1633..6a7b4ad1db 100644 --- a/app/assets/javascripts/search_autocomplete.js.coffee +++ b/app/assets/javascripts/search_autocomplete.js.coffee @@ -145,7 +145,10 @@ class @SearchAutocomplete @clearInput.on 'click', @onClearInputClick onDocumentClick: (e) => - if not $.contains(@dropdown[0], e.target) and @isFocused + # If clicking outside the search box + # And search input is not focused + # And we are not clicking inside a suggestion + if not $.contains(@dropdown[0], e.target) and @isFocused and not $(e.target).parents('ul').length @onSearchInputBlur() enableAutocomplete: -> @@ -290,5 +293,4 @@ class @SearchAutocomplete $el.removeClass('is-active') @disableAutocomplete() - @onSearchInputFocus() @searchInput.val('').focus() From 935bf7271d88c8623312004dd6cba791b76503f5 Mon Sep 17 00:00:00 2001 From: Drew Blessing Date: Tue, 5 Apr 2016 17:44:13 -0500 Subject: [PATCH 091/212] Only update main language if it is not already set --- CHANGELOG | 1 + app/services/git_push_service.rb | 10 +++++----- spec/services/git_push_service_spec.rb | 26 +++++++++++++++++++++----- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8db9a9b0d1..49140eea6c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,6 +24,7 @@ v 8.7.0 (unreleased) - Build status notifications v 8.6.5 (unreleased) + - Only update repository language if it is not set to improve performance - Check permissions when user attempts to import members from another project v 8.6.4 diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 36c9ee92da..dc74c02760 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -55,15 +55,15 @@ class GitPushService < BaseService end def update_main_language + # Performance can be bad so for now only check main_language once + # See https://gitlab.com/gitlab-org/gitlab-ce/issues/14937 + return if @project.main_language.present? + return unless is_default_branch? return unless push_to_new_branch? || push_to_existing_branch? current_language = @project.repository.main_language - - unless current_language == @project.main_language - return @project.update_attributes(main_language: current_language) - end - + @project.update_attributes(main_language: current_language) true end diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb index 1047e32960..b40a5c1c81 100644 --- a/spec/services/git_push_service_spec.rb +++ b/spec/services/git_push_service_spec.rb @@ -164,21 +164,37 @@ describe GitPushService, services: true do end context "after push" do - before do - @service = execute_service(project, user, @oldrev, @newrev, ref) + def execute + execute_service(project, user, @oldrev, @newrev, ref) end context "to master" do let(:ref) { @ref } - it { expect(@service.update_main_language).to eq(true) } - it { expect(project.main_language).to eq("Ruby") } + context 'when main_language is nil' do + it 'obtains the language from the repository' do + expect(project.repository).to receive(:main_language) + execute + end + + it 'sets the project main language' do + execute + expect(project.main_language).to eq("Ruby") + end + end + + context 'when main_language is already set' do + it 'does not check the repository' do + execute # do an initial run to simulate lang being preset + expect(project.repository).not_to receive(:main_language) + execute + end + end end context "to other branch" do let(:ref) { 'refs/heads/feature/branch' } - it { expect(@service.update_main_language).to eq(nil) } it { expect(project.main_language).to eq(nil) } end end From ebb91c7f0428ade28d78bcec4c02b60258cdab68 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Wed, 6 Apr 2016 09:15:01 -0700 Subject: [PATCH 092/212] Wrap code blocks to next line --- app/assets/stylesheets/framework/typography.scss | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/framework/typography.scss b/app/assets/stylesheets/framework/typography.scss index 7b2aada5a0..be64d93221 100644 --- a/app/assets/stylesheets/framework/typography.scss +++ b/app/assets/stylesheets/framework/typography.scss @@ -16,8 +16,9 @@ code { font-family: $monospace_font; - white-space: pre; + white-space: pre-wrap; word-wrap: normal; + word-break: break-word; } kbd { From dcdf0b2af2514f9f6778fd16cbcb77929a0bd708 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Wed, 6 Apr 2016 13:20:13 -0700 Subject: [PATCH 093/212] Horizontally scroll code blocks instead of wrapping --- app/assets/stylesheets/framework/files.scss | 1 + app/assets/stylesheets/framework/markdown_area.scss | 1 + app/assets/stylesheets/framework/typography.scss | 3 +-- app/assets/stylesheets/pages/detail_page.scss | 8 ++++++-- app/assets/stylesheets/pages/diff.scss | 5 +++++ app/assets/stylesheets/pages/notes.scss | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/framework/files.scss b/app/assets/stylesheets/framework/files.scss index a26ace5cc1..22f53e3b03 100644 --- a/app/assets/stylesheets/framework/files.scss +++ b/app/assets/stylesheets/framework/files.scss @@ -20,6 +20,7 @@ margin: 0; text-align: left; padding: 10px $gl-padding; + word-break: break-word; .file-actions { float: right; diff --git a/app/assets/stylesheets/framework/markdown_area.scss b/app/assets/stylesheets/framework/markdown_area.scss index ea8e1c902c..c8f86d60e3 100644 --- a/app/assets/stylesheets/framework/markdown_area.scss +++ b/app/assets/stylesheets/framework/markdown_area.scss @@ -84,6 +84,7 @@ .md-preview-holder { min-height: 167px; padding: 10px 0; + overflow-x: auto; } .markdown-area { diff --git a/app/assets/stylesheets/framework/typography.scss b/app/assets/stylesheets/framework/typography.scss index be64d93221..7b2aada5a0 100644 --- a/app/assets/stylesheets/framework/typography.scss +++ b/app/assets/stylesheets/framework/typography.scss @@ -16,9 +16,8 @@ code { font-family: $monospace_font; - white-space: pre-wrap; + white-space: pre; word-wrap: normal; - word-break: break-word; } kbd { diff --git a/app/assets/stylesheets/pages/detail_page.scss b/app/assets/stylesheets/pages/detail_page.scss index d3eda1a57e..5917f08972 100644 --- a/app/assets/stylesheets/pages/detail_page.scss +++ b/app/assets/stylesheets/pages/detail_page.scss @@ -33,8 +33,12 @@ .description { margin-top: 6px; - p:last-child { - margin-bottom: 0; + p { + overflow-x: auto; + + &:last-child { + margin-bottom: 0; + } } } } diff --git a/app/assets/stylesheets/pages/diff.scss b/app/assets/stylesheets/pages/diff.scss index f1368d74b3..7a12aa9647 100644 --- a/app/assets/stylesheets/pages/diff.scss +++ b/app/assets/stylesheets/pages/diff.scss @@ -59,10 +59,15 @@ border-collapse: separate; margin: 0; padding: 0; + .line_holder td { line-height: $code_line_height; font-size: $code_font_size; } + + td { + white-space: nowrap; + } } tr.line_holder.parallel { diff --git a/app/assets/stylesheets/pages/notes.scss b/app/assets/stylesheets/pages/notes.scss index 614ca48b90..aca86457c7 100644 --- a/app/assets/stylesheets/pages/notes.scss +++ b/app/assets/stylesheets/pages/notes.scss @@ -82,7 +82,7 @@ ul.notes { // On diffs code should wrap nicely and not overflow pre { code { - white-space: pre-wrap; + white-space: pre; } } From b3dd470854f83616bb6bd36bd73680bfda869d81 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 22:46:07 +0200 Subject: [PATCH 094/212] Fix wrong changelog item --- CHANGELOG | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a23c8a54af..92a0d8547e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,7 +23,6 @@ v 8.7.0 (unreleased) - Remove "Congratulations!" tweet button on newly-created project. (Connor Shea) - Improved UX of the navigation sidebar - Build status notifications - - API: Ability to retrieve a specific tag (Robert Schilling) - API: Expose user location (Robert Schilling) v 8.6.5 (unreleased) From 3a36fa895724aedb4bd919ec91cc00a24415e712 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 6 Apr 2016 16:03:35 -0500 Subject: [PATCH 095/212] Fix error that was causing only one group to be returned and corrected specs to use the proper attribute type --- lib/gitlab/saml/auth_hash.rb | 4 +++- spec/lib/gitlab/saml/user_spec.rb | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/saml/auth_hash.rb b/lib/gitlab/saml/auth_hash.rb index 5ffccc0e10..3414d24ca7 100644 --- a/lib/gitlab/saml/auth_hash.rb +++ b/lib/gitlab/saml/auth_hash.rb @@ -9,7 +9,9 @@ module Gitlab private def get_raw(key) - auth_hash.extra[:raw_info][key] + # Needs to call `all` because of https://github.com/onelogin/ruby-saml/blob/master/lib/onelogin/ruby-saml/attributes.rb#L78 + # otherwise just the first value is returned + auth_hash.extra[:raw_info].all[key] end end diff --git a/spec/lib/gitlab/saml/user_spec.rb b/spec/lib/gitlab/saml/user_spec.rb index 84a26af940..ed7b507dba 100644 --- a/spec/lib/gitlab/saml/user_spec.rb +++ b/spec/lib/gitlab/saml/user_spec.rb @@ -5,7 +5,7 @@ describe Gitlab::Saml::User, lib: true do let(:gl_user) { saml_user.gl_user } let(:uid) { 'my-uid' } let(:provider) { 'saml' } - let(:auth_hash) { OmniAuth::AuthHash.new(uid: uid, provider: provider, info: info_hash, extra: { raw_info: { groups: %w(Developers Freelancers Designers) } }) } + let(:auth_hash) { OmniAuth::AuthHash.new(uid: uid, provider: provider, info: info_hash, extra: { raw_info: OneLogin::RubySaml::Attributes.new({ 'groups' => %w(Developers Freelancers Designers) }) }) } let(:info_hash) do { name: 'John', @@ -48,6 +48,7 @@ describe Gitlab::Saml::User, lib: true do before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Freelancers), args: {} } }) } it 'marks the user as external' do saml_user.save + expect(gl_user).to be_valid expect(gl_user.external).to be_truthy end end @@ -56,6 +57,7 @@ describe Gitlab::Saml::User, lib: true do context 'are defined but the user does not belong there' do it 'does not mark the user as external' do saml_user.save + expect(gl_user).to be_valid expect(gl_user.external).to be_falsey end end @@ -64,6 +66,7 @@ describe Gitlab::Saml::User, lib: true do it 'should make user internal' do existing_user.update_attribute('external', true) saml_user.save + expect(gl_user).to be_valid expect(gl_user.external).to be_falsey end end @@ -105,6 +108,7 @@ describe Gitlab::Saml::User, lib: true do before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Freelancers), args: {} } }) } it 'marks the user as external' do saml_user.save + expect(gl_user).to be_valid expect(gl_user.external).to be_truthy end end @@ -113,6 +117,7 @@ describe Gitlab::Saml::User, lib: true do context 'are defined but the user does not belong there' do it 'does not mark the user as external' do saml_user.save + expect(gl_user).to be_valid expect(gl_user.external).to be_falsey end end From b95ac0962c96c933bc85b89558733055a21d3dd5 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 6 Apr 2016 16:04:11 -0500 Subject: [PATCH 096/212] Added documentation --- config/gitlab.yml.example | 1 + doc/integration/saml.md | 72 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index c607e32a05..ddee467b14 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -354,6 +354,7 @@ production: &base # issuer: 'https://gitlab.example.com', # name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient' # } } + # # - { name: 'crowd', # args: { # crowd_server_url: 'CROWD SERVER URL', diff --git a/doc/integration/saml.md b/doc/integration/saml.md index 1c3dc707f6..684f0a5b8c 100644 --- a/doc/integration/saml.md +++ b/doc/integration/saml.md @@ -131,8 +131,76 @@ On the sign in page there should now be a SAML button below the regular sign in Click the icon to begin the authentication process. If everything goes well the user will be returned to GitLab and will be signed in. +## External Groups + +>**Note:** +This setting is only available on GitLab 8.7 and above. + +SAML login includes support for external groups. You can define in the SAML +settings which groups, to which your users belong in your IdP, you wish to be +marked as [external](../permissions/permissions.md). + +### Requirements + +First you need to tell GitLab where to look for group information. For this you +need to make sure that your IdP server sends a specific `AttributeStament` along +with the regular SAML response. Here is an example: + +```xml + + + SecurityGroup + Developers + Designers + + +``` + +The name of the attribute can be anything you like, but it must contain the groups +to which a user belongs. In order to tell GitLab where to find these groups, you need +to add a `groups_attribute:` element to your SAML settings. You will also need to +tell GitLab which groups are external, for that you need the `external_groups:` +element: + +```yaml +{ name: 'saml', + label: 'Our SAML Provider', + groups_attribute: 'Groups', + external_groups: ['Freelancers', 'Interns'], + args: { + assertion_consumer_service_url: 'https://gitlab.example.com/users/auth/saml/callback', + idp_cert_fingerprint: '43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8', + idp_sso_target_url: 'https://login.example.com/idp', + issuer: 'https://gitlab.example.com', + name_identifier_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient' + } } +``` + ## Customization +### `auto_sign_in_with_provider` + +You can add this setting to your GitLab configuration to automatically redirect you +to your SAML server for authentication, thus removing the need to click a button +before actually signing in. + +For omnibus package: + +```ruby +gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'saml' +``` + +For installations from source: + +```yaml +omniauth: + auto_sign_in_with_provider: saml +``` + +Please keep in mind that every sign in attempt will be redirected to the SAML server, +so you will not be able to sign in using local credentials. Make sure that at least one +of the SAML users has admin permissions. + ### `attribute_statements` >**Note:** @@ -205,6 +273,10 @@ To bypass this you can add `skip_before_action :verify_authenticity_token` to th where it can then be seen in the usual logs, or as a flash message in the login screen. +That file is located at `/opt/gitlab/embedded/service/gitlab-rails/app/controllers` +for Omnibus installations and by default on `/home/git/gitlab/app/controllers` for +installations from source. + ### Invalid audience This error means that the IdP doesn't recognize GitLab as a valid sender and From eb0f1de36c6ebf13d86540bb79d7fb07fc3642f0 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 6 Apr 2016 16:21:58 -0500 Subject: [PATCH 097/212] Added CHANGELOG item --- CHANGELOG | 1 + lib/gitlab/saml/user.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index f72bb670ec..1b3fd97a1c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ v 8.7.0 (unreleased) - Expose label description in API (Mariusz Jachimowicz) - Allow back dating on issues when created through the API - Fix avatar stretching by providing a cropping feature + - Allow SAML to handle external users based on user's information !3530 - Add endpoints to archive or unarchive a project !3372 - Add links to CI setup documentation from project settings and builds pages - Handle nil descriptions in Slack issue messages (Stan Hu) diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index 6ab165cf51..73fc443a02 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -33,7 +33,6 @@ module Gitlab # Avoid an unnecessary change of values and the subsequent save @user.external = false if @user.external else - # Avoid an unnecessary change of values and the subsequent save @user.external = true unless @user.external end end From bc701284f2eb7e11f652211f45433ae206372bc1 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 23:27:42 +0200 Subject: [PATCH 098/212] Fix missing entries in permission matrix [ci skip] --- doc/permissions/permissions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/permissions/permissions.md b/doc/permissions/permissions.md index 3d375e47c8..cd0e81d730 100644 --- a/doc/permissions/permissions.md +++ b/doc/permissions/permissions.md @@ -52,8 +52,8 @@ documentation](../workflow/add-user/add-user.md). | Switch visibility level | | | | | ✓ | | Transfer project to another namespace | | | | | ✓ | | Remove project | | | | | ✓ | -| Force push to protected branches | | | | | | -| Remove protected branches | | | | | | +| Force push to protected branches | | | | | ✓ | +| Remove protected branches | | | | | ✓ | [^1]: If **Allow guest to access builds** is enabled in CI settings From 946b4519c99a91c18a23041c090568231410785a Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Wed, 6 Apr 2016 16:31:34 -0500 Subject: [PATCH 099/212] Use .new_record? instead --- app/views/layouts/_search.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/_search.html.haml b/app/views/layouts/_search.html.haml index ce9df1566d..baa93ba4c1 100644 --- a/app/views/layouts/_search.html.haml +++ b/app/views/layouts/_search.html.haml @@ -1,6 +1,6 @@ -- if controller.controller_path =~ /^groups/ && !@group.new_record? +- if controller.controller_path =~ /^groups/ && @group.persisted? - label = 'This group' -- if controller.controller_path =~ /^projects/ && !@project.new_record? +- if controller.controller_path =~ /^projects/ && @project.persisted? - label = 'This project' .search.search-form{class: "#{'has-location-badge' if label.present?}"} From 86d346b6f4991e0562061f9b9709cffc16fe1ee7 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Wed, 6 Apr 2016 14:40:29 -0700 Subject: [PATCH 100/212] Change word-break to word-wrap --- app/assets/stylesheets/framework/files.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/framework/files.scss b/app/assets/stylesheets/framework/files.scss index 22f53e3b03..b15f4e7bd5 100644 --- a/app/assets/stylesheets/framework/files.scss +++ b/app/assets/stylesheets/framework/files.scss @@ -20,7 +20,7 @@ margin: 0; text-align: left; padding: 10px $gl-padding; - word-break: break-word; + word-wrap: break-word; .file-actions { float: right; From 43b921770565518dfa03f3810915cb0f98e856c6 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 23:49:12 +0200 Subject: [PATCH 101/212] Fix missing entries in permission matrix [ci skip] --- doc/permissions/permissions.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/permissions/permissions.md b/doc/permissions/permissions.md index cd0e81d730..6219693b8a 100644 --- a/doc/permissions/permissions.md +++ b/doc/permissions/permissions.md @@ -52,10 +52,11 @@ documentation](../workflow/add-user/add-user.md). | Switch visibility level | | | | | ✓ | | Transfer project to another namespace | | | | | ✓ | | Remove project | | | | | ✓ | -| Force push to protected branches | | | | | ✓ | -| Remove protected branches | | | | | ✓ | +| Force push to protected branches [^2] | | | | | | +| Remove protected branches [^2] | | | | | | [^1]: If **Allow guest to access builds** is enabled in CI settings +[^2]: Not allowed for Guest, Reporter, Developer, Master, or Owner ## Group From 71b5010a940c4b0364126ba7e2dfc0ce07b69f25 Mon Sep 17 00:00:00 2001 From: frodsan Date: Wed, 6 Apr 2016 22:45:56 +0000 Subject: [PATCH 102/212] [ci skip] Fix typo. --- doc/ci/yaml/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ci/yaml/README.md b/doc/ci/yaml/README.md index 4316f3c1f6..7da9b31e30 100644 --- a/doc/ci/yaml/README.md +++ b/doc/ci/yaml/README.md @@ -38,7 +38,7 @@ services: - postgres before_script: - - bundle_install + - bundle install stages: - build From 1575a95b65d4cad91f775ae260b8828cdf303462 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Wed, 6 Apr 2016 20:09:15 -0300 Subject: [PATCH 103/212] little refactor and improvements on specs --- lib/banzai/filter/gollum_tags_filter.rb | 8 ++------ spec/lib/banzai/filter/gollum_tags_filter_spec.rb | 2 +- spec/lib/banzai/pipeline/wiki_pipeline_spec.rb | 9 +++------ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/banzai/filter/gollum_tags_filter.rb b/lib/banzai/filter/gollum_tags_filter.rb index f710a4971b..d08267a9d6 100644 --- a/lib/banzai/filter/gollum_tags_filter.rb +++ b/lib/banzai/filter/gollum_tags_filter.rb @@ -118,7 +118,7 @@ module Banzai end if path - content_tag(:img, nil, src: path, class: tag_class('image')) + content_tag(:img, nil, src: path, class: 'gfm') end end @@ -155,7 +155,7 @@ module Banzai href = ::File.join(project_wiki_base_path, reference) end - content_tag(:a, name || reference, href: href, class: tag_class('page')) + content_tag(:a, name || reference, href: href, class: 'gfm') end def project_wiki @@ -172,10 +172,6 @@ module Banzai def validate needs :project_wiki end - - def tag_class(type) - "gfm gollum gollum-#{type}" - end end end end diff --git a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb index ad777fe4b9..fe2ce092e6 100644 --- a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb +++ b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb @@ -70,7 +70,7 @@ describe Banzai::Filter::GollumTagsFilter, lib: true do end context 'linking internal resources' do - it "the created link's text will include the resource's text and project_wiki_base_path" do + it "the created link's text includes the resource's text and wiki base path" do tag = '[[wiki-slug]]' doc = filter("See #{tag}", project_wiki: project_wiki) expected_path = ::File.join(project_wiki.wiki_base_path, 'wiki-slug') diff --git a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb index 4f86b1d87e..7aa1b4a3bf 100644 --- a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb @@ -1,9 +1,6 @@ require 'rails_helper' describe Banzai::Pipeline::WikiPipeline do - let(:project_wiki) { double } - before(:each) { allow(project_wiki).to receive(:wiki_base_path) { '/some/repo/wikis' } } - describe 'TableOfContents' do it 'replaces the tag with the TableOfContentsFilter result' do markdown = <<-MD.strip_heredoc @@ -14,7 +11,7 @@ describe Banzai::Pipeline::WikiPipeline do Foo MD - result = described_class.call(markdown, project: spy, project_wiki: project_wiki) + result = described_class.call(markdown, project: spy, project_wiki: spy) aggregate_failures do expect(result[:output].text).not_to include '[[' @@ -32,7 +29,7 @@ describe Banzai::Pipeline::WikiPipeline do Foo MD - output = described_class.to_html(markdown, project: spy, project_wiki: project_wiki) + output = described_class.to_html(markdown, project: spy, project_wiki: spy) expect(output).to include('[[toc]]') end @@ -45,7 +42,7 @@ describe Banzai::Pipeline::WikiPipeline do Foo MD - output = described_class.to_html(markdown, project: spy, project_wiki: project_wiki) + output = described_class.to_html(markdown, project: spy, project_wiki: spy) aggregate_failures do expect(output).not_to include('
        ') From 8110e7530902de8744ff985f08938306e2c38367 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 6 Apr 2016 18:12:25 -0500 Subject: [PATCH 104/212] Implemented suggested fixes --- doc/integration/saml.md | 3 +-- lib/gitlab/saml/auth_hash.rb | 2 +- lib/gitlab/saml/config.rb | 1 - lib/gitlab/saml/user.rb | 7 +++--- spec/lib/gitlab/saml/user_spec.rb | 41 ++++++++++++------------------- 5 files changed, 21 insertions(+), 33 deletions(-) diff --git a/doc/integration/saml.md b/doc/integration/saml.md index 684f0a5b8c..8a7205caaa 100644 --- a/doc/integration/saml.md +++ b/doc/integration/saml.md @@ -159,8 +159,7 @@ with the regular SAML response. Here is an example: The name of the attribute can be anything you like, but it must contain the groups to which a user belongs. In order to tell GitLab where to find these groups, you need to add a `groups_attribute:` element to your SAML settings. You will also need to -tell GitLab which groups are external, for that you need the `external_groups:` -element: +tell GitLab which groups are external via the `external_groups:` element: ```yaml { name: 'saml', diff --git a/lib/gitlab/saml/auth_hash.rb b/lib/gitlab/saml/auth_hash.rb index 3414d24ca7..32c1c9ec5b 100644 --- a/lib/gitlab/saml/auth_hash.rb +++ b/lib/gitlab/saml/auth_hash.rb @@ -9,7 +9,7 @@ module Gitlab private def get_raw(key) - # Needs to call `all` because of https://github.com/onelogin/ruby-saml/blob/master/lib/onelogin/ruby-saml/attributes.rb#L78 + # Needs to call `all` because of https://git.io/vVo4u # otherwise just the first value is returned auth_hash.extra[:raw_info].all[key] end diff --git a/lib/gitlab/saml/config.rb b/lib/gitlab/saml/config.rb index 2b3cf840f6..0f40c00f54 100644 --- a/lib/gitlab/saml/config.rb +++ b/lib/gitlab/saml/config.rb @@ -1,4 +1,3 @@ -# Load a specific server configuration module Gitlab module Saml class Config diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index 73fc443a02..c1072452ab 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -28,12 +28,11 @@ module Gitlab if external_users_enabled? # Check if there is overlap between the user's groups and the external groups - # setting and set user as external or internal. + # setting then set user as external or internal. if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? - # Avoid an unnecessary change of values and the subsequent save - @user.external = false if @user.external + @user.external = false else - @user.external = true unless @user.external + @user.external = true end end diff --git a/spec/lib/gitlab/saml/user_spec.rb b/spec/lib/gitlab/saml/user_spec.rb index ed7b507dba..c2a51d9249 100644 --- a/spec/lib/gitlab/saml/user_spec.rb +++ b/spec/lib/gitlab/saml/user_spec.rb @@ -23,11 +23,15 @@ describe Gitlab::Saml::User, lib: true do allow(Gitlab::LDAP::Config).to receive_messages(messages) end - def stub_saml_config(messages) - allow(Gitlab::Saml::Config).to receive_messages(messages) + def stub_basic_saml_config + allow(Gitlab::Saml::Config).to receive_messages({ options: { name: 'saml', args: {} } }) end - before { stub_saml_config({ options: { name: 'saml', args: {} } }) } + def stub_saml_group_config(groups) + allow(Gitlab::Saml::Config).to receive_messages({ options: { name: 'saml', groups_attribute: 'groups', external_groups: groups, args: {} } }) + end + + before { stub_basic_saml_config } describe 'account exists on server' do before { stub_omniauth_config({ allow_single_sign_on: ['saml'], auto_link_saml_user: true }) } @@ -45,15 +49,15 @@ describe Gitlab::Saml::User, lib: true do context 'external groups' do context 'are defined' do - before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Freelancers), args: {} } }) } it 'marks the user as external' do + stub_saml_group_config(%w(Freelancers)) saml_user.save expect(gl_user).to be_valid expect(gl_user.external).to be_truthy end end - before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Interns), args: {} } }) } + before { stub_saml_group_config(%w(Interns)) } context 'are defined but the user does not belong there' do it 'does not mark the user as external' do saml_user.save @@ -105,17 +109,17 @@ describe Gitlab::Saml::User, lib: true do context 'external groups' do context 'are defined' do - before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Freelancers), args: {} } }) } it 'marks the user as external' do + stub_saml_group_config(%w(Freelancers)) saml_user.save expect(gl_user).to be_valid expect(gl_user.external).to be_truthy end end - before { stub_saml_config({ options: { name: 'saml', groups_attribute: 'groups', external_groups: %w(Interns), args: {} } }) } context 'are defined but the user does not belong there' do it 'does not mark the user as external' do + stub_saml_group_config(%w(Interns)) saml_user.save expect(gl_user).to be_valid expect(gl_user.external).to be_falsey @@ -131,12 +135,6 @@ describe Gitlab::Saml::User, lib: true do context 'with auto_link_ldap_user enabled' do before { stub_omniauth_config({ auto_link_ldap_user: true, auto_link_saml_user: false }) } - context 'and no LDAP provider defined' do - before { stub_ldap_config(providers: []) } - - include_examples 'to verify compliance with allow_single_sign_on' - end - context 'and at least one LDAP provider is defined' do before { stub_ldap_config(providers: %w(ldapmain)) } @@ -144,19 +142,18 @@ describe Gitlab::Saml::User, lib: true do before do allow(ldap_user).to receive(:uid) { uid } allow(ldap_user).to receive(:username) { uid } - allow(ldap_user).to receive(:email) { ['johndoe@example.com','john2@example.com'] } + allow(ldap_user).to receive(:email) { %w(john@mail.com john2@example.com) } allow(ldap_user).to receive(:dn) { 'uid=user1,ou=People,dc=example' } allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(ldap_user) end context 'and no account for the LDAP user' do - it 'creates a user with dual LDAP and SAML identities' do saml_user.save expect(gl_user).to be_valid expect(gl_user.username).to eql uid - expect(gl_user.email).to eql 'johndoe@example.com' + expect(gl_user.email).to eql 'john@mail.com' expect(gl_user.identities.length).to eql 2 identities_as_hash = gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } } expect(identities_as_hash).to match_array([ { provider: 'ldapmain', extern_uid: 'uid=user1,ou=People,dc=example' }, @@ -166,13 +163,13 @@ describe Gitlab::Saml::User, lib: true do end context 'and LDAP user has an account already' do - let!(:existing_user) { create(:omniauth_user, email: 'john@example.com', extern_uid: 'uid=user1,ou=People,dc=example', provider: 'ldapmain', username: 'john') } - it "adds the omniauth identity to the LDAP account" do + let!(:existing_user) { create(:omniauth_user, email: 'john@mail.com', extern_uid: 'uid=user1,ou=People,dc=example', provider: 'ldapmain', username: 'john') } + it 'adds the omniauth identity to the LDAP account' do saml_user.save expect(gl_user).to be_valid expect(gl_user.username).to eql 'john' - expect(gl_user.email).to eql 'john@example.com' + expect(gl_user.email).to eql 'john@mail.com' expect(gl_user.identities.length).to eql 2 identities_as_hash = gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } } expect(identities_as_hash).to match_array([ { provider: 'ldapmain', extern_uid: 'uid=user1,ou=People,dc=example' }, @@ -181,12 +178,6 @@ describe Gitlab::Saml::User, lib: true do end end end - - context 'and no corresponding LDAP person' do - before { allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(nil) } - - include_examples 'to verify compliance with allow_single_sign_on' - end end end From b471c76bcb3348506c2ec96e212433d473db16c1 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Wed, 6 Apr 2016 21:46:12 -0400 Subject: [PATCH 105/212] Reset MR opts --- app/assets/javascripts/merge_request_widget.js.coffee | 8 +++++++- app/views/projects/merge_requests/widget/_show.html.haml | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index 7102a0673e..84a8887fbc 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -15,6 +15,8 @@ class @MergeRequestWidget @pollCIStatus() notifyPermissions() + setOpts: (@opts) -> + mergeInProgress: (deleteSourceBranch = false)-> $.ajax type: 'GET' @@ -48,7 +50,7 @@ class @MergeRequestWidget @getCIStatus(true) @readyForCICheck = false - ), 5000 + ), 10000 getCIStatus: (showNotification) -> _this = @ @@ -61,6 +63,10 @@ class @MergeRequestWidget @firstCICheck = false @opts.ci_status = data.status + if @opts.ci_status is '' + @opts.ci_status = data.status + return + if data.status isnt @opts.ci_status @showCIStatus data.status if data.coverage diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml index 2be06aebe6..92d9535893 100644 --- a/app/views/projects/merge_requests/widget/_show.html.haml +++ b/app/views/projects/merge_requests/widget/_show.html.haml @@ -22,4 +22,6 @@ if(typeof merge_request_widget === 'undefined') { merge_request_widget = new MergeRequestWidget(opts); + } else { + merge_request_widget.setOpts(opts); } From 924e4b370013ae3a8448a2a68e6a4d353b23b699 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 6 Apr 2016 21:10:24 -0700 Subject: [PATCH 106/212] Return status code 303 after a branch DELETE operation to avoid project deletion Closes #14994 --- CHANGELOG | 1 + app/controllers/projects/application_controller.rb | 4 +++- app/controllers/projects/branches_controller.rb | 2 +- .../projects/branches_controller_spec.rb | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 80fc2302b3..e924346308 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.7.0 (unreleased) - All images in discussions and wikis now link to their source files !3464 (Connor Shea). + - Return status code 303 after a branch DELETE operation to avoid project deletion (Stan Hu) - Improved Markdown rendering performance !3389 (Yorick Peterse) - Don't attempt to look up an avatar in repo if repo directory does not exist (Stan Hu) - Preserve time notes/comments have been updated at when moving issue diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index 657ee94cfd..74150ad606 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -68,7 +68,9 @@ class Projects::ApplicationController < ApplicationController end def require_non_empty_project - redirect_to namespace_project_path(@project.namespace, @project) if @project.empty_repo? + # Be sure to return status code 303 to avoid a double DELETE: + # http://api.rubyonrails.org/classes/ActionController/Redirecting.html + redirect_to namespace_project_path(@project.namespace, @project), status: 303 if @project.empty_repo? end def require_branch_head diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index c0a5373492..d09e7375b6 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -48,7 +48,7 @@ class Projects::BranchesController < Projects::ApplicationController respond_to do |format| format.html do redirect_to namespace_project_branches_path(@project.namespace, - @project) + @project), status: 303 end format.js { render status: status[:return_code] } end diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 98ae424ed7..8ad7347211 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -93,6 +93,20 @@ describe Projects::BranchesController do end end + describe "POST destroy with HTML format" do + render_views + + it 'returns 303' do + post :destroy, + format: :html, + id: 'foo/bar/baz', + namespace_id: project.namespace.to_param, + project_id: project.to_param + + expect(response.status).to eq(303) + end + end + describe "POST destroy" do render_views From 50ef9fcafb671aa1598cb0cf83b30884b35809d4 Mon Sep 17 00:00:00 2001 From: connorshea Date: Wed, 6 Apr 2016 23:54:28 -0600 Subject: [PATCH 107/212] Update coveralls from 0.8.9 to 0.8.13 and simplecov from 0.10.0 to 0.11.2 This removes a few dependencies! It was also rude to be using coveralls 0.8.9, considering 0.8.12 introduced support for GitLab CI :) Also paves the way for updating mime-types to 3.0. Coveralls Changelog: https://github.com/lemurheavy/coveralls-ruby/releases Simplecov Changelog: https://github.com/colszowka/simplecov/blob/master/CHANGELOG.md --- Gemfile | 2 +- Gemfile.lock | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 6327227282..0279b4ac47 100644 --- a/Gemfile +++ b/Gemfile @@ -290,7 +290,7 @@ group :development, :test do gem 'rubocop', '~> 0.38.0', require: false gem 'scss_lint', '~> 0.47.0', require: false gem 'coveralls', '~> 0.8.2', require: false - gem 'simplecov', '~> 0.10.0', require: false + gem 'simplecov', '~> 0.11.0', require: false gem 'flog', require: false gem 'flay', require: false gem 'bundler-audit', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 0981c3195a..1ba8d748db 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -136,10 +136,9 @@ GEM colorize (0.7.7) concurrent-ruby (1.0.0) connection_pool (2.2.0) - coveralls (0.8.9) + coveralls (0.8.13) json (~> 1.8) - rest-client (>= 1.6.8, < 2) - simplecov (~> 0.10.0) + simplecov (~> 0.11.0) term-ansicolor (~> 1.3) thor (~> 0.19.1) tins (~> 1.6.0) @@ -176,8 +175,6 @@ GEM diff-lcs (1.2.5) diffy (3.0.7) docile (1.1.5) - domain_name (0.5.25) - unf (>= 0.0.5, < 1.0.0) doorkeeper (2.2.2) railties (>= 3.2) dropzonejs-rails (0.7.2) @@ -421,8 +418,6 @@ GEM nokogiri (~> 1.6.0) ruby_parser (~> 3.5) htmlentities (4.3.4) - http-cookie (1.0.2) - domain_name (~> 0.5) http_parser.rb (0.5.3) httparty (0.13.7) json (~> 1.8) @@ -480,7 +475,6 @@ GEM nested_form (0.3.2) net-ldap (0.12.1) net-ssh (3.0.1) - netrc (0.11.0) newrelic_rpm (3.14.1.311) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) @@ -657,10 +651,6 @@ GEM listen (~> 3.0) responders (2.1.1) railties (>= 4.2.0, < 5.1) - rest-client (1.8.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 3.0) - netrc (~> 0.7) rinku (1.7.3) rotp (2.1.1) rouge (1.10.1) @@ -754,7 +744,7 @@ GEM rufus-scheduler (>= 2.0.24) sidekiq (>= 4.0.0) simple_oauth (0.1.9) - simplecov (0.10.0) + simplecov (0.11.2) docile (~> 1.1.0) json (~> 1.8) simplecov-html (~> 0.10.0) @@ -845,7 +835,7 @@ GEM underscore-rails (1.8.3) unf (0.1.4) unf_ext - unf_ext (0.0.7.1) + unf_ext (0.0.7.2) unicode-display_width (1.0.2) unicorn (4.9.0) kgio (~> 2.6) @@ -1032,7 +1022,7 @@ DEPENDENCIES shoulda-matchers (~> 2.8.0) sidekiq (~> 4.0) sidekiq-cron (~> 0.4.0) - simplecov (~> 0.10.0) + simplecov (~> 0.11.0) sinatra (~> 1.4.4) six (~> 0.2.0) slack-notifier (~> 1.2.0) From 27b9f64efbbce9d74eeb9c4ae340506242c474cb Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 7 Apr 2016 00:23:02 -0700 Subject: [PATCH 108/212] Expire caches after project creation to ensure a consistent state Closes #14961 --- app/models/repository.rb | 2 ++ spec/models/repository_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/models/repository.rb b/app/models/repository.rb index a8e826c9cb..8dead3a588 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -331,6 +331,8 @@ class Repository # Runs code after a repository has been created. def after_create expire_exists_cache + expire_root_ref_cache + expire_emptiness_caches end # Runs code just before a repository is deleted. diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index f517f325c0..4e49c413f2 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -670,6 +670,19 @@ describe Repository, models: true do repository.after_create end + + it 'flushes the root ref cache' do + expect(repository).to receive(:expire_root_ref_cache) + + repository.after_create + end + + it 'flushes the emptiness caches' do + expect(repository).to receive(:expire_emptiness_caches) + + repository.after_create + end + end describe "#main_language" do From 00da609cfd8bf1105fe433dfc92ab263d6205eaf Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Apr 2016 11:19:29 +0200 Subject: [PATCH 109/212] Fix 2FA authentication spoofing vulnerability This commit attempts to change default user search scope if otp_user_id session variable has been set. If it is present, it means that user has 2FA enabled, and has already been verified with login and password. In this case we should look for user with otp_user_id first, before picking it up by login. --- app/controllers/sessions_controller.rb | 15 +-- spec/controllers/sessions_controller_spec.rb | 97 +++++++++++--------- 2 files changed, 61 insertions(+), 51 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 65677a3dd3..c29f4609e9 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -5,7 +5,8 @@ class SessionsController < Devise::SessionsController skip_before_action :check_2fa_requirement, only: [:destroy] prepend_before_action :check_initial_setup, only: [:new] - prepend_before_action :authenticate_with_two_factor, only: [:create] + prepend_before_action :authenticate_with_two_factor, + if: :two_factor_enabled?, only: [:create] prepend_before_action :store_redirect_path, only: [:new] before_action :auto_sign_in_with_provider, only: [:new] @@ -56,10 +57,10 @@ class SessionsController < Devise::SessionsController end def find_user - if user_params[:login] - User.by_login(user_params[:login]) - elsif user_params[:otp_attempt] && session[:otp_user_id] + if session[:otp_user_id] User.find(session[:otp_user_id]) + elsif user_params[:login] + User.by_login(user_params[:login]) end end @@ -83,11 +84,13 @@ class SessionsController < Devise::SessionsController end end + def two_factor_enabled? + find_user.try(:two_factor_enabled?) + end + def authenticate_with_two_factor user = self.resource = find_user - return unless user && user.two_factor_enabled? - if user_params[:otp_attempt].present? && session[:otp_user_id] if valid_otp_attempt?(user) # Remove any lingering user data from login diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index e7dbc3bdad..664b23d321 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -6,7 +6,7 @@ describe SessionsController do @request.env['devise.mapping'] = Devise.mappings[:user] end - context 'standard authentications' do + context 'when using standard authentications' do context 'invalid password' do it 'does not authenticate user' do post(:create, user: { login: 'invalid', password: 'invalid' }) @@ -16,7 +16,7 @@ describe SessionsController do end end - context 'valid password' do + context 'when using valid password' do let(:user) { create(:user) } it 'authenticates user correctly' do @@ -28,7 +28,7 @@ describe SessionsController do end end - context 'two-factor authentication' do + context 'when using two-factor authentication' do let(:user) { create(:user, :two_factor) } def authenticate_2fa(user_params) @@ -38,52 +38,59 @@ describe SessionsController do ## # See #14900 issue # - context 'authenticating with login and OTP belonging to another user' do - let(:another_user) { create(:user, :two_factor) } - - - context 'OTP valid for another user' do - it 'does not authenticate' do - authenticate_2fa(login: another_user.username, - otp_attempt: another_user.current_otp) - - expect(subject.current_user).to_not eq another_user - end - end - - context 'OTP invalid for another user' do - before do - authenticate_2fa(login: another_user.username, - otp_attempt: 'invalid') - end - - it 'does not authenticate' do - expect(subject.current_user).to_not eq another_user - end - - it 'does not leak information about 2FA enabled' do - expect(response).to_not set_flash.now[:alert].to /Invalid two-factor code/ - end - end - - context 'authenticating with OTP' do - context 'valid OTP' do - it 'authenticates correctly' do - authenticate_2fa(otp_attempt: user.current_otp) - - expect(subject.current_user).to eq user - end - end - - context 'invalid OTP' do - before { authenticate_2fa(otp_attempt: 'invalid') } + context 'when authenticating with login and OTP of another user' do + context 'when another user has 2FA enabled' do + let(:another_user) { create(:user, :two_factor) } + context 'when OTP is valid for another user' do it 'does not authenticate' do - expect(subject.current_user).to_not eq user + authenticate_2fa(login: another_user.username, + otp_attempt: another_user.current_otp) + + expect(subject.current_user).to_not eq another_user + end + end + + context 'when OTP is invalid for another user' do + it 'does not authenticate' do + authenticate_2fa(login: another_user.username, + otp_attempt: 'invalid') + + expect(subject.current_user).to_not eq another_user + end + end + + context 'when authenticating with OTP' do + context 'when OTP is valid' do + it 'authenticates correctly' do + authenticate_2fa(otp_attempt: user.current_otp) + + expect(subject.current_user).to eq user + end end - it 'warns about invalid OTP code' do - expect(response).to set_flash.now[:alert].to /Invalid two-factor code/ + context ' when OTP is invalid' do + before { authenticate_2fa(otp_attempt: 'invalid') } + + it 'does not authenticate' do + expect(subject.current_user).to_not eq user + end + + it 'warns about invalid OTP code' do + expect(response).to set_flash + .now[:alert].to /Invalid two-factor code/ + end + end + end + + context 'when another user does not have 2FA enabled' do + let(:another_user) { create(:user) } + + it 'does not leak that 2FA is disabled for another user' do + authenticate_2fa(login: another_user.username, + otp_attempt: 'invalid') + + expect(response).to_not set_flash.now[:alert].to /Invalid login or password/ end end end From 92649ca97a02021695eb4dc36fa59c1a8454bd11 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Thu, 7 Apr 2016 07:09:31 -0400 Subject: [PATCH 110/212] Hide "assign to me" link if not allowed --- app/views/shared/issuable/_sidebar.html.haml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml index 47e544acf5..43883a18fa 100644 --- a/app/views/shared/issuable/_sidebar.html.haml +++ b/app/views/shared/issuable/_sidebar.html.haml @@ -20,6 +20,7 @@ Next = form_for [@project.namespace.becomes(Namespace), @project, issuable], remote: true, html: {class: 'issuable-context-form inline-update js-issuable-update'} do |f| + - can_edit_assignee = can?(current_user, :"admin_#{issuable.to_ability_name}", @project) .block.assignee .sidebar-collapsed-icon.sidebar-collapsed-user{data: {toggle: "tooltip", placement: "left", container: "body"}, title: (issuable.assignee.to_reference if issuable.assignee)} - if issuable.assignee @@ -29,9 +30,9 @@ .title.hide-collapsed Assignee = icon('spinner spin', class: 'block-loading') - - if can?(current_user, :"admin_#{issuable.to_ability_name}", @project) + - if can_edit_assignee = link_to 'Edit', '#', class: 'edit-link pull-right' - .value.bold.hide-collapsed + .value.bold.hide-collapsed{data: {can_edit_assign: can_edit_assignee}} - if issuable.assignee = link_to_member(@project, issuable.assignee, size: 32) do - if issuable.instance_of?(MergeRequest) && !issuable.can_be_merged_by?(issuable.assignee) @@ -41,9 +42,10 @@ = issuable.assignee.to_reference - else %span.assign-yourself - No assignee - - %a.js-assign-yourself{ href: '#' } - assign yourself + No assignee + - if can_edit_assignee + %a.js-assign-yourself{ href: '#' } + \- assign yourself .selectbox.hide-collapsed = f.hidden_field 'assignee_id', value: issuable.assignee_id, id: 'issue_assignee_id' From 33a8dfd04fbd1c0858ead20c020ede07e7b0962a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Apr 2016 11:45:04 +0200 Subject: [PATCH 111/212] Make sessions controller specs more explicit --- spec/controllers/sessions_controller_spec.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 664b23d321..83cc8ec6d2 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -69,7 +69,7 @@ describe SessionsController do end end - context ' when OTP is invalid' do + context 'when OTP is invalid' do before { authenticate_2fa(otp_attempt: 'invalid') } it 'does not authenticate' do @@ -77,8 +77,8 @@ describe SessionsController do end it 'warns about invalid OTP code' do - expect(response).to set_flash - .now[:alert].to /Invalid two-factor code/ + expect(response).to set_flash.now[:alert] + .to /Invalid two-factor code/ end end end @@ -90,7 +90,8 @@ describe SessionsController do authenticate_2fa(login: another_user.username, otp_attempt: 'invalid') - expect(response).to_not set_flash.now[:alert].to /Invalid login or password/ + expect(response).to set_flash.now[:alert] + .to /Invalid two-factor code/ end end end From 8172d2c1f230329d5ad33282883ad9f14353e950 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Thu, 7 Apr 2016 08:17:05 -0400 Subject: [PATCH 112/212] Add optional colon. --- config/initializers/1_settings.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 2b98901527..8488482e4a 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -176,7 +176,8 @@ Settings.gitlab['signup_enabled'] ||= true if Settings.gitlab['signup_enabled']. Settings.gitlab['signin_enabled'] ||= true if Settings.gitlab['signin_enabled'].nil? Settings.gitlab['restricted_visibility_levels'] = Settings.send(:verify_constant_array, Gitlab::VisibilityLevel, Settings.gitlab['restricted_visibility_levels'], []) Settings.gitlab['username_changing_enabled'] = true if Settings.gitlab['username_changing_enabled'].nil? -Settings.gitlab['issue_closing_pattern'] = '((?:[Cc]los(?:e[sd]?|ing)|[Ff]ix(?:e[sd]|ing)?|[Rr]esolv(?:e[sd]?|ing)) +(?:(?:issues? +)?%{issue_ref}(?:(?:, *| +and +)?)|([A-Z][A-Z0-9_]+-\d+))+)' if Settings.gitlab['issue_closing_pattern'].nil? +Settings.gitlab['issue_closing_pattern'] = '((?:[Cc]los(?:e[sd]?|ing)|[Ff]ix(?:e[sd]|ing)?|[Rr]esolv(?:e[sd]?|ing))(:?) +(?:(?:issues? +)?%{issue_ref}(?:(?:, *| +and +)?)|([A-Z][A-Z0-9_]+-\d+))+)' if Settings.gitlab['issue_closing_pattern'].nil? +puts Settings.gitlab['issue_closing_pattern'] Settings.gitlab['default_projects_features'] ||= {} Settings.gitlab['webhook_timeout'] ||= 10 Settings.gitlab['max_attachment_size'] ||= 10 From d76a769d24b650f8dbfd6866b9d13c0acf4a9e4a Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Thu, 7 Apr 2016 08:32:37 -0400 Subject: [PATCH 113/212] Remove duplication. Remove JS data attributes --- app/views/shared/issuable/_sidebar.html.haml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml index 43883a18fa..94affa4b59 100644 --- a/app/views/shared/issuable/_sidebar.html.haml +++ b/app/views/shared/issuable/_sidebar.html.haml @@ -1,5 +1,6 @@ %aside.right-sidebar{ class: sidebar_gutter_collapsed_class } .issuable-sidebar + - can_edit_issuable = can?(current_user, :"admin_#{issuable.to_ability_name}", @project) .block.issuable-sidebar-header %span.issuable-count.hide-collapsed.pull-left = issuable.iid @@ -20,7 +21,6 @@ Next = form_for [@project.namespace.becomes(Namespace), @project, issuable], remote: true, html: {class: 'issuable-context-form inline-update js-issuable-update'} do |f| - - can_edit_assignee = can?(current_user, :"admin_#{issuable.to_ability_name}", @project) .block.assignee .sidebar-collapsed-icon.sidebar-collapsed-user{data: {toggle: "tooltip", placement: "left", container: "body"}, title: (issuable.assignee.to_reference if issuable.assignee)} - if issuable.assignee @@ -30,9 +30,9 @@ .title.hide-collapsed Assignee = icon('spinner spin', class: 'block-loading') - - if can_edit_assignee + - if can_edit_issuable = link_to 'Edit', '#', class: 'edit-link pull-right' - .value.bold.hide-collapsed{data: {can_edit_assign: can_edit_assignee}} + .value.bold.hide-collapsed - if issuable.assignee = link_to_member(@project, issuable.assignee, size: 32) do - if issuable.instance_of?(MergeRequest) && !issuable.can_be_merged_by?(issuable.assignee) @@ -43,7 +43,7 @@ - else %span.assign-yourself No assignee - - if can_edit_assignee + - if can_edit_issuable %a.js-assign-yourself{ href: '#' } \- assign yourself @@ -62,7 +62,7 @@ .title.hide-collapsed Milestone = icon('spinner spin', class: 'block-loading') - - if can?(current_user, :"admin_#{issuable.to_ability_name}", @project) + - if can_edit_issuable = link_to 'Edit', '#', class: 'edit-link pull-right' .value.bold.hide-collapsed - if issuable.milestone @@ -84,7 +84,7 @@ .title.hide-collapsed Labels = icon('spinner spin', class: 'block-loading') - - if can?(current_user, :"admin_#{issuable.to_ability_name}", @project) + - if can_edit_issuable = link_to 'Edit', '#', class: 'edit-link pull-right' .value.bold.issuable-show-labels.hide-collapsed{ class: ("has-labels" if issuable.labels.any?) } - if issuable.labels.any? From 0bbeebc8f9d97c72f2a8e93c8da4d0f0d9078af7 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Thu, 7 Apr 2016 08:47:29 -0400 Subject: [PATCH 114/212] Remove dumb debug statement and add many tests. --- config/gitlab.yml.example | 2 +- config/initializers/1_settings.rb | 1 - .../gitlab/closing_issue_extractor_spec.rb | 115 ++++++++++++++++++ 3 files changed, 116 insertions(+), 2 deletions(-) diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index ddee467b14..35c7c425a5 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -80,7 +80,7 @@ production: &base # This happens when the commit is pushed or merged into the default branch of a project. # When not specified the default issue_closing_pattern as specified below will be used. # Tip: you can test your closing pattern at http://rubular.com. - # issue_closing_pattern: '((?:[Cc]los(?:e[sd]?|ing)|[Ff]ix(?:e[sd]|ing)?) +(?:(?:issues? +)?%{issue_ref}(?:(?:, *| +and +)?))+)' + # issue_closing_pattern: '((?:[Cc]los(?:e[sd]?|ing)|[Ff]ix(?:e[sd]|ing)?|[Rr]esolv(?:e[sd]?|ing))(:?) +(?:(?:issues? +)?%{issue_ref}(?:(?:, *| +and +)?)|([A-Z][A-Z0-9_]+-\d+))+)' ## Default project features settings default_projects_features: diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 8488482e4a..72c4d8d61c 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -177,7 +177,6 @@ Settings.gitlab['signin_enabled'] ||= true if Settings.gitlab['signin_enabled']. Settings.gitlab['restricted_visibility_levels'] = Settings.send(:verify_constant_array, Gitlab::VisibilityLevel, Settings.gitlab['restricted_visibility_levels'], []) Settings.gitlab['username_changing_enabled'] = true if Settings.gitlab['username_changing_enabled'].nil? Settings.gitlab['issue_closing_pattern'] = '((?:[Cc]los(?:e[sd]?|ing)|[Ff]ix(?:e[sd]|ing)?|[Rr]esolv(?:e[sd]?|ing))(:?) +(?:(?:issues? +)?%{issue_ref}(?:(?:, *| +and +)?)|([A-Z][A-Z0-9_]+-\d+))+)' if Settings.gitlab['issue_closing_pattern'].nil? -puts Settings.gitlab['issue_closing_pattern'] Settings.gitlab['default_projects_features'] ||= {} Settings.gitlab['webhook_timeout'] ||= 10 Settings.gitlab['max_attachment_size'] ||= 10 diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb index a1f51429a7..e9b8ce6b5b 100644 --- a/spec/lib/gitlab/closing_issue_extractor_spec.rb +++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb @@ -22,11 +22,21 @@ describe Gitlab::ClosingIssueExtractor, lib: true do expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Awesome commit (Closes: #{reference})" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Awesome commit (closes #{reference})" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Awesome commit (closes: #{reference})" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Closed #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) @@ -37,106 +47,211 @@ describe Gitlab::ClosingIssueExtractor, lib: true do expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "closed: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Closing #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Closing: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "closing #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "closing: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Close #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Close: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "close #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "close: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Awesome commit (Fixes #{reference})" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Awesome commit (Fixes: #{reference})" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Awesome commit (fixes #{reference})" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Awesome commit (Fixes: #{reference})" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Fixed #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Fixed: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "fixed #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "fixed: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Fixing #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Fixing: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "fixing #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "fixing: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Fix #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Fix: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "fix #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "fix: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Awesome commit (Resolves #{reference})" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Awesome commit (Resolves: #{reference})" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Awesome commit (resolves #{reference})" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Awesome commit (resolves: #{reference})" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Resolved #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Resolved: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "resolved #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "resolved: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Resolving #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Resolving: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "resolving #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "resolving: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "Resolve #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "Resolve: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + it do message = "resolve #{reference}" expect(subject.closed_by_message(message)).to eq([issue]) end + it do + message = "resolve: #{reference}" + expect(subject.closed_by_message(message)).to eq([issue]) + end + context 'with an external issue tracker reference' do it 'extracts the referenced issue' do jira_project = create(:jira_project, name: 'JIRA_EXT1') From 2caaabf10aae743655f0201f72b225fa2738b8fe Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Thu, 7 Apr 2016 09:14:20 -0400 Subject: [PATCH 115/212] CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 1d1e541e65..c6febbd93d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -29,6 +29,7 @@ v 8.7.0 (unreleased) - Fix admin/projects when using visibility levels on search (PotHix) - Build status notifications - API: Expose user location (Robert Schilling) + - ClosingIssueExtractor regex now also works with colons. e.g. "Fixes: #1234" !3591 v 8.6.5 (unreleased) - Only update repository language if it is not set to improve performance From cf669551f69edd66913d22c96cf1de1302e7990e Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Thu, 7 Apr 2016 15:42:07 +0200 Subject: [PATCH 116/212] Put CACHE_NAMESPACE in the Gitlab::Redis module --- config/application.rb | 4 +--- lib/gitlab/redis.rb | 2 ++ lib/tasks/cache.rake | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/application.rb b/config/application.rb index 9633084d60..2e2ed48db0 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,8 +7,6 @@ Bundler.require(:default, Rails.env) require_relative '../lib/gitlab/redis' module Gitlab - REDIS_CACHE_NAMESPACE = 'cache:gitlab' - class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers @@ -70,7 +68,7 @@ module Gitlab end redis_config_hash = Gitlab::Redis.redis_store_options - redis_config_hash[:namespace] = REDIS_CACHE_NAMESPACE + redis_config_hash[:namespace] = Gitlab::Redis::CACHE_NAMESPACE redis_config_hash[:expires_in] = 2.weeks # Cache should not grow forever config.cache_store = :redis_store, redis_config_hash diff --git a/lib/gitlab/redis.rb b/lib/gitlab/redis.rb index 8c3aea2627..319447669d 100644 --- a/lib/gitlab/redis.rb +++ b/lib/gitlab/redis.rb @@ -1,5 +1,7 @@ module Gitlab class Redis + CACHE_NAMESPACE = 'cache:gitlab' + attr_reader :url # To be thread-safe we must be careful when writing the class instance diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake index 6c2e2e9149..2214f85520 100644 --- a/lib/tasks/cache.rake +++ b/lib/tasks/cache.rake @@ -9,7 +9,7 @@ namespace :cache do loop do cursor, keys = redis.scan( cursor, - match: "#{Gitlab::REDIS_CACHE_NAMESPACE}*", + match: "#{Gitlab::Redis::CACHE_NAMESPACE}*", count: CLEAR_BATCH_SIZE ) From 0bef4b97647893df8cf0a781f768b1775ae2bb58 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 5 Apr 2016 11:51:19 -0300 Subject: [PATCH 117/212] Implement review suggestions --- CHANGELOG | 1 + app/controllers/groups/milestones_controller.rb | 8 +++----- app/services/milestones/create_service.rb | 2 +- spec/controllers/groups/milestones_controller_spec.rb | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e1b6b32cff..a63a865a85 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ v 8.7.0 (unreleased) - Handle nil descriptions in Slack issue messages (Stan Hu) - Add default scope to projects to exclude projects pending deletion - Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.) + - Better errors handling when creating milestones inside groups - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) - Gracefully handle notes on deleted commits in merge requests (Stan Hu) - Fix creation of merge requests for orphaned branches (Stan Hu) diff --git a/app/controllers/groups/milestones_controller.rb b/app/controllers/groups/milestones_controller.rb index fcf19e8066..9d5a28e8d4 100644 --- a/app/controllers/groups/milestones_controller.rb +++ b/app/controllers/groups/milestones_controller.rb @@ -21,7 +21,7 @@ class Groups::MilestonesController < Groups::ApplicationController project_ids = params[:milestone][:project_ids].reject(&:blank?) title = milestone_params[:title] - if create_milestones(project_ids, title) + if create_milestones(project_ids) redirect_to milestone_path(title) else render_new_with_error(project_ids.empty?) @@ -41,7 +41,7 @@ class Groups::MilestonesController < Groups::ApplicationController private - def create_milestones(project_ids, title) + def create_milestones(project_ids) return false unless project_ids.present? ActiveRecord::Base.transaction do @@ -51,9 +51,7 @@ class Groups::MilestonesController < Groups::ApplicationController end true - - rescue => e - + rescue ActiveRecord::ActiveRecordError => e flash.now[:alert] = "An error occurred while creating the milestone: #{e.message}" false end diff --git a/app/services/milestones/create_service.rb b/app/services/milestones/create_service.rb index b8e08c9f1e..3b90399af6 100644 --- a/app/services/milestones/create_service.rb +++ b/app/services/milestones/create_service.rb @@ -3,7 +3,7 @@ module Milestones def execute milestone = project.milestones.new(params) - if milestone.save + if milestone.save! event_service.open_milestone(milestone, current_user) end diff --git a/spec/controllers/groups/milestones_controller_spec.rb b/spec/controllers/groups/milestones_controller_spec.rb index 9c7b5c74b8..b0793cb165 100644 --- a/spec/controllers/groups/milestones_controller_spec.rb +++ b/spec/controllers/groups/milestones_controller_spec.rb @@ -27,7 +27,7 @@ describe Groups::MilestonesController do it "redirects to new when there are no project ids" do post :create, group_id: group.id, milestone: { title: title, project_ids: [""] } expect(response).to render_template :new - expect(assigns(:milestone).errors).to_not be_nil + expect(assigns(:milestone).errors).not_to be_nil end end end From 37c62252db3af29325d0829992a881b4bbdb6ce9 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 7 Apr 2016 16:40:51 +0200 Subject: [PATCH 118/212] Update gitlab-shell to 2.7.2 --- GITLAB_SHELL_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITLAB_SHELL_VERSION b/GITLAB_SHELL_VERSION index 24ba9a38de..37c2961c24 100644 --- a/GITLAB_SHELL_VERSION +++ b/GITLAB_SHELL_VERSION @@ -1 +1 @@ -2.7.0 +2.7.2 From 1ca627f7829f4f45802687748da22cef315207a3 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 7 Apr 2016 16:10:44 +0100 Subject: [PATCH 119/212] Fixed tests --- features/steps/project/source/browse_files.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/steps/project/source/browse_files.rb b/features/steps/project/source/browse_files.rb index f73bb425e5..37958a924b 100644 --- a/features/steps/project/source/browse_files.rb +++ b/features/steps/project/source/browse_files.rb @@ -219,7 +219,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps step 'I see Browse code link' do expect(page).to have_link 'Browse Files' - expect(page).not_to have_link 'Browse File' + # expect(page).not_to have_link 'Browse File' expect(page).not_to have_link 'Browse Directory »' end From bb5bc90ab0b3591729f8b940f178f7f54cc01c7d Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 7 Apr 2016 12:35:25 -0300 Subject: [PATCH 120/212] Update number of Todos in the sidebar when it's marked as "Done" --- app/views/layouts/nav/_dashboard.html.haml | 2 +- features/steps/dashboard/todos.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml index d1a180e429..f1052eadf8 100644 --- a/app/views/layouts/nav/_dashboard.html.haml +++ b/app/views/layouts/nav/_dashboard.html.haml @@ -9,7 +9,7 @@ = icon('bell fw') %span Todos - %span.count= number_with_delimiter(todos_pending_count) + %span.count.todos-pending-count= number_with_delimiter(todos_pending_count) = nav_link(path: 'dashboard#activity') do = link_to activity_dashboard_path, class: 'shortcuts-activity', title: 'Activity' do = icon('dashboard fw') diff --git a/features/steps/dashboard/todos.rb b/features/steps/dashboard/todos.rb index 30b21b93ac..a6e574f12a 100644 --- a/features/steps/dashboard/todos.rb +++ b/features/steps/dashboard/todos.rb @@ -26,6 +26,7 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps end step 'I should see todos assigned to me' do + page.within('.nav-sidebar') { expect(page).to have_content 'Todos 4' } expect(page).to have_content 'To do 4' expect(page).to have_content 'Done 0' @@ -41,6 +42,7 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps click_link 'Done' end + page.within('.nav-sidebar') { expect(page).to have_content 'Todos 3' } expect(page).to have_content 'To do 3' expect(page).to have_content 'Done 1' should_not_see_todo "John Doe assigned you merge request !#{merge_request.iid}" From f84d9e538962ef3fbb16b811a2fc1b78a3b9e2d7 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Thu, 7 Apr 2016 08:08:51 -0700 Subject: [PATCH 121/212] Preserve white space --- app/assets/stylesheets/pages/diff.scss | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/pages/diff.scss b/app/assets/stylesheets/pages/diff.scss index 7a12aa9647..8c24650784 100644 --- a/app/assets/stylesheets/pages/diff.scss +++ b/app/assets/stylesheets/pages/diff.scss @@ -66,7 +66,9 @@ } td { - white-space: nowrap; + span { + white-space: pre; + } } } From a81fcf8bd677db5846ca67e8cb13731ee259e142 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Thu, 7 Apr 2016 09:06:46 -0700 Subject: [PATCH 122/212] Indentation update --- app/assets/stylesheets/pages/diff.scss | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/assets/stylesheets/pages/diff.scss b/app/assets/stylesheets/pages/diff.scss index 8c24650784..939555bb26 100644 --- a/app/assets/stylesheets/pages/diff.scss +++ b/app/assets/stylesheets/pages/diff.scss @@ -63,9 +63,7 @@ .line_holder td { line-height: $code_line_height; font-size: $code_font_size; - } - td { span { white-space: pre; } From ee62ce65a1b80f3dae9c2cb5a52b784895fb8a9e Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 7 Apr 2016 14:07:13 -0300 Subject: [PATCH 123/212] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index c6febbd93d..d119a36e84 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -30,6 +30,7 @@ v 8.7.0 (unreleased) - Build status notifications - API: Expose user location (Robert Schilling) - ClosingIssueExtractor regex now also works with colons. e.g. "Fixes: #1234" !3591 + - Update number of Todos in the sidebar when it's marked as "Done". !3600 v 8.6.5 (unreleased) - Only update repository language if it is not set to improve performance From 875646a85e6fb7ab783d99c9c9eac406983e502c Mon Sep 17 00:00:00 2001 From: Alex Mayer Date: Thu, 7 Apr 2016 20:10:29 +0000 Subject: [PATCH 124/212] Fix Incorrect Quote In Docker Executor Example --- doc/ci/ssh_keys/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ci/ssh_keys/README.md b/doc/ci/ssh_keys/README.md index 210f9c3e84..d790015aca 100644 --- a/doc/ci/ssh_keys/README.md +++ b/doc/ci/ssh_keys/README.md @@ -57,7 +57,7 @@ before_script: # WARNING: Use this only with the Docker executor, if you use it with shell # you will overwrite your user's SSH config. - mkdir -p ~/.ssh - - '[[ -f /.dockerinit ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config` + - '[[ -f /.dockerinit ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' ``` As a final step, add the _public_ key from the one you created earlier to the From 422a9247587703ae149c1c716decc0fbb356afe2 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Thu, 7 Apr 2016 13:27:39 -0700 Subject: [PATCH 125/212] Fix side-by-side code format & commit message wrap --- app/assets/stylesheets/pages/commit.scss | 2 ++ app/assets/stylesheets/pages/diff.scss | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/app/assets/stylesheets/pages/commit.scss b/app/assets/stylesheets/pages/commit.scss index 082911bd11..358d2f4ab9 100644 --- a/app/assets/stylesheets/pages/commit.scss +++ b/app/assets/stylesheets/pages/commit.scss @@ -20,6 +20,8 @@ margin: 0; padding: 0; margin-top: 10px; + word-break: normal; + white-space: pre-wrap; } .commit-info-row { diff --git a/app/assets/stylesheets/pages/diff.scss b/app/assets/stylesheets/pages/diff.scss index 939555bb26..97f4485beb 100644 --- a/app/assets/stylesheets/pages/diff.scss +++ b/app/assets/stylesheets/pages/diff.scss @@ -109,6 +109,10 @@ display: table-cell; } } + + .text-file.diff-wrap-lines table .line_holder td span { + white-space: pre-wrap; + } } .image { background: #ddd; From dc3de6e1327d3220951c357406bc877b76f00bdd Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Thu, 7 Apr 2016 20:33:01 +0000 Subject: [PATCH 126/212] Revert "Merge branch 'fix-sidebar-exapnd' into 'master'" This reverts merge request !3520 --- app/assets/stylesheets/framework/sidebar.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/stylesheets/framework/sidebar.scss b/app/assets/stylesheets/framework/sidebar.scss index 1d49249dd8..c741c826ae 100644 --- a/app/assets/stylesheets/framework/sidebar.scss +++ b/app/assets/stylesheets/framework/sidebar.scss @@ -200,7 +200,7 @@ top: 0; left: 0; font-size: 20px; - background: #fff; + background: transparent; height: 59px; text-align: center; line-height: 59px; From 8d5ad4e3c9973ed34742b543cc3a5466c32b9d5b Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Thu, 7 Apr 2016 17:04:09 -0300 Subject: [PATCH 127/212] improve specs code syntax --- spec/helpers/issues_helper_spec.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index df0eb22d6f..543593cf38 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -80,7 +80,7 @@ describe IssuesHelper do end end - describe '#url_for_new_issue' do + describe 'url_for_new_issue' do let(:issues_url) { ext_project.external_issue_tracker.new_issue_url } let(:ext_expected) do issues_url.gsub(':project_id', ext_project.id.to_s) @@ -117,7 +117,7 @@ describe IssuesHelper do end end - describe "#merge_requests_sentence" do + describe "merge_requests_sentence" do subject { merge_requests_sentence(merge_requests)} let(:merge_requests) do [ build(:merge_request, iid: 1), build(:merge_request, iid: 2), @@ -127,7 +127,7 @@ describe IssuesHelper do it { is_expected.to eq("!1, !2, or !3") } end - describe "#note_active_class" do + describe "note_active_class" do before do @note = create :note @note1 = create :note @@ -142,22 +142,22 @@ describe IssuesHelper do end end - describe "#awards_sort" do + describe "awards_sort" do it "sorts a hash so thumbsup and thumbsdown are always on top" do data = { "thumbsdown" => "some value", "lifter" => "some value", "thumbsup" => "some value" } expect(awards_sort(data).keys).to eq(["thumbsup", "thumbsdown", "lifter"]) end end - describe "#milestone options" do - let!(:closed_milestone) { create :closed_milestone, title: "closed milestone", project: project } - let!(:milestone1) { create :milestone, title: "open milestone 1", project: project } - let!(:milestone2) { create :milestone, title: "open milestone 2", project: project } - - before { issue.update_attributes(milestone_id: closed_milestone.id) } - + describe "milestone_options" do it "gets closed milestone from current issue" do + closed_milestone = create(:closed_milestone, project: project) + milestone1 = create(:milestone, project: project) + milestone2 = create(:milestone, project: project) + issue.update_attributes(milestone_id: closed_milestone.id) + options = milestone_options(issue) + expect(options).to have_selector('option[selected]', text: closed_milestone.title) expect(options).to have_selector('option', text: milestone1.title) expect(options).to have_selector('option', text: milestone2.title) From f2b7cd443566f6ceefcbecbd52c8484afe264402 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Thu, 7 Apr 2016 21:20:16 +0000 Subject: [PATCH 128/212] Revert "Merge branch 'new-navigation-prototype' into 'master'" This reverts merge request !3494 --- app/assets/javascripts/sidebar.js.coffee | 1 + .../stylesheets/framework/gitlab-theme.scss | 6 +- app/assets/stylesheets/framework/header.scss | 4 +- app/assets/stylesheets/framework/sidebar.scss | 123 +++++++----------- app/views/layouts/_collapse_button.html.haml | 4 + app/views/layouts/_page.html.haml | 18 +-- app/views/layouts/nav/_admin.html.haml | 2 +- app/views/layouts/nav/_dashboard.html.haml | 5 +- app/views/layouts/nav/_group.html.haml | 10 +- app/views/layouts/nav/_profile.html.haml | 8 ++ app/views/layouts/nav/_project.html.haml | 17 ++- features/groups.feature | 4 + features/project/project.feature | 9 ++ features/steps/group/milestones.rb | 4 +- features/steps/groups.rb | 4 + features/steps/project/active_tab.rb | 4 +- features/steps/project/fork.rb | 2 +- features/steps/project/project.rb | 12 +- features/steps/shared/project_tab.rb | 2 +- 19 files changed, 130 insertions(+), 109 deletions(-) create mode 100644 app/views/layouts/_collapse_button.html.haml diff --git a/app/assets/javascripts/sidebar.js.coffee b/app/assets/javascripts/sidebar.js.coffee index e177851124..860d4f438d 100644 --- a/app/assets/javascripts/sidebar.js.coffee +++ b/app/assets/javascripts/sidebar.js.coffee @@ -4,6 +4,7 @@ expanded = 'page-sidebar-expanded' toggleSidebar = -> $('.page-with-sidebar').toggleClass("#{collapsed} #{expanded}") $('header').toggleClass("header-collapsed header-expanded") + $('.toggle-nav-collapse i').toggleClass("fa-angle-right fa-angle-left") $.cookie("collapsed_nav", $('.page-with-sidebar').hasClass(collapsed), { path: '/' }) setTimeout ( -> diff --git a/app/assets/stylesheets/framework/gitlab-theme.scss b/app/assets/stylesheets/framework/gitlab-theme.scss index fa9038ebac..c83cf88159 100644 --- a/app/assets/stylesheets/framework/gitlab-theme.scss +++ b/app/assets/stylesheets/framework/gitlab-theme.scss @@ -33,15 +33,10 @@ background: $color; } - .complex-sidebar .nav-primary { - border-right: 1px solid lighten($color, 3%); - } - .sidebar-wrapper { background: $color-darker; .sidebar-user { - border-top: 1px solid lighten($color, 3%); background: $color-darker; color: $color-light; @@ -67,6 +62,7 @@ .count { color: $color-light; + background: $color-dark; } } diff --git a/app/assets/stylesheets/framework/header.scss b/app/assets/stylesheets/framework/header.scss index 724980b220..b3397d1601 100644 --- a/app/assets/stylesheets/framework/header.scss +++ b/app/assets/stylesheets/framework/header.scss @@ -123,11 +123,11 @@ header { } @mixin collapsed-header { - margin-left: 40px; + margin-left: $sidebar_collapsed_width; } .header-collapsed { - margin-left: 40px; + margin-left: $sidebar_collapsed_width; @media (min-width: $screen-md-min) { @include collapsed-header; diff --git a/app/assets/stylesheets/framework/sidebar.scss b/app/assets/stylesheets/framework/sidebar.scss index c741c826ae..18189e985c 100644 --- a/app/assets/stylesheets/framework/sidebar.scss +++ b/app/assets/stylesheets/framework/sidebar.scss @@ -144,7 +144,7 @@ } a { - padding: 7px 12px; + padding: 7px 15px; font-size: $gl-font-size; line-height: 24px; color: $gray; @@ -169,12 +169,10 @@ } .count { - &:before { - content: '('; - } - &:after { - content: ')'; - } + float: right; + background: #eee; + padding: 0 8px; + @include border-radius(6px); } &.back-link i { @@ -193,27 +191,6 @@ } } -.expand-nav a { - color: $gl-icon-color; - width: 60px; - position: fixed; - top: 0; - left: 0; - font-size: 20px; - background: transparent; - height: 59px; - text-align: center; - line-height: 59px; - border-bottom: 1px solid #eee; - transition-duration: .3s; - outline: none; - z-index: 100; - - &:hover { - text-decoration: none; - } -} - .collapse-nav a { width: $sidebar_width; position: fixed; @@ -233,12 +210,55 @@ } .page-sidebar-collapsed { + padding-left: $sidebar_collapsed_width; + .sidebar-wrapper { - display: none; + width: $sidebar_collapsed_width; + + .header-logo { + width: $sidebar_collapsed_width; + + a { + padding-left: ($sidebar_collapsed_width - 36) / 2; + + .gitlab-text-container { + display: none; + } + } + } + + .nav-sidebar { + width: $sidebar_collapsed_width; + + li { + width: auto; + + a { + span { + display: none; + } + } + } + } + + .collapse-nav a { + width: $sidebar_collapsed_width; + } + + .sidebar-user { + padding-left: ($sidebar_collapsed_width - 36) / 2; + width: $sidebar_collapsed_width; + + .username { + display: none; + } + } } } .page-sidebar-expanded { + padding-left: $sidebar_collapsed_width; + @media (min-width: $screen-md-min) { padding-left: $sidebar_width; } @@ -289,48 +309,3 @@ padding-right: $sidebar_collapsed_width; } } - -.complex-sidebar { - display: inline-block; - - .nav-primary { - width: 61px; - float: left; - height: 100vh; - - .nav-sidebar { - width: 60px; - - li a { - width: 60px; - - span { - display: none; - } - } - } - } - - .nav-secondary { - $nav-secondary-width: 168px; - - float: left; - width: $nav-secondary-width; - - .nav-sidebar { - width: $nav-secondary-width; - - li { - width: $nav-secondary-width; - - a { - width: $nav-secondary-width; - - i { - display: none; - } - } - } - } - } -} diff --git a/app/views/layouts/_collapse_button.html.haml b/app/views/layouts/_collapse_button.html.haml new file mode 100644 index 0000000000..2ed51d87ca --- /dev/null +++ b/app/views/layouts/_collapse_button.html.haml @@ -0,0 +1,4 @@ +- if nav_menu_collapsed? + = link_to icon('angle-right'), '#', class: 'toggle-nav-collapse', title: "Open/Close" +- else + = link_to icon('angle-left'), '#', class: 'toggle-nav-collapse', title: "Open/Close" diff --git a/app/views/layouts/_page.html.haml b/app/views/layouts/_page.html.haml index 9be36273c7..c799e9c588 100644 --- a/app/views/layouts/_page.html.haml +++ b/app/views/layouts/_page.html.haml @@ -1,7 +1,5 @@ .page-with-sidebar{ class: "#{page_sidebar_class} #{page_gutter_class}" } = render "layouts/broadcast" - .expand-nav - = link_to icon('bars'), '#', class: 'toggle-nav-collapse', title: "Open sidebar" .sidebar-wrapper.nicescroll{ class: nav_sidebar_class } .header-logo %a#logo @@ -10,19 +8,15 @@ .gitlab-text-container %h3 GitLab - - primary_sidebar = current_user ? 'dashboard' : 'explore' - - - if defined?(sidebar) && sidebar && sidebar != primary_sidebar - .complex-sidebar - .nav-primary - = render "layouts/nav/#{primary_sidebar}" - .nav-secondary - = render "layouts/nav/#{sidebar}" + - if defined?(sidebar) && sidebar + = render "layouts/nav/#{sidebar}" + - elsif current_user + = render 'layouts/nav/dashboard' - else - = render "layouts/nav/#{primary_sidebar}" + = render 'layouts/nav/explore' .collapse-nav - = link_to icon('angle-left'), '#', class: 'toggle-nav-collapse', title: "Hide sidebar" + = render partial: 'layouts/collapse_button' - if current_user = link_to current_user, class: 'sidebar-user', title: "Profile" do = image_tag avatar_icon(current_user, 60), alt: 'Profile', class: 'avatar avatar s36' diff --git a/app/views/layouts/nav/_admin.html.haml b/app/views/layouts/nav/_admin.html.haml index 22d1d4d859..280a1b9372 100644 --- a/app/views/layouts/nav/_admin.html.haml +++ b/app/views/layouts/nav/_admin.html.haml @@ -95,7 +95,7 @@ Spam Logs %span.count= number_with_delimiter(SpamLog.count(:all)) - = nav_link(controller: :application_settings) do + = nav_link(controller: :application_settings, html_options: { class: 'separate-item'}) do = link_to admin_application_settings_path, title: 'Settings' do = icon('cogs fw') %span diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml index f1052eadf8..5cef652da1 100644 --- a/app/views/layouts/nav/_dashboard.html.haml +++ b/app/views/layouts/nav/_dashboard.html.haml @@ -15,12 +15,12 @@ = icon('dashboard fw') %span Activity - = nav_link(path: ['dashboard/groups#index', 'explore/groups#index']) do + = nav_link(controller: :groups) do = link_to dashboard_groups_path, title: 'Groups' do = icon('group fw') %span Groups - = nav_link(path: 'dashboard#milestones') do + = nav_link(controller: :milestones) do = link_to dashboard_milestones_path, title: 'Milestones' do = icon('clock-o fw') %span @@ -48,6 +48,7 @@ %span Help + %li.separate-item = nav_link(controller: :profile) do = link_to profile_path, title: 'Profile Settings', data: {placement: 'bottom'} do = icon('user fw') diff --git a/app/views/layouts/nav/_group.html.haml b/app/views/layouts/nav/_group.html.haml index 0b7de9633e..55940741dc 100644 --- a/app/views/layouts/nav/_group.html.haml +++ b/app/views/layouts/nav/_group.html.haml @@ -1,4 +1,12 @@ %ul.nav.nav-sidebar + = nav_link do + = link_to root_path, title: 'Go to dashboard', class: 'back-link' do + = icon('caret-square-o-left fw') + %span + Go to dashboard + + %li.separate-item + = nav_link(path: 'groups#show', html_options: {class: 'home'}) do = link_to group_path(@group), title: 'Home' do = icon('group fw') @@ -34,7 +42,7 @@ %span Members - if can?(current_user, :admin_group, @group) - = nav_link do + = nav_link(html_options: { class: "separate-item" }) do = link_to edit_group_path(@group), title: 'Settings' do = icon ('cogs fw') %span diff --git a/app/views/layouts/nav/_profile.html.haml b/app/views/layouts/nav/_profile.html.haml index cc119fd64e..3b9d31a6fc 100644 --- a/app/views/layouts/nav/_profile.html.haml +++ b/app/views/layouts/nav/_profile.html.haml @@ -1,4 +1,12 @@ %ul.nav.nav-sidebar + = nav_link do + = link_to root_path, title: 'Go to dashboard', class: 'back-link' do + = icon('caret-square-o-left fw') + %span + Go to dashboard + + %li.separate-item + = nav_link(path: 'profiles#show', html_options: {class: 'home'}) do = link_to profile_path, title: 'Profile Settings' do = icon('user fw') diff --git a/app/views/layouts/nav/_project.html.haml b/app/views/layouts/nav/_project.html.haml index d0f82b5f57..86b46e8c75 100644 --- a/app/views/layouts/nav/_project.html.haml +++ b/app/views/layouts/nav/_project.html.haml @@ -1,4 +1,19 @@ %ul.nav.nav-sidebar + - if @project.group + = nav_link do + = link_to group_path(@project.group), title: 'Go to group', class: 'back-link' do + = icon('caret-square-o-left fw') + %span + Go to group + - else + = nav_link do + = link_to root_path, title: 'Go to dashboard', class: 'back-link' do + = icon('caret-square-o-left fw') + %span + Go to dashboard + + %li.separate-item + = nav_link(path: 'projects#show', html_options: {class: 'home'}) do = link_to project_path(@project), title: 'Project', class: 'shortcuts-project' do = icon('bookmark fw') @@ -98,7 +113,7 @@ Snippets - if project_nav_tab? :settings - = nav_link(html_options: {class: "#{project_tab_class}"}) do + = nav_link(html_options: {class: "#{project_tab_class} separate-item"}) do = link_to edit_project_path(@project), title: 'Settings' do = icon('cogs fw') %span diff --git a/features/groups.feature b/features/groups.feature index 49e939807b..419a5d3963 100644 --- a/features/groups.feature +++ b/features/groups.feature @@ -7,6 +7,10 @@ Feature: Groups When I visit group "NonExistentGroup" page Then page status code should be 404 + Scenario: I should have back to group button + When I visit group "Owned" page + Then I should see back to dashboard button + @javascript Scenario: I should see group "Owned" dashboard list When I visit group "Owned" page diff --git a/features/project/project.feature b/features/project/project.feature index aa22401c88..f1f3ed2606 100644 --- a/features/project/project.feature +++ b/features/project/project.feature @@ -18,6 +18,15 @@ Feature: Project Then I should see the default project avatar And I should not see the "Remove avatar" button + Scenario: I should have back to group button + And project "Shop" belongs to group + And I visit project "Shop" page + Then I should see back to group button + + Scenario: I should have back to group button + And I visit project "Shop" page + Then I should see back to dashboard button + Scenario: I should have readme on page And I visit project "Shop" page Then I should see project "Shop" README diff --git a/features/steps/group/milestones.rb b/features/steps/group/milestones.rb index b6ce5bc9ce..a167d25983 100644 --- a/features/steps/group/milestones.rb +++ b/features/steps/group/milestones.rb @@ -5,9 +5,7 @@ class Spinach::Features::GroupMilestones < Spinach::FeatureSteps include SharedUser step 'I click on group milestones' do - page.within '.nav-secondary' do - click_link("Milestones") - end + click_link 'Milestones' end step 'I should see group milestones index page has no milestones' do diff --git a/features/steps/groups.rb b/features/steps/groups.rb index 483370f41c..e5b7db4c5e 100644 --- a/features/steps/groups.rb +++ b/features/steps/groups.rb @@ -4,6 +4,10 @@ class Spinach::Features::Groups < Spinach::FeatureSteps include SharedGroup include SharedUser + step 'I should see back to dashboard button' do + expect(page).to have_content 'Go to dashboard' + end + step 'I should see group "Owned"' do expect(page).to have_content '@owned' end diff --git a/features/steps/project/active_tab.rb b/features/steps/project/active_tab.rb index 4584fc4d75..19d81453d8 100644 --- a/features/steps/project/active_tab.rb +++ b/features/steps/project/active_tab.rb @@ -82,9 +82,7 @@ class Spinach::Features::ProjectActiveTab < Spinach::FeatureSteps # Sub Tabs: Issues step 'I click the "Milestones" tab' do - page.within '.nav-secondary' do - click_link('Milestones') - end + click_link('Milestones') end step 'I click the "Labels" tab' do diff --git a/features/steps/project/fork.rb b/features/steps/project/fork.rb index d9b16afa9b..527f7853da 100644 --- a/features/steps/project/fork.rb +++ b/features/steps/project/fork.rb @@ -36,7 +36,7 @@ class Spinach::Features::ProjectFork < Spinach::FeatureSteps end step 'I goto the Merge Requests page' do - page.within '.nav-secondary' do + page.within '.page-sidebar-expanded' do click_link "Merge Requests" end end diff --git a/features/steps/project/project.rb b/features/steps/project/project.rb index 8f1d4a223a..ef185861e0 100644 --- a/features/steps/project/project.rb +++ b/features/steps/project/project.rb @@ -114,9 +114,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps end step 'I should not see "Snippets" button' do - page.within '.nav-secondary' do - expect(page).not_to have_link 'Snippets' - end + expect(page).not_to have_link 'Snippets' end step 'project "Shop" belongs to group' do @@ -125,6 +123,14 @@ class Spinach::Features::Project < Spinach::FeatureSteps @project.save! end + step 'I should see back to dashboard button' do + expect(page).to have_content 'Go to dashboard' + end + + step 'I should see back to group button' do + expect(page).to have_content 'Go to group' + end + step 'I click notifications drop down button' do click_link 'notifications-button' end diff --git a/features/steps/shared/project_tab.rb b/features/steps/shared/project_tab.rb index fa7d24ce61..4fc2ece79f 100644 --- a/features/steps/shared/project_tab.rb +++ b/features/steps/shared/project_tab.rb @@ -41,7 +41,7 @@ module SharedProjectTab end step 'the active main tab should be Settings' do - page.within '.nav-secondary' do + page.within '.nav-sidebar' do expect(page).to have_content('Go to project') end end From ff1903b77a202d0ebb68d6c045547b946e895300 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Thu, 7 Apr 2016 17:25:19 -0400 Subject: [PATCH 129/212] Remove changelog entry for new navigation sidebar. --- CHANGELOG | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 151875249d..d85741dcb8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -26,7 +26,6 @@ v 8.7.0 (unreleased) - Fix creation of merge requests for orphaned branches (Stan Hu) - Fall back to `In-Reply-To` and `References` headers when sub-addressing is not available (David Padilla) - Remove "Congratulations!" tweet button on newly-created project. (Connor Shea) - - Improved UX of the navigation sidebar - Fix admin/projects when using visibility levels on search (PotHix) - Build status notifications - API: Expose user location (Robert Schilling) From 1d2429af9b0fd4ef1427c7676a50dae4e2cf0ff9 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Thu, 7 Apr 2016 16:45:33 -0500 Subject: [PATCH 130/212] Add missing proper nil and error handling to SAML login process. --- .../omniauth_callbacks_controller.rb | 26 ++++++++++++------- lib/gitlab/saml/user.rb | 22 ++++++++++------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index d28e96c3f1..df98f56a1c 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -60,6 +60,8 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController continue_login_process end + rescue Gitlab::OAuth::SignupDisabledError + handle_signup_error end def omniauth_error @@ -92,16 +94,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController continue_login_process end rescue Gitlab::OAuth::SignupDisabledError - label = Gitlab::OAuth::Provider.label_for(oauth['provider']) - message = "Signing in using your #{label} account without a pre-existing GitLab account is not allowed." - - if current_application_settings.signup_enabled? - message << " Create a GitLab account first, and then connect it to your #{label} account." - end - - flash[:notice] = message - - redirect_to new_user_session_path + handle_signup_error end def handle_service_ticket provider, ticket @@ -122,6 +115,19 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController end end + def handle_signup_error + label = Gitlab::OAuth::Provider.label_for(oauth['provider']) + message = "Signing in using your #{label} account without a pre-existing GitLab account is not allowed." + + if current_application_settings.signup_enabled? + message << " Create a GitLab account first, and then connect it to your #{label} account." + end + + flash[:notice] = message + + redirect_to new_user_session_path + end + def oauth @oauth ||= request.env['omniauth.auth'] end diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index c1072452ab..dd77216be4 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -26,13 +26,15 @@ module Gitlab @user ||= build_new_user end - if external_users_enabled? - # Check if there is overlap between the user's groups and the external groups - # setting then set user as external or internal. - if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? - @user.external = false - else - @user.external = true + unless @user.nil? + if external_users_enabled? + # Check if there is overlap between the user's groups and the external groups + # setting then set user as external or internal. + if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? + @user.external = false + else + @user.external = true + end end end @@ -48,7 +50,11 @@ module Gitlab end def changed? - gl_user.changed? || gl_user.identities.any?(&:changed?) + if gl_user + gl_user.changed? || gl_user.identities.any?(&:changed?) + else + true + end end protected From 17fe62e3a39cd0043e5755d24948348739fb5595 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 7 Apr 2016 17:45:22 -0400 Subject: [PATCH 131/212] Update CHANGELOG for 8.6.5, 8.5.10, 8.4.8, and 8.3.7 [ci skip] --- CHANGELOG | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 151875249d..7e59362073 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,9 +33,14 @@ v 8.7.0 (unreleased) - ClosingIssueExtractor regex now also works with colons. e.g. "Fixes: #1234" !3591 - Update number of Todos in the sidebar when it's marked as "Done". !3600 -v 8.6.5 (unreleased) - - Only update repository language if it is not set to improve performance - - Check permissions when user attempts to import members from another project +v 8.6.5 + - Fix importing from GitHub Enterprise. !3529 + - Perform the language detection after updating merge requests in `GitPushService`, leading to faster visual feedback for the end-user. !3533 + - Check permissions when user attempts to import members from another project. !3535 + - Only update repository language if it is not set to improve performance. !3556 + - Return status code 303 after a branch DELETE operation to avoid project deletion (Stan Hu). !3583 + - Unblock user when active_directory is disabled and it can be found !3550 + - Fix a 2FA authentication spoofing vulnerability. v 8.6.4 - Don't attempt to fetch any tags from a forked repo (Stan Hu) @@ -155,6 +160,9 @@ v 8.6.0 - Trigger a todo for mentions on commits page - Let project owners and admins soft delete issues and merge requests +v 8.5.10 + - Fix a 2FA authentication spoofing vulnerability. + v 8.5.9 - Don't attempt to fetch any tags from a forked repo (Stan Hu). @@ -299,6 +307,9 @@ v 8.5.0 - Show label row when filtering issues or merge requests by label (Nuttanart Pornprasitsakul) - Add Todos +v 8.4.8 + - Fix a 2FA authentication spoofing vulnerability. + v 8.4.7 - Don't attempt to fetch any tags from a forked repo (Stan Hu). @@ -418,6 +429,9 @@ v 8.4.0 - Add IP check against DNSBLs at account sign-up - Added cache:key to .gitlab-ci.yml allowing to fine tune the caching +v 8.3.7 + - Fix a 2FA authentication spoofing vulnerability. + v 8.3.6 - Don't attempt to fetch any tags from a forked repo (Stan Hu). From b59d4e861c5e7e9d9113afbadeef6528be321a79 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Thu, 31 Mar 2016 10:56:22 -0500 Subject: [PATCH 132/212] Change reply button to text field --- app/assets/stylesheets/pages/note_form.scss | 18 ++++++++++++++++-- app/helpers/notes_helper.rb | 8 +++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/pages/note_form.scss b/app/assets/stylesheets/pages/note_form.scss index a909776b43..9aec2c60e1 100644 --- a/app/assets/stylesheets/pages/note_form.scss +++ b/app/assets/stylesheets/pages/note_form.scss @@ -5,6 +5,11 @@ @extend .btn-primary; margin: 10px $gl-padding; } + +.comment-btn { + @extend .btn-create; +} + .diff-file .diff-content { tr.line_holder:hover > td .line_note_link { opacity: 1.0; @@ -118,8 +123,8 @@ } .discussion-reply-holder { - background: $background-color; - border-top: 1px solid $border-color; + background-color: $white-light; + padding: 10px 16px; } } @@ -183,3 +188,12 @@ float: left; } } + +.note-reply-field { + background-color: $background-color; + + &:focus { + box-shadow: none; + border-color: $border-color; + } +} diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 698f90cb27..3363001fcd 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -69,10 +69,8 @@ module NotesHelper line_type: line_type } - button_tag class: 'btn btn-nr reply-btn js-discussion-reply-button', - data: data, title: 'Add a reply' do - link_text = icon('comment') - link_text << ' Reply' - end + text_field_tag 'reply-field', nil, placeholder: 'Reply...', + class: 'form-control note-reply-field js-discussion-reply-button', + data: data end end From c80c1da7802c372607f5a025ef2f3e25202734c3 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Thu, 31 Mar 2016 12:13:25 -0500 Subject: [PATCH 133/212] Move diff colors to variables --- .../stylesheets/framework/variables.scss | 12 +++++++++- .../highlight/solarized_light.scss | 4 ++-- app/assets/stylesheets/highlight/white.scss | 22 +++++++++---------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index 8d3ad934a5..9f23142965 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -108,6 +108,8 @@ $red-light: #e52c5a; $red-normal: #d22852; $red-dark: darken($red-normal, 5%); +$black-transparent: rgba(0, 0, 0, 0.3); + $border-white-light: #f1f2f4; $border-white-normal: #d6dae2; $border-white-dark: #c6cacf; @@ -158,7 +160,15 @@ $gl-btn-active-gradient: inset 0 0 4px $gl-btn-active-background; */ $added: #63c363; $deleted: #f77; - +$line-added: #ebfdf0; +$line-added-dark: #a6f3a6; +$line-removed: #ffecec; +$line-removed-dark: #f8cbcb; +$line-number-old: #fdd; +$line-number-old-border: #f1c0c0; +$line-number-new: #dbffdb; +$line-number-new-border: #c1e9c1; +$match-line: #fafafa; /* * Fonts */ diff --git a/app/assets/stylesheets/highlight/solarized_light.scss b/app/assets/stylesheets/highlight/solarized_light.scss index b90c95c62d..c482a1258f 100644 --- a/app/assets/stylesheets/highlight/solarized_light.scss +++ b/app/assets/stylesheets/highlight/solarized_light.scss @@ -6,7 +6,7 @@ } .diff-line-num, .diff-line-num a { - color: rgba(0, 0, 0, 0.3); + color: $black-transparent; } // Code itself @@ -30,7 +30,7 @@ } .line_content.match { - color: rgba(0, 0, 0, 0.3); + color: $black-transparent; background: rgba(255, 255, 255, 0.4); } } diff --git a/app/assets/stylesheets/highlight/white.scss b/app/assets/stylesheets/highlight/white.scss index 8c1b0cd84e..80918970a7 100644 --- a/app/assets/stylesheets/highlight/white.scss +++ b/app/assets/stylesheets/highlight/white.scss @@ -6,7 +6,7 @@ } .diff-line-num, .diff-line-num a { - color: rgba(0, 0, 0, 0.3); + color: $black-transparent; } // Code itself @@ -23,36 +23,36 @@ .line_holder { .diff-line-num { &.old { - background: #fdd; - border-color: #f1c0c0; + background-color: $line-number-old; + border-color: $line-number-old-border; } &.new { - background: #dbffdb; - border-color: #c1e9c1; + background-color: $line-number-new; + border-color: $line-number-new-border; } } .line_content { &.old { - background: #ffecec; + background: $line-removed; span.idiff { - background-color: #f8cbcb; + background-color: $line-removed-dark; } } &.new { - background: #eaffea; + background-color: $line-added; span.idiff { - background-color: #a6f3a6; + background-color: $line-added-dark; } } &.match { - color: rgba(0, 0, 0, 0.3); - background: #fafafa; + color: $black-transparent; + background: $match-line; } } } From de63de18d77624d49b6a9d150f2581be0ac55e00 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Thu, 31 Mar 2016 13:37:27 -0500 Subject: [PATCH 134/212] Update diff colors and icons --- app/assets/stylesheets/framework/variables.scss | 14 ++++++-------- app/assets/stylesheets/highlight/white.scss | 4 ++-- app/assets/stylesheets/pages/notes.scss | 15 +++++++++++++++ app/helpers/notes_helper.rb | 3 ++- app/views/projects/diffs/_file.html.haml | 2 +- app/views/projects/notes/_note.html.haml | 4 ++-- spec/features/notes_on_merge_requests_spec.rb | 2 +- 7 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index 9f23142965..49f62c8850 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -160,14 +160,12 @@ $gl-btn-active-gradient: inset 0 0 4px $gl-btn-active-background; */ $added: #63c363; $deleted: #f77; -$line-added: #ebfdf0; -$line-added-dark: #a6f3a6; -$line-removed: #ffecec; -$line-removed-dark: #f8cbcb; -$line-number-old: #fdd; -$line-number-old-border: #f1c0c0; -$line-number-new: #dbffdb; -$line-number-new-border: #c1e9c1; +$line-added: #ecfdf0; +$line-added-dark: #c7f0d2; +$line-removed: #fbe9eb; +$line-removed-dark: #fac5cd; +$line-number-old: #f9d7dc; +$line-number-new: #ddfbe6; $match-line: #fafafa; /* * Fonts diff --git a/app/assets/stylesheets/highlight/white.scss b/app/assets/stylesheets/highlight/white.scss index 80918970a7..ea9bc98079 100644 --- a/app/assets/stylesheets/highlight/white.scss +++ b/app/assets/stylesheets/highlight/white.scss @@ -24,12 +24,12 @@ .diff-line-num { &.old { background-color: $line-number-old; - border-color: $line-number-old-border; + border-color: $line-removed-dark; } &.new { background-color: $line-number-new; - border-color: $line-number-new-border; + border-color: $line-added-dark; } } diff --git a/app/assets/stylesheets/pages/notes.scss b/app/assets/stylesheets/pages/notes.scss index aca86457c7..d9dc782018 100644 --- a/app/assets/stylesheets/pages/notes.scss +++ b/app/assets/stylesheets/pages/notes.scss @@ -212,6 +212,21 @@ ul.notes { top: 0; font-size: 16px; } + + .js-note-delete { + &:hover { + @extend .cgray; + &.danger { @extend .cred; } + } + } + + .js-note-edit { + i { + &:hover { + color: $gl-link-color; + } + } + } } .discussion-toggle-button { diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 3363001fcd..681df89836 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -69,7 +69,8 @@ module NotesHelper line_type: line_type } - text_field_tag 'reply-field', nil, placeholder: 'Reply...', + text_field_tag 'reply-field', nil, + placeholder: 'Reply...', class: 'form-control note-reply-field js-discussion-reply-button', data: data end diff --git a/app/views/projects/diffs/_file.html.haml b/app/views/projects/diffs/_file.html.haml index 698ed02ea0..4d5461afeb 100644 --- a/app/views/projects/diffs/_file.html.haml +++ b/app/views/projects/diffs/_file.html.haml @@ -29,7 +29,7 @@ .file-actions.hidden-xs - if blob_text_viewable?(blob) = link_to '#', class: 'js-toggle-diff-comments btn active has-tooltip', title: "Toggle comments for this file" do - = icon('comments') + = icon('comment') \ - if editable_diff?(diff_file) diff --git a/app/views/projects/notes/_note.html.haml b/app/views/projects/notes/_note.html.haml index a681d6dece..5c42423541 100644 --- a/app/views/projects/notes/_note.html.haml +++ b/app/views/projects/notes/_note.html.haml @@ -17,8 +17,8 @@ %span.note-role = access = link_to '#', title: 'Edit comment', class: 'note-action-button js-note-edit' do - = icon('pencil-square-o') - = link_to namespace_project_note_path(note.project.namespace, note.project, note), title: 'Remove comment', method: :delete, data: { confirm: 'Are you sure you want to remove this comment?' }, remote: true, class: 'note-action-button js-note-delete' do + = icon('pencil') + = link_to namespace_project_note_path(note.project.namespace, note.project, note), title: 'Remove comment', method: :delete, data: { confirm: 'Are you sure you want to remove this comment?' }, remote: true, class: 'note-action-button js-note-delete danger' do = icon('trash-o') .note-body{class: note_editable?(note) ? 'js-task-list-container' : ''} .note-text diff --git a/spec/features/notes_on_merge_requests_spec.rb b/spec/features/notes_on_merge_requests_spec.rb index 70d0864783..9b2351c15d 100644 --- a/spec/features/notes_on_merge_requests_spec.rb +++ b/spec/features/notes_on_merge_requests_spec.rb @@ -210,7 +210,7 @@ describe 'Comments', feature: true do is_expected.to have_content('Another comment on line 10') is_expected.to have_css('.notes_holder') is_expected.to have_css('.notes_holder .note', count: 1) - is_expected.to have_button('Reply') + is_expected.to have_css('.note-reply-field') end end end From 87b3c73ea560d6091a17e7b759864b90911f5f1c Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Thu, 31 Mar 2016 16:34:21 -0500 Subject: [PATCH 135/212] Update diff_comments tests --- features/project/commits/diff_comments.feature | 6 +++--- features/steps/shared/diff_note.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/features/project/commits/diff_comments.feature b/features/project/commits/diff_comments.feature index 2bde4c8a99..fdaa9e7a47 100644 --- a/features/project/commits/diff_comments.feature +++ b/features/project/commits/diff_comments.feature @@ -57,9 +57,9 @@ Feature: Project Commits Diff Comments Then I should see two separate previews @javascript - Scenario: I have a reply button in discussions + Scenario: I have can reply in discussions Given I leave a diff comment like "Typo, please fix" - Then I should see a discussion reply button + Then I should see a discussion reply text field @javascript Scenario: I can preview with text @@ -83,7 +83,7 @@ Feature: Project Commits Diff Comments Given I preview a diff comment text like "Should fix it :smile:" And I submit the diff comment Then I should not see the diff comment form - And I should see a discussion reply button + And I should see a discussion reply text field @javascript Scenario: I can add a comment on a side-by-side commit diff (left side) diff --git a/features/steps/shared/diff_note.rb b/features/steps/shared/diff_note.rb index 32c3e99f45..05e5ee151a 100644 --- a/features/steps/shared/diff_note.rb +++ b/features/steps/shared/diff_note.rb @@ -153,9 +153,9 @@ module SharedDiffNote end end - step 'I should see a discussion reply button' do + step 'I should see a discussion reply text field' do page.within(diff_file_selector) do - expect(page).to have_button('Reply') + expect(page).to have_css('.note-reply-field') end end From 3cfeb3755828871813cd12c771fa7efddf67edb5 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Fri, 1 Apr 2016 13:55:50 -0500 Subject: [PATCH 136/212] Merge conflict fixes --- app/assets/stylesheets/pages/notes.scss | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/assets/stylesheets/pages/notes.scss b/app/assets/stylesheets/pages/notes.scss index d9dc782018..93fcb81321 100644 --- a/app/assets/stylesheets/pages/notes.scss +++ b/app/assets/stylesheets/pages/notes.scss @@ -194,6 +194,21 @@ ul.notes { float: right; margin-left: 10px; color: $notes-action-color; + + .js-note-delete { + &:hover { + @extend .cgray; + &.danger { @extend .cred; } + } + } + + .js-note-edit { + i { + &:hover { + color: $gl-link-color; + } + } + } } .note-action-button, @@ -212,21 +227,6 @@ ul.notes { top: 0; font-size: 16px; } - - .js-note-delete { - &:hover { - @extend .cgray; - &.danger { @extend .cred; } - } - } - - .js-note-edit { - i { - &:hover { - color: $gl-link-color; - } - } - } } .discussion-toggle-button { From dab4ac54b691f1c832b1fe444859c3183a231411 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Fri, 1 Apr 2016 14:27:39 -0500 Subject: [PATCH 137/212] Diff design updates --- app/assets/stylesheets/framework/buttons.scss | 29 +++++++++++- app/assets/stylesheets/framework/files.scss | 5 ++- .../stylesheets/framework/timeline.scss | 4 -- .../stylesheets/framework/variables.scss | 18 +++++--- app/assets/stylesheets/highlight/white.scss | 4 +- app/assets/stylesheets/pages/diff.scss | 8 ++++ app/assets/stylesheets/pages/note_form.scss | 6 --- app/assets/stylesheets/pages/notes.scss | 44 ++++++++----------- app/helpers/blob_helper.rb | 6 +-- app/helpers/commits_helper.rb | 2 +- app/helpers/notes_helper.rb | 8 ++-- app/views/projects/diffs/_file.html.haml | 10 ++--- .../project/commits/diff_comments.feature | 7 ++- features/steps/shared/diff_note.rb | 4 +- spec/features/notes_on_merge_requests_spec.rb | 2 +- 15 files changed, 90 insertions(+), 67 deletions(-) diff --git a/app/assets/stylesheets/framework/buttons.scss b/app/assets/stylesheets/framework/buttons.scss index 657c5f033c..e8c0172680 100644 --- a/app/assets/stylesheets/framework/buttons.scss +++ b/app/assets/stylesheets/framework/buttons.scss @@ -7,6 +7,7 @@ &:focus, &:active { outline: none; + background-color: $btn-active-gray; @include box-shadow($gl-btn-active-background); } } @@ -27,7 +28,8 @@ color: $color; } - &:active { + &:active, + &.active { @include box-shadow ($gl-btn-active-background); background-color: $dark; @@ -61,7 +63,7 @@ } @mixin btn-white { - @include btn-color($white-light, $border-white-light, $white-normal, $border-white-normal, $white-dark, $border-white-dark, #313236); + @include btn-color($white-light, $border-color, $white-normal, $border-white-normal, $white-dark, $border-white-dark, $btn-white-active); } .btn { @@ -218,3 +220,26 @@ margin-right: 5px; } } + +.btn-text-field { + width: 100%; + text-align: left; + padding: 6px 16px; + border-color: $border-color; + color: $btn-placeholder-gray; + background-color: $background-color; + + &:hover, + &:active, + &:focus { + cursor: text; + box-shadow: none; + border-color: $border-color; + color: $btn-placeholder-gray; + background-color: $background-color; + } +} + +.btn-file-option { + background: linear-gradient(180deg, $white-light 25%, $gray-light 100%); +} diff --git a/app/assets/stylesheets/framework/files.scss b/app/assets/stylesheets/framework/files.scss index b15f4e7bd5..a7958467a1 100644 --- a/app/assets/stylesheets/framework/files.scss +++ b/app/assets/stylesheets/framework/files.scss @@ -15,12 +15,13 @@ .file-title { position: relative; - background: $background-color; + background-color: $background-color; border-bottom: 1px solid $border-color; margin: 0; text-align: left; padding: 10px $gl-padding; word-wrap: break-word; + border-radius: 3px 3px 0px 0px; .file-actions { float: right; @@ -49,7 +50,7 @@ } } - a { + a:not(.btn) { color: $gl-dark-link-color; } diff --git a/app/assets/stylesheets/framework/timeline.scss b/app/assets/stylesheets/framework/timeline.scss index aa244fe548..b91f2f6f89 100644 --- a/app/assets/stylesheets/framework/timeline.scss +++ b/app/assets/stylesheets/framework/timeline.scss @@ -14,10 +14,6 @@ background: $row-hover; } - &:last-child { - border-bottom: none; - } - .avatar { margin-right: 15px; } diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index 49f62c8850..185137a401 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -10,10 +10,10 @@ $gutter_inner_width: 258px; /* * UI elements */ -$border-color: #efeff1; +$border-color: #e5e5e5; $focus-border-color: #3aabf0; $table-border-color: #eef0f2; -$background-color: #faf9f9; +$background-color: #fafafa; /* * Text @@ -81,7 +81,7 @@ $provider-btn-not-active-color: #4688f1; $white-light: #fff; $white-normal: #ededed; -$white-dark: #ededed; +$white-dark: #ECECEC; $gray-light: #faf9f9; $gray-normal: #f5f5f5; @@ -152,8 +152,8 @@ $gl-success: $green-normal; $gl-info: $blue-normal; $gl-warning: $orange-normal; $gl-danger: $red-normal; -$gl-btn-active-background: rgba(0, 0, 0, 0.12); -$gl-btn-active-gradient: inset 0 0 4px $gl-btn-active-background; +$gl-btn-active-background: rgba(0, 0, 0, 0.16); +$gl-btn-active-gradient: inset 0 2px 3px $gl-btn-active-background; /* * Commit Diff Colors @@ -167,6 +167,7 @@ $line-removed-dark: #fac5cd; $line-number-old: #f9d7dc; $line-number-new: #ddfbe6; $match-line: #fafafa; +$table-border-gray: #f0f0f0; /* * Fonts */ @@ -199,6 +200,13 @@ $dropdown-toggle-hover-border-color: darken($dropdown-toggle-border-color, 15%); $dropdown-toggle-icon-color: #c4c4c4; $dropdown-toggle-hover-icon-color: $dropdown-toggle-hover-border-color; +/* +* Buttons +*/ +$btn-active-gray: #ECECEC; +$btn-placeholder-gray: #C7C7C7; +$btn-white-active: #848484; + /* * Award emoji */ diff --git a/app/assets/stylesheets/highlight/white.scss b/app/assets/stylesheets/highlight/white.scss index ea9bc98079..d68a28bbfd 100644 --- a/app/assets/stylesheets/highlight/white.scss +++ b/app/assets/stylesheets/highlight/white.scss @@ -6,12 +6,12 @@ } .diff-line-num, .diff-line-num a { - color: $black-transparent; + color: #8f8f8f; } // Code itself pre.code, .diff-line-num { - border-color: $border-color; + border-color: $table-border-gray; } &, pre.code, .line_holder .line_content { diff --git a/app/assets/stylesheets/pages/diff.scss b/app/assets/stylesheets/pages/diff.scss index 97f4485beb..5a99fffb54 100644 --- a/app/assets/stylesheets/pages/diff.scss +++ b/app/assets/stylesheets/pages/diff.scss @@ -2,6 +2,7 @@ .diff-file { border: 1px solid $border-color; margin-bottom: $gl-padding; + border-radius: 3px; .diff-header { position: relative; @@ -31,6 +32,7 @@ overflow-y: hidden; background: #fff; color: #333; + border-radius: 0 0 3px 3px; .unfold { cursor: pointer; @@ -325,6 +327,12 @@ float: right; } +.diffs { + .content-block { + border-bottom: none; + } +} + // Mobile @media (max-width: 480px) { .diff-title { diff --git a/app/assets/stylesheets/pages/note_form.scss b/app/assets/stylesheets/pages/note_form.scss index 9aec2c60e1..a6427f1912 100644 --- a/app/assets/stylesheets/pages/note_form.scss +++ b/app/assets/stylesheets/pages/note_form.scss @@ -1,11 +1,6 @@ /** * Note Form */ -.reply-btn { - @extend .btn-primary; - margin: 10px $gl-padding; -} - .comment-btn { @extend .btn-create; } @@ -118,7 +113,6 @@ .discussion-body, .diff-file { .notes .note { - border-color: #ddd; padding: 10px 15px; } diff --git a/app/assets/stylesheets/pages/notes.scss b/app/assets/stylesheets/pages/notes.scss index 93fcb81321..7295fe5112 100644 --- a/app/assets/stylesheets/pages/notes.scss +++ b/app/assets/stylesheets/pages/notes.scss @@ -58,6 +58,7 @@ ul.notes { .note { display: block; position: relative; + border-bottom: 1px solid $table-border-gray; &.is-editting { .note-header, @@ -117,9 +118,6 @@ ul.notes { padding-bottom: 3px; } - &:last-child { - border-bottom: 1px solid $border-color; - } } } @@ -137,14 +135,14 @@ ul.notes { font-family: $regular_font; td { - border: 1px solid #ddd; + border: 1px solid $table-border-gray; border-left: none; &.notes_line { vertical-align: middle; text-align: center; padding: 10px 0; - background: #fff; + background: $background-color; color: $text-color; } &.notes_line2 { @@ -175,9 +173,6 @@ ul.notes { } } - .author_link { - font-weight: 600; - } } .note-headline-light, @@ -194,21 +189,6 @@ ul.notes { float: right; margin-left: 10px; color: $notes-action-color; - - .js-note-delete { - &:hover { - @extend .cgray; - &.danger { @extend .cred; } - } - } - - .js-note-edit { - i { - &:hover { - color: $gl-link-color; - } - } - } } .note-action-button, @@ -218,14 +198,26 @@ ul.notes { line-height: 24px; .fa { + color: $notes-action-color; position: relative; top: 1px; font-size: 17px; } - .fa-trash-o { - top: 0; - font-size: 16px; + &.js-note-delete { + i { + &:hover { + color: $gl-text-red; + } + } + } + + &.js-note-edit { + i { + &:hover { + color: $gl-link-color; + } + } } } diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 820d69c230..9e59a295fc 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -27,9 +27,9 @@ module BlobHelper link_opts) if !on_top_of_branch?(project, ref) - button_tag "Edit", class: "btn btn-default disabled has-tooltip", title: "You can only edit files when you are on a branch", data: { container: 'body' } + button_tag "Edit", class: "btn disabled has-tooltip btn-file-option", title: "You can only edit files when you are on a branch", data: { container: 'body' } elsif can_edit_blob?(blob, project, ref) - link_to "Edit", edit_path, class: 'btn' + link_to "Edit", edit_path, class: 'btn btn-file-option' elsif can?(current_user, :fork_project, project) continue_params = { to: edit_path, @@ -38,7 +38,7 @@ module BlobHelper } fork_path = namespace_project_forks_path(project.namespace, project, namespace_key: current_user.namespace.id, continue: continue_params) - link_to "Edit", fork_path, class: 'btn', method: :post + link_to "Edit", fork_path, class: 'btn btn-file-option', method: :post end end diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index bde0799f3d..de50803688 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -197,7 +197,7 @@ module CommitsHelper link_to( namespace_project_blob_path(project.namespace, project, tree_join(commit_sha, diff.new_path)), - class: 'btn view-file js-view-file' + class: 'btn view-file js-view-file btn-file-option' ) do raw('View file @') + content_tag(:span, commit_sha[0..6], class: 'commit-short-id') diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index 681df89836..d86954c105 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -69,9 +69,9 @@ module NotesHelper line_type: line_type } - text_field_tag 'reply-field', nil, - placeholder: 'Reply...', - class: 'form-control note-reply-field js-discussion-reply-button', - data: data + button_tag class: 'btn btn-text-field js-discussion-reply-button', + data: data, title: 'Add a reply' do + link_text = 'Reply...' + end end end diff --git a/app/views/projects/diffs/_file.html.haml b/app/views/projects/diffs/_file.html.haml index 4d5461afeb..83a8d7ae9b 100644 --- a/app/views/projects/diffs/_file.html.haml +++ b/app/views/projects/diffs/_file.html.haml @@ -3,7 +3,7 @@ - if diff_file.diff.submodule? %span = icon('archive fw') - %strong + %span = submodule_link(blob, @commit.id, project.repository) - else = blob_icon blob.mode, blob.name @@ -11,13 +11,13 @@ = link_to "#diff-#{i}" do - if diff_file.renamed_file - old_path, new_path = mark_inline_diffs(diff_file.old_path, diff_file.new_path) - %strong.filename.old + .filename.old = old_path → - %strong.filename.new + .filename.new = new_path - else - %strong + %span = diff_file.new_path - if diff_file.deleted_file deleted @@ -28,7 +28,7 @@ .file-actions.hidden-xs - if blob_text_viewable?(blob) - = link_to '#', class: 'js-toggle-diff-comments btn active has-tooltip', title: "Toggle comments for this file" do + = link_to '#', class: 'js-toggle-diff-comments btn active has-tooltip btn-file-option', title: "Toggle comments for this file" do = icon('comment') \ diff --git a/features/project/commits/diff_comments.feature b/features/project/commits/diff_comments.feature index fdaa9e7a47..1dda2ff8a6 100644 --- a/features/project/commits/diff_comments.feature +++ b/features/project/commits/diff_comments.feature @@ -57,10 +57,9 @@ Feature: Project Commits Diff Comments Then I should see two separate previews @javascript - Scenario: I have can reply in discussions + Scenario: I have a reply button in discussions Given I leave a diff comment like "Typo, please fix" - Then I should see a discussion reply text field - + Then I should see a discussion reply button @javascript Scenario: I can preview with text Given I open a diff comment form @@ -83,7 +82,7 @@ Feature: Project Commits Diff Comments Given I preview a diff comment text like "Should fix it :smile:" And I submit the diff comment Then I should not see the diff comment form - And I should see a discussion reply text field + And I should see a discussion reply button @javascript Scenario: I can add a comment on a side-by-side commit diff (left side) diff --git a/features/steps/shared/diff_note.rb b/features/steps/shared/diff_note.rb index 05e5ee151a..1448c3f44c 100644 --- a/features/steps/shared/diff_note.rb +++ b/features/steps/shared/diff_note.rb @@ -153,9 +153,9 @@ module SharedDiffNote end end - step 'I should see a discussion reply text field' do + step 'I should see a discussion reply button' do page.within(diff_file_selector) do - expect(page).to have_css('.note-reply-field') + expect(page).to have_button('Reply...') end end diff --git a/spec/features/notes_on_merge_requests_spec.rb b/spec/features/notes_on_merge_requests_spec.rb index 9b2351c15d..5f855ccc70 100644 --- a/spec/features/notes_on_merge_requests_spec.rb +++ b/spec/features/notes_on_merge_requests_spec.rb @@ -210,7 +210,7 @@ describe 'Comments', feature: true do is_expected.to have_content('Another comment on line 10') is_expected.to have_css('.notes_holder') is_expected.to have_css('.notes_holder .note', count: 1) - is_expected.to have_css('.note-reply-field') + is_expected.to have_button('Reply...') end end end From 04e798a5154b2b2a86288f51081da8495f96bee5 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Wed, 6 Apr 2016 15:00:11 -0700 Subject: [PATCH 138/212] Remove comment count & icon --- app/views/projects/notes/_diff_notes_with_reply.html.haml | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/projects/notes/_diff_notes_with_reply.html.haml b/app/views/projects/notes/_diff_notes_with_reply.html.haml index 11f9859a90..39be072855 100644 --- a/app/views/projects/notes/_diff_notes_with_reply.html.haml +++ b/app/views/projects/notes/_diff_notes_with_reply.html.haml @@ -3,9 +3,6 @@ - if !defined?(line) || line == note.diff_line %tr.notes_holder %td.notes_line{ colspan: 2 } - %span.discussion-notes-count - %i.fa.fa-comment - = notes.count %td.notes_content %ul.notes{ data: { discussion_id: note.discussion_id } } = render notes From 6ee2069768279a9f9e03ae20f10b906a807a5eb7 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Wed, 6 Apr 2016 18:33:00 -0700 Subject: [PATCH 139/212] Fix lint errors --- app/assets/stylesheets/framework/files.scss | 2 +- app/assets/stylesheets/framework/variables.scss | 6 +++--- app/helpers/notes_helper.rb | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/framework/files.scss b/app/assets/stylesheets/framework/files.scss index a7958467a1..789df42fb6 100644 --- a/app/assets/stylesheets/framework/files.scss +++ b/app/assets/stylesheets/framework/files.scss @@ -21,7 +21,7 @@ text-align: left; padding: 10px $gl-padding; word-wrap: break-word; - border-radius: 3px 3px 0px 0px; + border-radius: 3px 3px 0 0; .file-actions { float: right; diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index 185137a401..1ebbd9b0e5 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -81,7 +81,7 @@ $provider-btn-not-active-color: #4688f1; $white-light: #fff; $white-normal: #ededed; -$white-dark: #ECECEC; +$white-dark: #ececec; $gray-light: #faf9f9; $gray-normal: #f5f5f5; @@ -203,8 +203,8 @@ $dropdown-toggle-hover-icon-color: $dropdown-toggle-hover-border-color; /* * Buttons */ -$btn-active-gray: #ECECEC; -$btn-placeholder-gray: #C7C7C7; +$btn-active-gray: #ececec; +$btn-placeholder-gray: #c7c7c7; $btn-white-active: #848484; /* diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb index d86954c105..95072b5373 100644 --- a/app/helpers/notes_helper.rb +++ b/app/helpers/notes_helper.rb @@ -69,9 +69,7 @@ module NotesHelper line_type: line_type } - button_tag class: 'btn btn-text-field js-discussion-reply-button', - data: data, title: 'Add a reply' do - link_text = 'Reply...' - end + button_tag 'Reply...', class: 'btn btn-text-field js-discussion-reply-button', + data: data, title: 'Add a reply' end end From d76878b96040c8ae4752600aceb30200fa0049a0 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Thu, 7 Apr 2016 12:36:53 -0700 Subject: [PATCH 140/212] Diff touch ups --- app/assets/stylesheets/highlight/white.scss | 2 +- app/assets/stylesheets/pages/diff.scss | 5 +++++ app/assets/stylesheets/pages/note_form.scss | 9 --------- app/views/projects/diffs/_diffs.html.haml | 2 +- features/project/commits/diff_comments.feature | 1 + 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/assets/stylesheets/highlight/white.scss b/app/assets/stylesheets/highlight/white.scss index d68a28bbfd..28331f5975 100644 --- a/app/assets/stylesheets/highlight/white.scss +++ b/app/assets/stylesheets/highlight/white.scss @@ -6,7 +6,7 @@ } .diff-line-num, .diff-line-num a { - color: #8f8f8f; + color: $black-transparent; } // Code itself diff --git a/app/assets/stylesheets/pages/diff.scss b/app/assets/stylesheets/pages/diff.scss index 5a99fffb54..d0855f6691 100644 --- a/app/assets/stylesheets/pages/diff.scss +++ b/app/assets/stylesheets/pages/diff.scss @@ -11,6 +11,7 @@ padding: 10px 16px; color: #555; z-index: 10; + border-radius: 3px 3px 0 0; .diff-title { font-family: $monospace_font; @@ -333,6 +334,10 @@ } } +.files-changed { + border-bottom: none; +} + // Mobile @media (max-width: 480px) { .diff-title { diff --git a/app/assets/stylesheets/pages/note_form.scss b/app/assets/stylesheets/pages/note_form.scss index a6427f1912..4d4d508396 100644 --- a/app/assets/stylesheets/pages/note_form.scss +++ b/app/assets/stylesheets/pages/note_form.scss @@ -182,12 +182,3 @@ float: left; } } - -.note-reply-field { - background-color: $background-color; - - &:focus { - box-shadow: none; - border-color: $border-color; - } -} diff --git a/app/views/projects/diffs/_diffs.html.haml b/app/views/projects/diffs/_diffs.html.haml index 2e1a37aa06..eaab99973a 100644 --- a/app/views/projects/diffs/_diffs.html.haml +++ b/app/views/projects/diffs/_diffs.html.haml @@ -3,7 +3,7 @@ - diff_files = safe_diff_files(diffs, diff_refs) -.content-block.oneline-block +.content-block.oneline-block.files-changed .inline-parallel-buttons .btn-group = inline_diff_btn diff --git a/features/project/commits/diff_comments.feature b/features/project/commits/diff_comments.feature index 1dda2ff8a6..2bde4c8a99 100644 --- a/features/project/commits/diff_comments.feature +++ b/features/project/commits/diff_comments.feature @@ -60,6 +60,7 @@ Feature: Project Commits Diff Comments Scenario: I have a reply button in discussions Given I leave a diff comment like "Typo, please fix" Then I should see a discussion reply button + @javascript Scenario: I can preview with text Given I open a diff comment form From e65bccfcc3956a13ffc04f0a72226afe97b6b69d Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Thu, 7 Apr 2016 15:32:54 -0700 Subject: [PATCH 141/212] Remove comment count & icon from side by side view --- .../notes/_diff_notes_with_reply_parallel.html.haml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml b/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml index bb761ed2f9..f8aa5e2fa7 100644 --- a/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml +++ b/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml @@ -4,9 +4,6 @@ %tr.notes_holder - if note1 %td.notes_line.old - %span.btn.disabled - %i.fa.fa-comment - = notes_left.count %td.notes_content.parallel.old %ul.notes{ data: { discussion_id: note1.discussion_id } } = render notes_left @@ -19,9 +16,6 @@ - if note2 %td.notes_line.new - %span.btn.disabled - %i.fa.fa-comment - = notes_right.count %td.notes_content.parallel.new %ul.notes{ data: { discussion_id: note2.discussion_id } } = render notes_right From fb2fde9d62a599f08c065c54de236eacb6558d60 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Fri, 8 Apr 2016 08:41:10 +0200 Subject: [PATCH 142/212] API: Expose subscribed? on issues --- CHANGELOG | 1 + doc/api/issues.md | 17 +++++++++++------ doc/api/merge_requests.md | 19 +++++++++++++------ lib/api/entities.rb | 8 ++++++++ lib/api/issues.rb | 10 +++++----- lib/api/merge_requests.rb | 14 +++++++------- lib/api/milestones.rb | 2 +- 7 files changed, 46 insertions(+), 25 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1d1e541e65..7d9cba320b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ v 8.7.0 (unreleased) - Allow back dating on issues when created through the API - Fix Error 500 after renaming a project path (Stan Hu) - Fix avatar stretching by providing a cropping feature + - API: Expose `subscribed` for issues and merge requests (Robert Schilling) - Allow SAML to handle external users based on user's information !3530 - Add endpoints to archive or unarchive a project !3372 - Add links to CI setup documentation from project settings and builds pages diff --git a/doc/api/issues.md b/doc/api/issues.md index cc6355d34e..1c635a6cdc 100644 --- a/doc/api/issues.md +++ b/doc/api/issues.md @@ -76,8 +76,9 @@ Example response: "title" : "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.", "created_at" : "2016-01-04T15:31:51.081Z", "iid" : 6, - "labels" : [] - }, + "labels" : [], + "subscribed" : false + } ] ``` @@ -152,7 +153,8 @@ Example response: "id" : 41, "title" : "Ut commodi ullam eos dolores perferendis nihil sunt.", "updated_at" : "2016-01-04T15:31:46.176Z", - "created_at" : "2016-01-04T15:31:46.176Z" + "created_at" : "2016-01-04T15:31:46.176Z", + "subscribed" : false } ] ``` @@ -213,7 +215,8 @@ Example response: "id" : 41, "title" : "Ut commodi ullam eos dolores perferendis nihil sunt.", "updated_at" : "2016-01-04T15:31:46.176Z", - "created_at" : "2016-01-04T15:31:46.176Z" + "created_at" : "2016-01-04T15:31:46.176Z", + "subscribed": false } ``` @@ -267,7 +270,8 @@ Example response: }, "description" : null, "updated_at" : "2016-01-07T12:44:33.959Z", - "milestone" : null + "milestone" : null, + "subscribed" : true } ``` @@ -323,7 +327,8 @@ Example response: ], "id" : 85, "assignee" : null, - "milestone" : null + "milestone" : null, + "subscribed" : true } ``` diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md index b20a6300b7..20db73ea6c 100644 --- a/doc/api/merge_requests.md +++ b/doc/api/merge_requests.md @@ -66,7 +66,8 @@ Parameters: "due_date": null }, "merge_when_build_succeeds": true, - "merge_status": "can_be_merged" + "merge_status": "can_be_merged", + "subscribed" : false } ] ``` @@ -128,7 +129,8 @@ Parameters: "due_date": null }, "merge_when_build_succeeds": true, - "merge_status": "can_be_merged" + "merge_status": "can_be_merged", + "subscribed" : true } ``` @@ -227,6 +229,7 @@ Parameters: }, "merge_when_build_succeeds": true, "merge_status": "can_be_merged", + "subscribed" : true, "changes": [ { "old_path": "VERSION", @@ -304,7 +307,8 @@ Parameters: "due_date": null }, "merge_when_build_succeeds": true, - "merge_status": "can_be_merged" + "merge_status": "can_be_merged", + "subscribed" : true } ``` @@ -373,7 +377,8 @@ Parameters: "due_date": null }, "merge_when_build_succeeds": true, - "merge_status": "can_be_merged" + "merge_status": "can_be_merged", + "subscribed" : true } ``` @@ -466,7 +471,8 @@ Parameters: "due_date": null }, "merge_when_build_succeeds": true, - "merge_status": "can_be_merged" + "merge_status": "can_be_merged", + "subscribed" : true } ``` @@ -530,7 +536,8 @@ Parameters: "due_date": null }, "merge_when_build_succeeds": true, - "merge_status": "can_be_merged" + "merge_status": "can_be_merged", + "subscribed" : true } ``` diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 4c49442bf8..d76b46b883 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -170,6 +170,10 @@ module API expose :label_names, as: :labels expose :milestone, using: Entities::Milestone expose :assignee, :author, using: Entities::UserBasic + + expose :subscribed do |issue, options| + issue.subscribed?(options[:current_user]) + end end class MergeRequest < ProjectEntity @@ -183,6 +187,10 @@ module API expose :milestone, using: Entities::Milestone expose :merge_when_build_succeeds expose :merge_status + + expose :subscribed do |merge_request, options| + merge_request.subscribed?(options[:current_user]) + end end class MergeRequestChanges < MergeRequest diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 1fee1dee1a..c4ea05ee6c 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -55,7 +55,7 @@ module API issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? issues.reorder(issuable_order_by => issuable_sort) - present paginate(issues), with: Entities::Issue + present paginate(issues), with: Entities::Issue, current_user: current_user end end @@ -92,7 +92,7 @@ module API end issues.reorder(issuable_order_by => issuable_sort) - present paginate(issues), with: Entities::Issue + present paginate(issues), with: Entities::Issue, current_user: current_user end # Get a single project issue @@ -105,7 +105,7 @@ module API get ":id/issues/:issue_id" do @issue = user_project.issues.find(params[:issue_id]) not_found! unless can?(current_user, :read_issue, @issue) - present @issue, with: Entities::Issue + present @issue, with: Entities::Issue, current_user: current_user end # Create a new project issue @@ -149,7 +149,7 @@ module API issue.add_labels_by_names(params[:labels].split(',')) end - present issue, with: Entities::Issue + present issue, with: Entities::Issue, current_user: current_user else render_validation_error!(issue) end @@ -189,7 +189,7 @@ module API issue.add_labels_by_names(params[:labels].split(',')) end - present issue, with: Entities::Issue + present issue, with: Entities::Issue, current_user: current_user else render_validation_error!(issue) end diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 93052fba06..4e7de8867b 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -56,7 +56,7 @@ module API end merge_requests = merge_requests.reorder(issuable_order_by => issuable_sort) - present paginate(merge_requests), with: Entities::MergeRequest + present paginate(merge_requests), with: Entities::MergeRequest, current_user: current_user end # Create MR @@ -94,7 +94,7 @@ module API merge_request.add_labels_by_names(params[:labels].split(",")) end - present merge_request, with: Entities::MergeRequest + present merge_request, with: Entities::MergeRequest, current_user: current_user else handle_merge_request_errors! merge_request.errors end @@ -130,7 +130,7 @@ module API authorize! :read_merge_request, merge_request - present merge_request, with: Entities::MergeRequest + present merge_request, with: Entities::MergeRequest, current_user: current_user end # Show MR commits @@ -162,7 +162,7 @@ module API merge_request = user_project.merge_requests. find(params[:merge_request_id]) authorize! :read_merge_request, merge_request - present merge_request, with: Entities::MergeRequestChanges + present merge_request, with: Entities::MergeRequestChanges, current_user: current_user end # Update MR @@ -204,7 +204,7 @@ module API merge_request.add_labels_by_names(params[:labels].split(",")) end - present merge_request, with: Entities::MergeRequest + present merge_request, with: Entities::MergeRequest, current_user: current_user else handle_merge_request_errors! merge_request.errors end @@ -246,7 +246,7 @@ module API execute(merge_request) end - present merge_request, with: Entities::MergeRequest + present merge_request, with: Entities::MergeRequest, current_user: current_user end # Cancel Merge if Merge When build succeeds is enabled @@ -325,7 +325,7 @@ module API get "#{path}/closes_issues" do merge_request = user_project.merge_requests.find(params[:merge_request_id]) issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user)) - present paginate(issues), with: Entities::Issue + present paginate(issues), with: Entities::Issue, current_user: current_user end end end diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index afb6ffa360..0f3f505fa0 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -103,7 +103,7 @@ module API authorize! :read_milestone, user_project @milestone = user_project.milestones.find(params[:milestone_id]) - present paginate(@milestone.issues), with: Entities::Issue + present paginate(@milestone.issues), with: Entities::Issue, current_user: current_user end end From aa7cddc4fcd490ccd192d7d04fb67b375705b586 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 8 Apr 2016 16:25:17 +0200 Subject: [PATCH 143/212] Use more accurate timestamps for InfluxDB. This changes the timestamp of metrics to be more accurate/unique by using Time#to_f combined with a small random jitter value. This combination hopefully reduces the amount of collisions, though there's no way to fully prevent any from occurring. Fixes gitlab-com/operations#175 --- lib/gitlab/metrics/metric.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/metrics/metric.rb b/lib/gitlab/metrics/metric.rb index 7ea9555cc8..1cd1ca30f7 100644 --- a/lib/gitlab/metrics/metric.rb +++ b/lib/gitlab/metrics/metric.rb @@ -2,6 +2,8 @@ module Gitlab module Metrics # Class for storing details of a single metric (label, value, etc). class Metric + JITTER_RANGE = 0.000001..0.001 + attr_reader :series, :values, :tags, :created_at # series - The name of the series (as a String) to store the metric in. @@ -16,11 +18,29 @@ module Gitlab # Returns a Hash in a format that can be directly written to InfluxDB. def to_hash + # InfluxDB overwrites an existing point if a new point has the same + # series, tag set, and timestamp. In a highly concurrent environment + # this means that using the number of seconds since the Unix epoch is + # inevitably going to collide with another timestamp. For example, two + # Rails requests processed by different processes may end up generating + # metrics using the _exact_ same timestamp (in seconds). + # + # Due to the way InfluxDB is set up there's no solution to this problem, + # all we can do is lower the amount of collisions. We do this by using + # Time#to_f which returns the seconds as a Float providing greater + # accuracy. We then add a small random value that is large enough to + # distinguish most timestamps but small enough to not alter the amount + # of seconds. + # + # See https://gitlab.com/gitlab-com/operations/issues/175 for more + # information. + time = @created_at.to_f + rand(JITTER_RANGE) + { series: @series, tags: @tags, values: @values, - timestamp: @created_at.to_i * 1_000_000_000 + timestamp: (time * 1_000_000_000).to_i } end end From c56f702ec3806606459e4edc3de097f1bb6baf4e Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 8 Apr 2016 17:54:52 +0200 Subject: [PATCH 144/212] Instrument Rails cache code This allows us to track how much time of a transaction is spent in dealing with cached data. --- config/initializers/metrics.rb | 1 + lib/gitlab/metrics/subscribers/rails_cache.rb | 39 ++++++++++ .../metrics/subscribers/rails_cache_spec.rb | 71 +++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 lib/gitlab/metrics/subscribers/rails_cache.rb create mode 100644 spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb diff --git a/config/initializers/metrics.rb b/config/initializers/metrics.rb index 3e1deb8d30..a9fc38fb04 100644 --- a/config/initializers/metrics.rb +++ b/config/initializers/metrics.rb @@ -7,6 +7,7 @@ if Gitlab::Metrics.enabled? # ActiveSupport. require 'gitlab/metrics/subscribers/action_view' require 'gitlab/metrics/subscribers/active_record' + require 'gitlab/metrics/subscribers/rails_cache' Gitlab::Application.configure do |config| config.middleware.use(Gitlab::Metrics::RackMiddleware) diff --git a/lib/gitlab/metrics/subscribers/rails_cache.rb b/lib/gitlab/metrics/subscribers/rails_cache.rb new file mode 100644 index 0000000000..49e5f86e6e --- /dev/null +++ b/lib/gitlab/metrics/subscribers/rails_cache.rb @@ -0,0 +1,39 @@ +module Gitlab + module Metrics + module Subscribers + # Class for tracking the total time spent in Rails cache calls + class RailsCache < ActiveSupport::Subscriber + attach_to :active_support + + def cache_read(event) + increment(:cache_read_duration, event.duration) + end + + def cache_write(event) + increment(:cache_write_duration, event.duration) + end + + def cache_delete(event) + increment(:cache_delete_duration, event.duration) + end + + def cache_exist?(event) + increment(:cache_exists_duration, event.duration) + end + + def increment(key, duration) + return unless current_transaction + + current_transaction.increment(:cache_duration, duration) + current_transaction.increment(key, duration) + end + + private + + def current_transaction + Transaction.current + end + end + end + end +end diff --git a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb new file mode 100644 index 0000000000..e01b0b4bd2 --- /dev/null +++ b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe Gitlab::Metrics::Subscribers::RailsCache do + let(:transaction) { Gitlab::Metrics::Transaction.new } + let(:subscriber) { described_class.new } + + let(:event) { double(:event, duration: 15.2) } + + describe '#cache_read' do + it 'increments the cache_read duration' do + expect(subscriber).to receive(:increment). + with(:cache_read_duration, event.duration) + + subscriber.cache_read(event) + end + end + + describe '#cache_write' do + it 'increments the cache_write duration' do + expect(subscriber).to receive(:increment). + with(:cache_write_duration, event.duration) + + subscriber.cache_write(event) + end + end + + describe '#cache_delete' do + it 'increments the cache_delete duration' do + expect(subscriber).to receive(:increment). + with(:cache_delete_duration, event.duration) + + subscriber.cache_delete(event) + end + end + + describe '#cache_exist?' do + it 'increments the cache_exists duration' do + expect(subscriber).to receive(:increment). + with(:cache_exists_duration, event.duration) + + subscriber.cache_exist?(event) + end + end + + describe '#increment' do + context 'without a transaction' do + it 'returns' do + expect(transaction).not_to receive(:increment) + + subscriber.increment(:foo, 15.2) + end + end + + context 'with a transaction' do + before do + allow(subscriber).to receive(:current_transaction). + and_return(transaction) + end + + it 'increments the total and specific cache duration' do + expect(transaction).to receive(:increment). + with(:cache_duration, event.duration) + + expect(transaction).to receive(:increment). + with(:cache_delete_duration, event.duration) + + subscriber.increment(:cache_delete_duration, event.duration) + end + end + end +end From f9014e4ec60a87608c65028dcf5fa411a6145b4e Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Fri, 8 Apr 2016 09:46:32 -0700 Subject: [PATCH 145/212] Use meta key to open todo in new tab --- app/assets/javascripts/todos.js.coffee | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/todos.js.coffee b/app/assets/javascripts/todos.js.coffee index ec2df6c5b7..886da72e26 100644 --- a/app/assets/javascripts/todos.js.coffee +++ b/app/assets/javascripts/todos.js.coffee @@ -57,5 +57,10 @@ class @Todos $('.todos-pending .badge, .todos-pending-count').text data.count $('.todos-done .badge').text data.done_count - goToTodoUrl: -> - Turbolinks.visit($(this).data('url')) + goToTodoUrl: (e)-> + todoLink = $(this).data('url') + if e.metaKey + e.preventDefault() + window.open(todoLink,'_blank') + else + Turbolinks.visit(todoLink) From 6a0f839941ae367cb542fd59685b8f394f59fe75 Mon Sep 17 00:00:00 2001 From: connorshea Date: Fri, 8 Apr 2016 13:32:17 -0600 Subject: [PATCH 146/212] Add a missing Oxford comma in some text on the Activity graph. Resolves #14668. [ci skip] --- app/views/users/calendar.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/calendar.html.haml b/app/views/users/calendar.html.haml index 7f29918dba..1de71f37d1 100644 --- a/app/views/users/calendar.html.haml +++ b/app/views/users/calendar.html.haml @@ -7,4 +7,4 @@ '#{user_calendar_activities_path}' ); -.calendar-hint Summary of issues, merge requests and push events +.calendar-hint Summary of issues, merge requests, and push events From 3a196317abe1899b2b3c61fa97bed797c80456b9 Mon Sep 17 00:00:00 2001 From: connorshea Date: Thu, 7 Apr 2016 17:40:22 -0600 Subject: [PATCH 147/212] Add "sprite" parameter to emoji_icon helper The emoji_icon helper used to display the award emoji in Issue and Merge Request views. By default the spritesheet is used, but passing `sprite: false` to the `emoji_icon` helper makes the emoji render as separate images. For award emoji displayed by default (e.g. thumbs-up, thumbs-down, and any that have been awarded to the issue/MR) the independent images are used. Only when the full emoji menu is opened does the full spritesheet load. On a normal issue this change decreases the page load by 670KB or 250KB depending on pixel density. Resolves #14334. --- CHANGELOG | 1 + app/helpers/issues_helper.rb | 33 +++++++++++++++++++------- app/views/votes/_votes_block.html.haml | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 54d79259b3..0997c15cfd 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 8.7.0 (unreleased) + - Load award emoji images separately unless opening the full picker. Saves several hundred KBs of data for most pages. (Connor Shea) - All images in discussions and wikis now link to their source files !3464 (Connor Shea). - Return status code 303 after a branch DELETE operation to avoid project deletion (Stan Hu) - Improved Markdown rendering performance !3389 (Yorick Peterse) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 24b90fef4f..bcf8639c82 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -115,17 +115,32 @@ module IssuesHelper icon('eye-slash') if issue.confidential? end - def emoji_icon(name, unicode = nil, aliases = []) + def emoji_icon(name, unicode = nil, aliases = [], sprite: true) unicode ||= Emoji.emoji_filename(name) rescue "" - content_tag :div, "", - class: "icon emoji-icon emoji-#{unicode}", - title: name, - data: { - aliases: aliases.join(' '), - emoji: name, - unicode_name: unicode - } + data = { + aliases: aliases.join(" "), + emoji: name, + unicode_name: unicode + } + + if sprite + # Emoji icons for the emoji menu, these use a spritesheet. + content_tag :div, "", + class: "icon emoji-icon emoji-#{unicode}", + title: name, + data: data + else + # Emoji icons displayed separately, used for the awards already given + # to an issue or merge request. + content_tag :img, "", + class: "icon emoji", + title: name, + height: "20px", + width: "20px", + src: url_to_image("#{unicode}.png"), + data: data + end end def emoji_author_list(notes, current_user) diff --git a/app/views/votes/_votes_block.html.haml b/app/views/votes/_votes_block.html.haml index 8ffcdc4a32..49cfcd53d7 100644 --- a/app/views/votes/_votes_block.html.haml +++ b/app/views/votes/_votes_block.html.haml @@ -1,7 +1,7 @@ .awards.votes-block - awards_sort(votable.notes.awards.grouped_awards).each do |emoji, notes| %button.btn.award-control.js-emoji-btn.has-tooltip{class: (note_active_class(notes, current_user)), title: emoji_author_list(notes, current_user), data: {placement: "top"}} - = emoji_icon(emoji) + = emoji_icon(emoji, sprite: false) %span.award-control-text.js-counter = notes.count From cedcc1453cbbd4a8ba43cf932b8765d891f19e0c Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 9 Apr 2016 01:19:21 -0400 Subject: [PATCH 148/212] Minor Testing guide copyedits [ci skip] --- doc/development/testing.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/development/testing.md b/doc/development/testing.md index 23417845f1..672e3fb464 100644 --- a/doc/development/testing.md +++ b/doc/development/testing.md @@ -16,16 +16,18 @@ GitLab uses [factory_girl] as a test fixture replacement. - Factory definitions live in `spec/factories/`, named using the pluralization of their corresponding model (`User` factories are defined in `users.rb`). - There should be only one top-level factory definition per file. -- Make use of [Traits] to clean up definitions and usages. +- FactoryGirl methods are mixed in to all RSpec groups. This means you can (and + should) call `create(...)` instead of `FactoryGirl.create(...)`. +- Make use of [traits] to clean up definitions and usages. - When defining a factory, don't define attributes that are not required for the resulting record to pass validation. -- When instantiating from a factory, don't supply extraneous attributes that - aren't required by the test. +- When instantiating from a factory, don't supply attributes that aren't + required by the test. - Factories don't have to be limited to `ActiveRecord` objects. [See example](https://gitlab.com/gitlab-org/gitlab-ce/commit/0b8cefd3b2385a21cfed779bd659978c0402766d). [factory_girl]: https://github.com/thoughtbot/factory_girl -[Traits]: http://www.rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md#Traits +[traits]: http://www.rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md#Traits ## JavaScript @@ -40,9 +42,9 @@ the command line via `bundle exec teaspoon`, or via a web browser at `spec/javascripts/fixtures`. They should contain the bare minimum amount of markup necessary for the test. - > **Warning:** Keep in mind that a Rails view may change and - invalidate your test, but everything will still pass because your fixture - doesn't reflect the latest view. + > **Warning:** Keep in mind that a Rails view may change and + invalidate your test, but everything will still pass because your fixture + doesn't reflect the latest view. - Keep in mind that in a CI environment, these tests are run in a headless browser and you will not have access to certain APIs, such as @@ -102,7 +104,7 @@ Here are some things to keep in mind regarding test performance: - Don't `create` an object when `build`, `build_stubbed`, `attributes_for`, `spy`, or `double` will do. Database persistence is slow! - Use `create(:empty_project)` instead of `create(:project)` when you don't need - the underlying repository. Filesystem operations are slow! + the underlying Git repository. Filesystem operations are slow! - Don't mark a feature as requiring JavaScript (through `@javascript` in Spinach or `js: true` in RSpec) unless it's _actually_ required for the test to be valid. Headless browser testing is slow! From 1647e3e8849991629f5ebf1a11f9ca06e8f741ea Mon Sep 17 00:00:00 2001 From: connorshea Date: Sat, 9 Apr 2016 08:29:57 -0600 Subject: [PATCH 149/212] Upgrade Sprockets from 3.3.5 to 3.6.0. Sprockets 3.5.0 reintroduces GZIP-ing and 3.6.0 includes performance improvements. Changelog: https://github.com/rails/sprockets/blob/3.x/CHANGELOG.md Resolves #14344. --- Gemfile | 2 +- Gemfile.lock | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 3f29df0d81..298cfd260b 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'responders', '~> 2.0' # Specify a sprockets version due to increased performance # See https://gitlab.com/gitlab-org/gitlab-ce/issues/6069 -gem 'sprockets', '~> 3.3.5' +gem 'sprockets', '~> 3.6.0' # Default values for AR models gem "default_value_for", "~> 3.0.0" diff --git a/Gemfile.lock b/Gemfile.lock index 7eb4080183..28b71ac7bc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -776,7 +776,8 @@ GEM spring (>= 0.9.1) spring-commands-teaspoon (0.0.2) spring (>= 0.9.1) - sprockets (3.3.5) + sprockets (3.6.0) + concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.0.4) actionpack (>= 4.0) @@ -1033,7 +1034,7 @@ DEPENDENCIES spring-commands-rspec (~> 1.0.4) spring-commands-spinach (~> 1.0.0) spring-commands-teaspoon (~> 0.0.2) - sprockets (~> 3.3.5) + sprockets (~> 3.6.0) state_machines-activerecord (~> 0.3.0) task_list (~> 1.0.2) teaspoon (~> 1.1.0) From fb8afae1863c5daa6b1fbce04755fa573302b607 Mon Sep 17 00:00:00 2001 From: connorshea Date: Sat, 9 Apr 2016 11:28:47 -0600 Subject: [PATCH 150/212] Apparently I missed updating the schema.rb when removing the Twitter "Congrats" button From commit 85cc1729596ac1e5b31d8cfa1daa07477db6033d --- db/schema.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index e63e22ce86..ec235c1913 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160331133914) do +ActiveRecord::Schema.define(version: 20160331223143) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -44,7 +44,6 @@ ActiveRecord::Schema.define(version: 20160331133914) do t.datetime "updated_at" t.string "home_page_url" t.integer "default_branch_protection", default: 2 - t.boolean "twitter_sharing_enabled", default: true t.text "restricted_visibility_levels" t.boolean "version_check_enabled", default: true t.integer "max_attachment_size", default: 10, null: false From ca823065a905f8c19b2003a67e79831ba1ceff2e Mon Sep 17 00:00:00 2001 From: Benjamin Montgomery Date: Sat, 9 Apr 2016 20:51:15 +0000 Subject: [PATCH 151/212] actually enable artifacts --- doc/ci/build_artifacts/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ci/build_artifacts/README.md b/doc/ci/build_artifacts/README.md index 71db5aa5dc..bd26da2af6 100644 --- a/doc/ci/build_artifacts/README.md +++ b/doc/ci/build_artifacts/README.md @@ -31,7 +31,7 @@ To disable it site-wide, follow the steps below. 1. Edit `/etc/gitlab/gitlab.rb` and add the following line: ```ruby - gitlab_rails['artifacts_enabled'] = false + gitlab_rails['artifacts_enabled'] = true ``` 1. Save the file and [reconfigure GitLab][] for the changes to take effect. @@ -44,7 +44,7 @@ To disable it site-wide, follow the steps below. ```yaml artifacts: - enabled: false + enabled: true ``` 1. Save the file and [restart GitLab][] for the changes to take effect. From 44d9f52fd9dba09c352f64bb742291e5adab423a Mon Sep 17 00:00:00 2001 From: connorshea Date: Sat, 9 Apr 2016 16:31:41 -0600 Subject: [PATCH 152/212] Enable asset compression in production. `config.assets.compress` needed to be explicitly enabled. Follow-up to !3544. Resolves #14344. --- CHANGELOG | 1 + config/environments/production.rb | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index c25ee3c71d..b5dcc8bc8a 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 8.7.0 (unreleased) + - Enable gzip for assets, makes the page size significantly smaller. !3544 / !3632 (Connor Shea) - Load award emoji images separately unless opening the full picker. Saves several hundred KBs of data for most pages. (Connor Shea) - All images in discussions and wikis now link to their source files !3464 (Connor Shea). - Return status code 303 after a branch DELETE operation to avoid project deletion (Stan Hu) diff --git a/config/environments/production.rb b/config/environments/production.rb index 909526605a..a9d8ac4b6d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -21,6 +21,9 @@ Rails.application.configure do # Generate digests for assets URLs config.assets.digest = true + # Enable compression of compiled assets using gzip. + config.assets.compress = true + # Defaults to nil and saved in location specified by config.assets.prefix # config.assets.manifest = YOUR_PATH From b95c9217b75d84412d9a3e4f52f31158329755f4 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Fri, 1 Apr 2016 17:27:28 +0100 Subject: [PATCH 153/212] prevent users from being able to both upvote and downvote --- app/assets/javascripts/awards_handler.coffee | 15 +++++++++++++-- app/views/votes/_votes_block.html.haml | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/awards_handler.coffee b/app/assets/javascripts/awards_handler.coffee index 6a670d5e88..af4462ece3 100644 --- a/app/assets/javascripts/awards_handler.coffee +++ b/app/assets/javascripts/awards_handler.coffee @@ -22,8 +22,19 @@ class @AwardsHandler emoji = $(this) .find(".icon") .data "emoji" + + if emoji is "thumbsup" and awards_handler.didUserClickEmoji $(this), "thumbsdown" + awards_handler.addAward "thumbsdown" + + else if emoji is "thumbsdown" and awards_handler.didUserClickEmoji $(this), "thumbsup" + awards_handler.addAward "thumbsup" + awards_handler.addAward emoji + didUserClickEmoji: (that, emoji) -> + if $(that).siblings("button:has([data-emoji=#{emoji}])").attr("data-original-title") + $(that).siblings("button:has([data-emoji=#{emoji}])").attr("data-original-title").indexOf('me') > -1 + showEmojiMenu: -> if $(".emoji-menu").length if $(".emoji-menu").is ".is-visible" @@ -105,7 +116,7 @@ class @AwardsHandler if origTitle authors = origTitle.split(', ') authors.push("me") - award_block.attr("title", authors.join(", ")) + award_block.attr("data-original-title", authors.join(", ")) @resetTooltip(award_block) resetTooltip: (award) -> @@ -122,7 +133,7 @@ class @AwardsHandler nodes = [] nodes.push( - "" diff --git a/app/views/votes/_votes_block.html.haml b/app/views/votes/_votes_block.html.haml index 49cfcd53d7..dc249155b9 100644 --- a/app/views/votes/_votes_block.html.haml +++ b/app/views/votes/_votes_block.html.haml @@ -1,6 +1,6 @@ .awards.votes-block - awards_sort(votable.notes.awards.grouped_awards).each do |emoji, notes| - %button.btn.award-control.js-emoji-btn.has-tooltip{class: (note_active_class(notes, current_user)), title: emoji_author_list(notes, current_user), data: {placement: "top"}} + %button.btn.award-control.js-emoji-btn.has-tooltip{class: (note_active_class(notes, current_user)), data: {placement: "top", original_title: emoji_author_list(notes, current_user)}} = emoji_icon(emoji, sprite: false) %span.award-control-text.js-counter = notes.count From 91905ae3f5a9f755258b770482cd45916ee47fe4 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Tue, 5 Apr 2016 23:26:17 +0100 Subject: [PATCH 154/212] write test to prevent reoccurence of issue --- spec/features/issues/award_emoji_spec.rb | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 spec/features/issues/award_emoji_spec.rb diff --git a/spec/features/issues/award_emoji_spec.rb b/spec/features/issues/award_emoji_spec.rb new file mode 100644 index 0000000000..41af789aae --- /dev/null +++ b/spec/features/issues/award_emoji_spec.rb @@ -0,0 +1,64 @@ +require 'rails_helper' + +describe 'Awards Emoji', feature: true do + let!(:project) { create(:project) } + let!(:user) { create(:user) } + + before do + project.team << [user, :master] + login_as(user) + end + + describe 'Click award emoji from issue#show' do + let!(:issue) do + create(:issue, + author: @user, + assignee: @user, + project: project) + end + + before do + visit namespace_project_issue_path(project.namespace, project, issue) + end + + it 'should increment the thumbsdown emoji', js: true do + find('[data-emoji="thumbsdown"]').click + sleep 2 + expect(thumbsdown_emoji).to have_text("1") + end + + context 'click the thumbsup emoji' do + + it 'should increment the thumbsup emoji', js: true do + find('[data-emoji="thumbsup"]').click + sleep 2 + expect(thumbsup_emoji).to have_text("1") + end + + it 'should decrement the thumbsdown emoji', js: true do + expect(thumbsdown_emoji).to have_text("0") + end + end + + context 'click the thumbsdown emoji' do + + it 'should increment the thumbsdown emoji', js: true do + find('[data-emoji="thumbsdown"]').click + sleep 2 + expect(thumbsdown_emoji).to have_text("1") + end + + it 'should decrement the thumbsup emoji', js: true do + expect(thumbsup_emoji).to have_text("0") + end + end + end + + def thumbsup_emoji + page.all('span.js-counter').first + end + + def thumbsdown_emoji + page.all('span.js-counter').last + end +end From 2378ec0d635a4dbe0d1716a86bb3e3d038518e94 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 9 Apr 2016 19:32:22 -0400 Subject: [PATCH 155/212] Add a `program` tag to Sentry Raven context This will let us filter errors by the program environment in which they were encountered. Source: http://stackoverflow.com/a/28370539/223897 Closes #15092 --- app/controllers/application_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c81cb85dc1..97d53acde9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -47,6 +47,16 @@ class ApplicationController < ActionController::Base email: current_user.email, username: current_user.username, ) + + Raven.tags_context(program: sentry_program_context) + end + end + + def sentry_program_context + if Sidekiq.server? + 'sidekiq' + else + 'rails' end end From f03b5c4fde1bd6eb415457e60d3c79fbd9c2e4ee Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 9 Apr 2016 20:02:36 -0400 Subject: [PATCH 156/212] Remove tab stop from "Write", "Preview", "Go full screen" links Closes #15089 --- app/views/projects/_md_preview.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/projects/_md_preview.html.haml b/app/views/projects/_md_preview.html.haml index 4920910fee..7a78d61a61 100644 --- a/app/views/projects/_md_preview.html.haml +++ b/app/views/projects/_md_preview.html.haml @@ -2,13 +2,13 @@ .md-header %ul.nav-links %li.active - %a.js-md-write-button{ href: "#md-write-holder" } + %a.js-md-write-button{ href: "#md-write-holder", tabindex: -1 } Write %li - %a.js-md-preview-button{ href: "#md-preview-holder" } + %a.js-md-preview-button{ href: "#md-preview-holder", tabindex: -1 } Preview %li.pull-right - %button.zen-cotrol.zen-control-full.js-zen-enter{ type: 'button' } + %button.zen-cotrol.zen-control-full.js-zen-enter{ type: 'button', tabindex: -1 } Go full screen .md-write-holder From 98f536f1693d59942d91e18ece499bb35ec55259 Mon Sep 17 00:00:00 2001 From: Sytse Sijbrandij Date: Sat, 9 Apr 2016 20:09:07 -0400 Subject: [PATCH 157/212] Everything on one page. --- doc/integration/README.md | 17 +++-------------- doc/project_services/project_services.md | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/doc/integration/README.md b/doc/integration/README.md index 7c8f785a61..6fe04aa2a0 100644 --- a/doc/integration/README.md +++ b/doc/integration/README.md @@ -19,26 +19,15 @@ See the documentation below for details on how to configure these services. GitLab Enterprise Edition contains [advanced Jenkins support][jenkins]. +[jenkins]: http://doc.gitlab.com/ee/integration/jenkins.html + + ## Project services Integration with services such as Campfire, Flowdock, Gemnasium, HipChat, Pivotal Tracker, and Slack are available in the form of a [Project Service][]. -You can find these within GitLab in the Services page under Project Settings if -you are at least a master on the project. -Project Services are a bit like plugins in that they allow a lot of freedom in -adding functionality to GitLab. For example there is also a service that can -send an email every time someone pushes new commits. -Because GitLab is open source we can ship with the code and tests for all -plugins. This allows the community to keep the plugins up to date so that they -always work in newer GitLab versions. - -For an overview of what projects services are available without logging in, -please see the [project_services directory][projects-code]. - -[jenkins]: http://doc.gitlab.com/ee/integration/jenkins.html [Project Service]: ../project_services/project_services.md -[projects-code]: https://gitlab.com/gitlab-org/gitlab-ce/tree/master/app/models/project_services ## SSL certificate errors diff --git a/doc/project_services/project_services.md b/doc/project_services/project_services.md index 3fea2cff0b..a5af620d9b 100644 --- a/doc/project_services/project_services.md +++ b/doc/project_services/project_services.md @@ -1,7 +1,24 @@ # Project Services Project services allow you to integrate GitLab with other applications. Below -is list of the currently supported ones. Click on the service links to see +is list of the currently supported ones. + +You can find these within GitLab in the Services page under Project Settings if +you are at least a master on the project. +Project Services are a bit like plugins in that they allow a lot of freedom in +adding functionality to GitLab. For example there is also a service that can +send an email every time someone pushes new commits. + +Because GitLab is open source we can ship with the code and tests for all +plugins. This allows the community to keep the plugins up to date so that they +always work in newer GitLab versions. + +For an overview of what projects services are available without logging in, +please see the [project_services directory][projects-code]. + +[projects-code]: https://gitlab.com/gitlab-org/gitlab-ce/tree/master/app/models/project_services + +Click on the service links to see further configuration instructions and details. Contributions are welcome. ## Services From f833726ec048b0ddf85fa8d194956f71c6334785 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 9 Apr 2016 20:43:59 -0400 Subject: [PATCH 158/212] Remove `random_markdown_tip` helper Only usage got removed in !3442 --- app/helpers/gitlab_markdown_helper.rb | 23 --------------------- spec/helpers/gitlab_markdown_helper_spec.rb | 7 ------- 2 files changed, 30 deletions(-) diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index 2f760af02f..3a45205563 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -116,29 +116,6 @@ module GitlabMarkdownHelper end end - MARKDOWN_TIPS = [ - "End a line with two or more spaces for a line-break, or soft-return", - "Inline code can be denoted by `surrounding it with backticks`", - "Blocks of code can be denoted by three backticks ``` or four leading spaces", - "Emoji can be added by :emoji_name:, for example :thumbsup:", - "Notify other participants using @user_name", - "Notify a specific group using @group_name", - "Notify the entire team using @all", - "Reference an issue using a hash, for example issue #123", - "Reference a merge request using an exclamation point, for example MR !123", - "Italicize words or phrases using *asterisks* or _underscores_", - "Bold words or phrases using **double asterisks** or __double underscores__", - "Strikethrough words or phrases using ~~two tildes~~", - "Make a bulleted list using + pluses, - minuses, or * asterisks", - "Denote blockquotes using > at the beginning of a line", - "Make a horizontal line using three or more hyphens ---, asterisks ***, or underscores ___" - ].freeze - - # Returns a random markdown tip for use as a textarea placeholder - def random_markdown_tip - MARKDOWN_TIPS.sample - end - private # Return +text+, truncated to +max_chars+ characters, excluding any HTML diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 9adcd916ce..13de88e2f2 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -150,13 +150,6 @@ describe GitlabMarkdownHelper do end end - describe 'random_markdown_tip' do - it 'returns a random Markdown tip' do - stub_const("#{described_class}::MARKDOWN_TIPS", ['Random tip']) - expect(random_markdown_tip).to eq 'Random tip' - end - end - describe '#first_line_in_markdown' do let(:text) { "@#{user.username}, can you look at this?\nHello world\n"} From 66102e5017c2962d1fd1ffcbef09e605033643ba Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 9 Apr 2016 18:34:00 -0700 Subject: [PATCH 159/212] Use raw SQL instead of Rails models in 20130403003950 migration Closes gitlab-org/gitlab-development-kit#109 Closes https://github.com/gitlabhq/gitlabhq/issues/10123 --- ...3950_add_last_activity_column_into_project.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/db/migrate/20130403003950_add_last_activity_column_into_project.rb b/db/migrate/20130403003950_add_last_activity_column_into_project.rb index 2a036bd999..85e31608d7 100644 --- a/db/migrate/20130403003950_add_last_activity_column_into_project.rb +++ b/db/migrate/20130403003950_add_last_activity_column_into_project.rb @@ -3,14 +3,16 @@ class AddLastActivityColumnIntoProject < ActiveRecord::Migration add_column :projects, :last_activity_at, :datetime add_index :projects, :last_activity_at - Project.find_each do |project| - last_activity_date = if project.last_activity - project.last_activity.created_at - else - project.updated_at - end + select_all('SELECT id, updated_at FROM projects').each do |project| + project_id = project['id'] + update_date = project['updated_at'] + event = select_one("SELECT created_at FROM events WHERE project_id = #{project_id} ORDER BY created_at DESC LIMIT 1") - project.update_attribute(:last_activity_at, last_activity_date) + if event && event['created_at'] + update_date = event['created_at'] + end + + execute("UPDATE projects SET last_activity_at = '#{update_date}' WHERE id = #{project_id}") end end From c7ec5929b1f580e7078d11774df2e8c0d1abbe03 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 9 Apr 2016 21:49:47 -0400 Subject: [PATCH 160/212] First pass at a Code Review guide Largely borrowed from thoughtbot's code review guide, so attribution is included. [ci skip] --- doc/development/README.md | 2 + doc/development/code_review.md | 75 ++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 doc/development/code_review.md diff --git a/doc/development/README.md b/doc/development/README.md index 2f4e7845cc..3f3ef068f9 100644 --- a/doc/development/README.md +++ b/doc/development/README.md @@ -2,6 +2,8 @@ - [Architecture](architecture.md) of GitLab - [CI setup](ci_setup.md) for testing GitLab +- [Code review guidelines](code_review.md) for reviewing code and having code + reviewed. - [Gotchas](gotchas.md) to avoid - [How to dump production data to staging](db_dump.md) - [Instrumentation](instrumentation.md) diff --git a/doc/development/code_review.md b/doc/development/code_review.md new file mode 100644 index 0000000000..ab4236404c --- /dev/null +++ b/doc/development/code_review.md @@ -0,0 +1,75 @@ +# Code Review Guidelines + +This guide contains advice and best practices for performing code review, and +having your code reviewed. + +All merge requests for GitLab CE and EE, whether written by a GitLab team member +or a volunteer contributor, must go through a code review process to ensure the +code is effective, understandable, and maintainable. + +Any developer can, and is encouraged to, perform code review on merge requests +of colleagues and contributors. However, the final decision to accept a merge +request is up to one of our merge request "endbosses", denoted on the +[team page](https://about.gitlab.com/team). + +## Everyone + +- Accept that many programming decisions are opinions. Discuss tradeoffs, which + you prefer, and reach a resolution quickly. +- Ask questions; don't make demands. ("What do you think about naming this + `:user_id`?") +- Ask for clarification. ("I didn't understand. Can you clarify?") +- Avoid selective ownership of code. ("mine", "not mine", "yours") +- Avoid using terms that could be seen as referring to personal traits. ("dumb", + "stupid"). Assume everyone is attractive, intelligent, and well-meaning. +- Be explicit. Remember people don't always understand your intentions online. +- Be humble. ("I'm not sure - let's look it up.") +- Don't use hyperbole. ("always", "never", "endlessly", "nothing") +- Consider one-on-one chats or video calls if there are too many "I didn't + understand" or "Alternative solution:" comments. Post a follow-up comment + summarizing one-on-one discussion. + +## Having your code reviewed + +- The first reviewer of your code is _you_. Before you perform that first push + of your shiny new branch, read through the entire diff. Does it make sense? + Did you include something unrelated to the overall purpose of the changes? Did + you forget to remove any debugging code? +- Be grateful for the reviewer's suggestions. ("Good call. I'll make that + change.") +- Don't take it personally. The review is of the code, not of you. +- Explain why the code exists. ("It's like that because of these reasons. Would + it be more clear if I rename this class/file/method/variable?") +- Extract unrelated changes and refactorings into future merge requests/issues. +- Seek to understand the reviewer's perspective. +- Try to respond to every comment. +- Push commits based on earlier rounds of feedback as isolated commits to the + branch. Do not squash until the branch is ready to merge. Reviewers should be + able to read individual updates based on their earlier feedback. + +## Reviewing code + +Understand why the change is necessary (fixes a bug, improves the user +experience, refactors the existing code). Then: + +- Communicate which ideas you feel strongly about and those you don't. +- Identify ways to simplify the code while still solving the problem. +- Offer alternative implementations, but assume the author already considered + them. ("What do you think about using a custom validator here?") +- Seek to understand the author's perspective. +- If you don't understand a piece of code, _say so_. There's a good chance + someone else would be confused by it as well. +- After a round of line notes, it can be helpful to post a summary note such as + "LGTM :thumbsup:", or "Just a couple things to address." +- Avoid accepting a merge request before the build succeeds ("Merge when build + succeeds" is fine). + +## Credits + +Largely based on the [thoughtbot code review guide]. + +[thoughtbot code review guide]: https://github.com/thoughtbot/guides/tree/master/code-review + +--- + +[Return to Development documentation](README.md) From 8536dedbb1fd9154485a001d16e1414c6e3e8e36 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 10 Apr 2016 06:36:14 -0700 Subject: [PATCH 161/212] Fix seed_fu failure with inserting milestones into test DB Milestones were not being saved due to "invalid state" validation errors --- db/fixtures/development/07_milestones.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/fixtures/development/07_milestones.rb b/db/fixtures/development/07_milestones.rb index e028ac82ba..540e4e6825 100644 --- a/db/fixtures/development/07_milestones.rb +++ b/db/fixtures/development/07_milestones.rb @@ -4,7 +4,7 @@ Gitlab::Seeder.quiet do milestone_params = { title: "v#{i}.0", description: FFaker::Lorem.sentence, - state: ['opened', 'closed'].sample, + state: [:active, :closed].sample, } milestone = Milestones::CreateService.new( From 94b48d95570cd7c0b8dbd11eb4edc957ad5c7443 Mon Sep 17 00:00:00 2001 From: connorshea Date: Sun, 10 Apr 2016 14:36:31 -0600 Subject: [PATCH 162/212] Upgrade premailer-rails from 1.9.0 to 1.9.2 Includes compatibility with Rails 5. Changelog: https://github.com/fphilipe/premailer-rails/blob/master/CHANGELOG.md#v19 2 Working towards #14286. --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 28b71ac7bc..df0d848af4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,7 +145,7 @@ GEM crack (0.4.3) safe_yaml (~> 1.0.0) creole (0.5.0) - css_parser (1.3.7) + css_parser (1.4.1) addressable d3_rails (3.5.11) railties (>= 3.1.0) @@ -559,8 +559,8 @@ GEM premailer (1.8.6) css_parser (>= 1.3.6) htmlentities (>= 4.0.0) - premailer-rails (1.9.0) - actionmailer (>= 3, < 5) + premailer-rails (1.9.2) + actionmailer (>= 3, < 6) premailer (~> 1.7, >= 1.7.9) pry (0.10.3) coderay (~> 1.1.0) From 1e99e56202c0c96d4a70fba95e04b4f41d24327a Mon Sep 17 00:00:00 2001 From: Benjamin Montgomery Date: Sun, 10 Apr 2016 21:14:40 +0000 Subject: [PATCH 163/212] Make the purpose of artifact config options clearer --- doc/ci/build_artifacts/README.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/doc/ci/build_artifacts/README.md b/doc/ci/build_artifacts/README.md index bd26da2af6..a21cd12986 100644 --- a/doc/ci/build_artifacts/README.md +++ b/doc/ci/build_artifacts/README.md @@ -1,7 +1,8 @@ # Introduction to build artifacts Artifacts is a list of files and directories which are attached to a build -after it completes successfully. +after it completes successfully. Artificats is enabled by default. _If you are searching for ways to use artifacts, jump to +[Defining artifacts in `.gitlab-ci.yml`](#defining-artifacts-in-gitlab-ciyml)._ Since GitLab 8.2 and [GitLab Runner] 0.7.0, build artifacts that are created by GitLab Runner are uploaded to GitLab and are downloadable as a single archive @@ -16,13 +17,9 @@ The artifacts browser will be available only for new artifacts that are sent to GitLab using GitLab Runner version 1.0 and up. It will not be possible to browse old artifacts already uploaded to GitLab. -## Enabling build artifacts +## Disabling build artifacts -_If you are searching for ways to use artifacts, jump to -[Defining artifacts in `.gitlab-ci.yml`](#defining-artifacts-in-gitlab-ciyml)._ - -The artifacts feature is enabled by default in all GitLab installations. -To disable it site-wide, follow the steps below. +To disable artifacts site-wide, follow the steps below. --- @@ -31,7 +28,7 @@ To disable it site-wide, follow the steps below. 1. Edit `/etc/gitlab/gitlab.rb` and add the following line: ```ruby - gitlab_rails['artifacts_enabled'] = true + gitlab_rails['artifacts_enabled'] = false ``` 1. Save the file and [reconfigure GitLab][] for the changes to take effect. @@ -44,7 +41,7 @@ To disable it site-wide, follow the steps below. ```yaml artifacts: - enabled: true + enabled: false ``` 1. Save the file and [restart GitLab][] for the changes to take effect. From a7e1638b430627133a33986b8a8283891431567a Mon Sep 17 00:00:00 2001 From: connorshea Date: Sun, 10 Apr 2016 15:14:57 -0600 Subject: [PATCH 164/212] Upgrade annotate from 2.6.10 to 2.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Includes compatibility with Rails 5. We don’t have any tests for this, so no need to run them. [ci skip] Changelog: https://github.com/ctran/annotate_models/releases/tag/v2.7.0 Working towards #14286. --- Gemfile | 2 +- Gemfile.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 298cfd260b..258b5612cd 100644 --- a/Gemfile +++ b/Gemfile @@ -239,7 +239,7 @@ group :development do gem "foreman" gem 'brakeman', '~> 3.2.0', require: false - gem "annotate", "~> 2.6.0" + gem "annotate", "~> 2.7.0" gem "letter_opener", '~> 1.1.2' gem 'quiet_assets', '~> 1.0.2' gem 'rerun', '~> 0.11.0' diff --git a/Gemfile.lock b/Gemfile.lock index 28b71ac7bc..bd11489ee5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,8 +51,8 @@ GEM activerecord (>= 3.0) akismet (2.0.0) allocations (1.0.4) - annotate (2.6.10) - activerecord (>= 3.2, <= 4.3) + annotate (2.7.0) + activerecord (>= 3.2, < 6.0) rake (~> 10.4) arel (6.0.3) asana (0.4.0) @@ -888,7 +888,7 @@ DEPENDENCIES after_commit_queue akismet (~> 2.0) allocations (~> 1.0) - annotate (~> 2.6.0) + annotate (~> 2.7.0) asana (~> 0.4.0) asciidoctor (~> 1.5.2) attr_encrypted (~> 1.3.4) From 84ff30a6b2b522e35d608df311c58c180acb114e Mon Sep 17 00:00:00 2001 From: Benjamin Montgomery Date: Sun, 10 Apr 2016 21:16:06 +0000 Subject: [PATCH 165/212] fix typo --- doc/ci/build_artifacts/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/ci/build_artifacts/README.md b/doc/ci/build_artifacts/README.md index a21cd12986..9553bb11e9 100644 --- a/doc/ci/build_artifacts/README.md +++ b/doc/ci/build_artifacts/README.md @@ -1,7 +1,9 @@ # Introduction to build artifacts Artifacts is a list of files and directories which are attached to a build -after it completes successfully. Artificats is enabled by default. _If you are searching for ways to use artifacts, jump to +after it completes successfully. This feature is enabled by default in all GitLab installations. + +_If you are searching for ways to use artifacts, jump to [Defining artifacts in `.gitlab-ci.yml`](#defining-artifacts-in-gitlab-ciyml)._ Since GitLab 8.2 and [GitLab Runner] 0.7.0, build artifacts that are created by From 3b77a07856dc172959980918f19710e1b550b7cc Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 10 Apr 2016 06:22:58 -0700 Subject: [PATCH 166/212] Fix more SQL migrations to use raw commands gitlab-org/gitlab-development-kit#109 --- db/migrate/20130315124931_user_color_scheme.rb | 4 +++- ...0131112220935_add_visibility_level_to_projects.rb | 6 ++++-- ...140313092127_migrate_already_imported_projects.rb | 8 +++++--- ...20141007100818_add_visibility_level_to_snippet.rb | 12 ++++++------ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/db/migrate/20130315124931_user_color_scheme.rb b/db/migrate/20130315124931_user_color_scheme.rb index fe139e32ea..56c9a31ee3 100644 --- a/db/migrate/20130315124931_user_color_scheme.rb +++ b/db/migrate/20130315124931_user_color_scheme.rb @@ -1,7 +1,9 @@ class UserColorScheme < ActiveRecord::Migration + include Gitlab::Database + def up add_column :users, :color_scheme_id, :integer, null: false, default: 1 - User.where(dark_scheme: true).update_all(color_scheme_id: 2) + execute("UPDATE users SET color_scheme_id = 2 WHERE dark_scheme = #{true_value}") remove_column :users, :dark_scheme end diff --git a/db/migrate/20131112220935_add_visibility_level_to_projects.rb b/db/migrate/20131112220935_add_visibility_level_to_projects.rb index cf1e9f912a..89421cbeda 100644 --- a/db/migrate/20131112220935_add_visibility_level_to_projects.rb +++ b/db/migrate/20131112220935_add_visibility_level_to_projects.rb @@ -1,13 +1,15 @@ class AddVisibilityLevelToProjects < ActiveRecord::Migration + include Gitlab::Database + def self.up add_column :projects, :visibility_level, :integer, :default => 0, :null => false - Project.where(public: true).update_all(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + execute("UPDATE projects SET visibility_level = #{Gitlab::VisibilityLevel::PUBLIC} WHERE public = #{true_value}") remove_column :projects, :public end def self.down add_column :projects, :public, :boolean, :default => false, :null => false - Project.where(visibility_level: Gitlab::VisibilityLevel::PUBLIC).update_all(public: true) + execute("UPDATE projects SET public = #{true_value} WHERE visibility_level = #{Gitlab::VisibilityLevel::PUBLIC}") remove_column :projects, :visibility_level end end diff --git a/db/migrate/20140313092127_migrate_already_imported_projects.rb b/db/migrate/20140313092127_migrate_already_imported_projects.rb index f4392c0f05..0a9f73a575 100644 --- a/db/migrate/20140313092127_migrate_already_imported_projects.rb +++ b/db/migrate/20140313092127_migrate_already_imported_projects.rb @@ -1,12 +1,14 @@ class MigrateAlreadyImportedProjects < ActiveRecord::Migration + include Gitlab::Database + def up - Project.where(imported: true).update_all(import_status: "finished") - Project.where(imported: false).update_all(import_status: "none") + execute("UPDATE projects SET import_status = 'finished' WHERE imported = #{true_value}") + execute("UPDATE projects SET import_status = 'none' WHERE imported = #{false_value}") remove_column :projects, :imported end def down add_column :projects, :imported, :boolean, default: false - Project.where(import_status: 'finished').update_all(imported: true) + execute("UPDATE projects SET imported = #{true_value} WHERE import_status = 'finished'") end end diff --git a/db/migrate/20141007100818_add_visibility_level_to_snippet.rb b/db/migrate/20141007100818_add_visibility_level_to_snippet.rb index 7f125acb5d..bb3501f41d 100644 --- a/db/migrate/20141007100818_add_visibility_level_to_snippet.rb +++ b/db/migrate/20141007100818_add_visibility_level_to_snippet.rb @@ -2,8 +2,8 @@ class AddVisibilityLevelToSnippet < ActiveRecord::Migration def up add_column :snippets, :visibility_level, :integer, :default => 0, :null => false - Snippet.where(private: true).update_all(visibility_level: Gitlab::VisibilityLevel::PRIVATE) - Snippet.where(private: false).update_all(visibility_level: Gitlab::VisibilityLevel::INTERNAL) + execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::PRIVATE} WHERE private = true") + execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::INTERNAL} WHERE private = false") add_index :snippets, :visibility_level @@ -12,10 +12,10 @@ class AddVisibilityLevelToSnippet < ActiveRecord::Migration def down add_column :snippets, :private, :boolean, :default => false, :null => false - - Snippet.where(visibility_level: Gitlab::VisibilityLevel::INTERNAL).update_all(private: false) - Snippet.where(visibility_level: Gitlab::VisibilityLevel::PRIVATE).update_all(private: true) - + + execute("UPDATE snippets SET private = false WHERE visibility_level = #{Gitlab::VisibilityLevel::INTERNAL}") + execute("UPDATE snippets SET private = true WHERE visibility_level = #{Gitlab::VisibilityLevel::PRIVATE}") + remove_column :snippets, :visibility_level end end From a7c11fe47361527798b41d0ee9dc344b144a3b50 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Tue, 5 Apr 2016 13:25:32 -0500 Subject: [PATCH 167/212] Ignore toggling sidebar for above 1200px resolution --- app/assets/javascripts/merge_request_tabs.js.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/merge_request_tabs.js.coffee b/app/assets/javascripts/merge_request_tabs.js.coffee index 839e6ec2c0..e45f91c222 100644 --- a/app/assets/javascripts/merge_request_tabs.js.coffee +++ b/app/assets/javascripts/merge_request_tabs.js.coffee @@ -73,7 +73,8 @@ class @MergeRequestTabs @expandView() else if action == 'diffs' @loadDiff($target.attr('href')) - @shrinkView() + if bp.getBreakpointSize() isnt 'lg' + @shrinkView() else if action == 'builds' @loadBuilds($target.attr('href')) @expandView() From fe0aa823252eb468f468c9d813fdc28687c4a4b6 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Tue, 5 Apr 2016 14:37:15 -0500 Subject: [PATCH 168/212] Check existence of variable method This happens because tab's `shown` event is triggered first if we enter directly to the diff page therefore Breakpoints class is not initialized yet. --- app/assets/javascripts/merge_request_tabs.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/merge_request_tabs.js.coffee b/app/assets/javascripts/merge_request_tabs.js.coffee index e45f91c222..3500d796d2 100644 --- a/app/assets/javascripts/merge_request_tabs.js.coffee +++ b/app/assets/javascripts/merge_request_tabs.js.coffee @@ -73,7 +73,7 @@ class @MergeRequestTabs @expandView() else if action == 'diffs' @loadDiff($target.attr('href')) - if bp.getBreakpointSize() isnt 'lg' + if window.bp isnt undefined and window.bp.getBreakpointSize() isnt 'lg' @shrinkView() else if action == 'builds' @loadBuilds($target.attr('href')) From 836301676adba7a91e4539f3d0e554873f06fc99 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Tue, 5 Apr 2016 17:12:15 -0500 Subject: [PATCH 169/212] Use existence operator instead --- app/assets/javascripts/merge_request_tabs.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/merge_request_tabs.js.coffee b/app/assets/javascripts/merge_request_tabs.js.coffee index 3500d796d2..9946249adb 100644 --- a/app/assets/javascripts/merge_request_tabs.js.coffee +++ b/app/assets/javascripts/merge_request_tabs.js.coffee @@ -73,7 +73,7 @@ class @MergeRequestTabs @expandView() else if action == 'diffs' @loadDiff($target.attr('href')) - if window.bp isnt undefined and window.bp.getBreakpointSize() isnt 'lg' + if bp? and bp.getBreakpointSize() isnt 'lg' @shrinkView() else if action == 'builds' @loadBuilds($target.attr('href')) From 0c6923e2d13b6648c8e08017450a01e7068edfb9 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sun, 10 Apr 2016 22:54:32 -0400 Subject: [PATCH 170/212] Re-add a note about sarcasm to the Code Review guide [ci skip] --- doc/development/code_review.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/development/code_review.md b/doc/development/code_review.md index ab4236404c..40ae55ab90 100644 --- a/doc/development/code_review.md +++ b/doc/development/code_review.md @@ -25,6 +25,9 @@ request is up to one of our merge request "endbosses", denoted on the - Be explicit. Remember people don't always understand your intentions online. - Be humble. ("I'm not sure - let's look it up.") - Don't use hyperbole. ("always", "never", "endlessly", "nothing") +- Be careful about the use of sarcasm. Everything we do is public; what seems + like good-natured ribbing to you and a long-time colleague might come off as + mean and unwelcoming to a person new to the project. - Consider one-on-one chats or video calls if there are too many "I didn't understand" or "Alternative solution:" comments. Post a follow-up comment summarizing one-on-one discussion. From 13c00262f74d463e6adbc008aac00a4c63faac11 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 10 Apr 2016 21:19:09 -0700 Subject: [PATCH 171/212] Use false/true mixin in migration from !3640 --- .../20141007100818_add_visibility_level_to_snippet.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/migrate/20141007100818_add_visibility_level_to_snippet.rb b/db/migrate/20141007100818_add_visibility_level_to_snippet.rb index bb3501f41d..93826185e8 100644 --- a/db/migrate/20141007100818_add_visibility_level_to_snippet.rb +++ b/db/migrate/20141007100818_add_visibility_level_to_snippet.rb @@ -1,9 +1,11 @@ class AddVisibilityLevelToSnippet < ActiveRecord::Migration + include Gitlab::Database + def up add_column :snippets, :visibility_level, :integer, :default => 0, :null => false - execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::PRIVATE} WHERE private = true") - execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::INTERNAL} WHERE private = false") + execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::PRIVATE} WHERE private = #{true_value}") + execute("UPDATE snippets SET visibility_level = #{Gitlab::VisibilityLevel::INTERNAL} WHERE private = #{false_value}") add_index :snippets, :visibility_level @@ -13,8 +15,8 @@ class AddVisibilityLevelToSnippet < ActiveRecord::Migration def down add_column :snippets, :private, :boolean, :default => false, :null => false - execute("UPDATE snippets SET private = false WHERE visibility_level = #{Gitlab::VisibilityLevel::INTERNAL}") - execute("UPDATE snippets SET private = true WHERE visibility_level = #{Gitlab::VisibilityLevel::PRIVATE}") + execute("UPDATE snippets SET private = #{false_value} WHERE visibility_level = #{Gitlab::VisibilityLevel::INTERNAL}") + execute("UPDATE snippets SET private = #{true_value} WHERE visibility_level = #{Gitlab::VisibilityLevel::PRIVATE}") remove_column :snippets, :visibility_level end From 0e8aaad51044bbbd5fc544c322d2a17d1c1ce22a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 7 Apr 2016 17:13:57 +0200 Subject: [PATCH 172/212] Decrease threshold for ABC Size metric in Rubocop To 60. --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 71273ce609..2fda0b0311 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -691,7 +691,7 @@ Style/ZeroLengthPredicate: # branches, and conditions. Metrics/AbcSize: Enabled: true - Max: 70 + Max: 60 # Avoid excessive block nesting. Metrics/BlockNesting: From 643fe43d78044d200c863f34d05c210c3e45b5ce Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 11 Apr 2016 09:43:59 +0100 Subject: [PATCH 173/212] Addressed feedback Removed important from css --- app/assets/javascripts/gl_dropdown.js.coffee | 10 +++++----- app/assets/stylesheets/pages/merge_requests.scss | 5 +++-- .../projects/merge_requests/_new_compare.html.haml | 5 +++-- app/views/shared/issuable/_form.html.haml | 14 ++++++++------ features/steps/project/source/browse_files.rb | 1 - 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/gl_dropdown.js.coffee b/app/assets/javascripts/gl_dropdown.js.coffee index 82a82a27cc..4be4ab6083 100644 --- a/app/assets/javascripts/gl_dropdown.js.coffee +++ b/app/assets/javascripts/gl_dropdown.js.coffee @@ -61,7 +61,7 @@ class GitLabDropdownFilter if data? results = data - if search_text isnt "" + if search_text isnt '' results = fuzzaldrinPlus.filter(data, search_text, key: @options.keys ) @@ -139,7 +139,7 @@ class GitLabDropdown if _.isString(@filterInput) @filterInput = @getElement(@filterInput) - search_fields = if @options.search then @options.search.fields else []; + searchFields = if @options.search then @options.search.fields else []; if @options.data # If data is an array @@ -163,11 +163,11 @@ class GitLabDropdown filterInputBlur: @filterInputBlur remote: @options.filterRemote query: @options.data - keys: search_fields + keys: searchFields elements: => - selector = ".dropdown-content li:not(.divider)" + selector = '.dropdown-content li:not(.divider)' - if @dropdown.find(".dropdown-toggle-page").length + if @dropdown.find('.dropdown-toggle-page').length selector = ".dropdown-page-one #{selector}" return $(selector) diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index 4269afe4c5..3c955faf2a 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -258,6 +258,7 @@ } } -.merge-request-form .select2-container { - width: 250px!important; +.issuable-form-select-holder { + display: inline-block; + width: 250px; } diff --git a/app/views/projects/merge_requests/_new_compare.html.haml b/app/views/projects/merge_requests/_new_compare.html.haml index 036b193536..cae5d45231 100644 --- a/app/views/projects/merge_requests/_new_compare.html.haml +++ b/app/views/projects/merge_requests/_new_compare.html.haml @@ -16,9 +16,10 @@ = dropdown_title("Select source project") = dropdown_filter("Search projects") = dropdown_content do + - is_active = f.object.source_project_id == @merge_request.source_project.id %ul %li - %a{ href: "#", class: "#{("is-active" if f.object.source_project_id == @merge_request.source_project.id)}", data: { id: @merge_request.source_project.id } } + %a{ href: "#", class: "#{("is-active" if is_active)}", data: { id: @merge_request.source_project.id } } = @merge_request.source_project_path .merge-request-select.dropdown = f.hidden_field :source_branch @@ -33,7 +34,7 @@ %a{ href: "#", class: "#{("is-active" if f.object.source_branch == branch)}", data: { id: branch } } = branch .panel-footer - = icon('spinner spin', class: "js-source-loading") + = icon('spinner spin', class: 'js-source-loading') %ul.list-unstyled.mr_source_commit .col-md-6 diff --git a/app/views/shared/issuable/_form.html.haml b/app/views/shared/issuable/_form.html.haml index e2a9e5bfb9..5244e7f6cc 100644 --- a/app/views/shared/issuable/_form.html.haml +++ b/app/views/shared/issuable/_form.html.haml @@ -53,10 +53,11 @@ .issue-assignee = f.label :assignee_id, "Assignee", class: 'control-label' .col-sm-10 - = users_select_tag("#{issuable.class.model_name.param_key}[assignee_id]", - placeholder: 'Select assignee', class: 'custom-form-control', null_user: true, - selected: issuable.assignee_id, project: @target_project || @project, - first_user: true, current_user: true, include_blank: true) + .issuable-form-select-holder + = users_select_tag("#{issuable.class.model_name.param_key}[assignee_id]", + placeholder: 'Select assignee', class: 'custom-form-control', null_user: true, + selected: issuable.assignee_id, project: @target_project || @project, + first_user: true, current_user: true, include_blank: true)   = link_to 'Assign to me', '#', class: 'btn assign-to-me-link' .form-group @@ -64,8 +65,9 @@ = f.label :milestone_id, "Milestone", class: 'control-label' .col-sm-10 - if milestone_options(issuable).present? - = f.select(:milestone_id, milestone_options(issuable), - { include_blank: true }, { class: 'select2', data: { placeholder: 'Select milestone' } }) + .issuable-form-select-holder + = f.select(:milestone_id, milestone_options(issuable), + { include_blank: true }, { class: 'select2', data: { placeholder: 'Select milestone' } }) - else .prepend-top-10 %span.light No open milestones available. diff --git a/features/steps/project/source/browse_files.rb b/features/steps/project/source/browse_files.rb index 37958a924b..e072505e5d 100644 --- a/features/steps/project/source/browse_files.rb +++ b/features/steps/project/source/browse_files.rb @@ -219,7 +219,6 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps step 'I see Browse code link' do expect(page).to have_link 'Browse Files' - # expect(page).not_to have_link 'Browse File' expect(page).not_to have_link 'Browse Directory »' end From a4fff0e03368bf57081ae80d727bfc38ab165cd5 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 11 Apr 2016 09:52:12 +0100 Subject: [PATCH 174/212] Fixed dropdown title overlap --- app/assets/stylesheets/framework/dropdowns.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/framework/dropdowns.scss b/app/assets/stylesheets/framework/dropdowns.scss index 82dc1acbd0..ba6c7930cd 100644 --- a/app/assets/stylesheets/framework/dropdowns.scss +++ b/app/assets/stylesheets/framework/dropdowns.scss @@ -248,7 +248,7 @@ .dropdown-title { position: relative; - padding: 0 0 15px; + padding: 0 25px 15px; margin: 0 10px 10px; font-weight: 600; line-height: 1; @@ -275,7 +275,7 @@ } .dropdown-menu-close { - right: 7px; + right: 5px; width: 20px; height: 20px; top: -1px; From 12ff7ee93348239d545e0553a49881cfe490420e Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 11 Apr 2016 09:54:32 +0100 Subject: [PATCH 175/212] Merge request mobile spacing --- app/assets/stylesheets/pages/merge_requests.scss | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index 3c955faf2a..b79335eab9 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -242,10 +242,19 @@ } .merge-request-select { - float: left; - width: 50%; padding-left: 5px; padding-right: 5px; + margin-bottom: 10px; + + &:last-child { + margin-bottom: 0; + } + + @media (min-width: $screen-sm-min) { + float: left; + width: 50%; + margin-bottom: 0; + } .dropdown-menu-toggle { width: 100%; From 2f4dc45da2fbe6ab4469f1c836683bec9c8f0dd9 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 11 Apr 2016 11:38:24 +0100 Subject: [PATCH 176/212] Fixed issue with dashboard/issues not filtering by milestone Closes #15128 --- .../javascripts/milestone_select.js.coffee | 8 ++- spec/features/dashboard_issues_spec.rb | 54 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 spec/features/dashboard_issues_spec.rb diff --git a/app/assets/javascripts/milestone_select.js.coffee b/app/assets/javascripts/milestone_select.js.coffee index f73127f49f..6bd4e885a0 100644 --- a/app/assets/javascripts/milestone_select.js.coffee +++ b/app/assets/javascripts/milestone_select.js.coffee @@ -85,15 +85,21 @@ class @MilestoneSelect # display:block overrides the hide-collapse rule $value.removeAttr('style') clicked: (selected) -> + page = $('body').data 'page' + isIssueIndex = page is 'projects:issues:index' + isMRIndex = page is page is 'projects:merge_requests:index' + if $dropdown.hasClass 'js-filter-bulk-update' return - if $dropdown.hasClass('js-filter-submit') + if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) if selected.name? selectedMilestone = selected.name else selectedMilestone = '' Issues.filterResults $dropdown.closest('form') + else if $dropdown.hasClass('js-filter-submit') + $dropdown.closest('form').submit() else selected = $selectbox .find('input[type="hidden"]') diff --git a/spec/features/dashboard_issues_spec.rb b/spec/features/dashboard_issues_spec.rb new file mode 100644 index 0000000000..39805da9d0 --- /dev/null +++ b/spec/features/dashboard_issues_spec.rb @@ -0,0 +1,54 @@ +require 'spec_helper' + +describe "Dashboard Issues filtering", feature: true, js: true do + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:milestone) { create(:milestone, project: project) } + + context 'filtering by milestone' do + before do + project.team << [user, :master] + login_as(user) + + create(:issue, project: project, author: user, assignee: user) + create(:issue, project: project, author: user, assignee: user, milestone: milestone) + + visit_issues + end + + it 'should show all issues with no milestone' do + show_milestone_dropdown + + click_link 'No Milestone' + + expect(page).to have_selector('.issue', count: 1) + end + + it 'should show all issues with any milestone' do + show_milestone_dropdown + + click_link 'Any Milestone' + + expect(page).to have_selector('.issue', count: 2) + end + + it 'should show all issues with the selected milestone' do + show_milestone_dropdown + + page.within '.dropdown-content' do + click_link milestone.title + end + + expect(page).to have_selector('.issue', count: 1) + end + end + + def show_milestone_dropdown + click_button 'Milestone' + expect(page).to have_selector('.dropdown-content', visible: true) + end + + def visit_issues + visit issues_dashboard_path + end +end From 16926a676bdea4bfbbbaf9d390373073d2ff8bbd Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 11 Apr 2016 12:23:37 +0200 Subject: [PATCH 177/212] Store block timings as transaction values This makes it easier to query, simplifies the code, and makes it possible to figure out what transaction the data belongs to (simply because it's now stored _in_ the transaction). This new setup keeps track of both the real/wall time _and_ CPU time spent in a block, both measured using milliseconds (to keep all units the same). --- doc/development/instrumentation.md | 36 ++++++++++++++---------------- lib/gitlab/metrics.rb | 25 ++++++++++++--------- lib/gitlab/metrics/system.rb | 11 +++++++++ spec/lib/gitlab/metrics_spec.rb | 16 +++++-------- 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/doc/development/instrumentation.md b/doc/development/instrumentation.md index c0192bd670..f7e148fb3e 100644 --- a/doc/development/instrumentation.md +++ b/doc/development/instrumentation.md @@ -2,36 +2,34 @@ GitLab Performance Monitoring allows instrumenting of custom blocks of Ruby code. This can be used to measure the time spent in a specific part of a larger -chunk of code. The resulting data is written to a separate series. +chunk of code. The resulting data is stored as a field in the transaction that +executed the block. -To start measuring a block of Ruby code you should use -`Gitlab::Metrics.measure` and give it a name for the series to store the data -in: +To start measuring a block of Ruby code you should use `Gitlab::Metrics.measure` +and give it a name: ```ruby -Gitlab::Metrics.measure(:user_logins) do +Gitlab::Metrics.measure(:foo) do ... end ``` -The first argument of this method is the series name and should be plural. This -name will be prefixed with `rails_` or `sidekiq_` depending on whether the code -was run in the Rails application or one of the Sidekiq workers. In the -above example the final series names would be as follows: +Two values are measured for a block: -- rails_user_logins -- sidekiq_user_logins +1. The real time elapsed, stored in NAME_real_time +2. The CPU time elapsed, stored in NAME_cpu_time -Series names should be plural as this keeps the naming style in line with the -other series names. +Both the real and CPU timings are measured in milliseconds. -By default metrics measured using a block contain a single value, "duration", -which contains the number of milliseconds it took to execute the block. Custom -values can be added by passing a Hash as the 2nd argument. Custom tags can be -added by passing a Hash as the 3rd argument. A simple example is as follows: +Multiple calls to the same block will result in the final values being the sum +of all individual values. Take this code for example: ```ruby -Gitlab::Metrics.measure(:example_series, { number: 10 }, { class: self.class.to_s }) do - ... +3.times do + Gitlab::Metrics.measure(:sleep) do + sleep 1 + end end ``` + +Here the final value of `sleep_real_time` will be `3`, _not_ `1`. diff --git a/lib/gitlab/metrics.rb b/lib/gitlab/metrics.rb index 4a3f47b5a9..4d64555027 100644 --- a/lib/gitlab/metrics.rb +++ b/lib/gitlab/metrics.rb @@ -74,24 +74,29 @@ module Gitlab # # Example: # - # Gitlab::Metrics.measure(:find_by_username_timings) do + # Gitlab::Metrics.measure(:find_by_username_duration) do # User.find_by_username(some_username) # end # - # series - The name of the series to store the data in. - # values - A Hash containing extra values to add to the metric. - # tags - A Hash containing extra tags to add to the metric. + # name - The name of the field to store the execution time in. # # Returns the value yielded by the supplied block. - def self.measure(series, values = {}, tags = {}) + def self.measure(name) return yield unless Transaction.current - start = Time.now.to_f - retval = yield - duration = (Time.now.to_f - start) * 1000.0 - values = values.merge(duration: duration) + real_start = Time.now.to_f + cpu_start = System.cpu_time - Transaction.current.add_metric(series, values, tags) + retval = yield + + cpu_stop = System.cpu_time + real_stop = Time.now.to_f + + real_time = (real_stop - real_start) * 1000.0 + cpu_time = cpu_stop - cpu_start + + Transaction.current.increment("#{name}_real_time", real_time) + Transaction.current.increment("#{name}_cpu_time", cpu_time) retval end diff --git a/lib/gitlab/metrics/system.rb b/lib/gitlab/metrics/system.rb index 8337126527..a7d183b2f9 100644 --- a/lib/gitlab/metrics/system.rb +++ b/lib/gitlab/metrics/system.rb @@ -30,6 +30,17 @@ module Gitlab 0 end end + + # THREAD_CPUTIME is not supported on OS X + if Process.const_defined?(:CLOCK_THREAD_CPUTIME_ID) + def self.cpu_time + Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :millisecond) + end + else + def self.cpu_time + Process.clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID, :millisecond) + end + end end end end diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index 8f63a5f204..edefec909c 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -79,19 +79,13 @@ describe Gitlab::Metrics do end it 'adds a metric to the current transaction' do - expect(transaction).to receive(:add_metric). - with(:foo, { duration: a_kind_of(Numeric) }, { tag: 'value' }) + expect(transaction).to receive(:increment). + with('foo_real_time', a_kind_of(Numeric)) - Gitlab::Metrics.measure(:foo, {}, tag: 'value') { 10 } - end + expect(transaction).to receive(:increment). + with('foo_cpu_time', a_kind_of(Numeric)) - it 'supports adding of custom values' do - values = { duration: a_kind_of(Numeric), number: 10 } - - expect(transaction).to receive(:add_metric). - with(:foo, values, { tag: 'value' }) - - Gitlab::Metrics.measure(:foo, { number: 10 }, tag: 'value') { 10 } + Gitlab::Metrics.measure(:foo) { 10 } end it 'returns the return value of the block' do From 185d78bcb3064c25b764937949d2bb66ec66901a Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 11 Apr 2016 13:11:13 +0200 Subject: [PATCH 178/212] Added specs for Gitlab::Metrics::System.cpu_time --- spec/lib/gitlab/metrics/system_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb index f8c1d956ca..d6ae54e25e 100644 --- a/spec/lib/gitlab/metrics/system_spec.rb +++ b/spec/lib/gitlab/metrics/system_spec.rb @@ -26,4 +26,10 @@ describe Gitlab::Metrics::System do end end end + + describe '.cpu_time' do + it 'returns a Fixnum' do + expect(described_class.cpu_time).to be_an_instance_of(Fixnum) + end + end end From d9110a7ecab52ab0716a42c2075cebdf8028d5e7 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 11 Apr 2016 13:27:24 +0200 Subject: [PATCH 179/212] Track call counts in Gitlab::Metrics.measure_block --- doc/development/instrumentation.md | 7 ++++--- lib/gitlab/metrics.rb | 1 + spec/lib/gitlab/metrics_spec.rb | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/development/instrumentation.md b/doc/development/instrumentation.md index f7e148fb3e..c1cf2e77c2 100644 --- a/doc/development/instrumentation.md +++ b/doc/development/instrumentation.md @@ -14,10 +14,11 @@ Gitlab::Metrics.measure(:foo) do end ``` -Two values are measured for a block: +3 values are measured for a block: -1. The real time elapsed, stored in NAME_real_time -2. The CPU time elapsed, stored in NAME_cpu_time +1. The real time elapsed, stored in NAME_real_time. +2. The CPU time elapsed, stored in NAME_cpu_time. +3. The call count, stored in NAME_call_count. Both the real and CPU timings are measured in milliseconds. diff --git a/lib/gitlab/metrics.rb b/lib/gitlab/metrics.rb index 4d64555027..33dd3e39f4 100644 --- a/lib/gitlab/metrics.rb +++ b/lib/gitlab/metrics.rb @@ -97,6 +97,7 @@ module Gitlab Transaction.current.increment("#{name}_real_time", real_time) Transaction.current.increment("#{name}_cpu_time", cpu_time) + Transaction.current.increment("#{name}_call_count", 1) retval end diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index edefec909c..a3b6845526 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -85,6 +85,9 @@ describe Gitlab::Metrics do expect(transaction).to receive(:increment). with('foo_cpu_time', a_kind_of(Numeric)) + expect(transaction).to receive(:increment). + with('foo_call_count', 1) + Gitlab::Metrics.measure(:foo) { 10 } end From 7eed4608fe5adf65d6a29ef50c93485ca2e6806f Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 11 Apr 2016 14:29:38 +0200 Subject: [PATCH 180/212] Fixed stubbing for Gitlab::Metrics specs If the measure method uses Transaction.current directly the SQL subscriber (Subscribers::ActiveRecord) will add timings of queries triggered by DB cleaner. --- lib/gitlab/metrics.rb | 16 ++++++++++++---- spec/lib/gitlab/metrics_spec.rb | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/gitlab/metrics.rb b/lib/gitlab/metrics.rb index 33dd3e39f4..2a0a5629be 100644 --- a/lib/gitlab/metrics.rb +++ b/lib/gitlab/metrics.rb @@ -82,7 +82,9 @@ module Gitlab # # Returns the value yielded by the supplied block. def self.measure(name) - return yield unless Transaction.current + trans = current_transaction + + return yield unless trans real_start = Time.now.to_f cpu_start = System.cpu_time @@ -95,9 +97,9 @@ module Gitlab real_time = (real_stop - real_start) * 1000.0 cpu_time = cpu_stop - cpu_start - Transaction.current.increment("#{name}_real_time", real_time) - Transaction.current.increment("#{name}_cpu_time", cpu_time) - Transaction.current.increment("#{name}_call_count", 1) + trans.increment("#{name}_real_time", real_time) + trans.increment("#{name}_cpu_time", cpu_time) + trans.increment("#{name}_call_count", 1) retval end @@ -113,5 +115,11 @@ module Gitlab new(udp: { host: host, port: port }) end end + + private + + def self.current_transaction + Transaction.current + end end end diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index a3b6845526..3dee13e27f 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -74,7 +74,7 @@ describe Gitlab::Metrics do let(:transaction) { Gitlab::Metrics::Transaction.new } before do - allow(Gitlab::Metrics::Transaction).to receive(:current). + allow(Gitlab::Metrics).to receive(:current_transaction). and_return(transaction) end From 08c3936b83f3f67cbabf74289805a3938e2b7564 Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Mon, 11 Apr 2016 15:10:14 +0200 Subject: [PATCH 181/212] Check head unborn in rugged --- app/models/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 8dead3a588..3e52ee5d0a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -896,7 +896,7 @@ class Repository end def main_language - unless empty? + unless empty? or rugged.head_unborn? Linguist::Repository.new(rugged, rugged.head.target_id).language end end From ca0b3ea1f107562492babbaf5ce5fec43897bd88 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 11 Apr 2016 17:03:27 +0200 Subject: [PATCH 182/212] Go back to gitlab-workhorse 0.7.1 We found out that 0.7.2 breaks shallow `git clone`. GitLab 8.7 will work fine with gitlab-workhorse 0.7.1 too. --- GITLAB_WORKHORSE_VERSION | 2 +- doc/install/installation.md | 2 +- doc/update/8.6-to-8.7.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/GITLAB_WORKHORSE_VERSION b/GITLAB_WORKHORSE_VERSION index 7486fdbc50..39e898a4f9 100644 --- a/GITLAB_WORKHORSE_VERSION +++ b/GITLAB_WORKHORSE_VERSION @@ -1 +1 @@ -0.7.2 +0.7.1 diff --git a/doc/install/installation.md b/doc/install/installation.md index d97dc7d131..f8f7d6a9eb 100644 --- a/doc/install/installation.md +++ b/doc/install/installation.md @@ -352,7 +352,7 @@ GitLab Shell is an SSH access and repository management software developed speci cd /home/git sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git cd gitlab-workhorse - sudo -u git -H git checkout v0.7.2 + sudo -u git -H git checkout v0.7.1 sudo -u git -H make ### Initialize Database and Activate Advanced Features diff --git a/doc/update/8.6-to-8.7.md b/doc/update/8.6-to-8.7.md index 57847d2d9f..8599133a72 100644 --- a/doc/update/8.6-to-8.7.md +++ b/doc/update/8.6-to-8.7.md @@ -58,7 +58,7 @@ GitLab 8.1. ```bash cd /home/git/gitlab-workhorse sudo -u git -H git fetch --all -sudo -u git -H git checkout v0.7.2 +sudo -u git -H git checkout v0.7.1 sudo -u git -H make ``` From 935f913165b91467a70d9ba2b0ea29fad467db9d Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 11 Apr 2016 17:42:12 +0200 Subject: [PATCH 183/212] Instrument Banzai code --- config/initializers/metrics.rb | 23 +++++++++++++++++++++++ lib/banzai/renderer.rb | 20 ++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/config/initializers/metrics.rb b/config/initializers/metrics.rb index a9fc38fb04..1b445bbbd1 100644 --- a/config/initializers/metrics.rb +++ b/config/initializers/metrics.rb @@ -75,6 +75,29 @@ if Gitlab::Metrics.enabled? config.instrument_methods(const) config.instrument_instance_methods(const) end + + # Instruments all Banzai filters + Dir[Rails.root.join('lib', 'banzai', 'filter', '*.rb')].each do |file| + klass = File.basename(file, File.extname(file)).camelize + const = Banzai::Filter.const_get(klass) + + config.instrument_methods(const) + config.instrument_instance_methods(const) + end + + config.instrument_methods(Banzai::ReferenceExtractor) + config.instrument_instance_methods(Banzai::ReferenceExtractor) + + config.instrument_methods(Banzai::Renderer) + config.instrument_methods(Banzai::Querying) + + [Issuable, Mentionable, Participable].each do |klass| + config.instrument_instance_methods(klass) + config.instrument_instance_methods(klass::ClassMethods) + end + + config.instrument_methods(Gitlab::ReferenceExtractor) + config.instrument_instance_methods(Gitlab::ReferenceExtractor) end GC::Profiler.enable diff --git a/lib/banzai/renderer.rb b/lib/banzai/renderer.rb index ae714c87dc..c14a9c4c72 100644 --- a/lib/banzai/renderer.rb +++ b/lib/banzai/renderer.rb @@ -19,8 +19,10 @@ module Banzai cache_key = full_cache_key(cache_key, context[:pipeline]) if cache_key - Rails.cache.fetch(cache_key) do - cacheless_render(text, context) + Gitlab::Metrics.measure(:banzai_cached_render) do + Rails.cache.fetch(cache_key) do + cacheless_render(text, context) + end end else cacheless_render(text, context) @@ -64,13 +66,15 @@ module Banzai private def self.cacheless_render(text, context = {}) - result = render_result(text, context) + Gitlab::Metrics.measure(:banzai_cacheless_render) do + result = render_result(text, context) - output = result[:output] - if output.respond_to?(:to_html) - output.to_html - else - output.to_s + output = result[:output] + if output.respond_to?(:to_html) + output.to_html + else + output.to_s + end end end From 27d2b355358b52d840153cbb100c2820fab29afe Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Mon, 11 Apr 2016 18:11:49 +0200 Subject: [PATCH 184/212] Add changelog, change code to guard clause --- CHANGELOG | 3 +++ app/models/repository.rb | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3561c541df..a53a0615ca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -35,6 +35,9 @@ v 8.7.0 (unreleased) - ClosingIssueExtractor regex now also works with colons. e.g. "Fixes: #1234" !3591 - Update number of Todos in the sidebar when it's marked as "Done". !3600 +v 8.6.6 + - Fix error on language detection when repository has no HEAD (e.g., master branch). !3654 + v 8.6.5 - Fix importing from GitHub Enterprise. !3529 - Perform the language detection after updating merge requests in `GitPushService`, leading to faster visual feedback for the end-user. !3533 diff --git a/app/models/repository.rb b/app/models/repository.rb index 3e52ee5d0a..a24ce45a38 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -896,9 +896,9 @@ class Repository end def main_language - unless empty? or rugged.head_unborn? - Linguist::Repository.new(rugged, rugged.head.target_id).language - end + return nil if empty? || rugged.head_unborn? + + Linguist::Repository.new(rugged, rugged.head.target_id).language end def avatar From f36655dc8b796aac1a75cc28d4768280a9e2860b Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Mon, 11 Apr 2016 18:14:01 +0200 Subject: [PATCH 185/212] Dont return null --- app/models/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index a24ce45a38..462b48118e 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -896,7 +896,7 @@ class Repository end def main_language - return nil if empty? || rugged.head_unborn? + return if empty? || rugged.head_unborn? Linguist::Repository.new(rugged, rugged.head.target_id).language end From 60fd4188a540368776738896b1e10683b7fa9e65 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 5 Apr 2016 16:18:25 +0100 Subject: [PATCH 186/212] Build notification null check Cancels build notification interval on page change --- .../javascripts/merge_request_widget.js.coffee | 15 ++++++++++++++- .../merge_requests/widget/_show.html.haml | 7 +------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index 84a8887fbc..1e3a584752 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -12,10 +12,19 @@ class @MergeRequestWidget @readyForCICheck = true clearInterval @fetchBuildStatusInterval + @clearEventListeners() + @addEventListeners() @pollCIStatus() notifyPermissions() - setOpts: (@opts) -> + clearEventListeners: -> + $(document).off 'page:change.merge_request' + + addEventListeners: -> + $(document).on 'page:change.merge_request', => + if $('body').data('page') isnt 'projects:merge_requests:show' + clearInterval @fetchBuildStatusInterval + @clearEventListeners() mergeInProgress: (deleteSourceBranch = false)-> $.ajax @@ -63,11 +72,15 @@ class @MergeRequestWidget @firstCICheck = false @opts.ci_status = data.status +<<<<<<< a918e8bf277418048776a5d9c34a64b39f4e56f3 if @opts.ci_status is '' @opts.ci_status = data.status return if data.status isnt @opts.ci_status +======= + if data.status isnt @opts.ci_status and data.status? +>>>>>>> Build notification null check @showCIStatus data.status if data.coverage @showCICoverage data.coverage diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml index 92d9535893..003477dda1 100644 --- a/app/views/projects/merge_requests/widget/_show.html.haml +++ b/app/views/projects/merge_requests/widget/_show.html.haml @@ -8,7 +8,6 @@ = render 'projects/merge_requests/widget/locked' :javascript - var merge_request_widget; var opts = { merge_check_url: "#{merge_check_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", check_enable: #{@merge_request.unchecked? ? "true" : "false"}, @@ -20,8 +19,4 @@ builds_path: "#{builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}" }; - if(typeof merge_request_widget === 'undefined') { - merge_request_widget = new MergeRequestWidget(opts); - } else { - merge_request_widget.setOpts(opts); - } + new MergeRequestWidget(opts); From b87cc5f224428a332b63f3ac7832ea7d882b37b3 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 13:58:44 +0100 Subject: [PATCH 187/212] Preparing build status --- app/controllers/projects/merge_requests_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index ae613f5e09..9addcdf3f9 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -237,6 +237,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController end end + status = "preparing" if status == nil + response = { title: merge_request.title, sha: merge_request.last_commit_short_sha, From ce0678faa5a1e4688aa7491c49cebd4b172244af Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 14:50:34 +0100 Subject: [PATCH 188/212] Rubocop fix --- app/controllers/projects/merge_requests_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 9addcdf3f9..3e0cfc6aa6 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -237,7 +237,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController end end - status = "preparing" if status == nil + status = "preparing" if status.nil? response = { title: merge_request.title, From 99fe9c7b7703b1594c9cda571f43f20198f96b0f Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 14:58:50 +0100 Subject: [PATCH 189/212] Corrects the button color on build status change --- app/assets/javascripts/merge_request_widget.js.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index 1e3a584752..63f75be2da 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -111,6 +111,8 @@ class @MergeRequestWidget @setMergeButtonClass('btn-danger') when "running", "pending" @setMergeButtonClass('btn-warning') + when "success" + @setMergeButtonClass('btn-create') else $('.ci_widget.ci-error').show() @setMergeButtonClass('btn-danger') @@ -120,4 +122,6 @@ class @MergeRequestWidget $('.ci_widget:visible .ci-coverage').text(text) setMergeButtonClass: (css_class) -> - $('.accept_merge_request').removeClass("btn-create").addClass(css_class) + $('.accept_merge_request') + .removeClass('btn-danger btn-warning btn-create') + .addClass(css_class) From 552cde76fa96282dec4ba002cd1850d003a5b29f Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 15:06:27 +0100 Subject: [PATCH 190/212] Hides notification after X amount of seconds --- app/assets/javascripts/lib/notify.js.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/assets/javascripts/lib/notify.js.coffee b/app/assets/javascripts/lib/notify.js.coffee index 3f9ca39912..9e28353ac3 100644 --- a/app/assets/javascripts/lib/notify.js.coffee +++ b/app/assets/javascripts/lib/notify.js.coffee @@ -2,6 +2,11 @@ notificationGranted = (message, opts, onclick) -> notification = new Notification(message, opts) + # Hide the notification after X amount of seconds + setTimeout -> + notification.close() + , 8000 + if onclick notification.onclick = onclick From 843bc44aa9dea8a19af21dd13a82ecc02bf8840c Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 17:04:22 +0100 Subject: [PATCH 191/212] Preparing build text --- .../javascripts/merge_request_widget.js.coffee | 16 +++++++++++++--- .../merge_requests/widget/_show.html.haml | 9 ++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index 63f75be2da..a522f9189a 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -47,7 +47,7 @@ class @MergeRequestWidget $('.mr-state-widget').replaceWith(data) ciLabelForStatus: (status) -> - if status == 'success' + if status is 'success' 'passed' else status @@ -86,12 +86,22 @@ class @MergeRequestWidget @showCICoverage data.coverage if showNotification - message = @opts.ci_message.replace('{{status}}', @ciLabelForStatus(data.status)) + status = @ciLabelForStatus(data.status) + + if status is "preparing" + title = @opts.ci_title.preparing + status = status.charAt(0).toUpperCase() + status.slice(1); + message = @opts.ci_message.preparing.replace('{{status}}', status) + else + title = @opts.ci_title.normal + message = @opts.ci_message.normal.replace('{{status}}', status) + + title = title.replace('{{status}}', status) message = message.replace('{{sha}}', data.sha) message = message.replace('{{title}}', data.title) notify( - "Build #{@ciLabelForStatus(data.status)}", + title, message, @opts.gitlab_icon, -> diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml index 003477dda1..804ca3783e 100644 --- a/app/views/projects/merge_requests/widget/_show.html.haml +++ b/app/views/projects/merge_requests/widget/_show.html.haml @@ -14,8 +14,15 @@ ci_status_url: "#{ci_status_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}", gitlab_icon: "#{asset_path 'gitlab_logo.png'}", ci_status: "", - ci_message: "Build {{status}} for \"{{title}}\"", + ci_message: { + normal: "Build {{status}} for \"{{title}}\"", + preparing: "{{status}} build for \"{{title}}\"" + }, ci_enable: #{@project.ci_service ? "true" : "false"}, + ci_title: { + preparing: "{{status}} build", + normal: "Build {{status}}" + }, builds_path: "#{builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}" }; From 6a13b372224a5f7ae03dde92f455645441b62f84 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 7 Apr 2016 15:32:46 +0100 Subject: [PATCH 192/212] Fixed missed conflict --- app/assets/javascripts/merge_request_widget.js.coffee | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/assets/javascripts/merge_request_widget.js.coffee b/app/assets/javascripts/merge_request_widget.js.coffee index a522f9189a..065626beeb 100644 --- a/app/assets/javascripts/merge_request_widget.js.coffee +++ b/app/assets/javascripts/merge_request_widget.js.coffee @@ -72,15 +72,11 @@ class @MergeRequestWidget @firstCICheck = false @opts.ci_status = data.status -<<<<<<< a918e8bf277418048776a5d9c34a64b39f4e56f3 if @opts.ci_status is '' @opts.ci_status = data.status return - if data.status isnt @opts.ci_status -======= if data.status isnt @opts.ci_status and data.status? ->>>>>>> Build notification null check @showCIStatus data.status if data.coverage @showCICoverage data.coverage From 1b4a56bdb05afdb68b99067c60b9b453b2ecdc24 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 11 Apr 2016 17:28:54 +0100 Subject: [PATCH 193/212] Fixed failing tests --- app/views/projects/merge_requests/widget/_show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/merge_requests/widget/_show.html.haml b/app/views/projects/merge_requests/widget/_show.html.haml index 804ca3783e..3c68d61c4b 100644 --- a/app/views/projects/merge_requests/widget/_show.html.haml +++ b/app/views/projects/merge_requests/widget/_show.html.haml @@ -26,4 +26,4 @@ builds_path: "#{builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)}" }; - new MergeRequestWidget(opts); + merge_request_widget = new MergeRequestWidget(opts); From 6333ebe619848aaec3811c9e8908c017317c019f Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 6 Apr 2016 10:16:39 +0100 Subject: [PATCH 194/212] Prefills commit message in edit file See #14488 --- app/views/shared/_commit_message_container.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/_commit_message_container.html.haml b/app/views/shared/_commit_message_container.html.haml index 7afbaeddee..eeb4e2f556 100644 --- a/app/views/shared/_commit_message_container.html.haml +++ b/app/views/shared/_commit_message_container.html.haml @@ -6,7 +6,7 @@ .commit-message-container .max-width-marker = text_area_tag 'commit_message', - (params[:commit_message] || local_assigns[:text]), + (params[:commit_message] || local_assigns[:placeholder]), class: 'form-control js-commit-message', placeholder: local_assigns[:placeholder], required: true, rows: (local_assigns[:rows] || 3), id: "commit_message-#{nonce}" From 44a95c5dea278d9d835030e3cab8e9e7bead0b44 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 11 Apr 2016 17:41:47 +0100 Subject: [PATCH 195/212] Added back text used on merge commit message --- app/views/shared/_commit_message_container.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/_commit_message_container.html.haml b/app/views/shared/_commit_message_container.html.haml index eeb4e2f556..0a38327baa 100644 --- a/app/views/shared/_commit_message_container.html.haml +++ b/app/views/shared/_commit_message_container.html.haml @@ -6,7 +6,7 @@ .commit-message-container .max-width-marker = text_area_tag 'commit_message', - (params[:commit_message] || local_assigns[:placeholder]), + (params[:commit_message] || local_assigns[:text] || local_assigns[:placeholder]), class: 'form-control js-commit-message', placeholder: local_assigns[:placeholder], required: true, rows: (local_assigns[:rows] || 3), id: "commit_message-#{nonce}" From 05a611a0918f9a39de4ea3a051c2192c327f778d Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 11 Apr 2016 17:25:18 -0500 Subject: [PATCH 196/212] Better control flow and added guard clause. --- lib/gitlab/saml/user.rb | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index dd77216be4..dba4bbfc89 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -26,15 +26,13 @@ module Gitlab @user ||= build_new_user end - unless @user.nil? - if external_users_enabled? - # Check if there is overlap between the user's groups and the external groups - # setting then set user as external or internal. - if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? - @user.external = false - else - @user.external = true - end + if external_users_enabled? && @user + # Check if there is overlap between the user's groups and the external groups + # setting then set user as external or internal. + if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty? + @user.external = false + else + @user.external = true end end @@ -50,11 +48,8 @@ module Gitlab end def changed? - if gl_user - gl_user.changed? || gl_user.identities.any?(&:changed?) - else - true - end + return true unless gl_user + gl_user.changed? || gl_user.identities.any?(&:changed?) end protected From 8299129382e59a0b407be8c476b8ae2d0704d688 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 12 Apr 2016 12:24:16 +0200 Subject: [PATCH 197/212] Instrument all service classes Fixes gitlab-org/gitlab-ce#15162 --- config/initializers/metrics.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config/initializers/metrics.rb b/config/initializers/metrics.rb index 1b445bbbd1..9bd43dad0a 100644 --- a/config/initializers/metrics.rb +++ b/config/initializers/metrics.rb @@ -1,4 +1,5 @@ if Gitlab::Metrics.enabled? + require 'pathname' require 'influxdb' require 'connection_pool' require 'method_source' @@ -98,6 +99,17 @@ if Gitlab::Metrics.enabled? config.instrument_methods(Gitlab::ReferenceExtractor) config.instrument_instance_methods(Gitlab::ReferenceExtractor) + + # Instrument all service classes + services = Rails.root.join('app', 'services') + + Dir[services.join('**', '*.rb')].each do |file_path| + path = Pathname.new(file_path).relative_path_from(services) + const = path.to_s.sub('.rb', '').camelize.constantize + + config.instrument_methods(const) + config.instrument_instance_methods(const) + end end GC::Profiler.enable From 10080ce3624e199bd770a924d8d7f178008d4cb7 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 12:32:34 +0200 Subject: [PATCH 198/212] API: Expose updated_at for notes --- CHANGELOG | 1 + doc/api/notes.md | 3 +++ lib/api/entities.rb | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index c08b148c3a..7574387280 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -35,6 +35,7 @@ v 8.7.0 (unreleased) - API: Expose user location (Robert Schilling) - ClosingIssueExtractor regex now also works with colons. e.g. "Fixes: #1234" !3591 - Update number of Todos in the sidebar when it's marked as "Done". !3600 + - API: Expose 'updated_at' for issue, snippet, and merge request notes (Robert Schilling) v 8.6.5 - Fix importing from GitHub Enterprise. !3529 diff --git a/doc/api/notes.md b/doc/api/notes.md index d4d63e825a..9168ab00d7 100644 --- a/doc/api/notes.md +++ b/doc/api/notes.md @@ -32,6 +32,7 @@ Parameters: "created_at": "2013-09-30T13:46:01Z" }, "created_at": "2013-10-02T09:22:45Z", + "updated_at": "2013-10-02T10:22:45Z", "system": true, "upvote": false, "downvote": false, @@ -51,6 +52,7 @@ Parameters: "created_at": "2013-09-30T13:46:01Z" }, "created_at": "2013-10-02T09:56:03Z", + "updated_at": "2013-10-02T09:56:03Z", "system": true, "upvote": false, "downvote": false, @@ -223,6 +225,7 @@ Parameters: "created_at": "2013-09-30T13:46:01Z" }, "created_at": "2013-10-02T08:57:14Z", + "updated_at": "2013-10-02T08:57:14Z", "system": false, "upvote": false, "downvote": false, diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5ed9b7b1d9..939469b388 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -212,7 +212,7 @@ module API expose :note, as: :body expose :attachment_identifier, as: :attachment expose :author, using: Entities::UserBasic - expose :created_at + expose :created_at, :updated_at expose :system?, as: :system expose :noteable_id, :noteable_type # upvote? and downvote? are deprecated, always return false From 9d03e8fd5c564b20f3a1ef18583aa4c7c2b27cfc Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Thu, 7 Apr 2016 10:59:54 +0200 Subject: [PATCH 199/212] API: Add iid filter to milestones --- CHANGELOG | 1 + lib/api/milestones.rb | 2 ++ spec/requests/api/milestones_spec.rb | 8 +++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c08b148c3a..e5e027506c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ v 8.7.0 (unreleased) - Add default scope to projects to exclude projects pending deletion - Ensure empty recipients are rejected in BuildsEmailService - API: Ability to filter milestones by state `active` and `closed` (Robert Schilling) + - API: Fix milestone filtering by `iid` (Robert Schilling) - Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.) - Better errors handling when creating milestones inside groups - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index 0f3f505fa0..84b4d4cdd6 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -21,6 +21,7 @@ module API # state (optional) - Return "active" or "closed" milestones # Example Request: # GET /projects/:id/milestones + # GET /projects/:id/milestones?iid=42 # GET /projects/:id/milestones?state=active # GET /projects/:id/milestones?state=closed get ":id/milestones" do @@ -28,6 +29,7 @@ module API milestones = user_project.milestones milestones = filter_milestones_state(milestones, params[:state]) + milestones = filter_by_iid(milestones, params[:iid]) if params[:iid].present? present paginate(milestones), with: Entities::Milestone end diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb index d97bf6d38f..344f0fe0b7 100644 --- a/spec/requests/api/milestones_spec.rb +++ b/spec/requests/api/milestones_spec.rb @@ -50,10 +50,12 @@ describe API::API, api: true do end it 'should return a project milestone by iid' do - get api("/projects/#{project.id}/milestones?iid=#{milestone.iid}", user) + get api("/projects/#{project.id}/milestones?iid=#{closed_milestone.iid}", user) + expect(response.status).to eq 200 - expect(json_response.first['title']).to eq milestone.title - expect(json_response.first['id']).to eq milestone.id + expect(json_response.size).to eq(1) + expect(json_response.first['title']).to eq closed_milestone.title + expect(json_response.first['id']).to eq closed_milestone.id end it 'should return 401 error if user not authenticated' do From 20d4ca4cc3599b4335b73fd7c3bb0354efe397b4 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 13:59:50 +0200 Subject: [PATCH 200/212] API: Ability to retrieve a single tag --- doc/api/tags.md | 46 +++++++++++++++++++++++++++++++++- lib/api/tags.rb | 14 +++++++++++ spec/requests/api/tags_spec.rb | 17 +++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/doc/api/tags.md b/doc/api/tags.md index 17d12e9cc6..d428ca0ef5 100644 --- a/doc/api/tags.md +++ b/doc/api/tags.md @@ -38,6 +38,50 @@ Parameters: ] ``` +## Get a single repository tag + +Get a specific repository tag determined by its name. It returns 200 together +with the tag information if the tag exists. It returns 404 if the tag does not +exist. + +``` +GET /projects/:id/repository/tags/:tag_name +``` + +Parameters: + +| Attribute | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `id` | integer | yes | The ID of a project | +| `tag_name` | string | yes | The name of the tag | + +```bash +curl -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/repository/tags/v1.0.0 +``` + +Example Response: + +```json +{ + "name": "v5.0.0", + "message": null, + "commit": { + "id": "60a8ff033665e1207714d6670fcd7b65304ec02f", + "message": "v5.0.0\n", + "parent_ids": [ + "f61c062ff8bcbdb00e0a1b3317a91aed6ceee06b" + ], + "authored_date": "2015-02-01T21:56:31.000+01:00", + "author_name": "Arthur Verschaeve", + "author_email": "contact@arthurverschaeve.be", + "committed_date": "2015-02-01T21:56:31.000+01:00", + "committer_name": "Arthur Verschaeve", + "committer_email": "contact@arthurverschaeve.be" + }, + "release": null +} +``` + ## Create a new tag Creates a new tag in the repository that points to the supplied ref. @@ -148,4 +192,4 @@ Parameters: "tag_name": "1.0.0", "description": "Amazing release. Wow" } -``` \ No newline at end of file +``` diff --git a/lib/api/tags.rb b/lib/api/tags.rb index 2d8a9e51bb..731a68082b 100644 --- a/lib/api/tags.rb +++ b/lib/api/tags.rb @@ -16,6 +16,20 @@ module API with: Entities::RepoTag, project: user_project end + # Get a single repository tag + # + # Parameters: + # id (required) - The ID of a project + # tag_name (required) - The name of the tag + # Example Request: + # GET /projects/:id/repository/tags/:tag_name + get ":id/repository/tags/:tag_name", requirements: { tag_name: /.*/ } do + tag = user_project.repository.find_tag(params[:tag_name]) + not_found!('Tag') unless tag + + present tag, with: Entities::RepoTag, project: user_project + end + # Create tag # # Parameters: diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb index a15be07ed5..acbd9c3e33 100644 --- a/spec/requests/api/tags_spec.rb +++ b/spec/requests/api/tags_spec.rb @@ -40,6 +40,23 @@ describe API::API, api: true do end end + describe "GET /projects/:id/repository/tags/:tag_name" do + let(:tag_name) { project.repository.tag_names.sort.reverse.first } + + it 'should return a specific tag' do + get api("/projects/#{project.id}/repository/tags/#{tag_name}", user) + + expect(response.status).to eq(200) + expect(json_response['name']).to eq(tag_name) + end + + it 'should return 404 for an invalid tag name' do + get api("/projects/#{project.id}/repository/tags/foobar", user) + + expect(response.status).to eq(404) + end + end + describe 'POST /projects/:id/repository/tags' do context 'lightweight tags' do it 'should create a new tag' do From b3d8b995c3a5dddf1b27c00e2420effb62e548b4 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 12 Apr 2016 14:10:35 +0200 Subject: [PATCH 201/212] Un-instrument Banzai::ReferenceExtractor Instrumenting this class together with Gitlab::ReferenceExtractor causes a StackError for some reason. Since Gitlab::ReferenceExtractor has most of the interesting code we'll only instrument that class. --- config/initializers/metrics.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/config/initializers/metrics.rb b/config/initializers/metrics.rb index 1b445bbbd1..e85ac22f10 100644 --- a/config/initializers/metrics.rb +++ b/config/initializers/metrics.rb @@ -85,9 +85,6 @@ if Gitlab::Metrics.enabled? config.instrument_instance_methods(const) end - config.instrument_methods(Banzai::ReferenceExtractor) - config.instrument_instance_methods(Banzai::ReferenceExtractor) - config.instrument_methods(Banzai::Renderer) config.instrument_methods(Banzai::Querying) From f81352f531b22d02b1b80cfbd6daed809ea8cf5d Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 12:50:21 +0200 Subject: [PATCH 202/212] Fix minor styling issues from code review --- doc/api/tags.md | 4 ++-- lib/api/tags.rb | 6 +++--- spec/requests/api/tags_spec.rb | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/api/tags.md b/doc/api/tags.md index d428ca0ef5..ac9fac92f4 100644 --- a/doc/api/tags.md +++ b/doc/api/tags.md @@ -40,8 +40,8 @@ Parameters: ## Get a single repository tag -Get a specific repository tag determined by its name. It returns 200 together -with the tag information if the tag exists. It returns 404 if the tag does not +Get a specific repository tag determined by its name. It returns `200` together +with the tag information if the tag exists. It returns `404` if the tag does not exist. ``` diff --git a/lib/api/tags.rb b/lib/api/tags.rb index 731a68082b..d1a10479e4 100644 --- a/lib/api/tags.rb +++ b/lib/api/tags.rb @@ -19,15 +19,15 @@ module API # Get a single repository tag # # Parameters: - # id (required) - The ID of a project + # id (required) - The ID of a project # tag_name (required) - The name of the tag # Example Request: # GET /projects/:id/repository/tags/:tag_name - get ":id/repository/tags/:tag_name", requirements: { tag_name: /.*/ } do + get ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do tag = user_project.repository.find_tag(params[:tag_name]) not_found!('Tag') unless tag - present tag, with: Entities::RepoTag, project: user_project + present tag, with: Entities::RepoTag, project: user_project end # Create tag diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb index acbd9c3e33..9f9c3b1cf4 100644 --- a/spec/requests/api/tags_spec.rb +++ b/spec/requests/api/tags_spec.rb @@ -40,17 +40,17 @@ describe API::API, api: true do end end - describe "GET /projects/:id/repository/tags/:tag_name" do + describe 'GET /projects/:id/repository/tags/:tag_name' do let(:tag_name) { project.repository.tag_names.sort.reverse.first } - it 'should return a specific tag' do + it 'returns a specific tag' do get api("/projects/#{project.id}/repository/tags/#{tag_name}", user) expect(response.status).to eq(200) expect(json_response['name']).to eq(tag_name) end - it 'should return 404 for an invalid tag name' do + it 'returns 404 for an invalid tag name' do get api("/projects/#{project.id}/repository/tags/foobar", user) expect(response.status).to eq(404) From ba21c00f01bf4274d0e4cc3892293fc1e581b260 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 01:21:02 +0200 Subject: [PATCH 203/212] Delete notes via API --- CHANGELOG | 5 +++ app/controllers/projects/notes_controller.rb | 5 +-- app/services/notes/delete_service.rb | 8 ++++ doc/api/notes.md | 45 ++++++++++++++++++++ lib/api/notes.rb | 17 ++++++++ spec/requests/api/notes_spec.rb | 43 +++++++++++++++++++ spec/services/notes/delete_service_spec.rb | 15 +++++++ 7 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 app/services/notes/delete_service.rb create mode 100644 spec/services/notes/delete_service_spec.rb diff --git a/CHANGELOG b/CHANGELOG index 593e8f77ab..f4dbab8889 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -46,6 +46,11 @@ v 8.6.5 - Return status code 303 after a branch DELETE operation to avoid project deletion (Stan Hu). !3583 - Unblock user when active_directory is disabled and it can be found !3550 - Fix a 2FA authentication spoofing vulnerability. + - API: Delete notes of issues, snippets, and merge requests (Robert Schilling) + +v 8.6.5 (unreleased) + - Only update repository language if it is not set to improve performance + - Check permissions when user attempts to import members from another project v 8.6.4 - Don't attempt to fetch any tags from a forked repo (Stan Hu) diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index 1b9dd56804..a9a69573ee 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -39,8 +39,7 @@ class Projects::NotesController < Projects::ApplicationController def destroy if note.editable? - note.destroy - note.reset_events_cache + Notes::DeleteService.new(project, current_user).execute(note) end respond_to do |format| @@ -73,7 +72,7 @@ class Projects::NotesController < Projects::ApplicationController note = noteable.notes.find_by(data) if note - note.destroy + Notes::DeleteService.new(project, current_user).execute(note) else Notes::CreateService.new(project, current_user, note_params).execute end diff --git a/app/services/notes/delete_service.rb b/app/services/notes/delete_service.rb new file mode 100644 index 0000000000..7f1b30ec84 --- /dev/null +++ b/app/services/notes/delete_service.rb @@ -0,0 +1,8 @@ +module Notes + class DeleteService < BaseService + def execute(note) + note.destroy + note.reset_events_cache + end + end +end diff --git a/doc/api/notes.md b/doc/api/notes.md index 9168ab00d7..82494bf83f 100644 --- a/doc/api/notes.md +++ b/doc/api/notes.md @@ -105,6 +105,21 @@ Parameters: - `note_id` (required) - The ID of a note - `body` (required) - The content of a note +### Delete existing issue note + +Deletes an existing note of an issue. On success, this API method returns 200. +If the note does not exist, the API returns 404. + +``` +DELETE /projects/:id/issues/:issue_id/notes/:note_id +``` + +Parameters: + +- `id` (required) - The ID of a project +- `issue_id` (required) - The ID of an issue +- `note_id` (required) - The ID of a note + ## Snippets ### List all snippet notes @@ -182,6 +197,21 @@ Parameters: - `note_id` (required) - The ID of a note - `body` (required) - The content of a note +### Delete existing snippet note + +Deletes an existing note of a snippet. On success, this API method returns 200. +If the note does not exist, the API returns 404. + +``` +DELETE /projects/:id/snippets/:snippet_id/notes/:note_id +``` + +Parameters: + +- `id` (required) - The ID of a project +- `snippet_id` (required) - The ID of a snippet +- `note_id` (required) - The ID of a note + ## Merge Requests ### List all merge request notes @@ -262,3 +292,18 @@ Parameters: - `merge_request_id` (required) - The ID of a merge request - `note_id` (required) - The ID of a note - `body` (required) - The content of a note + +### Delete existing snippet note + +Deletes an existing note of a merge request. On success, this API method returns +200. If the note does not exist, the API returns 404. + +``` +DELETE /projects/:id/merge_requests/:merge_request_id/notes/:note_id +``` + +Parameters: + +- `id` (required) - The ID of a project +- `merge_request_id` (required) - The ID of a merge request +- `note_id` (required) - The ID of a note diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 174473f537..fd1704d395 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -112,6 +112,23 @@ module API end end + # Delete a +notable+ note + # + # Parameters: + # Parameters: + # id (required) - The ID of a project + # noteable_id (required) - The ID of an issue, MR, or snippet + # node_id (required) - The ID of a note + # Example Request: + # DELETE /projects/:id/issues/:noteable_id/notes/:note_id + # DELETE /projects/:id/snippets/:noteable_id/notes/:node_id + delete ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do + note = user_project.notes.find(params[:note_id]) + not_found!('Note') unless note + authorize! :admin_note, note + ::Notes::DeleteService.new(user_project, current_user).execute(note) + true + end end end end diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index 39f9a06fe1..23d3c63bc1 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -241,4 +241,47 @@ describe API::API, api: true do end end + describe ':id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id' do + context 'when noteable is an Issue' do + it 'should delete a note' do + delete api("/projects/#{project.id}/issues/#{issue.id}/"\ + "notes/#{issue_note.id}", user) + expect(response.status).to eq(200) + end + + it 'should return a 404 error when note id not found' do + delete api("/projects/#{project.id}/issues/#{issue.id}/notes/123", user) + expect(response.status).to eq(404) + end + end + + context 'when noteable is a Snippet' do + it 'should delete a note' do + delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ + "notes/#{snippet_note.id}", user) + expect(response.status).to eq(200) + end + + it 'should return a 404 error when note id not found' do + delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ + "notes/123", user) + expect(response.status).to eq(404) + end + end + + context 'when noteable is a Merge Request' do + it 'should delete a note' do + delete api("/projects/#{project.id}/merge_requests/"\ + "#{merge_request.id}/notes/#{merge_request_note.id}", user) + expect(response.status).to eq(200) + end + + it 'should return a 404 error when note id not found' do + delete api("/projects/#{project.id}/merge_requests/"\ + "#{merge_request.id}/notes/123", user) + expect(response.status).to eq(404) + end + end + end + end diff --git a/spec/services/notes/delete_service_spec.rb b/spec/services/notes/delete_service_spec.rb new file mode 100644 index 0000000000..88e71c135d --- /dev/null +++ b/spec/services/notes/delete_service_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe Notes::DeleteService, services: true do + let(:project) { create(:empty_project) } + let(:issue) { create(:issue, project: project) } + let(:user) { create(:user) } + let(:note) { create(:note, project: project, noteable: issue, author: user, note: 'Note') } + + describe '#execute' do + it 'deletes a note' do + Notes::DeleteService.new(project, user).execute(note) + expect(project.issues.find(issue.id).notes).to_not include(note) + end + end +end From 9aefaa41ab1442f81ffc15ad9a8279bd1e92c91a Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Wed, 6 Apr 2016 19:04:17 +0200 Subject: [PATCH 204/212] Fix code review issues --- app/controllers/projects/notes_controller.rb | 2 +- doc/api/notes.md | 130 ++++++++++++++++--- lib/api/notes.rb | 6 +- spec/requests/api/notes_spec.rb | 20 ++- spec/services/notes/delete_service_spec.rb | 9 +- 5 files changed, 140 insertions(+), 27 deletions(-) diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index a9a69573ee..707a0d0e5c 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -72,7 +72,7 @@ class Projects::NotesController < Projects::ApplicationController note = noteable.notes.find_by(data) if note - Notes::DeleteService.new(project, current_user).execute(note) + note.destroy else Notes::CreateService.new(project, current_user, note_params).execute end diff --git a/doc/api/notes.md b/doc/api/notes.md index 82494bf83f..2e0936f11b 100644 --- a/doc/api/notes.md +++ b/doc/api/notes.md @@ -105,10 +105,10 @@ Parameters: - `note_id` (required) - The ID of a note - `body` (required) - The content of a note -### Delete existing issue note +### Delete an issue note -Deletes an existing note of an issue. On success, this API method returns 200. -If the note does not exist, the API returns 404. +Deletes an existing note of an issue. On success, this API method returns 200 +and the deleted note. If the note does not exist, the API returns 404. ``` DELETE /projects/:id/issues/:issue_id/notes/:note_id @@ -116,9 +116,41 @@ DELETE /projects/:id/issues/:issue_id/notes/:note_id Parameters: -- `id` (required) - The ID of a project -- `issue_id` (required) - The ID of an issue -- `note_id` (required) - The ID of a note +| Attribute | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `id` | integer | yes | The ID of a project | +| `issue_id` | integer | yes | The ID of an issue | +| `note_id` | integer | yes | The ID of a note | + +```bash +curl -X DELETE -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/issues/11/notes/636 +``` + +Example Response: + +```json +{ + "id": 636, + "body": "This is a good idea.", + "attachment": null, + "author": { + "id": 1, + "username": "pipin", + "email": "admin@example.com", + "name": "Pip", + "state": "active", + "created_at": "2013-09-30T13:46:01Z", + "avatar_url": "http://www.gravatar.com/avatar/5224fd70153710e92fb8bcf79ac29d67?s=80&d=identicon", + "web_url": "https://gitlab.example.com/u/pipin" + }, + "created_at": "2016-04-05T22:10:44.164Z", + "system": false, + "noteable_id": 11, + "noteable_type": "Issue", + "upvote": false, + "downvote": false +} +``` ## Snippets @@ -197,10 +229,10 @@ Parameters: - `note_id` (required) - The ID of a note - `body` (required) - The content of a note -### Delete existing snippet note +### Delete a snippet note -Deletes an existing note of a snippet. On success, this API method returns 200. -If the note does not exist, the API returns 404. +Deletes an existing note of a snippet. On success, this API method returns 200 +and the deleted note. If the note does not exist, the API returns 404. ``` DELETE /projects/:id/snippets/:snippet_id/notes/:note_id @@ -208,9 +240,41 @@ DELETE /projects/:id/snippets/:snippet_id/notes/:note_id Parameters: -- `id` (required) - The ID of a project -- `snippet_id` (required) - The ID of a snippet -- `note_id` (required) - The ID of a note +| Attribute | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `id` | integer | yes | The ID of a project | +| `snippet_id` | integer | yes | The ID of a snippet | +| `note_id` | integer | yes | The ID of a note | + +```bash +curl -X DELETE -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/snippets/52/notes/1659 +``` + +Example Response: + +```json +{ + "id": 1659, + "body": "This is a good idea.", + "attachment": null, + "author": { + "id": 1, + "username": "pipin", + "email": "admin@example.com", + "name": "Pip", + "state": "active", + "created_at": "2013-09-30T13:46:01Z", + "avatar_url": "http://www.gravatar.com/avatar/5224fd70153710e92fb8bcf79ac29d67?s=80&d=identicon", + "web_url": "https://gitlab.example.com/u/pipin" + }, + "created_at": "2016-04-06T16:51:53.239Z", + "system": false, + "noteable_id": 52, + "noteable_type": "Snippet", + "upvote": false, + "downvote": false +} +``` ## Merge Requests @@ -293,10 +357,10 @@ Parameters: - `note_id` (required) - The ID of a note - `body` (required) - The content of a note -### Delete existing snippet note +### Delete a merge request note Deletes an existing note of a merge request. On success, this API method returns -200. If the note does not exist, the API returns 404. +200 and the deleted note. If the note does not exist, the API returns 404. ``` DELETE /projects/:id/merge_requests/:merge_request_id/notes/:note_id @@ -304,6 +368,38 @@ DELETE /projects/:id/merge_requests/:merge_request_id/notes/:note_id Parameters: -- `id` (required) - The ID of a project -- `merge_request_id` (required) - The ID of a merge request -- `note_id` (required) - The ID of a note +| Attribute | Type | Required | Description | +| --------- | ---- | -------- | ----------- | +| `id` | integer | yes | The ID of a project | +| `merge_request_id` | integer | yes | The ID of a merge request | +| `note_id` | integer | yes | The ID of a note | + +```bash +curl -X DELETE -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/merge_requests/7/notes/1602 +``` + +Example Response: + +```json +{ + "id": 1602, + "body": "This is a good idea.", + "attachment": null, + "author": { + "id": 1, + "username": "pipin", + "email": "admin@example.com", + "name": "Pip", + "state": "active", + "created_at": "2013-09-30T13:46:01Z", + "avatar_url": "http://www.gravatar.com/avatar/5224fd70153710e92fb8bcf79ac29d67?s=80&d=identicon", + "web_url": "https://gitlab.example.com/u/pipin" + }, + "created_at": "2016-04-05T22:11:59.923Z", + "system": false, + "noteable_id": 7, + "noteable_type": "MergeRequest", + "upvote": false, + "downvote": false +} +``` diff --git a/lib/api/notes.rb b/lib/api/notes.rb index fd1704d395..2ed986b9ec 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -112,10 +112,9 @@ module API end end - # Delete a +notable+ note + # Delete a +noteable+ note # # Parameters: - # Parameters: # id (required) - The ID of a project # noteable_id (required) - The ID of an issue, MR, or snippet # node_id (required) - The ID of a note @@ -124,10 +123,9 @@ module API # DELETE /projects/:id/snippets/:noteable_id/notes/:node_id delete ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do note = user_project.notes.find(params[:note_id]) - not_found!('Note') unless note authorize! :admin_note, note ::Notes::DeleteService.new(user_project, current_user).execute(note) - true + present note, with: Entities::Note end end end diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index 23d3c63bc1..b35e67b5bd 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -241,16 +241,22 @@ describe API::API, api: true do end end - describe ':id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id' do + describe 'DELETE /projects/:id/noteable/:noteable_id/notes/:note_id' do context 'when noteable is an Issue' do it 'should delete a note' do delete api("/projects/#{project.id}/issues/#{issue.id}/"\ "notes/#{issue_note.id}", user) + expect(response.status).to eq(200) + # Check if note is really deleted + delete api("/projects/#{project.id}/issues/#{issue.id}/"\ + "notes/#{issue_note.id}", user) + expect(response.status).to eq(404) end it 'should return a 404 error when note id not found' do delete api("/projects/#{project.id}/issues/#{issue.id}/notes/123", user) + expect(response.status).to eq(404) end end @@ -259,12 +265,18 @@ describe API::API, api: true do it 'should delete a note' do delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ "notes/#{snippet_note.id}", user) + expect(response.status).to eq(200) + # Check if note is really deleted + delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ + "notes/#{snippet_note.id}", user) + expect(response.status).to eq(404) end it 'should return a 404 error when note id not found' do delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ "notes/123", user) + expect(response.status).to eq(404) end end @@ -273,12 +285,18 @@ describe API::API, api: true do it 'should delete a note' do delete api("/projects/#{project.id}/merge_requests/"\ "#{merge_request.id}/notes/#{merge_request_note.id}", user) + expect(response.status).to eq(200) + # Check if note is really deleted + delete api("/projects/#{project.id}/merge_requests/"\ + "#{merge_request.id}/notes/#{merge_request_note.id}", user) + expect(response.status).to eq(404) end it 'should return a 404 error when note id not found' do delete api("/projects/#{project.id}/merge_requests/"\ "#{merge_request.id}/notes/123", user) + expect(response.status).to eq(404) end end diff --git a/spec/services/notes/delete_service_spec.rb b/spec/services/notes/delete_service_spec.rb index 88e71c135d..07aa57c464 100644 --- a/spec/services/notes/delete_service_spec.rb +++ b/spec/services/notes/delete_service_spec.rb @@ -3,13 +3,14 @@ require 'spec_helper' describe Notes::DeleteService, services: true do let(:project) { create(:empty_project) } let(:issue) { create(:issue, project: project) } - let(:user) { create(:user) } - let(:note) { create(:note, project: project, noteable: issue, author: user, note: 'Note') } + let(:note) { create(:note, project: project, noteable: issue) } describe '#execute' do it 'deletes a note' do - Notes::DeleteService.new(project, user).execute(note) - expect(project.issues.find(issue.id).notes).to_not include(note) + project = note.project + described_class.new(project, note.author).execute(note) + + expect(project.issues.find(issue.id).notes).not_to include(note) end end end From 49484f9a2c2efb670f044028c555f00378484dd4 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 14:20:58 +0200 Subject: [PATCH 205/212] Fix changelog entry --- CHANGELOG | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f4dbab8889..5dd1cf5f28 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,6 +24,7 @@ v 8.7.0 (unreleased) - Ensure empty recipients are rejected in BuildsEmailService - API: Ability to filter milestones by state `active` and `closed` (Robert Schilling) - API: Fix milestone filtering by `iid` (Robert Schilling) + - API: Delete notes of issues, snippets, and merge requests (Robert Schilling) - Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.) - Better errors handling when creating milestones inside groups - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) @@ -46,11 +47,6 @@ v 8.6.5 - Return status code 303 after a branch DELETE operation to avoid project deletion (Stan Hu). !3583 - Unblock user when active_directory is disabled and it can be found !3550 - Fix a 2FA authentication spoofing vulnerability. - - API: Delete notes of issues, snippets, and merge requests (Robert Schilling) - -v 8.6.5 (unreleased) - - Only update repository language if it is not set to improve performance - - Check permissions when user attempts to import members from another project v 8.6.4 - Don't attempt to fetch any tags from a forked repo (Stan Hu) From 6dbcb880cc72f7511358612bbc76e2ab9ded14c5 Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Fri, 8 Apr 2016 12:41:37 +0200 Subject: [PATCH 206/212] Allow a project member to leave the projected through the API --- CHANGELOG | 1 + doc/api/projects.md | 6 ++++-- lib/api/project_members.rb | 13 +++++++++---- spec/requests/api/project_members_spec.rb | 20 +++++++++++++++++--- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 593e8f77ab..3c03b26cf5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -37,6 +37,7 @@ v 8.7.0 (unreleased) - ClosingIssueExtractor regex now also works with colons. e.g. "Fixes: #1234" !3591 - Update number of Todos in the sidebar when it's marked as "Done". !3600 - API: Expose 'updated_at' for issue, snippet, and merge request notes (Robert Schilling) + - API: User can leave a project through the API when not master or owner. !3613 v 8.6.5 - Fix importing from GitHub Enterprise. !3529 diff --git a/doc/api/projects.md b/doc/api/projects.md index 3a909a2bc8..ab716c229d 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -780,8 +780,10 @@ Parameters: - `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project - `user_id` (required) - The ID of a team member -This method is idempotent and can be called multiple times with the same parameters. -Revoking team membership for a user who is not currently a team member is considered success. +This method removes the project member if the user has the proper access rights to do so. +It returns a status code 403 if the member does not have the proper rights to perform this action. +In all other cases this method is idempotent and revoking team membership for a user who is not +currently a team member is considered success. Please note that the returned JSON currently differs slightly. Thus you should not rely on the returned JSON structure. diff --git a/lib/api/project_members.rb b/lib/api/project_members.rb index c756bb479f..4aefdf319c 100644 --- a/lib/api/project_members.rb +++ b/lib/api/project_members.rb @@ -93,12 +93,17 @@ module API # Example Request: # DELETE /projects/:id/members/:user_id delete ":id/members/:user_id" do - authorize! :admin_project, user_project project_member = user_project.project_members.find_by(user_id: params[:user_id]) - unless project_member.nil? - project_member.destroy - else + + unless current_user.can?(:admin_project, user_project) || + current_user.can?(:destroy_project_member, project_member) + forbidden! + end + + if project_member.nil? { message: "Access revoked", id: params[:user_id].to_i } + else + project_member.destroy end end end diff --git a/spec/requests/api/project_members_spec.rb b/spec/requests/api/project_members_spec.rb index 4301588b16..c112ca5e3c 100644 --- a/spec/requests/api/project_members_spec.rb +++ b/spec/requests/api/project_members_spec.rb @@ -118,8 +118,10 @@ describe API::API, api: true do end describe "DELETE /projects/:id/members/:user_id" do - before { project_member } - before { project_member2 } + before do + project_member + project_member2 + end it "should remove user from project team" do expect do @@ -132,6 +134,7 @@ describe API::API, api: true do expect do delete api("/projects/#{project.id}/members/#{user3.id}", user) end.to_not change { ProjectMember.count } + expect(response.status).to eq(200) end it "should return 200 if team member already removed" do @@ -145,8 +148,19 @@ describe API::API, api: true do delete api("/projects/#{project.id}/members/1000000", user) end.to change { ProjectMember.count }.by(0) expect(response.status).to eq(200) - expect(json_response['message']).to eq("Access revoked") expect(json_response['id']).to eq(1000000) + expect(json_response['message']).to eq('Access revoked') + end + + context 'when the user is not an admin or owner' do + it 'can leave the project' do + expect do + delete api("/projects/#{project.id}/members/#{user3.id}", user3) + end.to change { ProjectMember.count }.by(-1) + + expect(response.status).to eq(200) + expect(json_response['id']).to eq(project_member2.id) + end end end end From 08a217cfcfc2e2387c6d4070ed8b0e121f47f50c Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 15:28:09 +0200 Subject: [PATCH 207/212] Add changelog entry --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index c08b148c3a..85539b1a12 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -28,6 +28,7 @@ v 8.7.0 (unreleased) - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) - Gracefully handle notes on deleted commits in merge requests (Stan Hu) - Fix creation of merge requests for orphaned branches (Stan Hu) + - API: Ability to retrieve a single tag (Robert Schilling) - Fall back to `In-Reply-To` and `References` headers when sub-addressing is not available (David Padilla) - Remove "Congratulations!" tweet button on newly-created project. (Connor Shea) - Fix admin/projects when using visibility levels on search (PotHix) From 050110c9c90d39ea9c128ac183c13a37250fd7a1 Mon Sep 17 00:00:00 2001 From: Arinde Eniola Date: Tue, 12 Apr 2016 14:41:34 +0100 Subject: [PATCH 208/212] hide help block when user is creating a new project inside a group --- CHANGELOG | 1 + .../behaviors/requires_input.js.coffee | 16 +++++++++++++++- app/helpers/namespaces_helper.rb | 12 ++++++++++-- app/views/projects/new.html.haml | 2 +- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 593e8f77ab..fa6d4d7551 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -26,6 +26,7 @@ v 8.7.0 (unreleased) - API: Fix milestone filtering by `iid` (Robert Schilling) - Implement 'Groups View' as an option for dashboard preferences !3379 (Elias W.) - Better errors handling when creating milestones inside groups + - Hide `Create a group` help block when creating a new project in a group - Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.) - Gracefully handle notes on deleted commits in merge requests (Stan Hu) - Fix creation of merge requests for orphaned branches (Stan Hu) diff --git a/app/assets/javascripts/behaviors/requires_input.js.coffee b/app/assets/javascripts/behaviors/requires_input.js.coffee index 79d750d184..0faa570ce1 100644 --- a/app/assets/javascripts/behaviors/requires_input.js.coffee +++ b/app/assets/javascripts/behaviors/requires_input.js.coffee @@ -35,4 +35,18 @@ $.fn.requiresInput = -> $form.on 'change input', fieldSelector, requireInput $ -> - $('form.js-requires-input').requiresInput() + $form = $('form.js-requires-input') + $form.requiresInput() + + # Hide or Show the help block when creating a new project + # based on the option selected + hideOrShowHelpBlock = (form) -> + selected = $('.js-select-namespace option:selected') + if selected.length and selected.data('options-parent') is 'groups' + return form.find('.help-block').hide() + else if selected.length + form.find('.help-block').show() + + hideOrShowHelpBlock($form) + + $('.select2.js-select-namespace').change -> hideOrShowHelpBlock($form) diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index faba418c4d..94c6b548ec 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -3,8 +3,16 @@ module NamespacesHelper groups = current_user.owned_groups + current_user.masters_groups users = [current_user.namespace] - group_opts = ["Groups", groups.sort_by(&:human_name).map {|g| [display_path ? g.path : g.human_name, g.id]} ] - users_opts = [ "Users", users.sort_by(&:human_name).map {|u| [display_path ? u.path : u.human_name, u.id]} ] + data_attr_group = { 'data-options-parent' => 'groups' } + data_attr_users = { 'data-options-parent' => 'users' } + + group_opts = [ + "Groups", groups.sort_by(&:human_name).map { |g| [display_path ? g.path : g.human_name, g.id, data_attr_group] } + ] + + users_opts = [ + "Users", users.sort_by(&:human_name).map { |u| [display_path ? u.path : u.human_name, u.id, data_attr_users] } + ] options = [] options << group_opts diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index 2523311213..a4c6094c69 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -19,7 +19,7 @@ - if current_user.can_select_namespace? .input-group-addon = root_url - = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user, display_path: true), {}, {class: 'select2', tabindex: 1} + = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user, display_path: true), {}, {class: 'select2 js-select-namespace', tabindex: 1} .input-group-addon \/ - else From dc39c8372d760eceba50a35505dad8663b9e851e Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Tue, 12 Apr 2016 15:43:29 +0200 Subject: [PATCH 209/212] Adapt tests to new testing guidelines --- lib/api/notes.rb | 2 ++ spec/requests/api/notes_spec.rb | 12 ++++++------ spec/services/notes/delete_service_spec.rb | 9 ++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 2ed986b9ec..a1c98f5e8f 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -124,7 +124,9 @@ module API delete ":id/#{noteables_str}/:#{noteable_id_str}/notes/:note_id" do note = user_project.notes.find(params[:note_id]) authorize! :admin_note, note + ::Notes::DeleteService.new(user_project, current_user).execute(note) + present note, with: Entities::Note end end diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index b35e67b5bd..a467bc935a 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -243,7 +243,7 @@ describe API::API, api: true do describe 'DELETE /projects/:id/noteable/:noteable_id/notes/:note_id' do context 'when noteable is an Issue' do - it 'should delete a note' do + it 'deletes a note' do delete api("/projects/#{project.id}/issues/#{issue.id}/"\ "notes/#{issue_note.id}", user) @@ -254,7 +254,7 @@ describe API::API, api: true do expect(response.status).to eq(404) end - it 'should return a 404 error when note id not found' do + it 'returns a 404 error when note id not found' do delete api("/projects/#{project.id}/issues/#{issue.id}/notes/123", user) expect(response.status).to eq(404) @@ -262,7 +262,7 @@ describe API::API, api: true do end context 'when noteable is a Snippet' do - it 'should delete a note' do + it 'deletes a note' do delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ "notes/#{snippet_note.id}", user) @@ -273,7 +273,7 @@ describe API::API, api: true do expect(response.status).to eq(404) end - it 'should return a 404 error when note id not found' do + it 'returns a 404 error when note id not found' do delete api("/projects/#{project.id}/snippets/#{snippet.id}/"\ "notes/123", user) @@ -282,7 +282,7 @@ describe API::API, api: true do end context 'when noteable is a Merge Request' do - it 'should delete a note' do + it 'deletes a note' do delete api("/projects/#{project.id}/merge_requests/"\ "#{merge_request.id}/notes/#{merge_request_note.id}", user) @@ -293,7 +293,7 @@ describe API::API, api: true do expect(response.status).to eq(404) end - it 'should return a 404 error when note id not found' do + it 'returns a 404 error when note id not found' do delete api("/projects/#{project.id}/merge_requests/"\ "#{merge_request.id}/notes/123", user) diff --git a/spec/services/notes/delete_service_spec.rb b/spec/services/notes/delete_service_spec.rb index 07aa57c464..1d0a747a48 100644 --- a/spec/services/notes/delete_service_spec.rb +++ b/spec/services/notes/delete_service_spec.rb @@ -1,13 +1,12 @@ require 'spec_helper' describe Notes::DeleteService, services: true do - let(:project) { create(:empty_project) } - let(:issue) { create(:issue, project: project) } - let(:note) { create(:note, project: project, noteable: issue) } - describe '#execute' do it 'deletes a note' do - project = note.project + project = create(:empty_project) + issue = create(:issue, project: project) + note = create(:note, project: project, noteable: issue) + described_class.new(project, note.author).execute(note) expect(project.issues.find(issue.id).notes).not_to include(note) From 435892ed4398afb67043c62be8831df07d2078f2 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 12 Apr 2016 16:07:58 +0200 Subject: [PATCH 210/212] Changelog entry for service class instrumentation [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index c08b148c3a..f4f864b301 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 8.7.0 (unreleased) + - All service classes (those residing in app/services) are now instrumented (Yorick Peterse) - Enable gzip for assets, makes the page size significantly smaller. !3544 / !3632 (Connor Shea) - Load award emoji images separately unless opening the full picker. Saves several hundred KBs of data for most pages. (Connor Shea) - All images in discussions and wikis now link to their source files !3464 (Connor Shea). From c87068658924d170f7eea787c7f924ef42d288a6 Mon Sep 17 00:00:00 2001 From: Jeroen Bobbeldijk Date: Tue, 12 Apr 2016 16:44:12 +0200 Subject: [PATCH 211/212] Add my name --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a53a0615ca..e77b659f26 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -36,7 +36,7 @@ v 8.7.0 (unreleased) - Update number of Todos in the sidebar when it's marked as "Done". !3600 v 8.6.6 - - Fix error on language detection when repository has no HEAD (e.g., master branch). !3654 + - Fix error on language detection when repository has no HEAD (e.g., master branch). !3654 (Jeroen Bobbeldijk) v 8.6.5 - Fix importing from GitHub Enterprise. !3529 From 6f74c7d4827955d44f53eeef0701e4e3c0f718a1 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Tue, 12 Apr 2016 18:06:57 +0200 Subject: [PATCH 212/212] fix export commits stuff --- .../projects/import_export/import_export.yml | 4 ++-- .../projects/import_export/project_tree_saver.rb | 2 +- .../import_export/project_tree_saver_spec.rb | 15 ++++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/services/projects/import_export/import_export.yml b/app/services/projects/import_export/import_export.yml index c622447ef0..92f492e901 100644 --- a/app/services/projects/import_export/import_export.yml +++ b/app/services/projects/import_export/import_export.yml @@ -12,8 +12,8 @@ - :merge_requests: - :merge_request_diff - :notes - - :commit_statuses: - - :commit + - :ci_commits: + - :statuses :attributes_only: :project: diff --git a/app/services/projects/import_export/project_tree_saver.rb b/app/services/projects/import_export/project_tree_saver.rb index b2ca85bd7c..37bf3e8e54 100644 --- a/app/services/projects/import_export/project_tree_saver.rb +++ b/app/services/projects/import_export/project_tree_saver.rb @@ -20,7 +20,7 @@ module Projects File.write(full_path, project_json_tree) true rescue - #TODO: handle error + # TODO: handle error false end diff --git a/spec/services/projects/import_export/project_tree_saver_spec.rb b/spec/services/projects/import_export/project_tree_saver_spec.rb index eda9e08cdc..05ece41341 100644 --- a/spec/services/projects/import_export/project_tree_saver_spec.rb +++ b/spec/services/projects/import_export/project_tree_saver_spec.rb @@ -20,9 +20,10 @@ describe Projects::ImportExport::ProjectTreeSaver, services: true do merge_requests: [merge_request], labels: [label], snippets: [snippet], - releases: [release], - commit_statuses: [commit_status]) + releases: [release] + ) end + let!(:ci_commit) { create(:ci_commit, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch, statuses: [commit_status]) } let!(:milestone) { create(:milestone, title: "Milestone v1.2", project: project) } let(:export_path) { "#{Dir::tmpdir}/project_tree_saver_spec" } let(:shared) { Projects::ImportExport::Shared.new(relative_path: project.path_with_namespace) } @@ -86,10 +87,6 @@ describe Projects::ImportExport::ProjectTreeSaver, services: true do expect(saved_project_json['issues'].first['notes']).not_to be_empty end - it 'has commit statuses' do - expect(saved_project_json['commit_statuses']).not_to be_empty - end - it 'has project members' do expect(saved_project_json['project_members']).not_to be_empty end @@ -102,8 +99,12 @@ describe Projects::ImportExport::ProjectTreeSaver, services: true do expect(saved_project_json['merge_requests'].first['notes']).not_to be_empty end + it 'has commit statuses' do + expect(saved_project_json['ci_commits'].first['statuses']).not_to be_empty + end + it 'has ci commits' do - expect(saved_project_json['commit_statuses'].first['commit']).not_to be_empty + expect(saved_project_json['ci_commits']).not_to be_empty end end end