浏览代码

Refs #29 Create the link label shortcut

isundil 1 年之前
父节点
当前提交
d313723edc
共有 6 个文件被更改,包括 19 次插入7 次删除
  1. 4 0
      model/access.js
  2. 4 1
      router/api.js
  3. 1 1
      router/index.js
  4. 4 3
      src/security.js
  5. 1 1
      static/public/js/uiAccess.js
  6. 5 1
      static/public/js/uiShare.js

+ 4 - 0
model/access.js

@@ -30,6 +30,7 @@ function AccessModel() {
     this.id = null;
     this.type = ACCESS_TYPE.unknown;
     this.typeData = "";
+    this.typeLabel = "";
     this.accessTo = ACCESS_TO.unknown;
     this.accessToData = "";
     this.accessToDataDeserialized = null;
@@ -51,12 +52,14 @@ AccessModel.prototype.createOrUpdateBase = async function(dbHelper) {
         accessToData STRING NOT NULL,
         grant TINYINT NOT NULL
         )`);
+    try { await dbHelper.runSql("ALTER TABLE 'access' ADD COLUMN typeLabel STRING"); } catch (err) {}
 }
 
 AccessModel.prototype.describe = function() {
     return {
         "id": this.id,
         "type": this.type,
+        "typeLabel": this.typeLabel,
         "typeData": this.typeData,
         "accessTo": this.accessTo,
         "accessToData": this.accessToData,
@@ -69,6 +72,7 @@ AccessModel.prototype.versionColumn = function() { return ""; }
 AccessModel.prototype.fromDb = function(dbObj) {
     this.id = dbObj["id"];
     this.type = dbObj["type"];
+    this.typeLabel = dbObj["typeLabel"];
     this.typeData = dbObj["typeData"];
     this.accessTo = dbObj["accessTo"];
     this.accessToData = dbObj["accessToData"];

+ 4 - 1
router/api.js

@@ -26,6 +26,7 @@ function accessToJson(access) {
     return {
         id: access.id,
         type: typeStr,
+        typeLabel: access.typeLabel,
         typeData: access.typeData,
         accessTo: accessToStr,
         accessToData: access.accessToData,
@@ -53,7 +54,7 @@ module.exports = { register: app => {
             for (let i of JSON.parse(req.post.linkIds)) {
                 const access = await app.databaseHelper.findOne(AccessModel, { type: ACCESS_TYPE.link, typeData: i });
                 if (access) {
-                    Security.addLinkToSession(req, access.id, i);
+                    Security.addLinkToSession(req, access.id, i, access.typeLabel);
                     if (access.accessTo == ACCESS_TO.admin)
                         Security.setAdmin(req, true);
                 }
@@ -79,6 +80,7 @@ module.exports = { register: app => {
         let access = new AccessModel();
         access.type = parseInt(req.body.typeId);
         access.typeData = req.body.typeData;
+        access.typeLabel = req.body.typeLabel;
         access.accessTo = parseInt(req.body.accessToId);
         access.accessToData = req.body.accessToData;
         access.grant = parseInt(req.body.grant);
@@ -105,6 +107,7 @@ module.exports = { register: app => {
         const access = (await app.databaseHelper.fetch(AccessModel, { id: parseInt(req.params.id) }))?.[0];
         if (!access)
             return app.routerUtils.onBadRequest(res);
+        access.typeLabel = req.body.typeLabel;
         access.typeData = req.body.typeData;
         access.accessTo = parseInt(req.body.accessToId);
         access.accessToData = req.body.accessToData;

+ 1 - 1
router/index.js

@@ -16,7 +16,7 @@ module.exports = { register: app => {
             return app.routerUtils.onBadRequest(res);
         const access = await app.databaseHelper.findOne(AccessModel, { type: ACCESS_TYPE.link, typeData: req.body.link });
         if (access) {
-            Security.addLinkToSession(req, access.id, access.typeData);
+            Security.addLinkToSession(req, access.id, access.typeData, access.linkLabel);
             if (access.accessTo == ACCESS_TO.admin)
                 Security.setAdmin(req, true);
         }

+ 4 - 3
src/security.js

@@ -16,9 +16,10 @@ function Access() {
 }
 Access.prototype.id = function() { return ""; }
 
-function LinkAccess(linkId) {
+function LinkAccess(linkId, linkLabel) {
     Access.call(this);
     this.linkId = linkId;
+    this.linkLabel = linkLabel;
 }
 LinkAccess.prototype = Object.create(Access.prototype);
 LinkAccess.prototype.id = function() { return "LINK_"+this.linkId; }
@@ -51,11 +52,11 @@ module.exports.setAdmin = (req, val) => {
     session.accessList.isAdmin = val;
     return session.accessList;
 };
-module.exports.addLinkToSession = (req, dbId, linkId) => {
+module.exports.addLinkToSession = (req, dbId, linkId, linkLabel) => {
     let session = module.exports.getSessionObj(req.cookies);
     if (!session)
         return;
-    let accessItem = new LinkAccess(linkId);
+    let accessItem = new LinkAccess(linkId, linkLabel);
     accessItem.dbId = dbId;
     session.accessList[accessItem.id()] = accessItem;
     return session.accessList;

+ 1 - 1
static/public/js/uiAccess.js

@@ -83,7 +83,7 @@ window.ReloadAccessList = function(accessList) {
         rootNode.appendChild(li);
     }
     for (let i in accessList) {
-        const accessTextValue = accessList[i].linkId;
+        const accessTextValue = accessList[i].linkLabel || accessList[i].linkId;
 
         let li = document.createElement("li");
         li.classList.add("accessItem");

+ 5 - 1
static/public/js/uiShare.js

@@ -14,6 +14,7 @@ class ShareData {
     dbId = 0;
     typeId = "";
     typeData = "";
+    typeLabel = "";
     accessToId = 0;
     accessToData = "";
     grant = 0;
@@ -23,6 +24,7 @@ class ShareData {
             this.dbId = data.id;
             this.typeId = [ "unknown", "ldapAccount", "email", "link", "every one" ].indexOf(data.type);
             this.typeData = data.typeData;
+            this.typeLabel = data.typeLabel;
             this.accessToId = [ "unknown", "item", "tag", "meta", "everything", "admin"].indexOf(data.accessTo);
             this.accessToData = data.accessToData;
             this.grant = [ "none", "read", "write", "read without meta"].indexOf(data.grant);
@@ -34,6 +36,7 @@ class ShareData {
             id: this.dbId,
             type: [ "unknown", "ldapAccount", "email", "link", "every one" ][this.typeId],
             typeData: this.typeData,
+            typeLabel: this.typeLabel,
             accessTo: [ "unknown", "item", "tag", "meta", "everything", "admin"][this.accessToId],
             accessToData: this.accessToData,
             grant: [ "none", "read", "write", "read without meta"][this.grant]
@@ -141,7 +144,7 @@ async function buildShareItem(data) {
     headerButton.type = "button";
     headerButton.dataset.bsToggle = "collapse";
     headerButton.dataset.bsTarget = `#${htmlId}`;
-    headerButton.textContent = data.typeData;
+    headerButton.textContent = data.typeLabel || data.typeData;
     headerButton.ariaExpanded = false;
     headerButton.ariaControls = htmlId;
     let accordionBodyContainer = document.createElement("div");
@@ -342,6 +345,7 @@ async function createShareData(typeId, typeData) {
     let share = new ShareData();
     share.typeId = typeId;
     share.typeData = typeData;
+    share.typeLabel = "";
     share.accessToId = 0;
     share.grant = 0;
     share = await createData(share);