introduce work_package_sharing EE action and apply to workflow administration

This commit is contained in:
ulferts
2023-11-07 13:50:27 +01:00
parent 535198c8d7
commit 7c92cfc27d
5 changed files with 41 additions and 23 deletions
+9 -4
View File
@@ -74,11 +74,11 @@ class WorkflowsController < ApplicationController
@source_role = if params[:source_role_id].blank? || params[:source_role_id] == 'any'
nil
else
ProjectRole.find(params[:source_role_id])
eligible_roles.find(params[:source_role_id])
end
@target_types = params[:target_type_ids].blank? ? nil : ::Type.where(id: params[:target_type_ids])
@target_roles = params[:target_role_ids].blank? ? nil : ProjectRole.where(id: params[:target_role_ids])
@target_roles = params[:target_role_ids].blank? ? nil : eligible_roles.where(id: params[:target_role_ids])
if request.post?
if params[:source_type_id].blank? || params[:source_role_id].blank? || (@source_type.nil? && @source_role.nil?)
@@ -148,7 +148,12 @@ class WorkflowsController < ApplicationController
end
def eligible_roles
Role.where(type: ProjectRole.name)
.or(Role.where(builtin: Role::BUILTIN_WORK_PACKAGE_EDITOR))
roles = Role.where(type: ProjectRole.name)
if EnterpriseToken.allows_to?(:work_package_sharing)
roles.or(Role.where(builtin: Role::BUILTIN_WORK_PACKAGE_EDITOR))
else
roles
end
end
end
+1
View File
@@ -41,6 +41,7 @@ module WarningBarHelper
def render_workflow_missing_warning?
current_user.admin? &&
EnterpriseToken.allows_to?(:work_package_sharing) &&
no_workflow_for_wp_edit_role?
end
+27 -17
View File
@@ -29,22 +29,32 @@
require 'spec_helper'
RSpec.describe WorkflowsController do
let!(:role_scope) do
role_scope = instance_double(ActiveRecord::Relation)
allow(Role)
.to receive(:where)
.with(type: ProjectRole.name)
.and_return(role_scope)
allow(role_scope)
.to receive_messages(order: role_scope, find_by: nil)
allow(role_scope)
.to receive(:find)
.with(role.id.to_s)
.and_return(role)
allow(role_scope)
.to receive(:find_by)
.with(id: role.id.to_s)
.and_return(role)
role_scope
end
let!(:role) do
build_stubbed(:project_role) do |r|
allow(Role)
.to receive(:find)
.with(r.id.to_s)
.and_return(r)
allow(Role)
.to receive(:find_by)
.and_return(nil)
allow(Role)
.to receive(:find_by)
.with(id: r.id.to_s)
.and_return(r)
end
build_stubbed(:project_role)
end
let!(:type) do
build_stubbed(:type) do |t|
@@ -105,7 +115,7 @@ RSpec.describe WorkflowsController do
.to receive(:order)
.and_return([type])
allow(Role)
allow(role_scope)
.to receive(:order)
.and_return([role])
end
@@ -283,7 +293,7 @@ RSpec.describe WorkflowsController do
end
before do
allow(Role)
allow(role_scope)
.to receive(:where)
.with(id: [target_role1.id.to_s, target_role2.id.to_s])
.and_return([target_role1, target_role2])
@@ -29,7 +29,8 @@
require 'spec_helper'
RSpec.describe 'Configuring the workflow for work package sharing',
with_config: { show_warning_bars: true } do
with_config: { show_warning_bars: true },
with_ee: %i[work_package_sharing] do
let!(:role) { create(:project_role) }
let!(:work_package_role) { create(:edit_work_package_role) }
let!(:type) { create(:type) }
@@ -89,7 +89,8 @@ RSpec.describe Authorization::EnterpriseService do
readonly_work_packages
team_planner_view
two_factor_authentication
work_package_query_relation_columns).each do |guarded_action|
work_package_query_relation_columns
work_package_sharing).each do |guarded_action|
context "guarded action #{guarded_action}" do
let(:action) { guarded_action }