Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
1dd1dbca
Commit
1dd1dbca
authored
Feb 14, 2020
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow creation of anonymous annotations and highlights
parent
b64ac1f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
15 deletions
+75
-15
frame-sync.js
src/sidebar/services/frame-sync.js
+12
-2
frame-sync-test.js
src/sidebar/services/test/frame-sync-test.js
+63
-13
No files found.
src/sidebar/services/frame-sync.js
View file @
1dd1dbca
...
...
@@ -40,7 +40,7 @@ export function formatAnnot(ann) {
* sidebar.
*/
// @ngInject
export
default
function
FrameSync
(
$rootScope
,
$window
,
store
,
bridge
)
{
export
default
function
FrameSync
(
$rootScope
,
$window
,
flash
,
store
,
bridge
)
{
// Set of tags of annotations that are currently loaded into the frame
const
inFrame
=
new
Set
();
...
...
@@ -128,8 +128,18 @@ export default function FrameSync($rootScope, $window, store, bridge) {
function
setupSyncFromFrame
()
{
// A new annotation, note or highlight was created in the frame
bridge
.
on
(
'beforeCreateAnnotation'
,
function
(
event
)
{
inFrame
.
add
(
event
.
tag
);
const
annot
=
Object
.
assign
({},
event
.
msg
,
{
$tag
:
event
.
tag
});
// If user is not logged in, we can't really create a meaningful highlight
// or annotation. Instead, we need to open the sidebar, show an error,
// and delete the (unsaved) annotation so it gets un-selected in the
// target document
if
(
!
store
.
isLoggedIn
())
{
bridge
.
call
(
'showSidebar'
);
flash
.
error
(
'Please log in to create annotations or highlights'
);
bridge
.
call
(
'deleteAnnotation'
,
formatAnnot
(
annot
));
return
;
}
inFrame
.
add
(
event
.
tag
);
$rootScope
.
$broadcast
(
events
.
BEFORE_ANNOTATION_CREATED
,
annot
);
});
...
...
src/sidebar/services/test/frame-sync-test.js
View file @
1dd1dbca
...
...
@@ -50,6 +50,7 @@ const fixtures = {
describe
(
'sidebar.frame-sync'
,
function
()
{
let
fakeStore
;
let
fakeBridge
;
let
fakeFlash
;
let
frameSync
;
let
$rootScope
;
...
...
@@ -58,6 +59,10 @@ describe('sidebar.frame-sync', function() {
});
beforeEach
(
function
()
{
fakeFlash
=
{
error
:
sinon
.
stub
(),
};
fakeStore
=
createFakeStore
(
{
annotations
:
[]
},
{
...
...
@@ -66,6 +71,7 @@ describe('sidebar.frame-sync', function() {
findIDsForTags
:
sinon
.
stub
(),
focusAnnotations
:
sinon
.
stub
(),
frames
:
sinon
.
stub
().
returns
([
fixtures
.
framesListEntry
]),
isLoggedIn
:
sinon
.
stub
().
returns
(
false
),
selectAnnotations
:
sinon
.
stub
(),
selectTab
:
sinon
.
stub
(),
toggleSelectedAnnotations
:
sinon
.
stub
(),
...
...
@@ -90,6 +96,7 @@ describe('sidebar.frame-sync', function() {
}
angular
.
mock
.
module
(
'app'
,
{
flash
:
fakeFlash
,
store
:
fakeStore
,
bridge
:
fakeBridge
,
});
...
...
@@ -211,21 +218,64 @@ describe('sidebar.frame-sync', function() {
});
context
(
'when a new annotation is created in the frame'
,
function
()
{
it
(
'emits a BEFORE_ANNOTATION_CREATED event'
,
function
()
{
const
onCreated
=
sinon
.
stub
();
const
ann
=
{
target
:
[]
};
$rootScope
.
$on
(
events
.
BEFORE_ANNOTATION_CREATED
,
onCreated
);
context
(
'when an authenticated user is present'
,
()
=>
{
it
(
'emits a BEFORE_ANNOTATION_CREATED event'
,
function
()
{
fakeStore
.
isLoggedIn
.
returns
(
true
);
const
onCreated
=
sinon
.
stub
();
const
ann
=
{
target
:
[]
};
$rootScope
.
$on
(
events
.
BEFORE_ANNOTATION_CREATED
,
onCreated
);
fakeBridge
.
emit
(
'beforeCreateAnnotation'
,
{
tag
:
't1'
,
msg
:
ann
});
assert
.
calledWithMatch
(
onCreated
,
sinon
.
match
.
any
,
sinon
.
match
({
$tag
:
't1'
,
target
:
[],
})
);
});
});
context
(
'when no authenticated user is present'
,
()
=>
{
beforeEach
(()
=>
{
fakeStore
.
isLoggedIn
.
returns
(
false
);
});
fakeBridge
.
emit
(
'beforeCreateAnnotation'
,
{
tag
:
't1'
,
msg
:
ann
});
it
(
'should not emit BEFORE_ANNOTATION_CREATED event'
,
()
=>
{
const
onCreated
=
sinon
.
stub
();
const
ann
=
{
target
:
[]
};
$rootScope
.
$on
(
events
.
BEFORE_ANNOTATION_CREATED
,
onCreated
);
assert
.
calledWithMatch
(
onCreated
,
sinon
.
match
.
any
,
sinon
.
match
({
$tag
:
't1'
,
target
:
[],
})
);
fakeBridge
.
emit
(
'beforeCreateAnnotation'
,
{
tag
:
't1'
,
msg
:
ann
});
assert
.
notCalled
(
onCreated
);
});
it
(
'should open the sidebar'
,
()
=>
{
const
ann
=
{
target
:
[]
};
fakeBridge
.
emit
(
'beforeCreateAnnotation'
,
{
tag
:
't1'
,
msg
:
ann
});
assert
.
calledWith
(
fakeBridge
.
call
,
'showSidebar'
);
});
it
(
'should flash an error message'
,
()
=>
{
const
ann
=
{
target
:
[]
};
fakeBridge
.
emit
(
'beforeCreateAnnotation'
,
{
tag
:
't1'
,
msg
:
ann
});
assert
.
calledWith
(
fakeFlash
.
error
,
'Please log in to create annotations or highlights'
);
});
it
(
'should send a "deleteAnnotation" message to the frame'
,
()
=>
{
const
ann
=
{
target
:
[]
};
fakeBridge
.
emit
(
'beforeCreateAnnotation'
,
{
tag
:
't1'
,
msg
:
ann
});
assert
.
calledWith
(
fakeBridge
.
call
,
'deleteAnnotation'
);
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment