Merge "User isCurrentProject in metadata action"

This commit is contained in:
Jenkins 2016-02-16 15:29:59 +00:00 committed by Gerrit Code Review
commit 8157b38f97
2 changed files with 7 additions and 22 deletions

View File

@ -44,7 +44,7 @@
userSessionService,
$qExtensions
) {
var userSessionPromise, scope;
var scope;
var service = {
initScope: initScope,
@ -58,7 +58,6 @@
function initScope(newScope) {
scope = newScope;
userSessionPromise = userSessionService.get();
}
function perform(image) {
@ -72,27 +71,12 @@
}
function allowed(image) {
return $q.all([ownedByUser(image), isActive(image)]);
return $q.all([userSessionService.isCurrentProject(image.owner), isActive(image)]);
}
function isActive(image) {
return $qExtensions.booleanAsPromise(image.status === 'active');
}
function ownedByUser(image) {
var deferred = $q.defer();
userSessionPromise.then(onUserSessionGet);
return deferred.promise;
function onUserSessionGet(userSession) {
if (userSession.project_id === image.owner) {
deferred.resolve();
} else {
deferred.reject();
}
}
}
} // end of updateMetadataService
})(); // end of IIFE

View File

@ -20,8 +20,8 @@
var deferred, service, $scope;
var userSession = {
get: function() {
deferred.resolve({project_id: 'project'});
isCurrentProject: function() {
deferred.resolve();
return deferred.promise;
}
};
@ -79,8 +79,9 @@
$scope.$apply();
});
it('should not allow Update Metadata if image is not owned by user', function() {
var image = {owner: 'another_project', status: 'active'};
it('should not allow Update Metadata if service call is rejected', function() {
var image = {owner: 'doesnt_matter', status: 'active'};
deferred.reject();
service.initScope($scope);
permissionShouldFail(service.allowed(image));
$scope.$apply();