Upgrade permission check function

fixes videos appearing in Videos Table but cannot be played.
video-slicer-reencoder
Moe 2022-09-28 13:39:25 -07:00
parent 01d1051e64
commit 48d7d6a99b
3 changed files with 11 additions and 11 deletions

View File

@ -150,7 +150,7 @@ module.exports = function(s,config){
}
if(config.debugLog === true){
// CANNOT USE `dbQuery.toString()` because it breaks the query
console.log(options)
console.log(JSON.stringify(options,null,3))
}
if(callback || options.update || options.insert || options.action === 'delete'){
dbQuery.asCallback(function(err,r) {
@ -331,10 +331,7 @@ module.exports = function(s,config){
var endTimeOperator = options.endTimeOperator
var startTime = options.startTime
var limitString = `${options.limit}`
const {
monitorPermissions,
monitorRestrictions,
} = s.getMonitorsPermitted(user.details,monitorId)
const monitorRestrictions = options.monitorRestrictions || s.getMonitorsPermitted(user.details,monitorId).monitorRestrictions
getDatabaseRows({
monitorRestrictions: monitorRestrictions,
table: theTableSelected,

View File

@ -1866,9 +1866,12 @@ module.exports = function(s,config,lang){
});
return response
}
s.getMonitorsPermitted = (userDetails,monitorId) => {
s.getMonitorsPermitted = (userDetails,monitorId,permissionTarget) => {
const monitorRestrictions = []
const monitors = {}
permissionTarget = permissionTarget || 'monitors'
const permissionSet = s.parseJSON(userDetails[permissionTarget]) || []
// const viewOnlyCheck = permissionTarget === 'monitors'
function setMonitorPermissions(mid){
// monitors : Can View Monitor
// monitor_edit : Can Edit Monitor (Delete as well)
@ -1894,12 +1897,11 @@ module.exports = function(s,config,lang){
if(
!monitorId &&
userDetails.sub &&
userDetails.monitors &&
permissionSet &&
userDetails.allmonitors !== '1'
){
try{
userDetails.monitors = s.parseJSON(userDetails.monitors)
userDetails.monitors.forEach(function(v,n){
permissionSet.forEach(function(v,n){
setMonitorPermissions(v)
addToQuery(v,n)
})
@ -1910,7 +1912,7 @@ module.exports = function(s,config,lang){
monitorId && (
!userDetails.sub ||
userDetails.allmonitors !== '0' ||
userDetails.monitors.indexOf(monitorId) >- 1
permissionSet.indexOf(monitorId) >- 1
)
){
setMonitorPermissions(monitorId)

View File

@ -974,7 +974,7 @@ module.exports = function(s,config,lang,app,io){
const {
monitorPermissions,
monitorRestrictions,
} = s.getMonitorsPermitted(user.details,monitorId)
} = s.getMonitorsPermitted(user.details,monitorId,'video_view')
const {
isRestricted,
isRestrictedApiKey,
@ -1014,6 +1014,7 @@ module.exports = function(s,config,lang,app,io){
endIsStartTo: !!req.query.endIsStartTo,
parseRowDetails: false,
rowName: 'videos',
monitorRestrictions: monitorRestrictions,
preliminaryValidationFailed: false
},(response) => {
if(response && response.videos){