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
Replace allowed_to_globally? -> allowed_globally? for global permission checks
Klaus Zanders2d5f5f3a2681
diff --git a/app/contracts/backups/create_contract.rb b/app/contracts/backups/create_contract.rbindex f56e1fe1bb8..3d6b274b3c8 100644--- a/app/contracts/backups/create_contract.rb+++ b/app/contracts/backups/create_contract.rb@@ -75,7 +75,7 @@ module Backupsenddef user_allowed_to_create_backup?- user.allowed_to_globally? Backup.permission+ user.allowed_globally?(Backup.permission)enddef pending_statusesdiff --git a/app/contracts/placeholder_users/base_contract.rb b/app/contracts/placeholder_users/base_contract.rbindex 9e48ba15f13..870149e1d4c 100644--- a/app/contracts/placeholder_users/base_contract.rb+++ b/app/contracts/placeholder_users/base_contract.rb@@ -51,7 +51,7 @@ module PlaceholderUsersenddef user_allowed_to_add?- user.allowed_to_globally?(:manage_placeholder_user)+ user.allowed_globally?(:manage_placeholder_user)endendenddiff --git a/app/contracts/placeholder_users/delete_contract.rb b/app/contracts/placeholder_users/delete_contract.rbindex fb99eb8b326..83241309436 100644--- a/app/contracts/placeholder_users/delete_contract.rb+++ b/app/contracts/placeholder_users/delete_contract.rb@@ -37,7 +37,7 @@ module PlaceholderUsers## @param actor [User] User who wants to delete the given placeholder user.def self.deletion_allowed?(placeholder_user, actor)- actor.allowed_to_globally?(:manage_placeholder_user) &&+ actor.allowed_globally?(:manage_placeholder_user) &&affected_projects_managed_by_actor?(placeholder_user, actor)enddiff --git a/app/contracts/projects/create_contract.rb b/app/contracts/projects/create_contract.rbindex e3185de71b4..6253013640e 100644--- a/app/contracts/projects/create_contract.rb+++ b/app/contracts/projects/create_contract.rb@@ -31,7 +31,7 @@ module Projectsprivatedef validate_user_allowed_to_manage- unless user.allowed_to_globally?(:add_project) ||+ unless user.allowed_globally?(:add_project) ||(model.parent && user.allowed_to?(:add_subprojects, model.parent))errors.add :base, :error_unauthorizeddiff --git a/app/contracts/user_preferences/base_contract.rb b/app/contracts/user_preferences/base_contract.rbindex c4df8b17a2b..c1b336d208e 100644--- a/app/contracts/user_preferences/base_contract.rb+++ b/app/contracts/user_preferences/base_contract.rb@@ -103,7 +103,7 @@ module UserPreferences# User preferences can only be accessed with the manage_user permission# or if an active, logged user is editing their own prefsdef user_allowed_to_access- unless user.allowed_to_globally?(:manage_user) || (user.logged? && user.active? && user.id == model.user_id)+ unless user.allowed_globally?(:manage_user) || (user.logged? && user.active? && user.id == model.user_id)errors.add :base, :error_unauthorizedendenddiff --git a/app/contracts/users/base_contract.rb b/app/contracts/users/base_contract.rbindex a96c873e505..3f7279e71ab 100644--- a/app/contracts/users/base_contract.rb+++ b/app/contracts/users/base_contract.rb@@ -32,8 +32,7 @@ module Usersattribute :login,writable: ->(*) {- (user.allowed_to_globally?(:manage_user) || user.allowed_to_globally?(:create_user)) &&- model.id != user.id+ can_create_or_manage_users? && model.id != user.id}attribute :firstnameattribute :lastname@@ -43,10 +42,10 @@ module Usersattribute :languageattribute :ldap_auth_source_id,- writable: ->(*) { user.allowed_to_globally?(:manage_user) || user.allowed_to_globally?(:create_user) }+ writable: ->(*) { can_create_or_manage_users? }attribute :status,- writable: ->(*) { user.allowed_to_globally?(:manage_user) || user.allowed_to_globally?(:create_user) }+ writable: ->(*) { can_create_or_manage_users? }attribute :identity_url,writable: ->(*) { user.admin? }@@ -96,5 +95,9 @@ module Usersendend# rubocop:enable Rails/DynamicFindBy++ def can_create_or_manage_users?+ user.allowed_globally?(:manage_user) || user.allowed_globally?(:create_user)+ endendenddiff --git a/app/contracts/users/create_contract.rb b/app/contracts/users/create_contract.rbindex 09e9b432d08..145488bf390 100644--- a/app/contracts/users/create_contract.rb+++ b/app/contracts/users/create_contract.rb@@ -69,7 +69,7 @@ module Users# Users can only be created by Admins or users with# the global right to :create_userdef user_allowed_to_add- unless user.allowed_to_globally?(:create_user)+ unless user.allowed_globally?(:create_user)errors.add :base, :error_unauthorizedendenddiff --git a/app/contracts/users/update_contract.rb b/app/contracts/users/update_contract.rbindex 426ae94e9d1..c282d28afb3 100644--- a/app/contracts/users/update_contract.rb+++ b/app/contracts/users/update_contract.rb@@ -54,7 +54,7 @@ module Users# Only admins can edit other admins# Only users with manage_user permission can edit other usersdef can_manage_user?- user.allowed_to_globally?(:manage_user) && (user.admin? || !model.admin?)+ user.allowed_globally?(:manage_user) && (user.admin? || !model.admin?)endendenddiff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rbindex e0154c18037..680fbb4fb7a 100644--- a/app/controllers/members_controller.rb+++ b/app/controllers/members_controller.rb@@ -142,7 +142,7 @@ class MembersController < ApplicationControllerenddef suggest_invite_via_email?(user, query, principals)- user.allowed_to_globally?(:create_user) &&+ user.allowed_globally?(:create_user) &&query =~ mail_regex &&principals.none? { |p| p.mail == query || p.login == query } &&query # finally return email@@ -218,7 +218,7 @@ class MembersController < ApplicationControlleruser_ids.filter_map do |id|if id.to_i == 0 && id.present? # we've got an email - invite that user# Only users with the create_user permission can add users.- if current_user.allowed_to_globally?(:create_user) && enterprise_allow_new_users?+ if current_user.allowed_globally?(:create_user) && enterprise_allow_new_users?# The invitation can pretty much only fail due to the user already# having been invited. So look them up if it does.user = UserInvitation.invite_new_user(email: id) ||@@ -236,10 +236,10 @@ class MembersController < ApplicationController!OpenProject::Enterprise.user_limit_reached? || !OpenProject::Enterprise.fail_fast?end- def each_comma_separated(array, &block)+ def each_comma_separated(array)array.map do |e|if e.to_s.match? /\d(,\d)*/- block.call(e)+ yield(e)elseeenddiff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex b5715ffb370..5351ba35aeb 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -244,8 +244,7 @@ class UsersController < ApplicationControllerenddef can_manage_or_create_users?- current_user.allowed_to_globally?(:manage_user) ||- current_user.allowed_to_globally?(:create_user)+ current_user.allowed_globally?(:manage_user) || current_user.allowed_globally?(:create_user)enddef eventsdiff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rbindex 754cb74ad0b..7bb83507795 100644--- a/app/helpers/projects_helper.rb+++ b/app/helpers/projects_helper.rb@@ -58,7 +58,7 @@ module ProjectsHelperenddef no_projects_result_box_params- if User.current.allowed_to_globally?(:add_project)+ if User.current.allowed_globally?(:add_project){ action_url: new_project_path, display_action: true }else{}@@ -266,12 +266,12 @@ module ProjectsHelper# Just like sort_header tag but removes sorting by# lft from the sort criteria as lft is mutually exclusive with# the other criteria.- def projects_sort_header_tag(*args)+ def projects_sort_header_tag(*)former_criteria = @sort_criteria.criteria.dup@sort_criteria.criteria.reject! { |a, _| a == 'lft' }- sort_header_tag(*args)+ sort_header_tag(*)ensure@sort_criteria.criteria = former_criteriaenddiff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rbindex 9afc395ab1c..b2ebcd7dffe 100644--- a/app/helpers/users_helper.rb+++ b/app/helpers/users_helper.rb@@ -127,7 +127,7 @@ module UsersHelperenddef allowed_management_user_profile_path(user)- if User.current.allowed_to_globally?(:manage_user)+ if User.current.allowed_globally?(:manage_user)edit_user_path(user)elseuser_path(user)diff --git a/app/models/placeholder_users/scopes/visible.rb b/app/models/placeholder_users/scopes/visible.rbindex c776784cb8f..f0e98f029fb 100644--- a/app/models/placeholder_users/scopes/visible.rb+++ b/app/models/placeholder_users/scopes/visible.rb@@ -38,7 +38,7 @@ module PlaceholderUsers::Scopesclass_methods dodef visible(user = User.current)- if user.allowed_to_globally?(:manage_placeholder_user) ||+ if user.allowed_globally?(:manage_placeholder_user) ||user.allowed_to_globally?(:manage_members)allelsediff --git a/app/models/principals/scopes/visible.rb b/app/models/principals/scopes/visible.rbindex 2d6cffd7f72..643c54ee496 100644--- a/app/models/principals/scopes/visible.rb+++ b/app/models/principals/scopes/visible.rb@@ -37,7 +37,7 @@ module Principals::Scopesclass_methods dodef visible(user = ::User.current)if user.allowed_to_globally?(:manage_members) ||- user.allowed_to_globally?(:manage_user) ||+ user.allowed_globally?(:manage_user) ||user.allowed_to_globally?(:share_work_packages)allelsediff --git a/app/models/users/permission_checks.rb b/app/models/users/permission_checks.rbindex eb42ef9f0cf..f49917b387e 100644--- a/app/models/users/permission_checks.rb+++ b/app/models/users/permission_checks.rb@@ -108,7 +108,7 @@ module Users::PermissionChecksenddef allowed_to_globally?(action)- # OpenProject::Deprecation.replaced(:allowed_to_globally?, :allowed_globally?, caller)+ OpenProject::Deprecation.replaced(:allowed_to_globally?, :allowed_globally?, caller)allowed_to?(action, nil, global: true)enddiff --git a/app/views/admin/backups/show.html.erb b/app/views/admin/backups/show.html.erbindex 6d5a9e16899..44a38da628d 100644--- a/app/views/admin/backups/show.html.erb+++ b/app/views/admin/backups/show.html.erb@@ -76,7 +76,7 @@ See COPYRIGHT and LICENSE files for more details.<ul><% Token::Backup.all.includes(:user).each do |token| %><li>- <% if current_user.allowed_to_globally?(:manage_user) %>+ <% if current_user.allowed_globally?(:manage_user) %><%= link_to token.user.name, edit_user_path(token.user) %><% else %><%= token.user.name %>diff --git a/app/views/homescreen/blocks/_projects.html.erb b/app/views/homescreen/blocks/_projects.html.erbindex 66d1e2cf4c0..59d6dc83d78 100644--- a/app/views/homescreen/blocks/_projects.html.erb+++ b/app/views/homescreen/blocks/_projects.html.erb@@ -17,7 +17,7 @@<% end %><div class="widget-box--blocks--buttons">- <% if User.current.allowed_to_globally?(:add_project) %>+ <% if User.current.allowed_globally?(:add_project) %><%= link_to new_project_path,{ class: 'button -alt-highlight',aria: {label: t(:label_project_new)},diff --git a/app/views/placeholder_users/show.html.erb b/app/views/placeholder_users/show.html.erbindex 4a7071a9dbd..42d847d4f75 100644--- a/app/views/placeholder_users/show.html.erb+++ b/app/views/placeholder_users/show.html.erb@@ -32,7 +32,7 @@ See COPYRIGHT and LICENSE files for more details.<% end %><% html_title t(:label_administration), t(:label_placeholder_user_plural) -%><%= toolbar title: "#{avatar @placeholder_user} #{h(@placeholder_user.name)}".html_safe do %>- <% if current_user.allowed_to_globally?(:manage_placeholder_user) %>+ <% if current_user.allowed_globally?(:manage_placeholder_user) %><li class="toolbar-item"><%= link_to edit_placeholder_user_path(@placeholder_user), class: 'button', accesskey: accesskey(:edit) do %><%= op_icon('button--icon icon-edit') %>diff --git a/app/views/projects/_menu_query_select.html.erb b/app/views/projects/_menu_query_select.html.erbindex ca845f86afc..d385786c703 100644--- a/app/views/projects/_menu_query_select.html.erb+++ b/app/views/projects/_menu_query_select.html.erb@@ -12,7 +12,7 @@</div><div class="op-sidebar--footer">- <% if User.current.allowed_to_globally?(:add_project) %>+ <% if User.current.allowed_globally?(:add_project) %><%= button_to new_project_path,{ method: :get,class: 'button -alt-highlight -expand',diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erbindex d548e2a67e2..7340ae16ce4 100644--- a/app/views/projects/index.html.erb+++ b/app/views/projects/index.html.erb@@ -31,7 +31,7 @@ See COPYRIGHT and LICENSE files for more details.<div data-controller="project"data-application-target="dynamic"><%= toolbar title: t(:label_project_plural), html: { class: '-with-dropdown' } do %>- <% if User.current.allowed_to_globally?(:add_project) %>+ <% if User.current.allowed_globally?(:add_project) %><li class="toolbar-item"><%= link_to new_project_path,{ class: 'button -alt-highlight',diff --git a/app/views/users/_toolbar.html.erb b/app/views/users/_toolbar.html.erbindex fca9a87f8ae..a4cd2d0ade4 100644--- a/app/views/users/_toolbar.html.erb+++ b/app/views/users/_toolbar.html.erb@@ -33,7 +33,7 @@ See COPYRIGHT and LICENSE files for more details.<span class="button--text"><%= t(:label_profile) %></span><% end %></li>- <% if current_user.allowed_to_globally?(:create_user) %>+ <% if current_user.allowed_globally?(:create_user) %><li class="toolbar-item hidden-for-tablet"><%= form_for(@user, html: { class: 'toolbar-item' },url: { action: :resend_invitation },diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erbindex e655b0ec28a..b3b5576cbf9 100644--- a/app/views/users/show.html.erb+++ b/app/views/users/show.html.erb@@ -32,7 +32,7 @@ See COPYRIGHT and LICENSE files for more details.<% local_assigns[:additional_breadcrumb] = @user.name %><% html_title t(:label_administration), t(:label_user_plural) -%><%= breadcrumb_toolbar "#{avatar @user} #{h(@user.name)}".html_safe do %>- <% if User.current.allowed_to_globally?(:manage_user) %>+ <% if User.current.allowed_globally?(:manage_user) %><li class="toolbar-item"><%= link_to edit_user_path(@user), class: 'button', accesskey: accesskey(:edit) do %><%= op_icon('button--icon icon-edit') %>@@ -40,7 +40,7 @@ See COPYRIGHT and LICENSE files for more details.<% end %></li><% end %>- <% if User.current.allowed_to_globally?(:create_user) %>+ <% if User.current.allowed_globally?(:create_user) %><li class="toolbar-item hidden-for-tablet"><%= form_for(@user, html: { class: 'toolbar-item' },url: { action: :resend_invitation },diff --git a/config/initializers/menus.rb b/config/initializers/menus.rbindex 6d5a3d9bc8d..cd4d660de35 100644--- a/config/initializers/menus.rb+++ b/config/initializers/menus.rb@@ -86,7 +86,7 @@ Redmine::MenuManager.map :quick_add_menu do |menu|title: I18n.t(:label_project_new)},if: ->(project) {- User.current.allowed_to_globally?(:add_project) ||+ User.current.allowed_globally?(:add_project) ||User.current.allowed_to?(:add_subprojects, project)}@@ -118,10 +118,10 @@ Redmine::MenuManager.map :account_menu do |menu|menu.push :administration,{ controller: '/admin', action: 'index' },if: Proc.new {- User.current.allowed_to_globally?(:create_backup) ||- User.current.allowed_to_globally?(:manage_placeholder_user) ||- User.current.allowed_to_globally?(:manage_user) ||- User.current.allowed_to_globally?(:create_user)+ User.current.allowed_globally?(:create_backup) ||+ User.current.allowed_globally?(:manage_placeholder_user) ||+ User.current.allowed_globally?(:manage_user) ||+ User.current.allowed_globally?(:create_user)}menu.push :logout,:signout_path,@@ -242,14 +242,14 @@ Redmine::MenuManager.map :admin_menu do |menu|{ controller: '/users' },if: Proc.new {!User.current.admin? &&- (User.current.allowed_to_globally?(:manage_user) || User.current.allowed_to_globally?(:create_user))+ (User.current.allowed_globally?(:manage_user) || User.current.allowed_globally?(:create_user))},caption: :label_user_plural,icon: 'group'menu.push :placeholder_users,{ controller: '/placeholder_users' },- if: Proc.new { !User.current.admin? && User.current.allowed_to_globally?(:manage_placeholder_user) },+ if: Proc.new { !User.current.admin? && User.current.allowed_globally?(:manage_placeholder_user) },caption: :label_placeholder_user_plural,icon: 'group'@@ -474,7 +474,7 @@ Redmine::MenuManager.map :admin_menu do |menu|menu.push :backups,{ controller: '/admin/backups', action: 'show' },- if: Proc.new { OpenProject::Configuration.backup_enabled? && User.current.allowed_to_globally?(Backup.permission) },+ if: Proc.new { OpenProject::Configuration.backup_enabled? && User.current.allowed_globally?(Backup.permission) },caption: :label_backup,last: true,icon: 'save'diff --git a/lib/api/v3/placeholder_users/placeholder_user_representer.rb b/lib/api/v3/placeholder_users/placeholder_user_representer.rbindex 9257065cb49..682ff942cb6 100644--- a/lib/api/v3/placeholder_users/placeholder_user_representer.rb+++ b/lib/api/v3/placeholder_users/placeholder_user_representer.rb@@ -60,7 +60,7 @@ module APIenddef current_user_can_manage?- current_user&.allowed_to_globally?(:manage_placeholder_user)+ current_user&.allowed_globally?(:manage_placeholder_user)endendenddiff --git a/lib/api/v3/projects/schemas/project_schema_representer.rb b/lib/api/v3/projects/schemas/project_schema_representer.rbindex da7b50d5b56..69ed1a9ac47 100644--- a/lib/api/v3/projects/schemas/project_schema_representer.rb+++ b/lib/api/v3/projects/schemas/project_schema_representer.rb@@ -89,7 +89,7 @@ module API# Users only having the add_subprojects permission need to provide# a parent when creating a new project.represented.model.new_record? &&- !current_user.allowed_to_globally?(:add_project)+ !current_user.allowed_globally?(:add_project)},href_callback: ->(*) {query_props = if represented.model.new_record?diff --git a/lib/api/v3/user_preferences/preferences_by_user_api.rb b/lib/api/v3/user_preferences/preferences_by_user_api.rbindex 2c8bcfc1eba..c46b0e793ad 100644--- a/lib/api/v3/user_preferences/preferences_by_user_api.rb+++ b/lib/api/v3/user_preferences/preferences_by_user_api.rb@@ -34,7 +34,7 @@ module API# The empty namespaces are added so that anonymous users can receive a 401 responsenamespace '' doafter_validation do- authorize_by_with_raise(current_user.allowed_to_globally?(:manage_user) || @user == current_user)+ authorize_by_with_raise(current_user.allowed_globally?(:manage_user) || @user == current_user)endget &::API::V3::Utilities::Endpoints::Show.new(model: UserPreference,@@ -44,7 +44,7 @@ module APInamespace '' doafter_validation do- authorize_by_with_raise(current_user.allowed_to_globally?(:manage_user) ||+ authorize_by_with_raise(current_user.allowed_globally?(:manage_user) ||(current_user.logged? && @user == current_user)) doif current_user.anonymous?raise API::Errors::Unauthenticateddiff --git a/lib/api/v3/users/user_representer.rb b/lib/api/v3/users/user_representer.rbindex 3dbe3c8c7ed..18308916540 100644--- a/lib/api/v3/users/user_representer.rb+++ b/lib/api/v3/users/user_representer.rb@@ -229,8 +229,8 @@ module APIdef current_user_can_manage?current_user && (- current_user.allowed_to_globally?(:manage_user) ||- current_user.allowed_to_globally?(:create_user) ||+ current_user.allowed_globally?(:manage_user) ||+ current_user.allowed_globally?(:create_user) ||current_user_is_self?)enddiff --git a/lib/api/v3/users/user_sql_representer.rb b/lib/api/v3/users/user_sql_representer.rbindex 7bf4277ba15..39a090a203e 100644--- a/lib/api/v3/users/user_sql_representer.rb+++ b/lib/api/v3/users/user_sql_representer.rb@@ -51,7 +51,7 @@ module APIenddef render_if_manage_user_or_self(*)- if User.current.allowed_to_globally?(:manage_user)+ if User.current.allowed_globally?(:manage_user)'TRUE'else"id = #{User.current.id}"diff --git a/lib/api/v3/users/users_api.rb b/lib/api/v3/users/users_api.rbindex 41fcbd0be11..b5686425620 100644--- a/lib/api/v3/users/users_api.rb+++ b/lib/api/v3/users/users_api.rb@@ -48,7 +48,7 @@ module API# The namespace only exists to add the after_validation callbacknamespace '' doafter_validation do- authorize_by_with_raise(current_user.allowed_to_globally?(:create_user))+ authorize_by_with_raise(current_user.allowed_globally?(:create_user))endpost &::API::V3::Utilities::Endpoints::Create.new(model: User).mount@@ -57,7 +57,7 @@ module API# The namespace only exists to add the after_validation callbacknamespace '' doafter_validation do- authorize_by_with_raise(current_user.allowed_to_globally?(:manage_user))+ authorize_by_with_raise(current_user.allowed_globally?(:manage_user))endget &::API::V3::Utilities::Endpoints::SqlFallbackedIndexdiff --git a/lib/redmine/menu_manager/top_menu/quick_add_menu.rb b/lib/redmine/menu_manager/top_menu/quick_add_menu.rbindex b1420f2abe1..45068e75920 100644--- a/lib/redmine/menu_manager/top_menu/quick_add_menu.rb+++ b/lib/redmine/menu_manager/top_menu/quick_add_menu.rb@@ -122,9 +122,8 @@ module Redmine::MenuManager::TopMenu::QuickAddMenuenddef global_add_permissions?- %i[add_project manage_members].any? do |permission|- User.current.allowed_to_globally?(permission)- end+ User.current.allowed_globally?(:add_project) ||+ User.current.alllowed_to_globally(:manage_members)enddef add_subproject_permission?