proxy_host.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Objection Docs:
  2. // http://vincit.github.io/objection.js/
  3. const db = require('../db');
  4. const Model = require('objection').Model;
  5. const User = require('./user');
  6. const AccessList = require('./access_list');
  7. const Certificate = require('./certificate');
  8. const now = require('./now_helper');
  9. Model.knex(db);
  10. class ProxyHost extends Model {
  11. $beforeInsert () {
  12. this.created_on = now();
  13. this.modified_on = now();
  14. // Default for domain_names
  15. if (typeof this.domain_names === 'undefined') {
  16. this.domain_names = [];
  17. }
  18. // Default for openidc_allowed_users
  19. if (typeof this.openidc_allowed_users === 'undefined') {
  20. this.openidc_allowed_users = [];
  21. }
  22. // Default for meta
  23. if (typeof this.meta === 'undefined') {
  24. this.meta = {};
  25. }
  26. // Openidc defaults
  27. if (typeof this.openidc_auth_method === 'undefined') {
  28. this.openidc_auth_method = 'client_secret_post';
  29. }
  30. this.domain_names.sort();
  31. this.openidc_allowed_users.sort();
  32. }
  33. $beforeUpdate () {
  34. this.modified_on = now();
  35. // Sort domain_names
  36. if (typeof this.domain_names !== 'undefined') {
  37. this.domain_names.sort();
  38. }
  39. // Sort openidc_allowed_users
  40. if (typeof this.openidc_allowed_users !== 'undefined') {
  41. this.openidc_allowed_users.sort();
  42. }
  43. }
  44. static get name () {
  45. return 'ProxyHost';
  46. }
  47. static get tableName () {
  48. return 'proxy_host';
  49. }
  50. static get jsonAttributes () {
  51. return ['domain_names', 'meta', 'locations', 'openidc_allowed_users'];
  52. }
  53. static get relationMappings () {
  54. return {
  55. owner: {
  56. relation: Model.HasOneRelation,
  57. modelClass: User,
  58. join: {
  59. from: 'proxy_host.owner_user_id',
  60. to: 'user.id'
  61. },
  62. modify: function (qb) {
  63. qb.where('user.is_deleted', 0);
  64. }
  65. },
  66. access_list: {
  67. relation: Model.HasOneRelation,
  68. modelClass: AccessList,
  69. join: {
  70. from: 'proxy_host.access_list_id',
  71. to: 'access_list.id'
  72. },
  73. modify: function (qb) {
  74. qb.where('access_list.is_deleted', 0);
  75. }
  76. },
  77. certificate: {
  78. relation: Model.HasOneRelation,
  79. modelClass: Certificate,
  80. join: {
  81. from: 'proxy_host.certificate_id',
  82. to: 'certificate.id'
  83. },
  84. modify: function (qb) {
  85. qb.where('certificate.is_deleted', 0);
  86. }
  87. }
  88. };
  89. }
  90. }
  91. module.exports = ProxyHost;