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
[#58143] Add the new role and apply defaults
Dombi Attila880cc6ecbb8d
diff --git a/app/models/global_role.rb b/app/models/global_role.rbindex 5600bfd1e0d..bda2366dac6 100644--- a/app/models/global_role.rb+++ b/app/models/global_role.rb@@ -31,4 +31,15 @@ class GlobalRole < Rolesuper.where(type: "GlobalRole")end++ def self.standard+ standard_global_role = where(builtin: BUILTIN_STANDARD_GLOBAL).first+ if standard_global_role.nil?+ standard_global_role = create(name: "Standard global role", position: 0) do |role|+ role.builtin = BUILTIN_STANDARD_GLOBAL+ end+ raise "Unable to create the standard global role." if standard_global_role.new_record?+ end+ standard_global_role+ endenddiff --git a/app/models/role.rb b/app/models/role.rbindex bbaff72cd4a..77c940dc55b 100644--- a/app/models/role.rb+++ b/app/models/role.rb@@ -36,6 +36,7 @@ class Role < ApplicationRecordBUILTIN_WORK_PACKAGE_EDITOR = 5BUILTIN_PROJECT_QUERY_VIEW = 6BUILTIN_PROJECT_QUERY_EDIT = 7+ BUILTIN_STANDARD_GLOBAL = 8HIDDEN_ROLE_TYPES = ["WorkPackageRole",@@ -93,7 +94,8 @@ class Role < ApplicationRecordRole::BUILTIN_WORK_PACKAGE_COMMENTER,Role::BUILTIN_WORK_PACKAGE_EDITOR,Role::BUILTIN_PROJECT_QUERY_VIEW,- Role::BUILTIN_PROJECT_QUERY_EDIT+ Role::BUILTIN_PROJECT_QUERY_EDIT,+ Role::BUILTIN_STANDARD_GLOBAL]).order(Arel.sql("position"))diff --git a/app/seeders/basic_data/base_role_seeder.rb b/app/seeders/basic_data/base_role_seeder.rbindex e1ffed74629..f3a09bfb404 100644--- a/app/seeders/basic_data/base_role_seeder.rb+++ b/app/seeders/basic_data/base_role_seeder.rb@@ -49,6 +49,7 @@ module BasicDatacase valuewhen :non_member then Role::BUILTIN_NON_MEMBERwhen :anonymous then Role::BUILTIN_ANONYMOUS+ when :standard_global then Role::BUILTIN_STANDARD_GLOBALwhen :work_package_editor then Role::BUILTIN_WORK_PACKAGE_EDITORwhen :work_package_commenter then Role::BUILTIN_WORK_PACKAGE_COMMENTERwhen :work_package_viewer then Role::BUILTIN_WORK_PACKAGE_VIEWERdiff --git a/app/seeders/common.yml b/app/seeders/common.ymlindex 16ca0a3560c..2b3544a5237 100644--- a/app/seeders/common.yml+++ b/app/seeders/common.yml@@ -398,3 +398,9 @@ global_roles:- :create_user- :manage_user- :manage_placeholder_user+ - reference: :default_role_standard_global+ t_name: Standard global role+ position: 7+ builtin: :standard_global+ permissions:+ - :view_user_emaildiff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex d0ea7360287..c7aba110e3a 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -81,6 +81,11 @@ Rails.application.reloader.to_prepare dorequire: :loggedin,contract_actions: { placeholder_users: %i[create read update] }+ map.permission :view_user_email,+ {},+ permissible_on: :global,+ require: :loggedin+map.permission :view_project,{ projects: [:show] },permissible_on: :project,diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 0d88e67097f..2766abfef7f 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3045,6 +3045,7 @@ en:permission_view_shared_work_packages: "View work package shares"permission_view_time_entries: "View spent time"permission_view_timelines: "View timelines"+ permission_view_user_email: "View users' mail addresses"permission_view_wiki_edits: "View wiki history"permission_view_wiki_pages: "View wiki"permission_work_package_assigned: "Become assignee/responsible"diff --git a/db/migrate/20241001205821_add_standard_global_role.rb b/db/migrate/20241001205821_add_standard_global_role.rbnew file mode 100644index 00000000000..7976567c11b--- /dev/null+++ b/db/migrate/20241001205821_add_standard_global_role.rb@@ -0,0 +1,12 @@+class AddStandardGlobalRole < ActiveRecord::Migration[7.1]+ def change+ standard_global_role ||= GlobalRole.find_or_initialize_by(builtin: Role::BUILTIN_STANDARD_GLOBAL)++ standard_global_role.update!(+ name: I18n.t("seeds.common.global_roles.item_1.name", default: "Standard global role"),+ permissions: %i[+ view_user_email+ ]+ )+ end+enddiff --git a/spec/factories/global_role_factory.rb b/spec/factories/global_role_factory.rbindex 7c55f7389ba..ab14faeb2b3 100644--- a/spec/factories/global_role_factory.rb+++ b/spec/factories/global_role_factory.rb@@ -29,5 +29,11 @@FactoryBot.define dofactory :global_role dosequence(:name) { |n| "Global Role #{n}" }++ factory :standard_global_role do+ name { "Standard global role" }+ builtin { Role::BUILTIN_STANDARD_GLOBAL }+ initialize_with { GlobalRole.where(builtin: Role::BUILTIN_STANDARD_GLOBAL).first_or_initialize }+ endendenddiff --git a/spec/models/global_role_spec.rb b/spec/models/global_role_spec.rbindex 023c642af79..1b49fc3cd3f 100644--- a/spec/models/global_role_spec.rb+++ b/spec/models/global_role_spec.rb@@ -29,16 +29,14 @@require "spec_helper"RSpec.describe GlobalRole do- before { GlobalRole.create name: "globalrole", permissions: ["permissions"] }+ let!(:global_role) { create(:global_role, name: "globalrole", permissions: ["permissions"]) }it { is_expected.to validate_presence_of :name }it { is_expected.to validate_uniqueness_of :name }it { is_expected.to validate_length_of(:name).is_at_most(256) }describe "attributes" do- before { @role = GlobalRole.new }-- subject { @role }+ subject(:role) { described_class.new }it { is_expected.to respond_to :name }it { is_expected.to respond_to :permissions }@@ -46,17 +44,13 @@ RSpec.describe GlobalRole doenddescribe "instance methods" do- before do- @role = GlobalRole.new- end-describe "WITH no attributes set" do- before do- @role = GlobalRole.new- end+ let(:role) { described_class.new }++ subject { role }describe "#permissions" do- subject { @role.permissions }+ subject { role.permissions }it { is_expected.to be_an_instance_of(Array) }@@ -66,38 +60,68 @@ RSpec.describe GlobalRole doenddescribe "#has_permission?" do- it { expect(@role.has_permission?(:perm)).to be_falsey }+ it { is_expected.not_to have_permission(:perm) }enddescribe "#allowed_to?" dodescribe "WITH requested permission" do- it { expect(@role.allowed_to?(:perm1)).to be_falsey }+ it { is_expected.not_to be_allowed_to(:perm1) }endendenddescribe "WITH set permissions" do- before { @role = GlobalRole.new permissions: %i[perm1 perm2 perm3] }+ subject(:role) { described_class.new permissions: %i[perm1 perm2 perm3] }describe "#has_permission?" do- it { expect(@role.has_permission?(:perm1)).to be_truthy }- it { expect(@role.has_permission?("perm1")).to be_truthy }- it { expect(@role.has_permission?(:perm5)).to be_falsey }+ it { is_expected.to have_permission(:perm1) }+ it { is_expected.to have_permission("perm1") }+ it { is_expected.not_to have_permission(:perm5) }enddescribe "#allowed_to?" dodescribe "WITH requested permission" do- it { expect(@role.allowed_to?(:perm1)).to be_truthy }- it { expect(@role.allowed_to?(:perm5)).to be_falsey }+ it { is_expected.to be_allowed_to(:perm1) }+ it { is_expected.not_to be_allowed_to(:perm5) }endendenddescribe "WITH set name" do- before { @role = GlobalRole.new name: "name" }+ let(:role) { described_class.new name: "name" }describe "#to_s" do- it { expect(@role.to_s).to eql("name") }+ it { expect(role.to_s).to eql("name") }+ end+ end+ end++ describe ".givable" do+ let!(:builtin_role) { create(:standard_global_role) }++ it { expect(described_class.givable).to contain_exactly global_role }+ end++ describe ".standard" do+ subject { described_class.standard }++ it "has the constant's builtin value" do+ expect(subject.builtin)+ .to eql(Role::BUILTIN_STANDARD_GLOBAL)+ end++ it "is builtin" do+ expect(subject)+ .to be_builtin+ end++ context "with a missing standard role" do+ before do+ described_class.where(builtin: Role::BUILTIN_STANDARD_GLOBAL).delete_all+ end++ it "creates a new standard role" do+ expect { subject }.to change(described_class, :count).by(1)endendenddiff --git a/spec/seeders/root_seeder_standard_edition_spec.rb b/spec/seeders/root_seeder_standard_edition_spec.rbindex 90b089cebcd..2d5f48c85d9 100644--- a/spec/seeders/root_seeder_standard_edition_spec.rb+++ b/spec/seeders/root_seeder_standard_edition_spec.rb@@ -57,7 +57,7 @@ RSpec.describe RootSeeder,expect(Query.count).to eq 26expect(ProjectRole.count).to eq 5expect(WorkPackageRole.count).to eq 3- expect(GlobalRole.count).to eq 1+ expect(GlobalRole.count).to eq 2expect(Grids::Overview.count).to eq 2expect(Version.count).to eq 4expect(VersionSetting.count).to eq 4@@ -126,7 +126,7 @@ RSpec.describe RootSeeder,include_examples "it creates records", model: Color, expected_count: 144include_examples "it creates records", model: DocumentCategory, expected_count: 3- include_examples "it creates records", model: GlobalRole, expected_count: 1+ include_examples "it creates records", model: GlobalRole, expected_count: 2include_examples "it creates records", model: WorkPackageRole, expected_count: 3include_examples "it creates records", model: ProjectRole, expected_count: 5include_examples "it creates records", model: ProjectQueryRole, expected_count: 2@@ -166,7 +166,7 @@ RSpec.describe RootSeeder,expect(Query.count).to eq 26expect(ProjectRole.count).to eq 5expect(WorkPackageRole.count).to eq 3- expect(GlobalRole.count).to eq 1+ expect(GlobalRole.count).to eq 2expect(Grids::Overview.count).to eq 2expect(Version.count).to eq 4expect(VersionSetting.count).to eq 4