access.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const DatabaseModel = require("./DatabaseModel.js").DatabaseModel;
  2. const ACCESS_TYPE = {
  3. unknown: 0,
  4. ldapAccount: 1,
  5. email: 2,
  6. link: 3,
  7. everyOne: 4
  8. };
  9. const ACCESS_TO = {
  10. unknown: 0,
  11. item: 1,
  12. tag: 2,
  13. meta: 3,
  14. everything: 4
  15. };
  16. const ACCESS_GRANT = {
  17. none: 0,
  18. read: 1,
  19. write: 2
  20. };
  21. function AccessModel() {
  22. DatabaseModel.call(this);
  23. this.id = null;
  24. this.type = ACCESS_TYPE.unknown;
  25. this.typeData = "";
  26. this.accessTo = ACCESS_TO.unknown;
  27. this.accessToData = "";
  28. this.accessToDataDeserialized = null;
  29. this.grant = ACCESS_GRANT.none;
  30. }
  31. AccessModel.prototype = Object.create(DatabaseModel.prototype);
  32. AccessModel.prototype.getTableName = function() {
  33. return "access";
  34. }
  35. AccessModel.prototype.createOrUpdateBase = async function(dbHelper) {
  36. await dbHelper.runSql(`CREATE TABLE IF NOT EXISTS 'access' (
  37. id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  38. type TINYINT NOT NULL,
  39. typeData STRING NOT NULL,
  40. accessTo TINYINT NOT NULL,
  41. accessToData STRING NOT NULL,
  42. grant TINYINT NOT NULL
  43. )`);
  44. }
  45. AccessModel.prototype.describe = function() {
  46. return {
  47. "id": this.id,
  48. "type": this.type,
  49. "typeData": this.typeData,
  50. "accessTo": this.accessTo,
  51. "accessToData": this.accessToData,
  52. "grant": this.grant
  53. };
  54. }
  55. AccessModel.prototype.versionColumn = function() { return ""; }
  56. AccessModel.prototype.fromDb = function(dbObj) {
  57. this.id = dbObj["id"];
  58. this.type = dbObj["type"];
  59. this.typeData = dbObj["typeData"];
  60. this.accessTo = dbObj["accessTo"];
  61. this.accessToData = dbObj["accessToData"];
  62. try {
  63. if (this.accessTo === ACCESS_TO.meta)
  64. this.accessToDataDeserialized = JSON.parse(this.accessToData);
  65. }
  66. catch (err) {}
  67. this.grant = dbObj["grant"];
  68. }
  69. module.exports.AccessModel = AccessModel;
  70. module.exports.ACCESS_TYPE = ACCESS_TYPE;
  71. module.exports.ACCESS_TO = ACCESS_TO;
  72. module.exports.ACCESS_GRANT = ACCESS_GRANT;