Skip to content

Commit 1b829ff

Browse files
authored
Merge pull request #22113 from opf/merge-17.0-in-17.1
Release/17.0
2 parents 4df1faa + 7742591 commit 1b829ff

40 files changed

Lines changed: 1376 additions & 138 deletions

File tree

app/models/attribute_help_text/work_package.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def type_caption
5353

5454
def self.visible_condition(user)
5555
visible_cf_names = WorkPackageCustomField
56-
.manageable_by_user(user)
56+
.visible(user)
5757
.pluck(:id)
5858
.map { |id| "custom_field_#{id}" }
5959

app/models/custom_field.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ class CustomField < ApplicationRecord
5353

5454
has_many :calculated_value_errors, dependent: :delete_all, inverse_of: "custom_field"
5555

56+
include Scopes::Scoped
57+
5658
scope :hierarchy_root_and_children, -> { includes(hierarchy_root: { children: :children }) }
5759
scope :required, -> { where(is_required: true).where.not(field_format: "calculated_value") }
5860

5961
scope :field_format_calculated_value, -> { where(field_format: "calculated_value") }
6062

63+
scopes :visible
64+
6165
acts_as_list scope: [:type]
6266

6367
validates :field_format, presence: true
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
# -- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
# ++
30+
31+
module CustomFields::Scopes
32+
module Visible
33+
extend ActiveSupport::Concern
34+
35+
class_methods do
36+
def visible(user = User.current)
37+
known_subclasses
38+
.inject(none) do |scope, klass|
39+
scope.or(where(type: klass.name).and(klass.visible(user)))
40+
end
41+
end
42+
43+
def known_subclasses
44+
# In dev/test without eager loading, subclasses might not be loaded.
45+
if Rails.env.local?
46+
CustomField
47+
.group(:type)
48+
.pluck(:type)
49+
.map(&:safe_constantize)
50+
end
51+
52+
CustomField.subclasses
53+
end
54+
end
55+
end
56+
end

app/models/group_custom_field.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#++
3030

3131
class GroupCustomField < CustomField
32+
scopes :visible
33+
3234
def type_name
3335
:label_group_plural
3436
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
# -- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
# ++
30+
31+
module GroupCustomFields::Scopes
32+
module Visible
33+
extend ActiveSupport::Concern
34+
35+
class_methods do
36+
def visible(user = User.current)
37+
if user.admin?
38+
all
39+
else
40+
where(admin_only: false)
41+
end
42+
end
43+
end
44+
end
45+
end

app/models/project_custom_field.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class ProjectCustomField < CustomField
4646
has_one :role, through: :custom_fields_role
4747
accepts_nested_attributes_for :custom_fields_role, allow_destroy: true
4848

49+
scopes :visible
50+
4951
scope :user_field_with_assigned_role, -> do
5052
joins(:custom_fields_role)
5153
.where.not(custom_fields_roles: { role_id: nil })
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
# -- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
# ++
30+
31+
module ProjectCustomFields::Scopes
32+
module Visible
33+
extend ActiveSupport::Concern
34+
35+
class_methods do
36+
def visible(user = User.current, project: nil)
37+
if user.admin?
38+
all
39+
elsif user.allowed_in_any_project?(:select_project_custom_fields) || user.allowed_globally?(:add_project)
40+
where(admin_only: false)
41+
else
42+
where(admin_only: false).where(mappings_with_view_project_attributes_permission(user, project).exists)
43+
end
44+
end
45+
end
46+
end
47+
end

app/models/queries/work_packages/selects/custom_field_select.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def self.instances(context = nil)
6363
else
6464
WorkPackageCustomField.all
6565
end
66-
.visible_by_user(User.current)
66+
.on_visible_type_and_project(User.current)
6767
.reject { |cf| cf.field_format == "text" }
6868
.map { |cf| new(cf) }
6969
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
# -- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
# ++
30+
31+
module TimeEntryCustomFields::Scopes
32+
module Visible
33+
extend ActiveSupport::Concern
34+
35+
class_methods do
36+
def visible(_user = User.current)
37+
all
38+
end
39+
end
40+
end
41+
end

app/models/user_custom_field.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#++
3030

3131
class UserCustomField < CustomField
32+
scopes :visible
33+
3234
def type_name
3335
:label_user_plural
3436
end

0 commit comments

Comments
 (0)