Skip to content

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

Allow non-admins to see/filter created_at of a project

Jan Sandbrink9109ab21bbc2
diff --git a/app/models/queries/projects/filters/created_at_filter.rb b/app/models/queries/projects/filters/created_at_filter.rb
index f1de4ea2818..cd2bdb19424 100644
--- a/app/models/queries/projects/filters/created_at_filter.rb
+++ b/app/models/queries/projects/filters/created_at_filter.rb
@@ -32,10 +32,4 @@ class Queries::Projects::Filters::CreatedAtFilter < Queries::Projects::Filters::
def type
:datetime_past
end
-
- def available?
- # The column is only available for admins.
- # When the filter is used, one could get the same information as with the column.
- User.current.admin?
- end
end
diff --git a/app/models/queries/projects/selects/created_at.rb b/app/models/queries/projects/selects/created_at.rb
index 3a04f73e4c0..f43a9600f55 100644
--- a/app/models/queries/projects/selects/created_at.rb
+++ b/app/models/queries/projects/selects/created_at.rb
@@ -32,8 +32,4 @@ class Queries::Projects::Selects::CreatedAt < Queries::Selects::Base
def self.key
:created_at
end
-
- def self.available?
- User.current.admin?
- end
end
diff --git a/spec/features/projects/lists/table_spec.rb b/spec/features/projects/lists/table_spec.rb
index c6cf949ef1f..58547fd4a6e 100644
--- a/spec/features/projects/lists/table_spec.rb
+++ b/spec/features/projects/lists/table_spec.rb
@@ -218,10 +218,6 @@ RSpec.describe "Projects lists table display and actions", :js, with_settings: {
within("#project-table") do
expect(page)
.to have_css("th", text: "REQUIRED DISK STORAGE")
- expect(page)
- .to have_css("th", text: "CREATED ON")
- expect(page)
- .to have_css("td", text: project.created_at.strftime("%m/%d/%Y"))
expect(page)
.to have_css("th", text: "LATEST ACTIVITY AT")
expect(page)
@@ -580,14 +576,8 @@ RSpec.describe "Projects lists table display and actions", :js, with_settings: {
within("#project-table") do
expect(page)
.to have_no_css("th", text: "REQUIRED DISK STORAGE")
- expect(page)
- .to have_no_css("th", text: "CREATED ON")
- expect(page)
- .to have_no_css("td", text: project.created_at.strftime("%m/%d/%Y"))
expect(page)
.to have_no_css("th", text: "LATEST ACTIVITY AT")
- expect(page)
- .to have_no_css("td", text: news.created_at.strftime("%m/%d/%Y"))
end
end
end
diff --git a/spec/features/projects/persisted_lists_spec.rb b/spec/features/projects/persisted_lists_spec.rb
index fccdcef9e6c..c87ee3724fa 100644
--- a/spec/features/projects/persisted_lists_spec.rb
+++ b/spec/features/projects/persisted_lists_spec.rb
@@ -621,10 +621,10 @@ RSpec.describe "Persisted lists on projects index page",
let!(:invalid_list) do
# Faking a query that has references stored to a custom field that no longer exists (e.g. has been deleted)
- create(:project_query, name: "My projects list", user:, select: %w[name created_at cf_1]) do |query|
+ create(:project_query, name: "My projects list", user:, select: %w[name latest_activity_at cf_1]) do |query|
query.where("member_of", "=", OpenProject::Database::DB_VALUE_TRUE)
query.where("cf_1", "=", 1)
- query.where("created_at", "=", "2020-01-01")
+ query.where("latest_activity_at", "=", "2020-01-01")
query.save(validate: false)
end
@@ -633,11 +633,11 @@ RSpec.describe "Persisted lists on projects index page",
it "still shows the query falling back to a valid subset" do
visit projects_path(query_id: invalid_list.id)
- # Keeps only the 'Name' column as the cf does not exist and Created on is admin only.
+ # Keeps only the 'Name' column as the cf does not exist and "Latest activity at" is admin only.
projects_page.expect_columns "Name"
- projects_page.expect_no_columns "Created on"
+ projects_page.expect_no_columns "Latest activity at"
- # Keeps only the 'I am member' filter as the cf does not exist and created_at is admin only.
+ # Keeps only the 'I am member' filter as the cf does not exist and latest_activity_at is admin only.
projects_page.expect_filter_count 1
projects_page.expect_filter_set("member_of")
diff --git a/spec/models/queries/factory_project_query_spec.rb b/spec/models/queries/factory_project_query_spec.rb
index 636cef8bcb0..f4335a76c49 100644
--- a/spec/models/queries/factory_project_query_spec.rb
+++ b/spec/models/queries/factory_project_query_spec.rb
@@ -812,7 +812,7 @@ RSpec.describe Queries::Factory,
end
context "without id, as non admin and with a non existing custom field id",
- with_settings: { enabled_projects_columns: %w[name created_at cf_1 cf_42] } do
+ with_settings: { enabled_projects_columns: %w[name latest_activity_at cf_1 cf_42] } do
before do
custom_field
end
diff --git a/spec/models/queries/projects/filters/created_at_filter_spec.rb b/spec/models/queries/projects/filters/created_at_filter_spec.rb
index 3ff3067b018..2316172b7ba 100644
--- a/spec/models/queries/projects/filters/created_at_filter_spec.rb
+++ b/spec/models/queries/projects/filters/created_at_filter_spec.rb
@@ -57,9 +57,9 @@ RSpec.describe Queries::Projects::Filters::CreatedAtFilter do
login_as user
end
- it "is false" do
+ it "is true" do
expect(instance)
- .not_to be_available
+ .to be_available
end
end
end
diff --git a/spec/models/queries/projects/project_query_spec.rb b/spec/models/queries/projects/project_query_spec.rb
index 5d723e0c700..499e68f1ad7 100644
--- a/spec/models/queries/projects/project_query_spec.rb
+++ b/spec/models/queries/projects/project_query_spec.rb
@@ -143,6 +143,7 @@ RSpec.describe ProjectQuery do
hierarchy
project_status
status_explanation
+ created_at
cf_23
cf_42
budget_available
@@ -240,7 +241,7 @@ RSpec.describe ProjectQuery do
before do
instance.where("active", "=", OpenProject::Database::DB_VALUE_TRUE)
- instance.where("created_at", ">t-", ["6"])
+ instance.where("latest_activity_at", ">t-", ["6"])
instance.valid_subset!
end
@@ -339,8 +340,8 @@ RSpec.describe ProjectQuery do
end
context "with them being invalid" do
- # No admin, hence no created_at column. CF column does not exist.
- let(:selects) { %i(bogus created_at cf_1) } # rubocop:disable Naming/VariableNumber
+ # No admin, hence no latest_activity_at column. CF column does not exist.
+ let(:selects) { %i(bogus latest_activity_at cf_1) } # rubocop:disable Naming/VariableNumber
it "removes the values" do
expect(instance.selects.map(&:attribute))
@@ -350,11 +351,11 @@ RSpec.describe ProjectQuery do
context "with them being partially invalid" do
let(:current_user) { admin }
- let(:selects) { %i(bogus name created_at cf_1 description) } # rubocop:disable Naming/VariableNumber
+ let(:selects) { %i(bogus name latest_activity_at cf_1 description) } # rubocop:disable Naming/VariableNumber
it "removes only the offending values" do
expect(instance.selects.map(&:attribute))
- .to eq %i(name created_at description)
+ .to eq %i(name latest_activity_at description)
end
end
end
diff --git a/spec/services/project_queries/set_attributes_service_spec.rb b/spec/services/project_queries/set_attributes_service_spec.rb
index 320db7e1444..090329064d2 100644
--- a/spec/services/project_queries/set_attributes_service_spec.rb
+++ b/spec/services/project_queries/set_attributes_service_spec.rb
@@ -175,7 +175,7 @@ RSpec.describe ProjectQueries::SetAttributesService, type: :model do
# rubocop:disable Naming/VariableNumber
it "assigns default selects for non admin",
- with_settings: { enabled_projects_columns: %w[name created_at cf_1] } do
+ with_settings: { enabled_projects_columns: %w[name latest_activity_at cf_1] } do
subject
expect(model_instance.selects.map(&:attribute))
@@ -183,7 +183,7 @@ RSpec.describe ProjectQueries::SetAttributesService, type: :model do
end
it "assigns default selects for admin",
- with_settings: { enabled_projects_columns: %w[name created_at cf_1] } do
+ with_settings: { enabled_projects_columns: %w[name latest_activity_at cf_1] } do
allow(User.current)
.to receive(:admin?)
.and_return(true)
@@ -191,7 +191,7 @@ RSpec.describe ProjectQueries::SetAttributesService, type: :model do
subject
expect(model_instance.selects.map(&:attribute))
- .to eql %i[favorited name created_at cf_1]
+ .to eql %i[favorited name latest_activity_at cf_1]
end
# rubocop:enable Naming/VariableNumber
end