Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
add authorization check on set-title
Browse files Browse the repository at this point in the history
  • Loading branch information
Niharika Khanna committed Aug 16, 2017
1 parent d17285e commit d411e4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ app.post("/api/set-title/:id/:domain", csrfProtection, function(req, res) {
simpleResponse(res, "Not logged in", 401);
return;
}
Shot.get(req.backend, shotId).then((shot) => {
Shot.get(req.backend, shotId, req.deviceId, req.accountId).then((shot) => {
if (!shot) {
simpleResponse(res, "No such shot", 404);
return;
Expand Down
11 changes: 7 additions & 4 deletions server/src/servershot.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ class ServerClip extends AbstractShot.prototype.Clip {

Shot.prototype.Clip = ServerClip;

Shot.get = function(backend, id, deviceId) {
return Shot.getRawValue(id, deviceId).then((rawValue) => {
Shot.get = function(backend, id, deviceId, accountId) {
return Shot.getRawValue(id, deviceId, accountId).then((rawValue) => {
if (!rawValue) {
return null;
}
Expand Down Expand Up @@ -409,14 +409,17 @@ Shot.getFullShot = function(backend, id) {
});
};

Shot.getRawValue = function(id, deviceId) {
Shot.getRawValue = function(id, deviceId, accountId) {
if (!id) {
throw new Error("Empty id: " + id);
}
let query = `SELECT value, deviceid, url, title, expire_time, deleted, block_type, devices.accountid
FROM data, devices WHERE data.deviceid = devices.id AND data.id = $1`;
let params = [id];
if (deviceId) {
if (accountId) {
query += ` AND devices.accountid = $2`
params.push(accountId);
} else if (deviceId) {
query += ` AND deviceid = $2`;
params.push(deviceId);
}
Expand Down

0 comments on commit d411e4e

Please sign in to comment.