From c3e70280dffe7ee0859ebd73b902d424ca5f809a Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 8 Mar 2016 21:01:33 -0300 Subject: Prevent projects to have higher visibility than groups Prevent Groups to have smaller visibility than projects Add default_group_visibility_level to configuration Code improvements --- app/services/projects/create_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/services/projects') diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index a6820183bee..522fae79503 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -11,8 +11,8 @@ module Projects # Make sure that the user is allowed to use the specified visibility # level - unless Gitlab::VisibilityLevel.allowed_for?(current_user, - params[:visibility_level]) + + unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level]) && @project.visibility_level_allowed?(@project.visibility_level) deny_visibility_level(@project) return @project end -- cgit v1.2.1 From a02fe251df7ea7316f51850fe603e7e5ac4431e2 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 14 Mar 2016 15:18:52 +0100 Subject: Allow project housekeeping only once an hour --- app/services/projects/housekeeping_service.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'app/services/projects') diff --git a/app/services/projects/housekeeping_service.rb b/app/services/projects/housekeeping_service.rb index 0db85ac2142..11be5b1badf 100644 --- a/app/services/projects/housekeeping_service.rb +++ b/app/services/projects/housekeeping_service.rb @@ -9,12 +9,26 @@ module Projects class HousekeepingService < BaseService include Gitlab::ShellAdapter + LEASE_TIMEOUT = 3600 + def initialize(project) @project = project end def execute + if !try_obtain_lease + return "Housekeeping was already triggered in the past #{LEASE_TIMEOUT / 60} minutes" + end + GitlabShellWorker.perform_async(:gc, @project.path_with_namespace) + return "Housekeeping successfully started" + end + + private + + def try_obtain_lease + lease = ::Gitlab::ExclusiveLease.new("project_housekeeping:#{@project.id}", timeout: LEASE_TIMEOUT) + lease.try_obtain end end end -- cgit v1.2.1 From 021d53c96d308df7c721984435442993357a3414 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 14 Mar 2016 16:49:24 +0100 Subject: Run 'git gc' every 10 pushes --- app/services/projects/housekeeping_service.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'app/services/projects') diff --git a/app/services/projects/housekeeping_service.rb b/app/services/projects/housekeeping_service.rb index 11be5b1badf..83bdedf7a8d 100644 --- a/app/services/projects/housekeeping_service.rb +++ b/app/services/projects/housekeeping_service.rb @@ -19,9 +19,21 @@ module Projects if !try_obtain_lease return "Housekeeping was already triggered in the past #{LEASE_TIMEOUT / 60} minutes" end - + GitlabShellWorker.perform_async(:gc, @project.path_with_namespace) - return "Housekeeping successfully started" + @project.pushes_since_gc = 0 + @project.save! + + "Housekeeping successfully started" + end + + def needed? + @project.pushes_since_gc >= 10 + end + + def increment! + @project.pushes_since_gc += 1 + @project.save! end private -- cgit v1.2.1 From 30b36c92c386e93b432166fb6f9dd973882a6d82 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 15 Mar 2016 11:03:43 +0100 Subject: Use an exception to pass messages --- app/services/projects/housekeeping_service.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'app/services/projects') diff --git a/app/services/projects/housekeeping_service.rb b/app/services/projects/housekeeping_service.rb index 83bdedf7a8d..bccd67d3dbf 100644 --- a/app/services/projects/housekeeping_service.rb +++ b/app/services/projects/housekeeping_service.rb @@ -11,20 +11,22 @@ module Projects LEASE_TIMEOUT = 3600 + class LeaseTaken < StandardError + def to_s + "Somebody already triggered housekeeping for this project in the past #{LEASE_TIMEOUT / 60} minutes" + end + end + def initialize(project) @project = project end def execute - if !try_obtain_lease - return "Housekeeping was already triggered in the past #{LEASE_TIMEOUT / 60} minutes" - end + raise LeaseTaken if !try_obtain_lease GitlabShellWorker.perform_async(:gc, @project.path_with_namespace) - @project.pushes_since_gc = 0 - @project.save! - - "Housekeeping successfully started" + ensure + @project.update_column(:pushes_since_gc, 0) end def needed? @@ -32,8 +34,7 @@ module Projects end def increment! - @project.pushes_since_gc += 1 - @project.save! + @project.increment!(:pushes_since_gc) end private -- cgit v1.2.1 From ec20fdf366843e60ed30abb5322c3c1b8f471b4a Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Wed, 16 Mar 2016 19:44:33 -0300 Subject: Code improvements and add Create group service --- app/services/projects/create_service.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/services/projects') diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 522fae79503..4c121106bda 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -12,7 +12,7 @@ module Projects # Make sure that the user is allowed to use the specified visibility # level - unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level]) && @project.visibility_level_allowed?(@project.visibility_level) + unless visibility_level_allowed? deny_visibility_level(@project) return @project end @@ -100,5 +100,9 @@ module Projects @project.import_start if @project.import? end + + def visibility_level_allowed? + Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level]) && @project.visibility_level_allowed?(@project.visibility_level) + end end end -- cgit v1.2.1 From 2057bc02a31a20765e165b503b877350e892908b Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Thu, 17 Mar 2016 11:02:11 +0100 Subject: Do not retry "git gc" --- app/services/projects/housekeeping_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/services/projects') diff --git a/app/services/projects/housekeeping_service.rb b/app/services/projects/housekeeping_service.rb index bccd67d3dbf..a0973c5d260 100644 --- a/app/services/projects/housekeeping_service.rb +++ b/app/services/projects/housekeeping_service.rb @@ -24,7 +24,7 @@ module Projects def execute raise LeaseTaken if !try_obtain_lease - GitlabShellWorker.perform_async(:gc, @project.path_with_namespace) + GitlabShellOneShotWorker.perform_async(:gc, @project.path_with_namespace) ensure @project.update_column(:pushes_since_gc, 0) end -- cgit v1.2.1 From 7ee528336ad86e478b6db6d0039aec607c8f0192 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 17 Mar 2016 17:39:56 -0300 Subject: Restrict access for confidential issues on autocomplete --- app/services/projects/autocomplete_service.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'app/services/projects') diff --git a/app/services/projects/autocomplete_service.rb b/app/services/projects/autocomplete_service.rb index 7408e09ed1e..ba50305dbd5 100644 --- a/app/services/projects/autocomplete_service.rb +++ b/app/services/projects/autocomplete_service.rb @@ -1,11 +1,7 @@ module Projects class AutocompleteService < BaseService - def initialize(project) - @project = project - end - def issues - @project.issues.opened.select([:iid, :title]) + @project.issues.visible_to_user(current_user).opened.select([:iid, :title]) end def merge_requests -- cgit v1.2.1 From b959ae553b1243e081d557b1e545d30830931e5b Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Fri, 18 Mar 2016 13:28:16 +0100 Subject: Improve group visibility level feature --- app/services/projects/create_service.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'app/services/projects') diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 4c121106bda..cebfc432002 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -9,13 +9,8 @@ module Projects @project = Project.new(params) - # Make sure that the user is allowed to use the specified visibility - # level - - unless visibility_level_allowed? - deny_visibility_level(@project) - return @project - end + # Make sure that the user is allowed to use the specified visibility level + return @project unless visibility_level_allowed? # Set project name from path if @project.name.present? && @project.path.present? @@ -55,9 +50,7 @@ module Projects @project.save if @project.persisted? && !@project.import? - unless @project.create_repository - raise 'Failed to create repository' - end + raise 'Failed to create repository' unless @project.create_repository end end -- cgit v1.2.1 From 8b830b8c3b32774e8ccf562b8bc9dbce3ecf3073 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Fri, 18 Mar 2016 21:04:53 -0300 Subject: Fix specs --- app/services/projects/create_service.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/services/projects') diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index cebfc432002..c4b8420f9f2 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -10,7 +10,10 @@ module Projects @project = Project.new(params) # Make sure that the user is allowed to use the specified visibility level - return @project unless visibility_level_allowed? + unless visibility_level_allowed? + deny_visibility_level(@project) + return @project + end # Set project name from path if @project.name.present? && @project.path.present? -- cgit v1.2.1 From 8db1292139cfdac4c29c03b876b68b9e752cf75a Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sun, 20 Mar 2016 21:03:53 +0100 Subject: Tweaks, refactoring, and specs --- app/services/projects/create_service.rb | 6 +----- app/services/projects/update_service.rb | 29 ++++++----------------------- 2 files changed, 7 insertions(+), 28 deletions(-) (limited to 'app/services/projects') diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index c4b8420f9f2..501e58c1407 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -10,7 +10,7 @@ module Projects @project = Project.new(params) # Make sure that the user is allowed to use the specified visibility level - unless visibility_level_allowed? + unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level]) deny_visibility_level(@project) return @project end @@ -96,9 +96,5 @@ module Projects @project.import_start if @project.import? end - - def visibility_level_allowed? - Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level]) && @project.visibility_level_allowed?(@project.visibility_level) - end end end diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb index 895e089bea3..941df08995c 100644 --- a/app/services/projects/update_service.rb +++ b/app/services/projects/update_service.rb @@ -3,16 +3,13 @@ module Projects def execute # check that user is allowed to set specified visibility_level new_visibility = params[:visibility_level] - if new_visibility - if new_visibility.to_i != project.visibility_level - unless can?(current_user, :change_visibility_level, project) && - Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility) - deny_visibility_level(project, new_visibility) - return project - end + if new_visibility && new_visibility.to_i != project.visibility_level + unless can?(current_user, :change_visibility_level, project) && + Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility) + + deny_visibility_level(project, new_visibility) + return project end - - return false unless visibility_level_allowed?(new_visibility) end new_branch = params[:default_branch] @@ -27,19 +24,5 @@ module Projects end end end - - private - - def visibility_level_allowed?(level) - return true if project.visibility_level_allowed?(level) - - level_name = Gitlab::VisibilityLevel.level_name(level) - project.errors.add( - :visibility_level, - "#{level_name} could not be set as visibility level of this project - parent project settings are more restrictive" - ) - - false - end end end -- cgit v1.2.1 From fa4126acffdfe13741e05a60ad5ed7fd407b4f16 Mon Sep 17 00:00:00 2001 From: Baldinof Date: Tue, 22 Mar 2016 15:34:35 +0100 Subject: Move unlink fork logic to a service --- app/services/projects/unlink_fork_service.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/services/projects/unlink_fork_service.rb (limited to 'app/services/projects') diff --git a/app/services/projects/unlink_fork_service.rb b/app/services/projects/unlink_fork_service.rb new file mode 100644 index 00000000000..d0703effa1d --- /dev/null +++ b/app/services/projects/unlink_fork_service.rb @@ -0,0 +1,19 @@ +module Projects + class UnlinkForkService < BaseService + def execute + return unless @project.forked? + + @project.forked_from_project.lfs_objects.find_each do |lfs_object| + lfs_object.projects << self + end + + merge_requests = @project.forked_from_project.merge_requests.opened.from_project(@project) + + merge_requests.each do |mr| + MergeRequests::CloseService.new(@project, @current_user).execute(mr) + end + + @project.forked_project_link.destroy + end + end +end -- cgit v1.2.1 From a6b5b50e14885a82530794c6ea35c940305244dd Mon Sep 17 00:00:00 2001 From: Baldinof Date: Mon, 4 Apr 2016 14:41:01 +0000 Subject: Fix incorrect variable name --- app/services/projects/unlink_fork_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/services/projects') diff --git a/app/services/projects/unlink_fork_service.rb b/app/services/projects/unlink_fork_service.rb index d0703effa1d..315c3e16292 100644 --- a/app/services/projects/unlink_fork_service.rb +++ b/app/services/projects/unlink_fork_service.rb @@ -4,7 +4,7 @@ module Projects return unless @project.forked? @project.forked_from_project.lfs_objects.find_each do |lfs_object| - lfs_object.projects << self + lfs_object.projects << @project end merge_requests = @project.forked_from_project.merge_requests.opened.from_project(@project) -- cgit v1.2.1 From f2005fa56682a5dc3b57d610cb733a34b2e08520 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 4 Apr 2016 19:35:39 -0300 Subject: Flush repository cache before import project data GitHub Pull Requests importer handle with the repository while importing data, we need to make sure that the cached values are valid. --- app/services/projects/import_service.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/services/projects') diff --git a/app/services/projects/import_service.rb b/app/services/projects/import_service.rb index 2015897dd19..ef15ef6a473 100644 --- a/app/services/projects/import_service.rb +++ b/app/services/projects/import_service.rb @@ -46,6 +46,8 @@ module Projects def import_data return unless has_importer? + project.repository.before_import + unless importer.execute raise Error, 'The remote data could not be imported.' end -- cgit v1.2.1