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
d53580a5
Commit
d53580a5
authored
Oct 29, 2015
by
Sean Hammond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the USER_CHANGED event
parent
034ef9e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
6 deletions
+43
-6
annotation.coffee
h/static/scripts/directive/annotation.coffee
+7
-5
annotation-test.coffee
h/static/scripts/directive/test/annotation-test.coffee
+36
-1
No files found.
h/static/scripts/directive/annotation.coffee
View file @
d53580a5
### global -validate ###
### global -validate ###
events
=
require
(
'../events'
)
# Validate an annotation.
# Validate an annotation.
# Annotations must be attributed to a user or marked as deleted.
# Annotations must be attributed to a user or marked as deleted.
# A public annotation is valid only if they have a body.
# A public annotation is valid only if they have a body.
...
@@ -59,6 +61,8 @@ AnnotationController = [
...
@@ -59,6 +61,8 @@ AnnotationController = [
model = $scope.annotationGet()
model = $scope.annotationGet()
model.user ?= session.state.userid
# Set the group of new annotations.
# Set the group of new annotations.
if not model.group
if not model.group
model.group = groups.focused().id
model.group = groups.focused().id
...
@@ -374,17 +378,15 @@ AnnotationController = [
...
@@ -374,17 +378,15 @@ AnnotationController = [
this.render()
this.render()
, true
, true
# Watch the current user
$scope.$on(events.USER_CHANGED, ->
# TODO: fire events instead since watchers are not free and auth is rare
model.user ?= session.state.userid
$scope.$watch (-> session.state.userid), (userid) ->
model.user ?= userid
# Set model.permissions on sign in, if it isn't already set.
# Set model.permissions on sign in, if it isn't already set.
# This is because you can create annotations when signed out and they
# This is because you can create annotations when signed out and they
# will have model.permissions = null, then when you sign in we set the
# will have model.permissions = null, then when you sign in we set the
# permissions correctly here.
# permissions correctly here.
model.permissions = model.permissions or permissions.default(model.group)
model.permissions = model.permissions or permissions.default(model.group)
)
# Start editing brand new annotations immediately
# Start editing brand new annotations immediately
unless model.id? or (this.isHighlight() and highlight) then this.edit()
unless model.id? or (this.isHighlight() and highlight) then this.edit()
...
...
h/static/scripts/directive/test/annotation-test.coffee
View file @
d53580a5
{
module
,
inject
}
=
angular
.
mock
{
module
,
inject
}
=
angular
.
mock
events
=
require
(
'../../events'
)
describe
'annotation'
,
->
describe
'annotation'
,
->
$compile
=
null
$compile
=
null
$document
=
null
$document
=
null
...
@@ -148,6 +150,7 @@ describe 'annotation', ->
...
@@ -148,6 +150,7 @@ describe 'annotation', ->
$scope
.
$digest
()
$scope
.
$digest
()
assert
.
notCalled
annotation
.
$create
assert
.
notCalled
annotation
.
$create
fakeSession
.
state
.
userid
=
'acct:ted@wyldstallyns.com'
fakeSession
.
state
.
userid
=
'acct:ted@wyldstallyns.com'
$scope
.
$broadcast
(
events
.
USER_CHANGED
,
{})
$scope
.
$digest
()
$scope
.
$digest
()
assert
.
calledOnce
annotation
.
$create
assert
.
calledOnce
annotation
.
$create
...
@@ -645,6 +648,14 @@ describe("AnnotationController", ->
...
@@ -645,6 +648,14 @@ describe("AnnotationController", ->
)
)
)
)
it
(
"sets the user of new annotations"
,
->
annotation
=
{}
{
session
}
=
createAnnotationDirective
({
annotation
:
annotation
})
assert
.
equal
(
annotation
.
user
,
session
.
state
.
userid
)
)
it
(
"sets the permissions of new annotations"
,
->
it
(
"sets the permissions of new annotations"
,
->
# This is a new annotation, doesn't have any permissions yet.
# This is a new annotation, doesn't have any permissions yet.
annotation
=
{
group
:
"test-group"
}
annotation
=
{
group
:
"test-group"
}
...
@@ -720,6 +731,29 @@ describe("AnnotationController", ->
...
@@ -720,6 +731,29 @@ describe("AnnotationController", ->
)
)
describe
(
"when the user signs in"
,
->
describe
(
"when the user signs in"
,
->
it
(
"sets the user of unsaved annotations"
,
->
# This annotation has no user yet, because that's what happens
# when you create a new annotation while not signed in.
annotation
=
{}
session
=
{
state
:
{
userid
:
null
}}
# Not signed in.
{
$rootScope
}
=
createAnnotationDirective
(
{
annotation
:
annotation
,
session
:
session
})
# At this point we would not expect the user to have been set,
# even though the annotation has been created, because the user isn't
# signed in.
assert
(
!
annotation
.
user
)
# Sign the user in.
session
.
state
.
userid
=
"acct:fred@hypothes.is"
# The session service would broadcast USER_CHANGED after sign in.
$rootScope
.
$broadcast
(
events
.
USER_CHANGED
,
{})
assert
.
equal
(
annotation
.
user
,
session
.
state
.
userid
)
)
it
(
"sets the permissions of unsaved annotations"
,
->
it
(
"sets the permissions of unsaved annotations"
,
->
# This annotation has no permissions yet, because that's what happens
# This annotation has no permissions yet, because that's what happens
# when you create a new annotation while not signed in.
# when you create a new annotation while not signed in.
...
@@ -749,7 +783,8 @@ describe("AnnotationController", ->
...
@@ -749,7 +783,8 @@ describe("AnnotationController", ->
# is signed in.
# is signed in.
permissions
.
default
=
->
"__default_permissions__"
permissions
.
default
=
->
"__default_permissions__"
$rootScope
.
$digest
()
# Trigger the $scope.$watch().
# The session service would broadcast USER_CHANGED after sign in.
$rootScope
.
$broadcast
(
events
.
USER_CHANGED
,
{})
assert
.
equal
(
annotation
.
permissions
,
"__default_permissions__"
)
assert
.
equal
(
annotation
.
permissions
,
"__default_permissions__"
)
)
)
...
...
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