Commit e149a3e3 authored by Sean Hammond's avatar Sean Hammond

Don't use vm.annotation.permissions

The templates read vm.isPrivate() and vm.isShared() and call vm.setPrivacy()
so vm.annotation.permissions just isn't needed.

The controller modifies domainModel.permissions when the permissions need to
change.

vm.annotation.permissions is still there, we just don't use it anymore, in the
future we should not copy it into vm.annotation at all.
parent 205efe04
......@@ -103,7 +103,9 @@ function isNew(annotation) {
*
*/
function updateDomainModel(domainModel, vm) {
var permissions = domainModel.permissions;
angular.extend(domainModel, vm);
domainModel.permissions = permissions;
domainModel.tags = vm.tags.map(function(tag) {
return tag.text;
});
......@@ -297,9 +299,9 @@ function AnnotationController(
if (isNew(domainModel)) {
var newGroup = groups.focused().id;
var isShared = permissions.isShared(
vm.annotation.permissions, domainModel.group);
domainModel.permissions, domainModel.group);
if (isShared) {
vm.annotation.permissions = permissions.shared(newGroup);
domainModel.permissions = permissions.shared(newGroup);
}
domainModel.group = newGroup;
}
......@@ -307,6 +309,7 @@ function AnnotationController(
if (drafts.get(domainModel)) {
var draftDomainModel = {};
updateDomainModel(draftDomainModel, vm.annotation);
draftDomainModel.permissions = domainModel.permissions;
updateDraft(draftDomainModel);
}
}
......@@ -536,7 +539,7 @@ function AnnotationController(
* @returns {boolean} True if the annotation is private to the current user.
*/
vm.isPrivate = function() {
return permissions.isPrivate(vm.annotation.permissions, domainModel.user);
return permissions.isPrivate(domainModel.permissions, domainModel.user);
};
/**
......@@ -546,8 +549,7 @@ function AnnotationController(
* current group or with everyone).
*/
vm.isShared = function() {
return permissions.isShared(
vm.annotation.permissions, domainModel.group);
return permissions.isShared(domainModel.permissions, domainModel.group);
};
// Save on Meta + Enter or Ctrl + Enter.
......@@ -677,9 +679,9 @@ function AnnotationController(
permissions.setDefault(privacy);
}
if (privacy === 'private') {
vm.annotation.permissions = permissions.private();
domainModel.permissions = permissions.private();
} else if (privacy === 'shared') {
vm.annotation.permissions = permissions.shared(domainModel.group);
domainModel.permissions = permissions.shared(domainModel.group);
}
};
......
......@@ -1478,12 +1478,14 @@ describe('annotation.js', function() {
parts.controller.edit();
parts.controller.annotation.text = 'unsaved-text';
parts.controller.annotation.tags = [];
parts.controller.annotation.permissions = 'new permissions';
parts.annotation.permissions = 'new permissions';
fakeDrafts.get = sinon.stub().returns({
text: 'old-draft'
});
fakeDrafts.update = sinon.stub();
$rootScope.$broadcast(events.GROUP_FOCUSED);
assert.calledWith(fakeDrafts.update, parts.annotation, {
text: 'unsaved-text',
tags: [],
......@@ -1534,7 +1536,7 @@ describe('annotation.js', function() {
annotation.permissions = {read: [annotation.group]};
// This is a shared annotation.
fakePermissions.isShared.returns(true);
var controller = createDirective(annotation).controller;
createDirective(annotation);
// Make permissions.shared() behave like we expect it to.
fakePermissions.shared = function(groupId) {
return {
......@@ -1546,11 +1548,7 @@ describe('annotation.js', function() {
fakeGroups.focused = sinon.stub().returns({id: 'new-group'});
$rootScope.$broadcast(events.GROUP_FOCUSED);
assert.deepEqual(
controller.annotation.permissions.read,
['new-group'],
'It should update the read permissions in the view model when ' +
'the focused group changes');
assert.deepEqual(annotation.permissions.read, ['new-group']);
}
);
......@@ -1570,16 +1568,12 @@ describe('annotation.js', function() {
// AnnotationController won't try to update the draft for the annotation.
fakeDrafts.get.returns(true);
// Make permissions.shared() behave like we expect it to.
fakePermissions.shared = function(groupId) {
return {
read: [groupId]
};
};
fakePermissions.shared = function(groupId) {return {read: [groupId]};};
// Change the focused group.
fakeGroups.focused = sinon.stub().returns({
id: 'new-group'
});
fakeGroups.focused = sinon.stub().returns({id: 'new-group'});
$rootScope.$broadcast(events.GROUP_FOCUSED);
assert.deepEqual(
fakeDrafts.update.lastCall.args[1].permissions.read,
['new-group'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment