debian-mirror-gitlab/app/controllers/ide_controller.rb

69 lines
1.7 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
class IdeController < ApplicationController
2023-03-04 22:38:38 +05:30
include VSCodeCDNCSP
2020-04-08 14:13:33 +05:30
include ClientsidePreviewCSP
include StaticObjectExternalStorageCSP
2021-04-17 20:07:23 +05:30
include Gitlab::Utils::StrongMemoize
2020-04-08 14:13:33 +05:30
2021-07-02 01:05:55 +05:30
before_action :authorize_read_project!
2020-06-23 00:09:42 +05:30
before_action do
push_frontend_feature_flag(:build_service_proxy)
2022-07-16 23:28:13 +05:30
push_frontend_feature_flag(:reject_unsigned_commits_by_gitlab)
2021-04-17 20:07:23 +05:30
define_index_vars
2020-06-23 00:09:42 +05:30
end
2021-01-03 14:25:43 +05:30
feature_category :web_ide
2022-06-21 17:19:12 +05:30
urgency :low
2018-05-09 12:01:36 +05:30
def index
2019-10-12 21:52:04 +05:30
Gitlab::UsageDataCounters::WebIdeCounter.increment_views_count
2022-07-23 23:45:48 +05:30
if project && Feature.enabled?(:route_hll_to_snowplow_phase2, project&.namespace)
Gitlab::Tracking.event(self.class.to_s, 'web_ide_views',
namespace: project&.namespace, user: current_user)
end
2022-11-25 23:54:43 +05:30
render layout: 'fullscreen', locals: { minimal: helpers.use_new_web_ide? }
2018-05-09 12:01:36 +05:30
end
2021-04-17 20:07:23 +05:30
private
2021-07-02 01:05:55 +05:30
def authorize_read_project!
render_404 unless can?(current_user, :read_project, project)
end
2021-04-17 20:07:23 +05:30
def define_index_vars
return unless project
@branch = params[:branch]
@path = params[:path]
@merge_request = params[:merge_request_id]
2021-04-29 21:17:54 +05:30
@fork_info = fork_info(project, @branch)
end
def fork_info(project, branch)
return if can?(current_user, :push_code, project)
existing_fork = current_user.fork_of(project)
2021-04-17 20:07:23 +05:30
2021-04-29 21:17:54 +05:30
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 }
2021-04-17 20:07:23 +05:30
end
end
def project
strong_memoize(:project) do
next unless params[:project_id].present?
Project.find_by_full_path(params[:project_id])
end
end
2018-05-09 12:01:36 +05:30
end