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) { ...@@ -103,7 +103,9 @@ function isNew(annotation) {
* *
*/ */
function updateDomainModel(domainModel, vm) { function updateDomainModel(domainModel, vm) {
var permissions = domainModel.permissions;
angular.extend(domainModel, vm); angular.extend(domainModel, vm);
domainModel.permissions = permissions;
domainModel.tags = vm.tags.map(function(tag) { domainModel.tags = vm.tags.map(function(tag) {
return tag.text; return tag.text;
}); });
...@@ -297,9 +299,9 @@ function AnnotationController( ...@@ -297,9 +299,9 @@ function AnnotationController(
if (isNew(domainModel)) { if (isNew(domainModel)) {
var newGroup = groups.focused().id; var newGroup = groups.focused().id;
var isShared = permissions.isShared( var isShared = permissions.isShared(
vm.annotation.permissions, domainModel.group); domainModel.permissions, domainModel.group);
if (isShared) { if (isShared) {
vm.annotation.permissions = permissions.shared(newGroup); domainModel.permissions = permissions.shared(newGroup);
} }
domainModel.group = newGroup; domainModel.group = newGroup;
} }
...@@ -307,6 +309,7 @@ function AnnotationController( ...@@ -307,6 +309,7 @@ function AnnotationController(
if (drafts.get(domainModel)) { if (drafts.get(domainModel)) {
var draftDomainModel = {}; var draftDomainModel = {};
updateDomainModel(draftDomainModel, vm.annotation); updateDomainModel(draftDomainModel, vm.annotation);
draftDomainModel.permissions = domainModel.permissions;
updateDraft(draftDomainModel); updateDraft(draftDomainModel);
} }
} }
...@@ -536,7 +539,7 @@ function AnnotationController( ...@@ -536,7 +539,7 @@ function AnnotationController(
* @returns {boolean} True if the annotation is private to the current user. * @returns {boolean} True if the annotation is private to the current user.
*/ */
vm.isPrivate = function() { vm.isPrivate = function() {
return permissions.isPrivate(vm.annotation.permissions, domainModel.user); return permissions.isPrivate(domainModel.permissions, domainModel.user);
}; };
/** /**
...@@ -546,8 +549,7 @@ function AnnotationController( ...@@ -546,8 +549,7 @@ function AnnotationController(
* current group or with everyone). * current group or with everyone).
*/ */
vm.isShared = function() { vm.isShared = function() {
return permissions.isShared( return permissions.isShared(domainModel.permissions, domainModel.group);
vm.annotation.permissions, domainModel.group);
}; };
// Save on Meta + Enter or Ctrl + Enter. // Save on Meta + Enter or Ctrl + Enter.
...@@ -677,9 +679,9 @@ function AnnotationController( ...@@ -677,9 +679,9 @@ function AnnotationController(
permissions.setDefault(privacy); permissions.setDefault(privacy);
} }
if (privacy === 'private') { if (privacy === 'private') {
vm.annotation.permissions = permissions.private(); domainModel.permissions = permissions.private();
} else if (privacy === 'shared') { } 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() { ...@@ -1478,12 +1478,14 @@ describe('annotation.js', function() {
parts.controller.edit(); parts.controller.edit();
parts.controller.annotation.text = 'unsaved-text'; parts.controller.annotation.text = 'unsaved-text';
parts.controller.annotation.tags = []; parts.controller.annotation.tags = [];
parts.controller.annotation.permissions = 'new permissions'; parts.annotation.permissions = 'new permissions';
fakeDrafts.get = sinon.stub().returns({ fakeDrafts.get = sinon.stub().returns({
text: 'old-draft' text: 'old-draft'
}); });
fakeDrafts.update = sinon.stub(); fakeDrafts.update = sinon.stub();
$rootScope.$broadcast(events.GROUP_FOCUSED); $rootScope.$broadcast(events.GROUP_FOCUSED);
assert.calledWith(fakeDrafts.update, parts.annotation, { assert.calledWith(fakeDrafts.update, parts.annotation, {
text: 'unsaved-text', text: 'unsaved-text',
tags: [], tags: [],
...@@ -1534,7 +1536,7 @@ describe('annotation.js', function() { ...@@ -1534,7 +1536,7 @@ describe('annotation.js', function() {
annotation.permissions = {read: [annotation.group]}; annotation.permissions = {read: [annotation.group]};
// This is a shared annotation. // This is a shared annotation.
fakePermissions.isShared.returns(true); fakePermissions.isShared.returns(true);
var controller = createDirective(annotation).controller; createDirective(annotation);
// Make permissions.shared() behave like we expect it to. // Make permissions.shared() behave like we expect it to.
fakePermissions.shared = function(groupId) { fakePermissions.shared = function(groupId) {
return { return {
...@@ -1546,11 +1548,7 @@ describe('annotation.js', function() { ...@@ -1546,11 +1548,7 @@ describe('annotation.js', function() {
fakeGroups.focused = sinon.stub().returns({id: 'new-group'}); fakeGroups.focused = sinon.stub().returns({id: 'new-group'});
$rootScope.$broadcast(events.GROUP_FOCUSED); $rootScope.$broadcast(events.GROUP_FOCUSED);
assert.deepEqual( assert.deepEqual(annotation.permissions.read, ['new-group']);
controller.annotation.permissions.read,
['new-group'],
'It should update the read permissions in the view model when ' +
'the focused group changes');
} }
); );
...@@ -1570,16 +1568,12 @@ describe('annotation.js', function() { ...@@ -1570,16 +1568,12 @@ describe('annotation.js', function() {
// AnnotationController won't try to update the draft for the annotation. // AnnotationController won't try to update the draft for the annotation.
fakeDrafts.get.returns(true); fakeDrafts.get.returns(true);
// Make permissions.shared() behave like we expect it to. // Make permissions.shared() behave like we expect it to.
fakePermissions.shared = function(groupId) { fakePermissions.shared = function(groupId) {return {read: [groupId]};};
return {
read: [groupId]
};
};
// Change the focused group. // Change the focused group.
fakeGroups.focused = sinon.stub().returns({ fakeGroups.focused = sinon.stub().returns({id: 'new-group'});
id: 'new-group'
});
$rootScope.$broadcast(events.GROUP_FOCUSED); $rootScope.$broadcast(events.GROUP_FOCUSED);
assert.deepEqual( assert.deepEqual(
fakeDrafts.update.lastCall.args[1].permissions.read, fakeDrafts.update.lastCall.args[1].permissions.read,
['new-group'], ['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