I have an object that resembles the following
$scope.object = {
Title: 'A title',
Status: 'Open',
Responsible: 'John Doe',
Author: 'Jane Doe',
Description: 'lorem ipsum dolor sit'
}
My aim now is to verify if the current user has authorization to modify this item. In order for the user to be able to edit, certain conditions must be met:
- The object must exist (not null or undefined)
- The Responsible field must match
$scope.currentUser
- The Status field must be 'Open'
If all of these conditions are true, our function should return true. I am approaching it in the following manner
$scope.isTrue = function(){
if($scope.object && $scope.object.Status == 'Open' && $scope.object.Responsible == $scope.currentUser){
return true;
} else {
return false;
}
}
It's quite simple, but is there a more efficient way to perform these checks?