Implement authentication and access control

This commit is contained in:
Zaid Abdulla committed 2018-12-26 00:22:07 -08:00
1 parent e1bdcda191
commit 327cb78f1a
27 files changed
+600 -167

No files matched your search

+3 -2
View File
@@ -50,11 +50,12 @@ const component = {
title: "Delete device",
onclick: () => {
if (!confirm("Deleting this device. Are you sure?")) return;
const deviceId = device["DeviceID.ID"].value[0];
store
.deleteResource("devices", device["DeviceID.ID"].value[0])
.deleteResource("devices", deviceId)
.then(() => {
notifications.push("success", "Device deleted");
notifications.push("success", `${deviceId}: Device deleted`);
m.route.set("/devices");
})
.catch(err => {
+27 -17
View File
@@ -31,23 +31,33 @@ const component = {
};
taskQueue
.commit([task], (deviceId, connectionRequestStatus, tasks2) => {
for (let t of tasks2)
if (t.status === "stale") taskQueue.deleteTask(t);
if (connectionRequestStatus !== "OK")
notifications.push(
"error",
`${deviceId}: ${connectionRequestStatus}`
);
else if (tasks2[0].status === "stale")
notifications.push(
"error",
`${deviceId}: No contact from device`
);
else if (tasks2[0].status === "fault")
notifications.push("error", `${deviceId}: Refresh faulted`);
else notifications.push("success", `${deviceId}: Summoned`);
})
.commit(
[task],
(deviceId, err, connectionRequestStatus, tasks2) => {
if (err)
return notifications.push(
"error",
`${deviceId}: ${err.message}`
);
for (let t of tasks2)
if (t.status === "stale") taskQueue.deleteTask(t);
if (connectionRequestStatus !== "OK")
notifications.push(
"error",
`${deviceId}: ${connectionRequestStatus}`
);
else if (tasks2[0].status === "stale")
notifications.push(
"error",
`${deviceId}: No contact from device`
);
else if (tasks2[0].status === "fault")
notifications.push("error", `${deviceId}: Refresh faulted`);
else notifications.push("success", `${deviceId}: Summoned`);
}
)
.then(() => {
e.target.disabled = false;
store.fulfill(0, Date.now());
+14 -6
View File
@@ -29,14 +29,18 @@ const component = {
{
onclick: e => {
e.target.disabled = true;
const deviceId = device["DeviceID.ID"].value[0];
store
.updateTags(device["DeviceID.ID"].value[0], { [tag]: false })
.updateTags(deviceId, { [tag]: false })
.then(() => {
e.target.disabled = false;
notifications.push("success", `Tag '${tag}' unassigned`);
notifications.push("success", `${deviceId}: Tags updated`);
store.fulfill(0, Date.now());
})
.catch(err => notifications.push("error", err.message));
.catch(err => {
e.target.disabled = false;
notifications.push("error", `${deviceId}: ${err.message}`);
});
}
},
"✕"
@@ -50,6 +54,7 @@ const component = {
{
onclick: e => {
e.target.disabled = true;
const deviceId = device["DeviceID.ID"].value[0];
const tag = prompt(`Enter tag to assign to device:`);
if (!tag) {
e.target.disabled = false;
@@ -57,13 +62,16 @@ const component = {
}
store
.updateTags(device["DeviceID.ID"].value[0], { [tag]: true })
.updateTags(deviceId, { [tag]: true })
.then(() => {
e.target.disabled = false;
notifications.push("success", `Tag '${tag}' assigned`);
notifications.push("success", `${deviceId}: Tags updated`);
store.fulfill(0, Date.now());
})
.catch(err => notifications.push("error", err.message));
.catch(err => {
e.target.disabled = false;
notifications.push("error", `${deviceId}: ${err.message}`);
});
}
},
"🞢"