OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
set User.system on type queries
ulfertscb185c2c0392
diff --git a/app/services/base_type_service.rb b/app/services/base_type_service.rbindex bf9bf187640..070b877df2a 100644--- a/app/services/base_type_service.rb+++ b/app/services/base_type_service.rb@@ -130,7 +130,7 @@ class BaseTypeService[name,- group['attributes'].map { |attr| attr['key'] }+ group['attributes'].pluck('key')]end@@ -140,6 +140,11 @@ class BaseTypeServicequery = Query.new_default(name: "Embedded table: #{name}")+ query.extend(OpenProject::ChangedBySystem)+ query.change_by_system do+ query.user = User.system+ end+::API::V3::UpdateQueryFromV3ParamsService.new(query, user).call(props.with_indifferent_access)diff --git a/spec/services/shared_type_service.rb b/spec/services/shared_type_service.rbindex df91edd254b..d1497bbd3a8 100644--- a/spec/services/shared_type_service.rb+++ b/spec/services/shared_type_service.rb@@ -50,6 +50,21 @@ endshared_examples_for 'type service' dolet(:success) { true }let(:params) { {} }+ let!(:contract) do+ instance_double(::Types::BaseContract).tap do |contract|+ allow(contract)+ .to receive(:validate)+ .and_return(contract_valid)+ allow(contract)+ .to receive(:errors)+ .and_return(contract_errors)+ allow(Types::BaseContract)+ .to receive(:new)+ .and_return(contract)+ end+ end+ let(:contract_errors) { instance_double(ActiveModel::Errors) }+ let(:contract_valid) { success }describe '#call' dobefore do@@ -232,7 +247,7 @@ shared_examples_for 'type service' do{ 'type' => 'query', 'name' => 'group1', 'query' => JSON.dump(query_params) }endlet(:params) { { attribute_groups: [query_group_params] } }- let(:query) { create(:query, user_id: 0) }+ let(:query) { Query.new }let(:service_result) { ServiceResult.success(result: query) }before do@@ -240,20 +255,9 @@ shared_examples_for 'type service' do.to receive(:new_default).with(name: "Embedded table: group1").and_return(query)-- parse_service = instance_double(::API::V3::ParseQueryParamsService)- allow(::API::V3::UpdateQueryFromV3ParamsService)- .to receive(:new)- .with(query, user)- .and_return(parse_service)-- allow(parse_service)- .to receive(:call)- .with(query_params)- .and_return(service_result)end- it 'assigns the fully parsed query to the type\'s attribute group' do+ it 'assigns the fully parsed query to the type\'s attribute group with the system user as the querie\'s user' doexpect(service_call).to be_successexpect(type.attribute_groups[0].query)@@ -264,9 +268,12 @@ shared_examples_for 'type service' doexpect(query.filters[0].name).to be :status_id++ expect(query.user)+ .to eq User.systemend- context 'when the query service reports an error' do+ context 'when the query parse service reports an error' dolet(:success) { false }let(:service_result) { ServiceResult.failure(result: nil) }@@ -290,8 +297,8 @@ shared_examples_for 'type service' doendit 'returns the errors of the type' do- type.name = nil- expect(subject.errors.symbols_for(:name)).to include :blank+ expect(subject.errors)+ .to eql contract_errorsenddescribe 'custom fields' do