Commit f1ae7c66 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '2747-protected-environments-backend-ce' into 'master'

CE Port of Protected Environments backend

See merge request gitlab-org/gitlab-ce!20859
parents 91795dcd 33311cb6
...@@ -251,6 +251,7 @@ class ProjectPolicy < BasePolicy ...@@ -251,6 +251,7 @@ class ProjectPolicy < BasePolicy
enable :update_pages enable :update_pages
enable :read_cluster enable :read_cluster
enable :create_cluster enable :create_cluster
enable :create_environment_terminal
end end
rule { (mirror_available & can?(:admin_project)) | admin }.enable :admin_remote_mirror rule { (mirror_available & can?(:admin_project)) | admin }.enable :admin_remote_mirror
......
...@@ -23,9 +23,8 @@ class EnvironmentEntity < Grape::Entity ...@@ -23,9 +23,8 @@ class EnvironmentEntity < Grape::Entity
stop_project_environment_path(environment.project, environment) stop_project_environment_path(environment.project, environment)
end end
expose :terminal_path, if: ->(environment, _) { environment.has_terminals? } do |environment| expose :terminal_path, if: ->(*) { environment.has_terminals? && can_access_terminal? } do |environment|
can?(request.current_user, :admin_environment, environment.project) && terminal_project_environment_path(environment.project, environment)
terminal_project_environment_path(environment.project, environment)
end end
expose :folder_path do |environment| expose :folder_path do |environment|
...@@ -40,7 +39,13 @@ class EnvironmentEntity < Grape::Entity ...@@ -40,7 +39,13 @@ class EnvironmentEntity < Grape::Entity
private private
alias_method :environment, :object
def current_user def current_user
request.current_user request.current_user
end end
def can_access_terminal?
can?(request.current_user, :create_environment_terminal, environment)
end
end end
# frozen_string_literal: true
module Ci
class EnqueueBuildService < BaseService
def execute(build)
build.enqueue
end
end
end
...@@ -37,7 +37,7 @@ module Ci ...@@ -37,7 +37,7 @@ module Ci
def process_build(build, current_status) def process_build(build, current_status)
if valid_statuses_for_when(build.when).include?(current_status) if valid_statuses_for_when(build.when).include?(current_status)
build.action? ? build.actionize : build.enqueue build.action? ? build.actionize : enqueue_build(build)
true true
else else
build.skip build.skip
...@@ -93,5 +93,9 @@ module Ci ...@@ -93,5 +93,9 @@ module Ci
.where.not(id: latest_statuses.map(&:first)) .where.not(id: latest_statuses.map(&:first))
.update_all(retried: true) if latest_statuses.any? .update_all(retried: true) if latest_statuses.any?
end end
def enqueue_build(build)
Ci::EnqueueBuildService.new(project, @user).execute(build)
end
end end
end end
---
title: CE Port of Protected Environments backend
merge_request: 20859
author:
type: other
...@@ -47,7 +47,7 @@ module Gitlab ...@@ -47,7 +47,7 @@ module Gitlab
end end
def initialize(relation_sym:, relation_hash:, members_mapper:, user:, project:, excluded_keys: []) def initialize(relation_sym:, relation_hash:, members_mapper:, user:, project:, excluded_keys: [])
@relation_name = OVERRIDES[relation_sym] || relation_sym @relation_name = self.class.overrides[relation_sym] || relation_sym
@relation_hash = relation_hash.except('noteable_id') @relation_hash = relation_hash.except('noteable_id')
@members_mapper = members_mapper @members_mapper = members_mapper
@user = user @user = user
...@@ -76,6 +76,10 @@ module Gitlab ...@@ -76,6 +76,10 @@ module Gitlab
generate_imported_object generate_imported_object
end end
def self.overrides
OVERRIDES
end
private private
def setup_models def setup_models
......
# frozen_string_literal: true
require 'spec_helper'
describe Ci::EnqueueBuildService, '#execute' do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:ci_build) { create(:ci_build, :created) }
subject { described_class.new(project, user).execute(ci_build) }
it 'enqueues the build' do
subject
expect(ci_build.pending?).to be_truthy
end
end
...@@ -9,7 +9,7 @@ module ConfigurationHelper ...@@ -9,7 +9,7 @@ module ConfigurationHelper
end end
def relation_class_for_name(relation_name) def relation_class_for_name(relation_name)
relation_name = Gitlab::ImportExport::RelationFactory::OVERRIDES[relation_name.to_sym] || relation_name relation_name = Gitlab::ImportExport::RelationFactory.overrides[relation_name.to_sym] || relation_name
Gitlab::ImportExport::RelationFactory.relation_class(relation_name) Gitlab::ImportExport::RelationFactory.relation_class(relation_name)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment