Skip to content

Commit

Permalink
Merge pull request #3093 from hypothesis/t256-permission-warning
Browse files Browse the repository at this point in the history
Display message if a direct-linked annotation is not available
  • Loading branch information
nickstenning committed Mar 22, 2016
2 parents cbe897a + 3e49cb2 commit c6f6faa
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
13 changes: 13 additions & 0 deletions h/static/images/icons/lock.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion h/static/scripts/test/widget-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ describe('WidgetController', function () {
clearSelectedAnnotations: sandbox.spy(),
selectedAnnotationMap: {},
hasSelectedAnnotations: function () {
return Object.keys(this.selectedAnnotationMap).length > 0;
return !!this.selectedAnnotationMap &&
Object.keys(this.selectedAnnotationMap).length > 0;
},
};
fakeCrossFrame = {
Expand Down Expand Up @@ -286,4 +287,26 @@ describe('WidgetController', function () {
assert.notCalled($scope.clearSelection);
});
});

describe('direct linking messages', function () {
it('displays a message if the selection is unavailable', function () {
fakeAnnotationUI.selectedAnnotationMap = {'missing': true};
fakeThreading.idTable = {'123': {}};
$scope.$digest();
assert.isTrue($scope.selectedAnnotationUnavailable());
});

it('does not show a message if the selection is available', function () {
fakeAnnotationUI.selectedAnnotationMap = {'123': true};
fakeThreading.idTable = {'123': {}};
$scope.$digest();
assert.isFalse($scope.selectedAnnotationUnavailable());
});

it('does not a show a message if there is no selection', function () {
fakeAnnotationUI.selectedAnnotationMap = null;
$scope.$digest();
assert.isFalse($scope.selectedAnnotationUnavailable());
});
});
});
18 changes: 17 additions & 1 deletion h/static/scripts/widget-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
var events = require('./events');
var SearchClient = require('./search-client');

function firstKey(object) {
for (var k in object) {
if (!object.hasOwnProperty(k)) {
continue;
}
return k;
}
return null;
}

/**
* Returns the group ID of the first annotation in `results` whose
* ID is a key in `selection`.
*/
function groupIDFromSelection(selection, results) {
var id = Object.keys(selection)[0];
var id = firstKey(selection);
var annot = results.find(function (annot) {
return annot.id === id;
});
Expand Down Expand Up @@ -193,6 +203,12 @@ module.exports = function WidgetController(
return annotation.$$tag in $scope.focusedAnnotations;
};

$scope.selectedAnnotationUnavailable = function () {
return searchClients.length === 0 &&
annotationUI.hasSelectedAnnotations() &&
!threading.idTable[firstKey(annotationUI.selectedAnnotationMap)];
};

$rootScope.$on(events.BEFORE_ANNOTATION_CREATED, function (event, data) {
if (data.$highlight || (data.references && data.references.length > 0)) {
return;
Expand Down
23 changes: 23 additions & 0 deletions h/static/styles/thread.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ $thread-padding: $annotation-card-left-padding;
}
}

.annotation-unavailable-message {
display: flex;
flex-direction: column;
border: 1px solid $gray-lighter;
padding-top: 30px;
padding-bottom: 30px;
border-radius: 3px;
align-items: center;

&__label {
margin-top: 10px;
max-width: 160px;
text-align: center;
}

&__icon {
background-image: url(../images/icons/lock.svg);
background-repeat: no-repeat;
width: 56px;
height: 48px;
}
}

.thread-replies .thread:first-child {
margin-top: 0.5em;
}
Expand Down
7 changes: 7 additions & 0 deletions h/templates/client/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
on-change-sort-by="sort.name = sortBy">
</sort-dropdown>
</li>
<li class="annotation-unavailable-message"
ng-if="selectedAnnotationUnavailable()">
<div class="annotation-unavailable-message__icon"></div>
<p class="annotation-unavailable-message__label">
You do not have permission to see this annotation
</p>
</li>
<li id="{{vm.id}}"
class="annotation-card thread"
ng-class="{'js-hover': hasFocus(child.message)}"
Expand Down

0 comments on commit c6f6faa

Please sign in to comment.