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
9a12984b
Commit
9a12984b
authored
Aug 05, 2014
by
Aron Carroll
Committed by
Randall Leeds
Aug 21, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log the user out after disabling the account
parent
75a58033
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
12 deletions
+20
-12
account-management.coffee
h/static/scripts/controllers/account-management.coffee
+11
-7
account-management-test.coffee
tests/js/controllers/account-management-test.coffee
+9
-5
No files found.
h/static/scripts/controllers/account-management.coffee
View file @
9a12984b
class
AccountManagement
class
AccountManagement
@
inject
=
[
'$scope'
,
'$rootScope'
,
'$filter'
,
'flash'
,
'profile'
,
'util'
]
@
inject
=
[
'$scope'
,
'$rootScope'
,
'$filter'
,
'flash'
,
'profile'
,
'
identity'
,
'
util'
]
constructor
:
(
$scope
,
$rootScope
,
$filter
,
flash
,
profile
,
util
)
->
constructor
:
(
$scope
,
$rootScope
,
$filter
,
flash
,
profile
,
identity
,
util
)
->
persona_filter
=
$filter
(
'persona'
)
persona_filter
=
$filter
(
'persona'
)
onSuccess
=
(
response
)
->
onSuccess
=
(
response
)
->
...
@@ -9,31 +9,35 @@ class AccountManagement
...
@@ -9,31 +9,35 @@ class AccountManagement
for
type
,
msgs
of
response
.
flash
for
type
,
msgs
of
response
.
flash
flash
(
type
,
msgs
)
flash
(
type
,
msgs
)
onDelete
=
(
response
)
->
identity
.
logout
()
onSuccess
(
response
)
onError
=
(
form
,
data
)
->
onError
=
(
form
,
data
)
->
if
400
>=
data
.
status
<
500
if
400
>=
data
.
status
<
500
util
.
applyValidationErrors
(
form
,
data
.
errors
)
util
.
applyValidationErrors
(
form
,
data
.
errors
)
else
else
flash
(
'error'
,
'Sorry, we were unable to perform your request'
)
flash
(
'error'
,
'Sorry, we were unable to perform your request'
)
$scope
.
delete
Account
=
(
form
)
->
$scope
.
delete
=
(
form
)
->
# If the password is correct, the account is deleted.
# If the password is correct, the account is deleted.
# The extension is then removed from the page.
# The extension is then removed from the page.
# Confirmation of success is given.
# Confirmation of success is given.
return
unless
form
.
$valid
return
unless
form
.
$valid
username
=
persona_filter
$scope
.
session
.
persona
username
=
persona_filter
$scope
.
session
.
userid
packet
=
packet
=
username
:
username
username
:
username
pwd
:
form
.
deleteaccountpassword
.
$modelValue
pwd
:
form
.
deleteaccountpassword
.
$modelValue
promise
=
profile
.
disable_user
(
packet
)
promise
=
profile
.
disable_user
(
packet
)
promise
.
$promise
.
then
(
on
Success
,
angular
.
bind
(
null
,
onError
,
form
))
promise
.
$promise
.
then
(
on
Delete
,
angular
.
bind
(
null
,
onError
,
form
))
$scope
.
submit
=
(
form
)
->
$scope
.
submit
=
(
form
)
->
# In the frontend change_email and change_password are two different
# In the frontend change_email and change_password are two different
# forms. However, in the backend it is just one: edit_profile
# forms. However, in the backend it is just one: edit_profile
return
unless
form
.
$valid
return
unless
form
.
$valid
username
=
persona_filter
$scope
.
session
.
persona
username
=
persona_filter
$scope
.
session
.
userid
if
form
.
$name
is
'editProfile'
if
form
.
$name
is
'editProfile'
packet
=
packet
=
username
:
username
username
:
username
...
@@ -49,7 +53,7 @@ class AccountManagement
...
@@ -49,7 +53,7 @@ class AccountManagement
promise
.
$promise
.
then
(
onSuccess
,
angular
.
bind
(
null
,
onError
,
form
))
promise
.
$promise
.
then
(
onSuccess
,
angular
.
bind
(
null
,
onError
,
form
))
$rootScope
.
$on
'nav:account'
,
->
$rootScope
.
$on
'nav:account'
,
->
$scope
.
sheet
=
true
$scope
.
$apply
->
$scope
.
sheet
=
true
$rootScope
.
$on
'logout'
,
->
$rootScope
.
$on
'logout'
,
->
$scope
.
sheet
=
false
$scope
.
sheet
=
false
...
...
tests/js/controllers/account-management-test.coffee
View file @
9a12984b
...
@@ -7,6 +7,7 @@ describe 'h.controllers.AccountManagement', ->
...
@@ -7,6 +7,7 @@ describe 'h.controllers.AccountManagement', ->
fakeUtil
=
null
fakeUtil
=
null
fakeFlash
=
null
fakeFlash
=
null
fakeProfile
=
null
fakeProfile
=
null
fakeIdentity
=
null
editProfilePromise
=
null
editProfilePromise
=
null
disableUserPromise
=
null
disableUserPromise
=
null
createController
=
null
createController
=
null
...
@@ -14,6 +15,8 @@ describe 'h.controllers.AccountManagement', ->
...
@@ -14,6 +15,8 @@ describe 'h.controllers.AccountManagement', ->
beforeEach
module
(
$provide
,
$filterProvider
)
->
beforeEach
module
(
$provide
,
$filterProvider
)
->
fakeProfile
=
{}
fakeProfile
=
{}
fakeFlash
=
sandbox
.
spy
()
fakeFlash
=
sandbox
.
spy
()
fakeIdentity
=
logout
:
sandbox
.
spy
()
fakeUtil
=
fakeUtil
=
applyValidationErrors
:
sandbox
.
spy
()
applyValidationErrors
:
sandbox
.
spy
()
...
@@ -22,6 +25,7 @@ describe 'h.controllers.AccountManagement', ->
...
@@ -22,6 +25,7 @@ describe 'h.controllers.AccountManagement', ->
$provide
.
value
'profile'
,
fakeProfile
$provide
.
value
'profile'
,
fakeProfile
$provide
.
value
'flash'
,
fakeFlash
$provide
.
value
'flash'
,
fakeFlash
$provide
.
value
'identity'
,
fakeIdentity
$provide
.
value
'util'
,
fakeUtil
$provide
.
value
'util'
,
fakeUtil
return
return
...
@@ -29,7 +33,7 @@ describe 'h.controllers.AccountManagement', ->
...
@@ -29,7 +33,7 @@ describe 'h.controllers.AccountManagement', ->
beforeEach
inject
(
$rootScope
,
$q
,
$controller
)
->
beforeEach
inject
(
$rootScope
,
$q
,
$controller
)
->
$scope
=
$rootScope
.
$new
()
$scope
=
$rootScope
.
$new
()
$scope
.
session
=
persona
:
'egon@columbia.edu'
$scope
.
session
=
userid
:
'egon@columbia.edu'
disableUserPromise
=
{
then
:
sandbox
.
stub
()}
disableUserPromise
=
{
then
:
sandbox
.
stub
()}
editProfilePromise
=
{
then
:
sandbox
.
stub
()}
editProfilePromise
=
{
then
:
sandbox
.
stub
()}
...
@@ -127,7 +131,7 @@ describe 'h.controllers.AccountManagement', ->
...
@@ -127,7 +131,7 @@ describe 'h.controllers.AccountManagement', ->
assert
.
calledWith
(
fakeFlash
,
'error'
)
assert
.
calledWith
(
fakeFlash
,
'error'
)
describe
'.delete
Account
'
,
->
describe
'.delete'
,
->
it
'disables the user account'
,
->
it
'disables the user account'
,
->
fakeForm
=
fakeForm
=
$name
:
'deleteAccount'
$name
:
'deleteAccount'
...
@@ -135,7 +139,7 @@ describe 'h.controllers.AccountManagement', ->
...
@@ -135,7 +139,7 @@ describe 'h.controllers.AccountManagement', ->
deleteaccountpassword
:
$modelValue
:
'paranormal'
deleteaccountpassword
:
$modelValue
:
'paranormal'
controller
=
createController
()
controller
=
createController
()
$scope
.
delete
Account
(
fakeForm
)
$scope
.
delete
(
fakeForm
)
assert
.
calledWith
fakeProfile
.
disable_user
,
assert
.
calledWith
fakeProfile
.
disable_user
,
username
:
'STUBBED_PERSONA_FILTER'
username
:
'STUBBED_PERSONA_FILTER'
...
@@ -150,7 +154,7 @@ describe 'h.controllers.AccountManagement', ->
...
@@ -150,7 +154,7 @@ describe 'h.controllers.AccountManagement', ->
deleteaccountpassword
:
$modelValue
:
'paranormal'
deleteaccountpassword
:
$modelValue
:
'paranormal'
controller
=
createController
()
controller
=
createController
()
$scope
.
delete
Account
(
fakeForm
)
$scope
.
delete
(
fakeForm
)
# Resolve the request.
# Resolve the request.
disableUserPromise
.
then
.
callArg
1
,
disableUserPromise
.
then
.
callArg
1
,
...
@@ -168,7 +172,7 @@ describe 'h.controllers.AccountManagement', ->
...
@@ -168,7 +172,7 @@ describe 'h.controllers.AccountManagement', ->
deleteaccountpassword
:
$modelValue
:
'paranormal'
deleteaccountpassword
:
$modelValue
:
'paranormal'
controller
=
createController
()
controller
=
createController
()
$scope
.
delete
Account
(
fakeForm
)
$scope
.
delete
(
fakeForm
)
# Resolve the request.
# Resolve the request.
disableUserPromise
.
then
.
callArg
1
,
disableUserPromise
.
then
.
callArg
1
,
...
...
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