diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /app/controllers/import | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'app/controllers/import')
-rw-r--r-- | app/controllers/import/base_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/bitbucket_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/import/bulk_imports_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/import/fogbugz_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/gitea_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/import/github_controller.rb | 47 | ||||
-rw-r--r-- | app/controllers/import/gitlab_controller.rb | 92 | ||||
-rw-r--r-- | app/controllers/import/gitlab_projects_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/manifest_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/import/phabricator_controller.rb | 35 |
10 files changed, 52 insertions, 146 deletions
diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb index 7ef07032913..bcb6aed9e38 100644 --- a/app/controllers/import/base_controller.rb +++ b/app/controllers/import/base_controller.rb @@ -18,7 +18,7 @@ class Import::BaseController < ApplicationController if params[:namespace_id]&.present? @namespace = Namespace.find_by_id(params[:namespace_id]) - render_404 unless current_user.can?(:create_projects, @namespace) + render_404 unless current_user.can?(:import_projects, @namespace) end end end diff --git a/app/controllers/import/bitbucket_controller.rb b/app/controllers/import/bitbucket_controller.rb index 8a0f4a36781..c933b05e0c4 100644 --- a/app/controllers/import/bitbucket_controller.rb +++ b/app/controllers/import/bitbucket_controller.rb @@ -57,7 +57,7 @@ class Import::BitbucketController < Import::BaseController extra: { user_role: user_role(current_user, target_namespace), import_type: 'bitbucket' } ) - if current_user.can?(:create_projects, target_namespace) + if current_user.can?(:import_projects, target_namespace) # The token in a session can be expired, we need to get most recent one because # Bitbucket::Connection class refreshes it. session[:bitbucket_token] = bitbucket_client.connection.token @@ -70,7 +70,7 @@ class Import::BitbucketController < Import::BaseController render json: { errors: project_save_error(project) }, status: :unprocessable_entity end else - render json: { errors: _('This namespace has already been taken! Please choose another one.') }, status: :unprocessable_entity + render json: { errors: _('You are not allowed to import projects in this namespace.') }, status: :unprocessable_entity end end diff --git a/app/controllers/import/bulk_imports_controller.rb b/app/controllers/import/bulk_imports_controller.rb index f4eea3abd32..d7d7ad84bc8 100644 --- a/app/controllers/import/bulk_imports_controller.rb +++ b/app/controllers/import/bulk_imports_controller.rb @@ -5,9 +5,6 @@ class Import::BulkImportsController < ApplicationController before_action :ensure_bulk_import_enabled before_action :verify_blocked_uri, only: :status - before_action only: :status do - push_frontend_feature_flag(:bulk_import_projects) - end feature_category :importers urgency :low diff --git a/app/controllers/import/fogbugz_controller.rb b/app/controllers/import/fogbugz_controller.rb index 77043e174b4..9ee8e59053f 100644 --- a/app/controllers/import/fogbugz_controller.rb +++ b/app/controllers/import/fogbugz_controller.rb @@ -19,7 +19,7 @@ class Import::FogbugzController < Import::BaseController # If the URI is invalid various errors can occur return redirect_to new_import_fogbugz_path(namespace_id: params[:namespace_id]), alert: _('Could not connect to FogBugz, check your URL') end - session[:fogbugz_token] = res.get_token + session[:fogbugz_token] = res.get_token.to_s session[:fogbugz_uri] = params[:uri] redirect_to new_user_map_import_fogbugz_path(namespace_id: params[:namespace_id]) diff --git a/app/controllers/import/gitea_controller.rb b/app/controllers/import/gitea_controller.rb index 61e32650db3..2778b97419a 100644 --- a/app/controllers/import/gitea_controller.rb +++ b/app/controllers/import/gitea_controller.rb @@ -32,7 +32,7 @@ class Import::GiteaController < Import::GithubController if params[:namespace_id].present? @namespace = Namespace.find_by_id(params[:namespace_id]) - render_404 unless current_user.can?(:create_projects, @namespace) + render_404 unless current_user.can?(:import_projects, @namespace) end end end @@ -71,6 +71,11 @@ class Import::GiteaController < Import::GithubController end end + override :serialized_imported_projects + def serialized_imported_projects(projects = already_added_projects) + ProjectSerializer.new.represent(projects, serializer: :import, provider_url: provider_url) + end + override :client_repos def client_repos @client_repos ||= filtered(client.repos) diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb index 0bee1faccf5..41477519ba5 100644 --- a/app/controllers/import/github_controller.rb +++ b/app/controllers/import/github_controller.rb @@ -11,6 +11,10 @@ class Import::GithubController < Import::BaseController before_action :provider_auth, only: [:status, :realtime_changes, :create] before_action :expire_etag_cache, only: [:status, :create] + before_action only: [:status] do + push_frontend_feature_flag(:import_details_page) + end + rescue_from Octokit::Unauthorized, with: :provider_unauthorized rescue_from Octokit::TooManyRequests, with: :provider_rate_limit rescue_from Gitlab::GithubImport::RateLimitError, with: :rate_limit_threshold_exceeded @@ -53,19 +57,24 @@ class Import::GithubController < Import::BaseController render json: { imported_projects: serialized_imported_projects, provider_repos: serialized_provider_repos, incompatible_repos: serialized_incompatible_repos, - page_info: client_repos_response[:page_info] } + page_info: client_repos_response[:page_info], + provider_repo_count: client_repos_response[:count] } end format.html do if params[:namespace_id].present? @namespace = Namespace.find_by_id(params[:namespace_id]) - render_404 unless current_user.can?(:create_projects, @namespace) + render_404 unless current_user.can?(:import_projects, @namespace) end end end end + def details + render_404 unless Feature.enabled?(:import_details_page) + end + def create result = Import::GithubService.new(client, current_user, import_params).execute(access_params, provider_name) @@ -82,6 +91,21 @@ class Import::GithubController < Import::BaseController render json: Import::GithubRealtimeRepoSerializer.new.represent(already_added_projects) end + def failures + project = Project.imported_from(provider_name).find(params[:project_id]) + + unless project.import_finished? + return render status: :bad_request, json: { + message: _('The import is not complete.') + } + end + + failures = project.import_failures.with_external_identifiers + serializer = Import::GithubFailureSerializer.new.with_pagination(request, response) + + render json: serializer.represent(failures) + end + def cancel project = Project.imported_from(provider_name).find(params[:project_id]) result = Import::Github::CancelProjectImportService.new(project, current_user).execute @@ -110,6 +134,14 @@ class Import::GithubController < Import::BaseController render json: canceled end + def counts + render json: { + owned: client_proxy.count_repos_by('owned', current_user.id), + collaborated: client_proxy.count_repos_by('collaborated', current_user.id), + organization: client_proxy.count_repos_by('organization', current_user.id) + } + end + protected override :importable_repos @@ -145,7 +177,10 @@ class Import::GithubController < Import::BaseController end def serialized_imported_projects(projects = already_added_projects) - ProjectSerializer.new.represent(projects, serializer: :import, provider_url: provider_url) + ProjectSerializer.new.represent( + projects, + serializer: :import, provider_url: provider_url, client: client_proxy + ) end def expire_etag_cache @@ -245,11 +280,7 @@ class Import::GithubController < Import::BaseController { before: params[:before].presence, after: params[:after].presence, - first: PAGE_LENGTH, - # TODO: remove after rollout FF github_client_fetch_repos_via_graphql - # https://gitlab.com/gitlab-org/gitlab/-/issues/385649 - page: [1, params[:page].to_i].max, - per_page: PAGE_LENGTH + first: PAGE_LENGTH } end diff --git a/app/controllers/import/gitlab_controller.rb b/app/controllers/import/gitlab_controller.rb deleted file mode 100644 index dd25698d0a9..00000000000 --- a/app/controllers/import/gitlab_controller.rb +++ /dev/null @@ -1,92 +0,0 @@ -# frozen_string_literal: true - -class Import::GitlabController < Import::BaseController - extend ::Gitlab::Utils::Override - - MAX_PROJECT_PAGES = 15 - PER_PAGE_PROJECTS = 100 - - before_action :verify_gitlab_import_enabled - before_action :gitlab_auth, except: :callback - - rescue_from OAuth2::Error, with: :gitlab_unauthorized - - def callback - session[:gitlab_access_token] = client.get_token(params[:code], callback_import_gitlab_url(namespace_id: params[:namespace_id])) - redirect_to status_import_gitlab_url(namespace_id: params[:namespace_id]) - end - - # We need to re-expose controller's internal method 'status' as action. - # rubocop:disable Lint/UselessMethodDefinition - def status - super - end - # rubocop:enable Lint/UselessMethodDefinition - - def create - repo = client.project(params[:repo_id].to_i) - target_namespace = find_or_create_namespace(repo['namespace']['path'], client.user['username']) - - if current_user.can?(:create_projects, target_namespace) - project = Gitlab::GitlabImport::ProjectCreator.new(repo, target_namespace, current_user, access_params).execute - - if project.persisted? - render json: ProjectSerializer.new.represent(project, serializer: :import) - else - render json: { errors: project_save_error(project) }, status: :unprocessable_entity - end - else - render json: { errors: _('This namespace has already been taken! Please choose another one.') }, status: :unprocessable_entity - end - end - - protected - - override :importable_repos - def importable_repos - client.projects(starting_page: 1, page_limit: MAX_PROJECT_PAGES, per_page: PER_PAGE_PROJECTS).to_a - end - - override :incompatible_repos - def incompatible_repos - [] - end - - override :provider_name - def provider_name - :gitlab - end - - override :provider_url - def provider_url - 'https://gitlab.com' - end - - private - - def client - @client ||= Gitlab::GitlabImport::Client.new(session[:gitlab_access_token]) - end - - def verify_gitlab_import_enabled - render_404 unless gitlab_import_enabled? - end - - def gitlab_auth - if session[:gitlab_access_token].blank? - go_to_gitlab_for_permissions - end - end - - def go_to_gitlab_for_permissions - redirect_to client.authorize_url(callback_import_gitlab_url(namespace_id: params[:namespace_id])) - end - - def gitlab_unauthorized - go_to_gitlab_for_permissions - end - - def access_params - { gitlab_access_token: session[:gitlab_access_token] } - end -end diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb index 9b8c480e529..d1b182a57d8 100644 --- a/app/controllers/import/gitlab_projects_controller.rb +++ b/app/controllers/import/gitlab_projects_controller.rb @@ -8,7 +8,7 @@ class Import::GitlabProjectsController < Import::BaseController def new @namespace = Namespace.find(project_params[:namespace_id]) - return render_404 unless current_user.can?(:create_projects, @namespace) + return render_404 unless current_user.can?(:import_projects, @namespace) @path = project_params[:path] end diff --git a/app/controllers/import/manifest_controller.rb b/app/controllers/import/manifest_controller.rb index 461ba982969..03884717e54 100644 --- a/app/controllers/import/manifest_controller.rb +++ b/app/controllers/import/manifest_controller.rb @@ -20,8 +20,8 @@ class Import::ManifestController < Import::BaseController def upload group = Group.find(params[:group_id]) - unless can?(current_user, :create_projects, group) - @errors = ["You don't have enough permissions to create projects in the selected group"] + unless can?(current_user, :import_projects, group) + @errors = ["You don't have enough permissions to import projects in the selected group"] render :new && return end diff --git a/app/controllers/import/phabricator_controller.rb b/app/controllers/import/phabricator_controller.rb deleted file mode 100644 index d1c04817689..00000000000 --- a/app/controllers/import/phabricator_controller.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -class Import::PhabricatorController < Import::BaseController - include ImportHelper - - before_action :verify_import_enabled - - def new - end - - def create - @project = Gitlab::PhabricatorImport::ProjectCreator - .new(current_user, import_params).execute - - if @project&.persisted? - redirect_to @project - else - @name = params[:name] - @path = params[:path] - @errors = @project&.errors&.full_messages || [_("Invalid import params")] - - render :new - end - end - - def verify_import_enabled - render_404 unless phabricator_import_enabled? - end - - private - - def import_params - params.permit(:path, :phabricator_server_url, :api_token, :name, :namespace_id) - end -end |