Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ide_controller.rb « controllers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4a4d41f3e6fe735d1cb451a07d2c802fe6f1c3dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true

class IdeController < ApplicationController
  include WebIdeCSP
  include StaticObjectExternalStorageCSP
  include Gitlab::Utils::StrongMemoize

  before_action :authorize_read_project!, only: [:index]
  before_action :ensure_web_ide_oauth_application!, only: [:index]

  before_action do
    push_frontend_feature_flag(:build_service_proxy)
    push_frontend_feature_flag(:reject_unsigned_commits_by_gitlab)
  end

  feature_category :web_ide

  urgency :low

  def index
    Gitlab::UsageDataCounters::WebIdeCounter.increment_views_count

    if project
      Gitlab::Tracking.event(self.class.to_s, 'web_ide_views', namespace: project.namespace, user: current_user)
      @fork_info = fork_info(project, params[:branch])
    end

    render layout: helpers.use_new_web_ide? ? 'fullscreen' : 'application'
  end

  def oauth_redirect
    return render_404 unless ::Gitlab::WebIde::DefaultOauthApplication.feature_enabled?(current_user)
    # TODO - It's **possible** we end up here and no oauth application has been set up.
    # We need to have better handling of these edge cases. Here's a follow-up issue:
    # https://gitlab.com/gitlab-org/gitlab/-/issues/433322
    return render_404 unless ::Gitlab::WebIde::DefaultOauthApplication.oauth_application

    render layout: 'fullscreen', locals: { minimal: true }
  end

  private

  def authorize_read_project!
    render_404 unless can?(current_user, :read_project, project)
  end

  def ensure_web_ide_oauth_application!
    return unless ::Gitlab::WebIde::DefaultOauthApplication.feature_enabled?(current_user)

    ::Gitlab::WebIde::DefaultOauthApplication.ensure_oauth_application!
  end

  def fork_info(project, branch)
    return if can?(current_user, :push_code, project)

    existing_fork = current_user.fork_of(project)

    if existing_fork
      path = helpers.ide_edit_path(existing_fork, branch, '')
      { ide_path: path }
    elsif can?(current_user, :fork_project, project)
      path = helpers.ide_fork_and_edit_path(project, branch, '', with_notice: false)
      { fork_path: path }
    end
  end

  def project
    strong_memoize(:project) do
      next unless params[:project_id].present?

      Project.find_by_full_path(params[:project_id])
    end
  end
end