Fixes #4097 - Latest upgrade to 5.1 is not possible.
This commit is contained in:
parent
757a9b274e
commit
c38c4e6226
2 changed files with 79 additions and 1 deletions
|
@ -5,6 +5,52 @@ class Issue4089FixDraftAttribute < ActiveRecord::Migration[5.0]
|
|||
# return if it's a new setup
|
||||
return if !Setting.exists?(name: 'system_init_done')
|
||||
|
||||
ObjectManager::Attribute.find_by(name: 'shared_drafts', object_lookup_id: ObjectLookup.by_name('Group')).update(editable: false)
|
||||
field = ObjectManager::Attribute.find_by(name: 'shared_drafts', object_lookup_id: ObjectLookup.by_name('Group'))
|
||||
if !field
|
||||
add_field
|
||||
return
|
||||
end
|
||||
|
||||
field.update(editable: false)
|
||||
end
|
||||
|
||||
def add_field
|
||||
UserInfo.current_user_id = 1
|
||||
ObjectManager::Attribute.add(
|
||||
force: true,
|
||||
object: 'Group',
|
||||
name: 'shared_drafts',
|
||||
display: 'Shared Drafts',
|
||||
data_type: 'active',
|
||||
data_option: {
|
||||
null: false,
|
||||
default: true,
|
||||
permission: ['admin.group'],
|
||||
},
|
||||
editable: false,
|
||||
active: true,
|
||||
screens: {
|
||||
create: {
|
||||
'-all-' => {
|
||||
null: true,
|
||||
},
|
||||
},
|
||||
edit: {
|
||||
'-all-': {
|
||||
null: false,
|
||||
},
|
||||
},
|
||||
view: {
|
||||
'-all-' => {
|
||||
shown: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
to_create: false,
|
||||
to_migrate: false,
|
||||
to_delete: false,
|
||||
position: 1400,
|
||||
)
|
||||
ObjectManager::Attribute.migration_execute
|
||||
end
|
||||
end
|
||||
|
|
32
spec/db/migrate/issue_4089_fix_draft_attribute_spec.rb
Normal file
32
spec/db/migrate/issue_4089_fix_draft_attribute_spec.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Issue4089FixDraftAttribute, type: :db_migration do
|
||||
def field
|
||||
ObjectManager::Attribute.find_by(name: 'shared_drafts', object_lookup_id: ObjectLookup.by_name('Group'))
|
||||
end
|
||||
|
||||
context 'when field does not exist', db_strategy: :reset do
|
||||
before do
|
||||
field.destroy
|
||||
ObjectManager::Attribute.migration_execute
|
||||
migrate
|
||||
end
|
||||
|
||||
it 'does create the field and set it not editable' do
|
||||
expect(field.reload.editable).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when field does exist' do
|
||||
before do
|
||||
field.update(editable: true)
|
||||
migrate
|
||||
end
|
||||
|
||||
it 'does set the field to not editable' do
|
||||
expect(field.reload.editable).to be(false)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue