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
b1989cf8
Commit
b1989cf8
authored
Apr 04, 2016
by
Robert Knight
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3142 from hypothesis/csp-violation-admin-confirm-users-delete
CSP violation: admin confirm users delete
parents
e7e47d79
fb3b1586
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
0 deletions
+86
-0
admin-site.js
h/static/scripts/admin-site.js
+20
-0
admin-users.js
h/static/scripts/admin-users.js
+19
-0
admin-users-test.js
h/static/scripts/test/admin-users-test.js
+47
-0
No files found.
h/static/scripts/admin-site.js
View file @
b1989cf8
'use strict'
;
// configure error reporting
var
settings
=
require
(
'./settings'
)(
document
);
if
(
settings
.
raven
)
{
require
(
'./raven'
).
init
(
settings
.
raven
);
}
window
.
$
=
window
.
jQuery
=
require
(
'jquery'
);
require
(
'bootstrap'
);
var
page
=
require
(
'page'
);
var
AdminUsersController
=
require
(
'./admin-users'
);
page
(
'/admin/users'
,
function
()
{
new
AdminUsersController
(
document
.
body
,
window
);
});
document
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
page
.
start
();
});
h/static/scripts/admin-users.js
0 → 100644
View file @
b1989cf8
'use strict'
;
function
AdminUsersController
(
element
,
window_
)
{
this
.
_form
=
element
.
querySelector
(
'#js-users-delete-form'
);
function
confirmFormSubmit
()
{
return
window_
.
confirm
(
'This will permanently delete all the user
\'
s data. Are you sure?'
);
}
if
(
this
.
_form
)
{
this
.
_form
.
addEventListener
(
'submit'
,
function
(
event
)
{
if
(
!
confirmFormSubmit
())
{
event
.
preventDefault
();
}
});
}
}
module
.
exports
=
AdminUsersController
;
h/static/scripts/test/admin-users-test.js
0 → 100644
View file @
b1989cf8
'use strict'
;
var
AdminUsersController
=
require
(
'../admin-users'
);
// helper to dispatch a native event to an element
function
sendEvent
(
element
,
eventType
)
{
// createEvent() used instead of Event constructor
// for PhantomJS compatibility
var
event
=
document
.
createEvent
(
'Event'
);
event
.
initEvent
(
eventType
,
true
/* bubbles */
,
true
/* cancelable */
);
element
.
dispatchEvent
(
event
);
return
event
;
}
describe
(
'AdminUsersController'
,
function
()
{
var
root
;
var
form
;
beforeEach
(
function
()
{
root
=
document
.
createElement
(
'div'
);
root
.
innerHTML
=
'<form id="js-users-delete-form">'
+
'<input type="submit" id="submit-btn">'
;
form
=
root
.
querySelector
(
'form'
);
document
.
body
.
appendChild
(
root
);
});
afterEach
(
function
()
{
root
.
parentNode
.
removeChild
(
root
);
});
it
(
'it submits the form when confirm returns true'
,
function
()
{
var
fakeWindow
=
{
confirm
:
sinon
.
stub
().
returns
(
true
)};
new
AdminUsersController
(
root
,
fakeWindow
);
var
event
=
sendEvent
(
form
,
'submit'
);
assert
.
isFalse
(
event
.
defaultPrevented
);
});
it
(
'it cancels the form submission when confirm returns false'
,
function
()
{
var
fakeWindow
=
{
confirm
:
sinon
.
stub
().
returns
(
false
)};
new
AdminUsersController
(
root
,
fakeWindow
);
var
event
=
sendEvent
(
form
,
'submit'
);
assert
.
isTrue
(
event
.
defaultPrevented
);
});
});
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