access.js 1.6 KB

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