20230705132353_pgp_integration.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class PGPIntegration < ActiveRecord::Migration[6.1]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. create_pgp_keys_table
  7. create_pgp_keys_table_indices
  8. create_pgp_keys_table_foreign_keys
  9. create_pgp_integration_settings
  10. rename_postmaster_pre_filter
  11. end
  12. private
  13. def create_pgp_keys_table
  14. create_table :pgp_keys do |t|
  15. t.string :fingerprint, limit: 40, null: false
  16. t.text :key, limit: 500.kilobytes + 1, null: false
  17. t.datetime :expires_at, null: true, limit: 3
  18. t.string :uids, limit: 3000, null: false
  19. t.boolean :secret, null: false, default: false
  20. t.string :passphrase, limit: 500, null: true
  21. t.string :domain_alias, limit: 255, null: true, default: ''
  22. t.integer :updated_by_id, null: false
  23. t.integer :created_by_id, null: false
  24. t.timestamps limit: 3, null: false
  25. end
  26. end
  27. def create_pgp_keys_table_indices
  28. add_index :pgp_keys, [:fingerprint], unique: true
  29. add_index :pgp_keys, [:uids], length: 255
  30. add_index :pgp_keys, [:domain_alias]
  31. end
  32. def create_pgp_keys_table_foreign_keys
  33. add_foreign_key :pgp_keys, :users, column: :created_by_id
  34. add_foreign_key :pgp_keys, :users, column: :updated_by_id
  35. end
  36. def create_pgp_integration_settings
  37. Setting.create_if_not_exists(
  38. title: 'PGP integration',
  39. name: 'pgp_integration',
  40. area: 'Integration::Switch',
  41. description: 'Defines if PGP encryption is enabled or not.',
  42. options: {
  43. form: [
  44. {
  45. display: '',
  46. null: true,
  47. name: 'pgp_integration',
  48. tag: 'boolean',
  49. options: {
  50. true => 'yes',
  51. false => 'no',
  52. },
  53. },
  54. ],
  55. },
  56. state: false,
  57. preferences: {
  58. prio: 1,
  59. authentication: true,
  60. permission: ['admin.integration'],
  61. },
  62. frontend: true
  63. )
  64. Setting.create_if_not_exists(
  65. title: 'PGP config',
  66. name: 'pgp_config',
  67. area: 'Integration::PGP',
  68. description: 'Defines the PGP config.',
  69. options: {},
  70. state: {},
  71. preferences: {
  72. prio: 2,
  73. permission: ['admin.integration'],
  74. },
  75. frontend: true,
  76. )
  77. Setting.create_if_not_exists(
  78. title: 'PGP Recipient Alias Configuration',
  79. name: 'pgp_recipient_alias_configuration',
  80. area: 'Core::Integration::PGP',
  81. description: 'Defines if the PGP recipient alias configuration is enabled or not.',
  82. options: {},
  83. state: false,
  84. preferences: { online_service_disable: true },
  85. frontend: true
  86. )
  87. end
  88. def rename_postmaster_pre_filter
  89. Setting.find_by(name: '0016_postmaster_filter_smime').update!(name: '0016_postmaster_filter_secure_mailing')
  90. end
  91. end