From de7c3291e9e7d4a8f542c912c7575ec97a3a78df Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Thu, 20 Nov 2014 09:29:56 +0300 Subject: [PATCH 01/21] Trigger merge request hook when source updated --- app/services/merge_requests/refresh_service.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index baf0936cc3..e557dd3ab0 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -51,7 +51,7 @@ module MergeRequests if merge_request.source_branch == @branch_name || force_push? merge_request.reload_code - merge_request.mark_as_unchecked + update_merge_request(merge_request) else mr_commit_ids = merge_request.commits.map(&:id) push_commit_ids = @commits.map(&:id) @@ -59,14 +59,20 @@ module MergeRequests if matches.any? merge_request.reload_code - merge_request.mark_as_unchecked + update_merge_request(merge_request) else - merge_request.mark_as_unchecked + update_merge_request(merge_request) end end end end + def update_merge_request(merge_request) + MergeRequests::UpdateService.new( + merge_request.target_project, + @current_user, merge_status: 'unchecked').execute(merge_request) + end + # Add comment about pushing new commits to merge requests def comment_mr_with_commits merge_requests = @project.origin_merge_requests.opened.where(source_branch: @branch_name).to_a From af44c65030a1fbc4e29c3cf51e4d3c33b9666201 Mon Sep 17 00:00:00 2001 From: yglukhov Date: Mon, 9 Feb 2015 15:34:06 +0200 Subject: [PATCH 02/21] Diff headers made sticky --- app/assets/javascripts/application.js.coffee | 1 + app/assets/javascripts/diff.js.coffee | 2 ++ vendor/assets/javascripts/jquery.sticky-kit.min.js | 9 +++++++++ 3 files changed, 12 insertions(+) create mode 100644 vendor/assets/javascripts/jquery.sticky-kit.min.js diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 9c97582e6d..9c5ca879ec 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -16,6 +16,7 @@ #= require jquery.scrollTo #= require jquery.blockUI #= require jquery.turbolinks +#= require jquery.sticky-kit.min #= require turbolinks #= require autosave #= require bootstrap diff --git a/app/assets/javascripts/diff.js.coffee b/app/assets/javascripts/diff.js.coffee index 52b4208524..b0b312e774 100644 --- a/app/assets/javascripts/diff.js.coffee +++ b/app/assets/javascripts/diff.js.coffee @@ -36,6 +36,8 @@ class @Diff ) ) + $('.diff-header').stick_in_parent(offset_top: $('.navbar').height()) + lineNumbers: (line) -> return ([0, 0]) unless line.children().length lines = line.children().slice(0, 2) diff --git a/vendor/assets/javascripts/jquery.sticky-kit.min.js b/vendor/assets/javascripts/jquery.sticky-kit.min.js new file mode 100644 index 0000000000..e8bb207c5a --- /dev/null +++ b/vendor/assets/javascripts/jquery.sticky-kit.min.js @@ -0,0 +1,9 @@ +/* + Sticky-kit v1.1.1 | WTFPL | Leaf Corcoran 2014 | http://leafo.net +*/ +(function(){var k,e;k=this.jQuery||window.jQuery;e=k(window);k.fn.stick_in_parent=function(d){var v,y,n,p,h,C,s,G,q,H;null==d&&(d={});s=d.sticky_class;y=d.inner_scrolling;C=d.recalc_every;h=d.parent;p=d.offset_top;n=d.spacer;v=d.bottoming;null==p&&(p=0);null==h&&(h=void 0);null==y&&(y=!0);null==s&&(s="is_stuck");null==v&&(v=!0);G=function(a,d,q,z,D,t,r,E){var u,F,m,A,c,f,B,w,x,g,b;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);f=a.parent();null!=h&&(f=f.closest(h));if(!f.length)throw"failed to find stick parent"; +u=m=!1;(g=null!=n?n&&a.closest(n):k("
"))&&g.css("position",a.css("position"));B=function(){var c,e,l;if(!E&&(c=parseInt(f.css("border-top-width"),10),e=parseInt(f.css("padding-top"),10),d=parseInt(f.css("padding-bottom"),10),q=f.offset().top+c+e,z=f.height(),m&&(u=m=!1,null==n&&(a.insertAfter(g),g.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(s),l=!0),D=a.offset().top-parseInt(a.css("margin-top"),10)-p,t=a.outerHeight(!0),r=a.css("float"),g&&g.css({width:a.outerWidth(!0), +height:t,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),l))return b()};B();if(t!==z)return A=void 0,c=p,x=C,b=function(){var b,k,l,h;if(!E&&(null!=x&&(--x,0>=x&&(x=C,B())),l=e.scrollTop(),null!=A&&(k=l-A),A=l,m?(v&&(h=l+t+c>z+q,u&&!h&&(u=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),lb&&!u&&(c-=k,c=Math.max(b-t,c),c=Math.min(p,c),m&&a.css({top:c+"px"})))):l>D&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(s),null==n&&(a.after(g),"left"!==r&&"right"!==r||g.append(a)),a.trigger("sticky_kit:stick")),m&&v&&(null==h&&(h=l+t+c>z+q),!u&&h)))return u=!0,"static"===f.css("position")&&f.css({position:"relative"}),a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")}, +w=function(){B();return b()},F=function(){E=!0;e.off("touchmove",b);e.off("scroll",b);e.off("resize",w);k(document.body).off("sticky_kit:recalc",w);a.off("sticky_kit:detach",F);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});f.position("position","");if(m)return null==n&&("left"!==r&&"right"!==r||a.insertAfter(g),g.remove()),a.removeClass(s)},e.on("touchmove",b),e.on("scroll",b),e.on("resize",w),k(document.body).on("sticky_kit:recalc",w),a.on("sticky_kit:detach",F),setTimeout(b, +0)}};q=0;for(H=this.length;q Date: Thu, 12 Feb 2015 13:47:23 +0100 Subject: [PATCH 03/21] Don't cache classes in tests Signed-off-by: Jeroen van Baarsen --- config/environments/test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 25b082b98d..2d5e7addcd 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -5,7 +5,7 @@ Gitlab::Application.configure do # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + config.cache_classes = false # Configure static asset server for tests with Cache-Control for performance config.serve_static_assets = true From 597359b04ff8c696a64ef5891689217af9f8a636 Mon Sep 17 00:00:00 2001 From: Jeroen van Baarsen Date: Thu, 12 Feb 2015 14:23:15 +0100 Subject: [PATCH 04/21] Updated spring Signed-off-by: Jeroen van Baarsen --- Gemfile | 4 ++-- Gemfile.lock | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 4d6d6e7e14..c4812c451c 100644 --- a/Gemfile +++ b/Gemfile @@ -250,8 +250,8 @@ group :development, :test do gem 'jasmine', '2.0.2' - gem "spring", '1.1.3' - gem "spring-commands-rspec", '1.0.1' + gem "spring", '1.3.1' + gem "spring-commands-rspec", '1.0.4' gem "spring-commands-spinach", '1.0.0' end diff --git a/Gemfile.lock b/Gemfile.lock index aef30046d3..f9693d6a77 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -539,8 +539,8 @@ GEM capybara (>= 2.0.0) railties (>= 3) spinach (>= 0.4) - spring (1.1.3) - spring-commands-rspec (1.0.1) + spring (1.3.1) + spring-commands-rspec (1.0.4) spring (>= 0.9.1) spring-commands-spinach (1.0.0) spring (>= 0.9.1) @@ -742,8 +742,8 @@ DEPENDENCIES slack-notifier (~> 1.0.0) slim spinach-rails - spring (= 1.1.3) - spring-commands-rspec (= 1.0.1) + spring (= 1.3.1) + spring-commands-rspec (= 1.0.4) spring-commands-spinach (= 1.0.0) stamp state_machine From c217860ae74381d75a4932fabb4417ac08b014b4 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Sat, 14 Feb 2015 20:19:13 +0100 Subject: [PATCH 05/21] Update charlock_holmes to 0.7.3 Version 0.6.9.4 fails to install on Gentoo Linux. --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3283da40f8..4418d80c0a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,7 +74,7 @@ GEM json (>= 1.7) celluloid (0.16.0) timers (~> 4.0.0) - charlock_holmes (0.6.9.4) + charlock_holmes (0.7.3) cliver (0.3.2) coderay (1.1.0) coercible (1.0.0) From 198d75b3a8516e75c595c5baaa6359c239bc800d Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 20 Feb 2015 14:58:42 +0100 Subject: [PATCH 06/21] Initialize ZenMode on commit show and milestone edit pages. --- app/assets/javascripts/dispatcher.js.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index 1643ca941f..ed1bdd6ca3 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -26,7 +26,7 @@ class Dispatcher new ZenMode() when 'projects:milestones:show' new Milestone() - when 'projects:milestones:new' + when 'projects:milestones:new', 'projects:milestones:edit' new ZenMode() when 'projects:issues:new','projects:issues:edit' GitLab.GfmAutoComplete.setup() @@ -54,6 +54,7 @@ class Dispatcher when 'projects:commit:show' new Commit() new Diff() + new ZenMode() shortcut_handler = new ShortcutsNavigation() when 'projects:commits:show' shortcut_handler = new ShortcutsNavigation() From 31774a3bb739260622b31001cac778468d7dd92f Mon Sep 17 00:00:00 2001 From: Sytse Sijbrandij Date: Sun, 22 Feb 2015 12:49:00 -0800 Subject: [PATCH 07/21] Ensure that people don't view the changelog on the stable branch because we don't update that one. --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 6702ba2ba4..234a5609e0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +Please view this file on the master branch, on stable branches it's out of date. + v 7.9.0 (unreleased) - Move labels/milestones tabs to sidebar - Upgrade Rails gem to version 4.1.9. From 5f232b5687b447e7eac40f58c56628da22580de6 Mon Sep 17 00:00:00 2001 From: Vinnie Okada Date: Sun, 22 Feb 2015 16:01:49 -0700 Subject: [PATCH 08/21] Improve error messages when file editing fails Give more specific errors in API responses and web UI flash messages when a file update fails. --- CHANGELOG | 1 + app/services/base_service.rb | 7 +++-- app/services/files/update_service.rb | 14 ++++++---- lib/api/files.rb | 3 +- .../satellite/files/edit_file_action.rb | 28 +++++++++++++++---- lib/gitlab/satellite/satellite.rb | 4 +++ spec/requests/api/files_spec.rb | 28 ++++++++++++++++--- 7 files changed, 66 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6702ba2ba4..6571f0d1de 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ v 7.9.0 (unreleased) - Move labels/milestones tabs to sidebar - Upgrade Rails gem to version 4.1.9. + - Improve error messages for file edit failures - Improve UI for commits, issues and merge request lists - Fix commit comments on first line of diff not rendering in Merge Request Discussion view. diff --git a/app/services/base_service.rb b/app/services/base_service.rb index bb51795df7..52ab29f149 100644 --- a/app/services/base_service.rb +++ b/app/services/base_service.rb @@ -37,11 +37,14 @@ class BaseService private - def error(message) - { + def error(message, http_status = nil) + result = { message: message, status: :error } + + result[:http_status] = http_status if http_status + result end def success diff --git a/app/services/files/update_service.rb b/app/services/files/update_service.rb index b4986e1c5c..bcf0e7f3ce 100644 --- a/app/services/files/update_service.rb +++ b/app/services/files/update_service.rb @@ -20,17 +20,19 @@ module Files end edit_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path) - created_successfully = edit_file_action.commit!( + edit_file_action.commit!( params[:content], params[:commit_message], params[:encoding] ) - if created_successfully - success - else - error("Your changes could not be committed. Maybe the file was changed by another process or there was nothing to commit?") - end + success + rescue Gitlab::Satellite::CheckoutFailed => ex + error("Your changes could not be committed because ref '#{ref}' could not be checked out", 400) + rescue Gitlab::Satellite::CommitFailed => ex + error("Your changes could not be committed. Maybe there was nothing to commit?", 409) + rescue Gitlab::Satellite::PushFailed => ex + error("Your changes could not be committed. Maybe the file was changed by another process?", 409) end end end diff --git a/lib/api/files.rb b/lib/api/files.rb index e6e71bac36..3176ef0e25 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -117,7 +117,8 @@ module API branch_name: branch_name } else - render_api_error!(result[:message], 400) + http_status = result[:http_status] || 400 + render_api_error!(result[:message], http_status) end end diff --git a/lib/gitlab/satellite/files/edit_file_action.rb b/lib/gitlab/satellite/files/edit_file_action.rb index 2834b722b2..82d71ab990 100644 --- a/lib/gitlab/satellite/files/edit_file_action.rb +++ b/lib/gitlab/satellite/files/edit_file_action.rb @@ -15,7 +15,11 @@ module Gitlab prepare_satellite!(repo) # create target branch in satellite at the corresponding commit from bare repo - repo.git.checkout({ raise: true, timeout: true, b: true }, ref, "origin/#{ref}") + begin + repo.git.checkout({ raise: true, timeout: true, b: true }, ref, "origin/#{ref}") + rescue Grit::Git::CommandFailed => ex + log_and_raise(CheckoutFailed, ex.message) + end # update the file in the satellite's working dir file_path_in_satellite = File.join(repo.working_dir, file_path) @@ -31,19 +35,31 @@ module Gitlab # commit the changes # will raise CommandFailed when commit fails - repo.git.commit(raise: true, timeout: true, a: true, m: commit_message) + begin + repo.git.commit(raise: true, timeout: true, a: true, m: commit_message) + rescue Grit::Git::CommandFailed => ex + log_and_raise(CommitFailed, ex.message) + end # push commit back to bare repo # will raise CommandFailed when push fails - repo.git.push({ raise: true, timeout: true }, :origin, ref) + begin + repo.git.push({ raise: true, timeout: true }, :origin, ref) + rescue Grit::Git::CommandFailed => ex + log_and_raise(PushFailed, ex.message) + end # everything worked true end - rescue Grit::Git::CommandFailed => ex - Gitlab::GitLogger.error(ex.message) - false + end + + private + + def log_and_raise(errorClass, message) + Gitlab::GitLogger.error(message) + raise(errorClass, message) end end end diff --git a/lib/gitlab/satellite/satellite.rb b/lib/gitlab/satellite/satellite.rb index 62d1bb364d..70125d539d 100644 --- a/lib/gitlab/satellite/satellite.rb +++ b/lib/gitlab/satellite/satellite.rb @@ -1,5 +1,9 @@ module Gitlab module Satellite + class CheckoutFailed < StandardError; end + class CommitFailed < StandardError; end + class PushFailed < StandardError; end + class Satellite include Gitlab::Popen diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb index cfac7d289e..bab8888a63 100644 --- a/spec/requests/api/files_spec.rb +++ b/spec/requests/api/files_spec.rb @@ -98,13 +98,33 @@ describe API::API, api: true do expect(response.status).to eq(400) end - it "should return a 400 if satellite fails to create file" do - Gitlab::Satellite::EditFileAction.any_instance.stub( - commit!: false, - ) + it 'should return a 400 if the checkout fails' do + Gitlab::Satellite::EditFileAction.any_instance.stub(:commit!) + .and_raise(Gitlab::Satellite::CheckoutFailed) put api("/projects/#{project.id}/repository/files", user), valid_params expect(response.status).to eq(400) + + ref = valid_params[:branch_name] + expect(response.body).to match("ref '#{ref}' could not be checked out") + end + + it 'should return a 409 if the file was not modified' do + Gitlab::Satellite::EditFileAction.any_instance.stub(:commit!) + .and_raise(Gitlab::Satellite::CommitFailed) + + put api("/projects/#{project.id}/repository/files", user), valid_params + expect(response.status).to eq(409) + expect(response.body).to match("Maybe there was nothing to commit?") + end + + it 'should return a 409 if the push fails' do + Gitlab::Satellite::EditFileAction.any_instance.stub(:commit!) + .and_raise(Gitlab::Satellite::PushFailed) + + put api("/projects/#{project.id}/repository/files", user), valid_params + expect(response.status).to eq(409) + expect(response.body).to match("Maybe the file was changed by another process?") end end From 5ce2d44b136aae8e9e42397474a0e75bc6b32ded Mon Sep 17 00:00:00 2001 From: Sabba Petri Date: Mon, 23 Feb 2015 11:51:18 -0800 Subject: [PATCH 09/21] Added Profile tooltip For consistency sake, the profile in the navbar has a tooltip. --- app/views/layouts/_head_panel.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_head_panel.html.haml b/app/views/layouts/_head_panel.html.haml index 77bfe4f996..d5928d2ed2 100644 --- a/app/views/layouts/_head_panel.html.haml +++ b/app/views/layouts/_head_panel.html.haml @@ -42,7 +42,7 @@ = link_to destroy_user_session_path, class: "logout", method: :delete, title: "Logout", class: 'has_bottom_tooltip', 'data-original-title' => 'Logout' do %i.fa.fa-sign-out %li.hidden-xs - = link_to current_user, class: "profile-pic", id: 'profile-pic' do + = link_to current_user, class: "profile-pic has_bottom_tooltip", id: 'profile-pic', 'data-original-title' => 'Your profile' do = image_tag avatar_icon(current_user.email, 60), alt: 'User activity' = render 'shared/outdated_browser' From b821a1bd41166c295ea1625ccf57b9bb48f61649 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 23 Feb 2015 16:29:32 -0800 Subject: [PATCH 10/21] Fix markdown image uploader after rails update --- config/routes.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index f0979eac90..c0dbf738c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,9 +86,9 @@ Gitlab::Application.routes.draw do constraints: { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /.+/ } # Project markdown uploads - get ":id/:secret/:filename", - to: "projects/uploads#show", - constraints: { id: /[a-zA-Z.0-9_\-]+\/[a-zA-Z.0-9_\-]+/, filename: /.+/ } + get ":namespace_id/:id/:secret/:filename", + to: "projects/uploads#show", + constraints: { namespace_id: /[a-zA-Z.0-9_\-]+/, id: /[a-zA-Z.0-9_\-]+/, filename: /.+/ } end # From 0f6221e7365a93a356410f4d38443381924d4cc6 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 23 Feb 2015 17:56:05 -0800 Subject: [PATCH 11/21] Make services migration more reliable --- ...0907220153_serialize_service_properties.rb | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/db/migrate/20140907220153_serialize_service_properties.rb b/db/migrate/20140907220153_serialize_service_properties.rb index bd75ab1eac..d45a10465b 100644 --- a/db/migrate/20140907220153_serialize_service_properties.rb +++ b/db/migrate/20140907220153_serialize_service_properties.rb @@ -1,6 +1,9 @@ class SerializeServiceProperties < ActiveRecord::Migration def change - add_column :services, :properties, :text + unless column_exists?(:services, :properties) + add_column :services, :properties, :text + end + Service.reset_column_information associations = @@ -19,18 +22,21 @@ class SerializeServiceProperties < ActiveRecord::Migration :api_version, :jira_issue_transition_id], } - Service.all.each do |service| + Service.find_each(batch_size: 500).each do |service| associations[service.type.to_sym].each do |attribute| service.send("#{attribute}=", service.attributes[attribute.to_s]) end - service.save + + service.save(validate: false) end - remove_column :services, :project_url, :string - remove_column :services, :subdomain, :string - remove_column :services, :room, :string - remove_column :services, :recipients, :text - remove_column :services, :api_key, :string - remove_column :services, :token, :string + if column_exists?(:services, :project_url) + remove_column :services, :project_url, :string + remove_column :services, :subdomain, :string + remove_column :services, :room, :string + remove_column :services, :recipients, :text + remove_column :services, :api_key, :string + remove_column :services, :token, :string + end end end From b0dfe434c60da7d04ddf23f7a3e85af97d377568 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 23 Feb 2015 12:38:30 -0800 Subject: [PATCH 12/21] Using gitlab url to build links for gitlab issue tracker and add a spec. Fix rubocop warnings in path. --- .../gitlab_issue_tracker_service.rb | 12 +++- config/routes.rb | 27 +++++---- spec/helpers/gitlab_markdown_helper_spec.rb | 6 +- .../gitlab_issue_tracker_service_spec.rb | 60 +++++++++++++++++++ 4 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 spec/models/project_services/gitlab_issue_tracker_service_spec.rb diff --git a/app/models/project_services/gitlab_issue_tracker_service.rb b/app/models/project_services/gitlab_issue_tracker_service.rb index 782cf42ce5..05c048e4e4 100644 --- a/app/models/project_services/gitlab_issue_tracker_service.rb +++ b/app/models/project_services/gitlab_issue_tracker_service.rb @@ -27,14 +27,20 @@ class GitlabIssueTrackerService < IssueTrackerService end def project_url - namespace_project_issues_path(project.namespace, project) + "#{gitlab_url}#{namespace_project_issues_path(project.namespace, project)}" end def new_issue_url - new_namespace_project_issue_path namespace_id: project.namespace, project_id: project + "#{gitlab_url}#{new_namespace_project_issue_path(namespace_id: project.namespace, project_id: project)}" end def issue_url(iid) - "#{Gitlab.config.gitlab.url}#{namespace_project_issue_path(namespace_id: project.namespace, project_id: project, id: iid)}" + "#{gitlab_url}#{namespace_project_issue_path(namespace_id: project.namespace, project_id: project, id: iid)}" + end + + private + + def gitlab_url + Gitlab.config.gitlab.relative_url_root.chomp("/") if Gitlab.config.gitlab.relative_url_root end end diff --git a/config/routes.rb b/config/routes.rb index c0dbf738c1..ecd439aece 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -269,16 +269,23 @@ Gitlab::Application.routes.draw do post '/preview/*id', to: 'blob#preview', constraints: { id: /.+/ }, as: 'preview_blob' scope do - get('/blob/*id/diff', - to: 'blob#diff', - constraints: { id: /.+/, format: false }, - as: :blob_diff) - get('/blob/*id', - to: 'blob#show', - constraints: { id: /.+/, format: false }, as: :blob) - delete('/blob/*id', - to: 'blob#destroy', - constraints: { id: /.+/, format: false }) + get( + '/blob/*id/diff', + to: 'blob#diff', + constraints: { id: /.+/, format: false }, + as: :blob_diff + ) + get( + '/blob/*id', + to: 'blob#show', + constraints: { id: /.+/, format: false }, + as: :blob + ) + delete( + '/blob/*id', + to: 'blob#destroy', + constraints: { id: /.+/, format: false } + ) end scope do diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 68269ad25a..76fcf888a6 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -474,7 +474,7 @@ describe GitlabMarkdownHelper do # First issue link expect(groups[1]). - to match(/href="#{namespace_project_issue_url(project.namespace, project, issues[0])}"/) + to match(/href="#{namespace_project_issue_path(project.namespace, project, issues[0])}"/) expect(groups[1]).to match(/##{issues[0].iid}$/) # Internal commit link @@ -483,7 +483,7 @@ describe GitlabMarkdownHelper do # Second issue link expect(groups[3]). - to match(/href="#{namespace_project_issue_url(project.namespace, project, issues[1])}"/) + to match(/href="#{namespace_project_issue_path(project.namespace, project, issues[1])}"/) expect(groups[3]).to match(/##{issues[1].iid}$/) # Trailing commit link @@ -611,7 +611,7 @@ describe GitlabMarkdownHelper do end it "should generate absolute urls for refs" do - expect(markdown("##{issue.iid}")).to include(namespace_project_issue_url(project.namespace, project, issue)) + expect(markdown("##{issue.iid}")).to include(namespace_project_issue_path(project.namespace, project, issue)) end it "should generate absolute urls for emoji" do diff --git a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb new file mode 100644 index 0000000000..c474f4a2d9 --- /dev/null +++ b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb @@ -0,0 +1,60 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# template :boolean default(FALSE) +# +require 'spec_helper' + +describe GitlabIssueTrackerService do + describe "Associations" do + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } + end + + + describe 'project and issue urls' do + let(:project) { create(:project) } + + context 'with absolute urls' do + before do + @service = project.create_gitlab_issue_tracker_service(active: true) + end + + after do + @service.destroy! + end + + it 'should give the correct path' do + expect(@service.project_url).to eq("/#{project.path_with_namespace}/issues") + expect(@service.new_issue_url).to eq("/#{project.path_with_namespace}/issues/new") + expect(@service.issue_url(432)).to eq("/#{project.path_with_namespace}/issues/432") + end + end + + context 'with enabled relative urls' do + before do + Settings.gitlab.stub(:relative_url_root).and_return("/gitlab/root") + @service = project.create_gitlab_issue_tracker_service(active: true) + end + + after do + @service.destroy! + end + + it 'should give the correct path' do + expect(@service.project_url).to eq("/gitlab/root/#{project.path_with_namespace}/issues") + expect(@service.new_issue_url).to eq("/gitlab/root/#{project.path_with_namespace}/issues/new") + expect(@service.issue_url(432)).to eq("/gitlab/root/#{project.path_with_namespace}/issues/432") + end + end + end +end From 12589d339070d86b57a4f97778a48b1b9cc5a0a1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 23 Feb 2015 18:43:39 -0800 Subject: [PATCH 13/21] Improve sidebar menu for project settings --- app/assets/stylesheets/sections/nav_sidebar.scss | 2 +- app/views/layouts/nav/_project.html.haml | 8 +------- features/steps/shared/project_tab.rb | 4 +++- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/sections/nav_sidebar.scss b/app/assets/stylesheets/sections/nav_sidebar.scss index 17923ca499..8e02b37507 100644 --- a/app/assets/stylesheets/sections/nav_sidebar.scss +++ b/app/assets/stylesheets/sections/nav_sidebar.scss @@ -47,7 +47,7 @@ border-left: 3px solid $style_color; &.no-highlight { - background: none; + background: none !important; border: none; } diff --git a/app/views/layouts/nav/_project.html.haml b/app/views/layouts/nav/_project.html.haml index 4d859e817a..15b489c7d9 100644 --- a/app/views/layouts/nav/_project.html.haml +++ b/app/views/layouts/nav/_project.html.haml @@ -6,12 +6,7 @@ %span Back to project - = nav_link(html_options: {class: "#{project_tab_class} separate-item"}) do - = link_to edit_namespace_project_path(@project.namespace, @project), title: 'Settings', class: "stat-tab tab no-highlight" do - %i.fa.fa-cogs - %span - Settings - %i.fa.fa-angle-down + %li.separate-item = render 'projects/settings_nav' @@ -98,4 +93,3 @@ %i.fa.fa-cogs %span Settings - %i.fa.fa-angle-down diff --git a/features/steps/shared/project_tab.rb b/features/steps/shared/project_tab.rb index 6aa4f1b20d..c5aed19331 100644 --- a/features/steps/shared/project_tab.rb +++ b/features/steps/shared/project_tab.rb @@ -41,6 +41,8 @@ module SharedProjectTab end step 'the active main tab should be Settings' do - ensure_active_main_tab('Settings') + within '.nav-sidebar' do + page.should have_content('Back to project') + end end end From 897a2de54c1d5cbead4589d44a3d173c14849f23 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 23 Feb 2015 19:35:42 -0800 Subject: [PATCH 14/21] Allow non authenticated access to avatars --- app/controllers/uploads_controller.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index d587797725..73b124bb34 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -1,4 +1,7 @@ class UploadsController < ApplicationController + skip_before_filter :authenticate_user!, :reject_blocked + before_filter :authorize_access + def show model = params[:model].camelize.constantize.find(params[:id]) uploader = model.send(params[:mounted_as]) @@ -14,4 +17,10 @@ class UploadsController < ApplicationController redirect_to uploader.url end end + + def authorize_access + unless params[:mounted_as] == 'avatar' + authenticate_user! && reject_blocked + end + end end From c9829146f88ff87460add83a3719db3e2593f278 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 23 Feb 2015 22:21:49 +0100 Subject: [PATCH 15/21] LDAP users don't need to set a password to Git over HTTP. --- app/models/user.rb | 5 +++++ app/views/shared/_clone_panel.html.haml | 2 +- app/views/shared/_no_password.html.haml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 21ccc76978..08ad619a90 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -45,6 +45,7 @@ # last_credential_check_at :datetime # github_access_token :string(255) # notification_email :string(255) +# password_automatically_set :boolean default(FALSE) # require 'carrierwave/orm/activerecord' @@ -350,6 +351,10 @@ class User < ActiveRecord::Base keys.count == 0 end + def require_password? + password_automatically_set? && !ldap_user? + end + def can_change_username? gitlab_config.username_changing_enabled end diff --git a/app/views/shared/_clone_panel.html.haml b/app/views/shared/_clone_panel.html.haml index df0bde7698..a1121750ca 100644 --- a/app/views/shared/_clone_panel.html.haml +++ b/app/views/shared/_clone_panel.html.haml @@ -9,7 +9,7 @@ :"data-container" => "body"} SSH %button{ | - class: "btn #{ 'active' if default_clone_protocol == 'http' }#{ ' has_tooltip' if current_user && current_user.password_automatically_set? }", | + class: "btn #{ 'active' if default_clone_protocol == 'http' }#{ ' has_tooltip' if current_user && current_user.require_password? }", | :"data-clone" => project.http_url_to_repo, | :"data-title" => "Set a password on your account
to pull or push via #{gitlab_config.protocol.upcase}", :"data-html" => "true", diff --git a/app/views/shared/_no_password.html.haml b/app/views/shared/_no_password.html.haml index 022097cda1..a43bf33751 100644 --- a/app/views/shared/_no_password.html.haml +++ b/app/views/shared/_no_password.html.haml @@ -1,4 +1,4 @@ -- if cookies[:hide_no_password_message].blank? && !current_user.hide_no_password && current_user.password_automatically_set? +- if cookies[:hide_no_password_message].blank? && !current_user.hide_no_password && current_user.require_password? .no-password-message.alert.alert-warning.hidden-xs You won't be able to pull or push project code via #{gitlab_config.protocol.upcase} until you #{link_to 'set a password', edit_profile_password_path} on your account From 64ca07c3b95c6b1e9444d9139858b11a6097c1ca Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 23 Feb 2015 21:27:41 -0800 Subject: [PATCH 16/21] Better readme title --- app/assets/stylesheets/sections/tree.scss | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/sections/tree.scss b/app/assets/stylesheets/sections/tree.scss index ff9464e217..60a1c00b04 100644 --- a/app/assets/stylesheets/sections/tree.scss +++ b/app/assets/stylesheets/sections/tree.scss @@ -120,13 +120,13 @@ } .readme-holder { - border-top: 1px dashed #CCC; - padding-top: 10px; - .readme-file-title { font-size: 14px; + font-weight: bold; margin-bottom: 20px; color: #777; + border-bottom: 1px solid #DDD; + padding: 10px 0; } } From bd6550a5121d5a386c5928bbd74b79ab382c548f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 23 Feb 2015 22:54:32 -0800 Subject: [PATCH 17/21] Bump gitlab-shell to 2.5.4 --- GITLAB_SHELL_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITLAB_SHELL_VERSION b/GITLAB_SHELL_VERSION index aedc15bb0c..fe16b348d9 100644 --- a/GITLAB_SHELL_VERSION +++ b/GITLAB_SHELL_VERSION @@ -1 +1 @@ -2.5.3 +2.5.4 From 2feaa69cd5831578f99c3833f8b1e3e5a8031c1d Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 23 Feb 2015 23:10:35 -0800 Subject: [PATCH 18/21] Update version of gitlab-shell in the installation and update documentation. --- doc/install/installation.md | 4 ++-- doc/update/6.x-or-7.x-to-7.8.md | 4 ++-- doc/update/7.7-to-7.8.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/install/installation.md b/doc/install/installation.md index f5dcec2f61..28597fd39d 100644 --- a/doc/install/installation.md +++ b/doc/install/installation.md @@ -141,7 +141,7 @@ We recommend using a PostgreSQL database. For MySQL check [MySQL setup guide](da # Try connecting to the new database with the new user sudo -u git -H psql -d gitlabhq_production - + # Quit the database session gitlabhq_production> \q @@ -280,7 +280,7 @@ We recommend using a PostgreSQL database. For MySQL check [MySQL setup guide](da GitLab Shell is an SSH access and repository management software developed specially for GitLab. # Run the installation task for gitlab-shell (replace `REDIS_URL` if needed): - sudo -u git -H bundle exec rake gitlab:shell:install[v2.4.3] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production + sudo -u git -H bundle exec rake gitlab:shell:install[v2.5.4] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production # By default, the gitlab-shell config is generated from your main GitLab config. # You can review (and modify) the gitlab-shell config as follows: diff --git a/doc/update/6.x-or-7.x-to-7.8.md b/doc/update/6.x-or-7.x-to-7.8.md index 859f4c1a6d..5884312c47 100644 --- a/doc/update/6.x-or-7.x-to-7.8.md +++ b/doc/update/6.x-or-7.x-to-7.8.md @@ -123,7 +123,7 @@ sudo apt-get install libkrb5-dev ```bash cd /home/git/gitlab-shell sudo -u git -H git fetch -sudo -u git -H git checkout v2.4.3 +sudo -u git -H git checkout v2.5.4 ``` ## 7. Install libs, migrations, etc. @@ -163,7 +163,7 @@ git diff 6-0-stable:config/gitlab.yml.example 7-8-stable:config/gitlab.yml.examp * Make `/home/git/gitlab/config/gitlab.yml` the same as https://gitlab.com/gitlab-org/gitlab-ce/blob/7-8-stable/config/gitlab.yml.example but with your settings. * Make `/home/git/gitlab/config/unicorn.rb` the same as https://gitlab.com/gitlab-org/gitlab-ce/blob/7-8-stable/config/unicorn.rb.example but with your settings. -* Make `/home/git/gitlab-shell/config.yml` the same as https://gitlab.com/gitlab-org/gitlab-shell/blob/v2.4.3/config.yml.example but with your settings. +* Make `/home/git/gitlab-shell/config.yml` the same as https://gitlab.com/gitlab-org/gitlab-shell/blob/v2.5.4/config.yml.example but with your settings. * Copy rack attack middleware config ```bash diff --git a/doc/update/7.7-to-7.8.md b/doc/update/7.7-to-7.8.md index a8a5c7f66c..46ca163c1b 100644 --- a/doc/update/7.7-to-7.8.md +++ b/doc/update/7.7-to-7.8.md @@ -37,7 +37,7 @@ sudo -u git -H git checkout 7-8-stable-ee ```bash cd /home/git/gitlab-shell sudo -u git -H git fetch -sudo -u git -H git checkout v2.5.3 +sudo -u git -H git checkout v2.5.4 ``` ### 4. Install libs, migrations, etc. @@ -102,7 +102,7 @@ If all items are green, then congratulations upgrade is complete! ### 8. GitHub settings (if applicable) -If you are using GitHub as an OAuth provider for authentication, you should change the callback URL so that it +If you are using GitHub as an OAuth provider for authentication, you should change the callback URL so that it only contains a root URL (ex. `https://gitlab.example.com/`) ## Things went south? Revert to previous version (7.7) From 51b18fe6f6558f14e5a8123d27f65f3557134822 Mon Sep 17 00:00:00 2001 From: Igor Bogoslavskyi Date: Tue, 24 Feb 2015 10:50:18 +0100 Subject: [PATCH 19/21] typo fixed fixed a typo in an url to gitlab-ssl. Now it does not return the 404 error --- doc/update/6.x-or-7.x-to-7.8.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/update/6.x-or-7.x-to-7.8.md b/doc/update/6.x-or-7.x-to-7.8.md index 5884312c47..673d9253d6 100644 --- a/doc/update/6.x-or-7.x-to-7.8.md +++ b/doc/update/6.x-or-7.x-to-7.8.md @@ -179,7 +179,7 @@ sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab ### Change Nginx settings * HTTP setups: Make `/etc/nginx/sites-available/gitlab` the same as https://gitlab.com/gitlab-org/gitlab-ce/blob/7-8-stable/lib/support/nginx/gitlab but with your settings. -* HTTPS setups: Make `/etc/nginx/sites-available/gitlab-ssl` the same as https://gitlab.com/gitlab-org/gitlab-ce/blob/7-8-stablef/lib/support/nginx/gitlab-ssl but with your settings. +* HTTPS setups: Make `/etc/nginx/sites-available/gitlab-ssl` the same as https://gitlab.com/gitlab-org/gitlab-ce/blob/7-8-stable/lib/support/nginx/gitlab-ssl but with your settings. * A new `location /uploads/` section has been added that needs to have the same content as the existing `location @gitlab` section. ## 9. Start application From 1e1a95f5c36357b03df9420903d421edf7ac08c4 Mon Sep 17 00:00:00 2001 From: Bugagazavr Date: Tue, 24 Feb 2015 15:12:25 +0300 Subject: [PATCH 20/21] Update Changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index d879ee8572..deda7ffc32 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ v 7.9.0 (unreleased) - Improve error messages for file edit failures - Improve UI for commits, issues and merge request lists - Fix commit comments on first line of diff not rendering in Merge Request Discussion view. + - Improve trigger merge request hook when source project branch has been updated (Kirill Zaitsev) v 7.8.0 - Fix access control and protection against XSS for note attachments and other uploads. From f7c948223d000e4488d864d50f3292a6c7afeaf7 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 24 Feb 2015 09:08:34 -0800 Subject: [PATCH 21/21] Fix access to attachments uploaded with 'Choose file' button for public access --- app/controllers/files_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 9671245d3f..a130bcba9c 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -1,4 +1,6 @@ class FilesController < ApplicationController + skip_before_filter :authenticate_user!, :reject_blocked + def download note = Note.find(params[:id]) uploader = note.attachment