From 35882e681b681f68a818bda9a8d2624edfecc219 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Thu, 18 Jan 2018 16:07:07 +0000 Subject: Adds option to push over SSH to create a new project --- lib/api/internal.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 063f0d6599c..a83f714a1f3 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -43,7 +43,7 @@ module API access_checker_klass = wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess access_checker = access_checker_klass - .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, redirected_path: redirected_path) + .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, redirected_path: redirected_path, target_namespace: user.namespace) begin access_checker.check(params[:action], params[:changes]) @@ -51,6 +51,19 @@ module API return { status: false, message: e.message } end + if project.blank? && params[:action] == 'git-receive-pack' + project_params = { + description: "", + path: params[:project].split('/').last.gsub("\.git", ''), + namespace_id: user.namespace.id.to_s, + visibility_level: Gitlab::VisibilityLevel::PRIVATE.to_s + } + + @project = ::Projects::CreateService.new(user, project_params).execute + + return { status: false, message: "Could not create project" } unless @project.saved? + end + log_user_activity(actor) { -- cgit v1.2.1 From 32b2ff26011a5274bdb8a3dd41ad360a67c3148a Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Fri, 19 Jan 2018 13:04:14 +0000 Subject: Adds remote messsage when project is created in a push over SSH or HTTP --- lib/api/internal.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index a83f714a1f3..f641ef457a3 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -43,7 +43,7 @@ module API access_checker_klass = wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess access_checker = access_checker_klass - .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, redirected_path: redirected_path, target_namespace: user.namespace) + .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, redirected_path: redirected_path, target_namespace: namespace) begin access_checker.check(params[:action], params[:changes]) @@ -51,17 +51,21 @@ module API return { status: false, message: e.message } end - if project.blank? && params[:action] == 'git-receive-pack' + if user && project.blank? && receive_pack? project_params = { description: "", - path: params[:project].split('/').last.gsub("\.git", ''), - namespace_id: user.namespace.id.to_s, + path: Project.parse_project_id(project_match[:project_name]), + namespace_id: namespace&.id, visibility_level: Gitlab::VisibilityLevel::PRIVATE.to_s } @project = ::Projects::CreateService.new(user, project_params).execute - return { status: false, message: "Could not create project" } unless @project.saved? + if @project.saved? + Gitlab::Checks::NewProject.new(user, @project, protocol).add_new_project_message + else + return { status: false, message: "Could not create project" } + end end log_user_activity(actor) @@ -221,7 +225,10 @@ module API # key could be used if user redirect_message = Gitlab::Checks::ProjectMoved.fetch_redirect_message(user.id, project.id) + new_project_message = Gitlab::Checks::NewProject.fetch_new_project_message(user.id, project.id) + output[:redirected_message] = redirect_message if redirect_message + output[:new_project_message] = new_project_message if new_project_message end output -- cgit v1.2.1 From bc78ae6985ee37f9ac2ffc2dbf6f445078d16038 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Mon, 22 Jan 2018 18:10:56 +0000 Subject: Add specs --- lib/api/internal.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index f641ef457a3..b7475af2044 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -43,7 +43,7 @@ module API access_checker_klass = wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess access_checker = access_checker_klass - .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, redirected_path: redirected_path, target_namespace: namespace) + .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, redirected_path: redirected_path, target_namespace: project_namespace) begin access_checker.check(params[:action], params[:changes]) @@ -52,13 +52,6 @@ module API end if user && project.blank? && receive_pack? - project_params = { - description: "", - path: Project.parse_project_id(project_match[:project_name]), - namespace_id: namespace&.id, - visibility_level: Gitlab::VisibilityLevel::PRIVATE.to_s - } - @project = ::Projects::CreateService.new(user, project_params).execute if @project.saved? -- cgit v1.2.1 From e42a548f1dac02577d0c1731fef508dab68c45a5 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Thu, 25 Jan 2018 12:26:52 +0000 Subject: Move new project on push logic to a service --- lib/api/internal.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index b7475af2044..841a34eb67f 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -51,13 +51,11 @@ module API return { status: false, message: e.message } end - if user && project.blank? && receive_pack? - @project = ::Projects::CreateService.new(user, project_params).execute - - if @project.saved? - Gitlab::Checks::NewProject.new(user, @project, protocol).add_new_project_message - else - return { status: false, message: "Could not create project" } + if receive_pack? && project.blank? + begin + @project = ::Projects::CreateFromPushService.new(user, project_match[:project_path], project_namespace, protocol).execute + rescue Gitlab::GitAccess::ProjectCreationError => e + return { status: false, message: e.message } end end @@ -218,10 +216,10 @@ module API # key could be used if user redirect_message = Gitlab::Checks::ProjectMoved.fetch_redirect_message(user.id, project.id) - new_project_message = Gitlab::Checks::NewProject.fetch_new_project_message(user.id, project.id) + project_created_message = Gitlab::Checks::ProjectCreated.fetch_project_created_message(user.id, project.id) output[:redirected_message] = redirect_message if redirect_message - output[:new_project_message] = new_project_message if new_project_message + output[:project_created_message] = project_created_message if project_created_message end output -- cgit v1.2.1 From dc229c076cdc0ef6e7f3f74f6e462c22880ff08c Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Fri, 26 Jan 2018 14:28:08 +0000 Subject: Abstracts ProjectMoved and ProjectCreated into a BaseProject --- lib/api/internal.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index 841a34eb67f..ed6d022df97 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -215,8 +215,8 @@ module API # A user is not guaranteed to be returned; an orphaned write deploy # key could be used if user - redirect_message = Gitlab::Checks::ProjectMoved.fetch_redirect_message(user.id, project.id) - project_created_message = Gitlab::Checks::ProjectCreated.fetch_project_created_message(user.id, project.id) + redirect_message = Gitlab::Checks::ProjectMoved.fetch_message(user.id, project.id) + project_created_message = Gitlab::Checks::ProjectCreated.fetch_message(user.id, project.id) output[:redirected_message] = redirect_message if redirect_message output[:project_created_message] = project_created_message if project_created_message -- cgit v1.2.1 From 1e56b3f476f9779ec747534e94156a6b8076209c Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Fri, 2 Feb 2018 15:27:30 +0000 Subject: Moves project creationg to git access check for git push --- lib/api/internal.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'lib/api/internal.rb') diff --git a/lib/api/internal.rb b/lib/api/internal.rb index ed6d022df97..9285fb90cdc 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -42,23 +42,18 @@ module API end access_checker_klass = wiki? ? Gitlab::GitAccessWiki : Gitlab::GitAccess - access_checker = access_checker_klass - .new(actor, project, protocol, authentication_abilities: ssh_authentication_abilities, redirected_path: redirected_path, target_namespace: project_namespace) + access_checker = access_checker_klass.new(actor, project, + protocol, authentication_abilities: ssh_authentication_abilities, + namespace_path: namespace_path, project_path: project_path, + redirected_path: redirected_path) begin access_checker.check(params[:action], params[:changes]) + @project ||= access_checker.project rescue Gitlab::GitAccess::UnauthorizedError, Gitlab::GitAccess::NotFoundError => e return { status: false, message: e.message } end - if receive_pack? && project.blank? - begin - @project = ::Projects::CreateFromPushService.new(user, project_match[:project_path], project_namespace, protocol).execute - rescue Gitlab::GitAccess::ProjectCreationError => e - return { status: false, message: e.message } - end - end - log_user_activity(actor) { -- cgit v1.2.1