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
b040f21f
Commit
b040f21f
authored
Dec 12, 2014
by
Gergely Ujvari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify auth service
parent
9e4a3a45
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
86 deletions
+26
-86
controllers.coffee
h/static/scripts/controllers.coffee
+10
-26
auth.coffee
h/static/scripts/services/auth.coffee
+10
-60
controllers-test.coffee
tests/js/controllers-test.coffee
+6
-0
No files found.
h/static/scripts/controllers.coffee
View file @
b040f21f
...
...
@@ -11,6 +11,9 @@ class AppController
)
->
{
plugins
,
host
,
providers
}
=
annotator
$scope
.
auth
=
auth
isFirstRun
=
$location
.
search
().
hasOwnProperty
(
'firstrun'
)
applyUpdates
=
(
action
,
data
)
->
"""Update the application with new data from the websocket."""
return
unless
data
?
.
length
...
...
@@ -103,24 +106,6 @@ class AppController
annotator
.
deleteAnnotation
first
$timeout
->
cleanup
rest
onlogin
=
(
assertion
)
->
user
.
login
assertion
,
reset
onlogout
=
->
user
.
logout
()
reset
()
onready
=
->
persona
=
user
.
getPersona
()
if
not
user
.
checkingInProgress
()
and
typeof
persona
==
'undefined'
# If we're not checking the token and persona is undefined, onlogin
# hasn't run, which means we aren't authenticated.
user
.
noPersona
()
reset
()
if
isFirstRun
$scope
.
login
()
oncancel
=
->
$scope
.
dialog
.
visible
=
false
...
...
@@ -154,7 +139,7 @@ class AppController
$scope
.
sort
=
{
name
,
predicate
}
$scope
.
$watch
'store.entities'
,
(
entities
,
oldEntities
)
->
return
if
entities
is
oldEntities
or
not
entities
return
if
entities
is
oldEntities
if
entities
.
length
streamfilter
...
...
@@ -163,14 +148,18 @@ class AppController
streamer
.
send
({
filter
:
streamfilter
.
getFilter
()})
$scope
.
$watch
'auth.user'
,
(
newVal
,
oldVal
)
->
reset
()
if
newVal
isnt
undefined
$scope
.
login
()
if
isFirstRun
and
newVal
is
null
and
oldVal
is
undefined
$scope
.
login
=
->
$scope
.
dialog
.
visible
=
true
auth
.
login
().
then
(
reset
,
oncancel
)
identity
.
request
(
oncancel
)
$scope
.
logout
=
->
return
unless
drafts
.
discard
()
$scope
.
dialog
.
visible
=
false
auth
.
logout
().
then
(
reset
)
identity
.
logout
(
)
$scope
.
loadMore
=
(
number
)
->
unless
streamfilter
.
getPastData
().
hits
then
return
...
...
@@ -199,11 +188,6 @@ class AppController
$scope
.
sort
=
name
:
'Location'
$scope
.
threading
=
plugins
.
Threading
auth
.
getInitialUser
().
then
(
reset
,
->
reset
()
$scope
.
login
()
)
class
AnnotationViewerController
this
.
$inject
=
[
...
...
h/static/scripts/services/auth.coffee
View file @
b040f21f
LOGIN_REQUEST
=
'login'
LOGOUT_REQUEST
=
'logout'
INITIAL_REQUEST
=
'initial'
pendingRequests
=
login
:
[]
logout
:
[]
initial
:
[]
resolvePendingRequests
=
(
requestType
,
user
)
->
for
request
in
pendingRequests
[
requestType
]
request
.
resolve
user
if
request
.
resolve
?
pendingRequests
[
requestType
]
=
[]
rejectPendingRequests
=
(
requestType
,
reason
)
->
for
request
in
pendingRequests
[
requestType
]
request
.
reject
reason
if
request
.
reject
?
pendingRequests
[
requestType
]
=
[]
class
Auth
_checkingToken
:
false
login
:
null
logout
:
null
getInitialUser
:
null
user
:
null
user
:
undefined
this
.
$inject
=
[
'$location'
,
'$
q
'
,
this
.
$inject
=
[
'$location'
,
'$
rootScope
'
,
'annotator'
,
'documentHelpers'
,
'identity'
]
constructor
:
(
$location
,
$
q
,
constructor
:
(
$location
,
$
rootScope
,
annotator
,
documentHelpers
,
identity
)
->
{
plugins
}
=
annotator
@
login
=
->
oncancel
=
->
rejectPendingRequests
LOGIN_REQUEST
,
null
deferred
=
$q
.
defer
()
pendingRequests
[
LOGIN_REQUEST
].
push
deferred
identity
.
request
({
oncancel
})
deferred
.
promise
@
logout
=
->
deferred
=
$q
.
defer
()
identity
.
logout
()
pendingRequests
[
LOGOUT_REQUEST
].
push
deferred
deferred
.
promise
@
getInitialUser
=
->
deferred
=
$q
.
defer
()
pendingRequests
[
INITIAL_REQUEST
].
push
deferred
deferred
.
promise
_checkingToken
=
false
onlogin
=
(
assertion
)
=>
@
_checkingToken
=
true
_checkingToken
=
true
# Configure the Auth plugin with the issued assertion as refresh token.
annotator
.
addPlugin
'Auth'
,
...
...
@@ -65,13 +18,12 @@ class Auth
# Set the user from the token.
plugins
.
Auth
.
withToken
(
token
)
=>
@
_checkingToken
=
false
_checkingToken
=
false
annotator
.
addPlugin
'Permissions'
,
user
:
token
.
userId
userAuthorize
:
@
permits
@
user
=
token
.
userId
resolvePendingRequests
INITIAL_REQUEST
,
@
user
resolvePendingRequests
LOGIN_REQUEST
,
@
user
$rootScope
.
$apply
()
onlogout
=
=>
plugins
.
Auth
?
.
element
.
removeData
(
'annotator:headers'
)
...
...
@@ -83,13 +35,11 @@ class Auth
delete
plugins
.
Permissions
@
user
=
null
@
_checkingToken
=
false
resolvePendingRequests
LOGOUT_REQUEST
,
@
user
_checkingToken
=
false
onready
=
=>
if
not
@
_checkingToken
rejectPendingRequests
INITIAL_REQUEST
,
null
if
@
user
is
undefined
and
not
_checkingToken
@
user
=
null
identity
.
watch
{
onlogin
,
onlogout
,
onready
}
...
...
tests/js/controllers-test.coffee
View file @
b040f21f
...
...
@@ -7,6 +7,7 @@ describe 'h', ->
fakeLocation
=
null
fakeParams
=
null
fakeStreamer
=
null
fakeIdentity
=
null
sandbox
=
null
beforeEach
module
(
'h'
)
...
...
@@ -21,6 +22,11 @@ describe 'h', ->
resolve
()
}
fakeIdentity
=
{
watch
:
sandbox
.
spy
()
request
:
sandbox
.
spy
()
}
fakeAnnotator
=
{
plugins
:
{
Auth
:
{
withToken
:
sandbox
.
spy
()}
...
...
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