Skip to content

Commit 627e323

Browse files
Release OpenProject 17.0.4
2 parents bdd7124 + 6f3507b commit 627e323

56 files changed

Lines changed: 1183 additions & 255 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/contracts/messages/update_contract.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,20 @@
3131
# TODO: This is but a stub
3232
module Messages
3333
class UpdateContract < BaseContract
34+
validate :moving_message_to_another_forum
35+
36+
private
37+
38+
def moving_message_to_another_forum
39+
return if !model.forum_id_changed?
40+
return if model.forum_id_was.nil?
41+
42+
old_forum = Forum.find_by(id: model.forum_id_was)
43+
return if old_forum.nil?
44+
45+
return if old_forum.project_id == model.forum.project_id
46+
47+
errors.add(:forum_id, :cannot_move_message_to_forum_of_different_project)
48+
end
3449
end
3550
end

app/contracts/queries/base_contract.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ def user_allowed_to_make_public
9292
end
9393
end
9494

95+
def user_allowed_to_save_queries?
96+
if model.project
97+
user.allowed_in_project?(:save_queries, model.project)
98+
else
99+
user.allowed_in_any_project?(:save_queries)
100+
end
101+
end
102+
95103
def timestamps_are_parsable
96104
invalid_timestamps = model.timestamps.reject(&:valid?)
97105

app/contracts/queries/create_contract.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@
3030

3131
module Queries
3232
class CreateContract < BaseContract
33+
validate :user_allowed_to_save
34+
35+
def user_allowed_to_save
36+
errors.add :base, :error_unauthorized unless user_allowed_to_save_queries?
37+
end
3338
end
3439
end

app/contracts/queries/update_contract.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ def user_allowed_to_edit_work_packages?
6464
user.allowed_in_any_work_package?(:edit_work_packages, in_project: model.project)
6565
end
6666

67-
def user_allowed_to_save_queries?
68-
if model.project
69-
user.allowed_in_project?(:save_queries, model.project)
70-
else
71-
user.allowed_in_any_project?(:save_queries)
72-
end
73-
end
74-
7567
def user_allowed_to_change_query_to_private
7668
if model.user.is_a? DeletedUser
7769
errors.add :base, :error_unauthorized

app/models/capabilities/scopes/default.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def default_sql_by_member
7272
ON members.id = member_roles.member_id
7373
AND members.entity_type IS NULL
7474
AND members.entity_id IS NULL
75-
JOIN (#{principal_sql}) users
75+
JOIN users
7676
ON "users".id = members.user_id
7777
LEFT OUTER JOIN "projects"
7878
ON "projects".id = members.project_id
@@ -91,7 +91,7 @@ def default_sql_by_admin
9191
users.id principal_id,
9292
projects.id context_id
9393
FROM (#{Action.default.to_sql}) actions
94-
JOIN (#{principal_sql}) users
94+
JOIN users
9595
ON "users".admin = true AND actions.grant_to_admin = true
9696
LEFT OUTER JOIN "projects"
9797
ON "projects".active = true
@@ -115,7 +115,7 @@ def default_sql_by_non_member
115115
JOIN "roles"
116116
ON ("roles".id = "role_permissions".role_id OR "actions"."public")
117117
AND roles.builtin = #{Role::BUILTIN_NON_MEMBER}
118-
JOIN (#{principal_sql}) users
118+
JOIN users
119119
ON 1 = 1
120120
JOIN "projects"
121121
ON "projects".active = true
@@ -157,12 +157,6 @@ def default_sql_by_non_member_with_anonymous
157157
WHERE enabled_modules.project_id IS NOT NULL OR "actions".module IS NULL
158158
SQL_PART
159159
end
160-
161-
def principal_sql
162-
RequestStore.fetch(:capabilities_principal_sql) do
163-
Principal.visible.not_builtin.not_locked.to_sql
164-
end
165-
end
166160
end
167161
end
168162
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 Capabilities::Scopes
32+
module Visible
33+
extend ActiveSupport::Concern
34+
35+
class_methods do
36+
def visible(user = User.current)
37+
scope = if user.admin?
38+
all
39+
else
40+
where(context_id: nil)
41+
.or(where(context_id: Project.visible(user).select(:id)))
42+
end
43+
44+
scope.where(principal_id: Principal.visible(user).not_builtin.not_locked)
45+
end
46+
end
47+
end
48+
end

app/models/capability.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class Capability < ApplicationRecord
3232
include Tableless
3333
include Scopes::Scoped
3434

35-
scopes :default
35+
scopes :default,
36+
:visible
3637

3738
default_scope { default }
3839

app/models/queries/capabilities/capability_query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def results
4343

4444
def default_scope
4545
Capability
46-
.default
46+
.visible
4747
.distinct
4848
end
4949

app/views/user_mailer/activation_limit_reached.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ See COPYRIGHT and LICENSE files for more details.
2828
++# %>
2929

3030
<p>
31-
<% mail_link = "<a href=\"mailto:#{@email}\">#{@email}</a>" %>
32-
<% host = Rails.application.root_url %>
33-
<% host_link = "<a href=\"#{host}\">#{Setting.app_title}</a>" %>
31+
<% mail_link = content_tag(:a, @email, href: "mailto:#{@email}") %>
32+
<% host_link = content_tag(:a, Setting.app_title, href: Rails.application.root_url) %>
3433
<%= t("mail_user_activation_limit_reached.message", email: mail_link, host: host_link).html_safe %>
3534
</p>
3635

app/views/user_mailer/wiki_page_added.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ See COPYRIGHT and LICENSE files for more details.
3131
<%= raw t(
3232
:mail_body_wiki_page_added,
3333
id: link_to(@wiki_page.title, project_wiki_url(@wiki_page.project, @wiki_page)),
34-
author: @wiki_page.author
34+
author: h(@wiki_page.author)
3535
) %><br>
3636
<em><%= @wiki_page.journals.last.notes %></em>
3737
</p>

0 commit comments

Comments
 (0)