object_spec.rb 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe ObjectManager::Object do
  4. describe 'attribute permissions', db_strategy: :reset do
  5. let(:user) do
  6. create(:user, roles: [role_attribute_permissions])
  7. end
  8. let(:attribute) { described_class.new('Ticket').attributes(user).detect { |attribute| attribute[:name] == attribute_name } }
  9. let(:role_attribute_permissions) do
  10. create(:role).tap do |role|
  11. role.permission_grant('admin.organization')
  12. role.permission_grant('ticket.agent')
  13. end
  14. end
  15. let(:attribute_name) { 'example_attribute' }
  16. before do
  17. create(:object_manager_attribute_text, name: attribute_name, screens: screens)
  18. ObjectManager::Attribute.migration_execute
  19. end
  20. context 'when true and false values for show exist' do
  21. let(:screens) do
  22. {
  23. create: {
  24. 'admin.organization': {
  25. shown: true
  26. },
  27. 'ticket.agent': {
  28. shown: false
  29. }
  30. }
  31. }
  32. end
  33. it 'uses true' do
  34. expect(attribute[:screen]['create']['shown']).to be true
  35. end
  36. end
  37. context 'when -all- is present' do
  38. let(:screens) do
  39. {
  40. create: {
  41. '-all-': {
  42. shown: true
  43. },
  44. 'admin.organization': {
  45. shown: false
  46. },
  47. 'ticket.agent': {
  48. shown: false
  49. }
  50. }
  51. }
  52. end
  53. it 'takes its values into account' do
  54. expect(attribute[:screen]['create']['shown']).to be true
  55. end
  56. end
  57. context 'when non boolean values are present' do
  58. let(:screens) do
  59. {
  60. create: {
  61. '-all-': {
  62. shown: true,
  63. item_class: 'column'
  64. },
  65. 'admin.organization': {
  66. shown: false
  67. },
  68. 'ticket.agent': {
  69. shown: false
  70. }
  71. }
  72. }
  73. end
  74. it 'takes these values into account' do
  75. expect(attribute[:screen]['create']['item_class']).to eq('column')
  76. end
  77. end
  78. context 'when agent is also customer' do
  79. let(:user) { create(:agent_and_customer) }
  80. let(:screens) do
  81. {
  82. create: {
  83. 'ticket.customer': {
  84. filter: [2, 4]
  85. },
  86. 'ticket.agent': {
  87. filter: [3, 5]
  88. }
  89. }
  90. }
  91. end
  92. it 'prefers agent over customer permissions' do
  93. expect(attribute[:screen]['create']['filter']).to eq([3, 5])
  94. end
  95. end
  96. end
  97. end