Fixed project default dashboard, if project system dashboard is defined
This commit is contained in:
parent
ff9816717d
commit
9685886a43
@ -9,6 +9,7 @@ Changelog
|
||||
- Ruby 2.6 is required
|
||||
- Use redmine_plugin_kit gem as loader
|
||||
- Move settings rake tasks and true?/false? to redmine_plugin_kit
|
||||
- fixed default dashboard order for system default for specific project
|
||||
|
||||
3.0.3
|
||||
+++++
|
||||
|
@ -84,7 +84,11 @@ class Dashboard < ActiveRecord::Base
|
||||
|
||||
if dashboard.blank?
|
||||
scope = scope.where(system_default: true).or(scope.where(author_id: user.id))
|
||||
dashboard = scope.order(system_default: :desc, project_id: :desc, id: :asc).first
|
||||
scope = scope.order(system_default: :desc)
|
||||
.order(Arel.sql("CASE WHEN #{Dashboard.table_name}.project_id IS NOT NULL THEN 0 ELSE 1 END"))
|
||||
.order(id: :asc)
|
||||
|
||||
dashboard = scope.first
|
||||
|
||||
if recently_id.present?
|
||||
Rails.logger.debug 'default cleanup required'
|
||||
|
20
test/fixtures/dashboards.yml
vendored
20
test/fixtures/dashboards.yml
vendored
@ -60,6 +60,26 @@ system_default_project:
|
||||
:title: Project overview right
|
||||
:text: Some example text in right text block
|
||||
|
||||
system_default_defined_project:
|
||||
name: Project default dashboard only for Project 2
|
||||
dashboard_type: <%= DashboardContentProject::TYPE_NAME %>
|
||||
system_default: true
|
||||
enable_sidebar: true
|
||||
project_id: 2
|
||||
author_id: 1
|
||||
visibility: 2
|
||||
options: |
|
||||
---
|
||||
:layout:
|
||||
left:
|
||||
- projectinformation
|
||||
right:
|
||||
- text
|
||||
:layout_settings:
|
||||
text:
|
||||
:title: Project overview left
|
||||
:text: Some example text in left text block
|
||||
|
||||
private_welcome:
|
||||
name: Only for user 1
|
||||
dashboard_type: <%= DashboardContentWelcome::TYPE_NAME %>
|
||||
|
@ -75,7 +75,8 @@ class DashboardTest < Additionals::TestCase
|
||||
end
|
||||
|
||||
def test_system_default_project_should_exist
|
||||
assert_equal 1, Dashboard.project_only.where(system_default: true).count
|
||||
assert_equal 1, Dashboard.project_only.where(system_default: true,
|
||||
project_id: nil).count
|
||||
end
|
||||
|
||||
def test_change_system_default_welcome_without_set_system_default
|
||||
@ -122,7 +123,8 @@ class DashboardTest < Additionals::TestCase
|
||||
author: User.current,
|
||||
visibility: 2)
|
||||
|
||||
assert_equal 1, Dashboard.project_only.where(system_default: true).count
|
||||
assert_equal 1, Dashboard.project_only.where(system_default: true,
|
||||
project_id: nil).count
|
||||
end
|
||||
|
||||
def test_system_default_welcome_requires_public_visibility
|
||||
@ -191,7 +193,7 @@ class DashboardTest < Additionals::TestCase
|
||||
end
|
||||
|
||||
def test_dashboard_project_scope
|
||||
assert_equal 3, Dashboard.visible.project_only.count
|
||||
assert_equal 4, Dashboard.visible.project_only.count
|
||||
end
|
||||
|
||||
def test_destroy_dashboard_without_roles
|
||||
@ -289,4 +291,20 @@ class DashboardTest < Additionals::TestCase
|
||||
dashboard.reload
|
||||
assert_equal 'new name', dashboard.name
|
||||
end
|
||||
|
||||
def test_default_dashboard_in_project
|
||||
project = projects :projects_001
|
||||
dashboard = Dashboard.default DashboardContentProject::TYPE_NAME, project
|
||||
|
||||
assert dashboard.system_default
|
||||
assert_nil dashboard.project_id
|
||||
end
|
||||
|
||||
def test_default_dashboard_in_project_with_existing_project_system_dashboard
|
||||
project = projects :projects_002
|
||||
dashboard = Dashboard.default DashboardContentProject::TYPE_NAME, project
|
||||
|
||||
assert dashboard.system_default
|
||||
assert_equal project.id, dashboard.project_id
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user